mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-12-13 06:33:02 +00:00
Test fixes
This commit is contained in:
parent
75ddd08bbd
commit
0eafe44445
@ -649,7 +649,6 @@ public class OptionsDialogTest extends AbstractGhidraHeadedIntegrationTest {
|
||||
|
||||
Options options = tool.getOptions(ToolConstants.TOOL_OPTIONS);
|
||||
|
||||
Color c = options.getColor("Favorite Color", Palette.RED);
|
||||
String currentValue = options.getString("Favorite String", null);
|
||||
assertEquals("Bar", currentValue);
|
||||
|
||||
|
@ -246,15 +246,21 @@ public class OptionsTest extends AbstractGenericTest {
|
||||
options.addOptionsChangeListener(listener1);
|
||||
options.addOptionsChangeListener(listener2);
|
||||
|
||||
options.setColor("COLOR", Palette.BLUE);
|
||||
try {
|
||||
options.setColor("COLOR", Palette.BLUE);
|
||||
fail("Expected an OptionsVetoExcepton");
|
||||
}
|
||||
catch (OptionsVetoException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
assertEquals(Palette.RED, options.getColor("COLOR", Palette.RED));
|
||||
|
||||
if (listener1.callOrder == 1) {
|
||||
if (listener1.callCount == 1) {
|
||||
assertEquals(Palette.RED, listener1.value);
|
||||
assertEquals(null, listener2.value);
|
||||
}
|
||||
if (listener2.callOrder == 1) {
|
||||
if (listener2.callCount == 1) {
|
||||
assertEquals(Palette.RED, listener2.value);
|
||||
assertEquals(null, listener1.value);
|
||||
}
|
||||
@ -601,17 +607,17 @@ public class OptionsTest extends AbstractGenericTest {
|
||||
private static class OptionsChangeListenerForTestVeto implements OptionsChangeListener {
|
||||
static int count = 0;
|
||||
private Object value;
|
||||
private int callOrder = -1;
|
||||
private int callCount = -1;
|
||||
|
||||
@Override
|
||||
public void optionsChanged(ToolOptions options, String optionName, Object oldValue,
|
||||
Object newValue) {
|
||||
|
||||
if (callOrder < 0) {
|
||||
callOrder = ++count;
|
||||
if (callCount < 0) {
|
||||
callCount = ++count;
|
||||
}
|
||||
|
||||
if (callOrder > 1) {
|
||||
if (callCount > 1) {
|
||||
throw new OptionsVetoException("Test");
|
||||
}
|
||||
|
||||
|
@ -175,9 +175,8 @@ public abstract class AbstractOptions implements Options {
|
||||
}
|
||||
|
||||
private void warnShouldUseTheme(String optionType) {
|
||||
Throwable throwable =
|
||||
ReflectionUtilities.createThrowableWithStackOlderThan(AbstractOptions.class,
|
||||
SubOptions.class);
|
||||
Throwable throwable = ReflectionUtilities
|
||||
.createThrowableWithStackOlderThan(AbstractOptions.class, SubOptions.class);
|
||||
String call = throwable.getStackTrace()[0].toString();
|
||||
Msg.warn(this, "Registering a direct " + optionType + " in the options is deprecated." +
|
||||
" Use registerTheme" + optionType + "Binding() instead!\n Called from " + call + "\n");
|
||||
@ -343,8 +342,15 @@ public abstract class AbstractOptions implements Options {
|
||||
Object oldValue = option.getCurrentValue();
|
||||
option.setCurrentValue(newValue);
|
||||
|
||||
if (!notifyOptionChanged(optionName, oldValue, newValue)) {
|
||||
option.setCurrentValue(oldValue);
|
||||
boolean success = false;
|
||||
try {
|
||||
// this can throw an OptionsVetoException
|
||||
success = notifyOptionChanged(optionName, oldValue, newValue);
|
||||
}
|
||||
finally {
|
||||
if (!success) {
|
||||
option.setCurrentValue(oldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,16 +117,25 @@ public class EditorState implements PropertyChangeListener {
|
||||
return;
|
||||
}
|
||||
|
||||
options.putObject(name, currentValue);
|
||||
Object newValue = options.getObject(name, null);
|
||||
boolean success = Objects.equals(currentValue, newValue);
|
||||
if (success) {
|
||||
originalValue = newValue;
|
||||
currentValue = newValue;
|
||||
//
|
||||
// The call to put() may throw an exception or may choose not to take the new value. Handle
|
||||
// both cases using a finally block along with checking the value after making the put()
|
||||
// call.
|
||||
//
|
||||
try {
|
||||
options.putObject(name, currentValue);
|
||||
}
|
||||
else {
|
||||
editor.setValue(originalValue);
|
||||
currentValue = originalValue;
|
||||
finally {
|
||||
Object newValue = options.getObject(name, null);
|
||||
boolean success = Objects.equals(currentValue, newValue);
|
||||
if (success) {
|
||||
originalValue = newValue;
|
||||
currentValue = newValue;
|
||||
}
|
||||
else {
|
||||
editor.setValue(originalValue);
|
||||
currentValue = originalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user