Kaydet (Commit) 9ab76447 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

LinkUpdateMode property values must be in the range 0--2 or 0--3

...avoid setting bad values from generic qadevOOo property set tests, and throw
an IllegalArgumentException if bad values do get set.  Found via
-fsanitize=enum.  The TODO about ScLkUpdMode vs. LinkUpdateModes mismatch looks
worrying.

Change-Id: Ibc01845e7e3179dc693fe8c59c1f1ffad5282420
üst a93db93c
...@@ -454,7 +454,7 @@ public class MultiPropertyTest extends MultiMethodTest ...@@ -454,7 +454,7 @@ public class MultiPropertyTest extends MultiMethodTest
protected Object getNewValue(String propName, Object oldValue) protected Object getNewValue(String propName, Object oldValue)
throws java.lang.IllegalArgumentException throws java.lang.IllegalArgumentException
{ {
return ValueChanger.changePValue(oldValue); return ValueChanger.changePValue(oldValue, propName);
} }
/** /**
......
...@@ -58,9 +58,15 @@ public class ValueChanger { ...@@ -58,9 +58,15 @@ public class ValueChanger {
newValue = Long.valueOf(oldlong + 15); newValue = Long.valueOf(oldlong + 15);
} else if (oldValue instanceof Short) { } else if (oldValue instanceof Short) {
short n = ((Short) oldValue).shortValue(); short n = ((Short) oldValue).shortValue();
// css.form.component.{CheckBox,RadioButton} DefaultState properties
// must have values in the range 0--2:
if ("DefaultState".equals(name) && n == 2) { if ("DefaultState".equals(name) && n == 2) {
// css.form.component.{CheckBox,RadioButton} DefaultState
// properties must have values in the range 0--2:
--n;
} else if ("LinkUpdateMode".equals(name) && n >= 2) {
// css.document.Settings LinkUpdateMode property must have
// values in the css.document.LinkUpdateModes range (0--3),
// while css.sheet.XGlobalSheetSettings LinkUpdateMode property
// must have values in the range 0--2:
--n; --n;
} else { } else {
++n; ++n;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "sc.hrc" #include "sc.hrc"
#include "unonames.hxx" #include "unonames.hxx"
#include "funcdesc.hxx" #include "funcdesc.hxx"
#include <com/sun/star/document/LinkUpdateModes.hpp>
#include <com/sun/star/sheet/FunctionArgument.hpp> #include <com/sun/star/sheet/FunctionArgument.hpp>
#include "ScPanelFactory.hxx" #include "ScPanelFactory.hxx"
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
...@@ -395,7 +396,19 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue( ...@@ -395,7 +396,19 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue(
} }
else if (aString == SC_UNONAME_LINKUPD) else if (aString == SC_UNONAME_LINKUPD)
{ {
aAppOpt.SetLinkMode( (ScLkUpdMode) ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); sal_Int16 n;
if (!(aValue >>= n) || n < css::document::LinkUpdateModes::NEVER
|| n > css::document::LinkUpdateModes::GLOBAL_SETTING)
{
throw css::lang::IllegalArgumentException(
("LinkUpdateMode property value must be a SHORT with a value in"
" the range of the css.document.LinkUpdateModes constants"),
css::uno::Reference<css::uno::XInterface>(), -1);
}
//TODO: ScLkUpdMode (LM_ALWAYS=0, LM_NEVER=1, LM_ON_DEMAND=2,
// LM_UNKNOWN=3) does not match css.document.LinkUpdateModes (NEVER=0,
// MANUAL=1, AUTO=2, GLOBAL_SETTINGS=3):
aAppOpt.SetLinkMode( static_cast<ScLkUpdMode>(n) );
bSaveApp = true; bSaveApp = true;
} }
else if (aString == SC_UNONAME_MARKHDR) else if (aString == SC_UNONAME_MARKHDR)
......
...@@ -156,7 +156,20 @@ void SAL_CALL ScDocumentConfiguration::setPropertyValue( ...@@ -156,7 +156,20 @@ void SAL_CALL ScDocumentConfiguration::setPropertyValue(
else if ( aPropertyName == SC_UNO_SHOWPAGEBR ) else if ( aPropertyName == SC_UNO_SHOWPAGEBR )
aViewOpt.SetOption(VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); aViewOpt.SetOption(VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
else if ( aPropertyName == SC_UNONAME_LINKUPD ) else if ( aPropertyName == SC_UNONAME_LINKUPD )
rDoc.SetLinkMode( static_cast<ScLkUpdMode> ( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ) ); {
sal_Int16 n;
//TODO: css.sheet.XGlobalSheetSettings LinkUpdateMode property is
// documented to take values in the range 0--2 (always, never, on
// demaned), but appears to be routinely set to 3 here,
// corresponding to ScLkUpdMode LM_UNKNOWN:
if (!(aValue >>= n) || n < 0 || n > 3) {
throw css::lang::IllegalArgumentException(
("LinkUpdateMode property value must be a SHORT in the"
" range 0--3"),
css::uno::Reference<css::uno::XInterface>(), -1);
}
rDoc.SetLinkMode( static_cast<ScLkUpdMode>(n) );
}
else if ( aPropertyName == SC_UNO_COLROWHDR ) else if ( aPropertyName == SC_UNO_COLROWHDR )
aViewOpt.SetOption(VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); aViewOpt.SetOption(VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
else if ( aPropertyName == SC_UNO_SHEETTABS ) else if ( aPropertyName == SC_UNO_SHEETTABS )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment