1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @run junit jdk.vm.ci.options.test.NestedBooleanOptionValueTest 27 */ 28 29 package org.graalvm.compiler.options.test; 30 31 import static org.graalvm.compiler.options.test.NestedBooleanOptionValueTest.Options.Master0; 32 import static org.graalvm.compiler.options.test.NestedBooleanOptionValueTest.Options.Master1; 33 import static org.graalvm.compiler.options.test.NestedBooleanOptionValueTest.Options.Master2; 34 import static org.graalvm.compiler.options.test.NestedBooleanOptionValueTest.Options.NestedOption0; 35 import static org.graalvm.compiler.options.test.NestedBooleanOptionValueTest.Options.NestedOption1; 36 import static org.graalvm.compiler.options.test.NestedBooleanOptionValueTest.Options.NestedOption2; 37 import static org.junit.Assert.assertFalse; 38 import static org.junit.Assert.assertTrue; 39 40 import org.junit.Test; 41 42 import org.graalvm.compiler.options.NestedBooleanOptionValue; 43 import org.graalvm.compiler.options.OptionDescriptor; 44 import org.graalvm.compiler.options.OptionValue; 45 import org.graalvm.compiler.options.OptionValue.OverrideScope; 46 47 public class NestedBooleanOptionValueTest { 48 49 public static class Options { 50 public static final OptionValue<Boolean> Master0 = new OptionValue<>(true); 51 public static final OptionValue<Boolean> NestedOption0 = new NestedBooleanOptionValue(Master0, true); 52 public static final OptionValue<Boolean> Master1 = new OptionValue<>(true); 53 public static final OptionValue<Boolean> NestedOption1 = new NestedBooleanOptionValue(Master1, true); 54 public static final OptionValue<Boolean> Master2 = new OptionValue<>(true); 55 public static final OptionValue<Boolean> NestedOption2 = new NestedBooleanOptionValue(Master2, false); 56 } 57 58 static final OptionDescriptor master0 = OptionDescriptor.create("Master0", Boolean.class, "", Options.class, "Master0", Master0); 59 static final OptionDescriptor nestedOption0 = OptionDescriptor.create("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0); 60 static final OptionDescriptor master1 = OptionDescriptor.create("Master1", Boolean.class, "", Options.class, "Master1", Master1); 61 static final OptionDescriptor nestedOption1 = OptionDescriptor.create("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1); 62 static final OptionDescriptor master2 = OptionDescriptor.create("Master2", Boolean.class, "", Options.class, "Master2", Master2); 63 static final OptionDescriptor nestedOption2 = OptionDescriptor.create("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2); 64 65 @SuppressWarnings("try") 66 @Test 67 public void runOverrides() { 68 assertTrue(Master0.getValue()); 69 assertTrue(NestedOption0.getValue()); 70 try (OverrideScope s1 = OptionValue.override(Master0, false)) { 71 assertFalse(Master0.getValue()); 72 assertFalse(NestedOption0.getValue()); 73 try (OverrideScope s2 = OptionValue.override(NestedOption0, false)) { 74 assertFalse(NestedOption0.getValue()); 75 } 76 try (OverrideScope s2 = OptionValue.override(NestedOption0, true)) { 77 assertTrue(NestedOption0.getValue()); 78 } 79 } 80 assertTrue(Master0.getValue()); 81 try (OverrideScope s1 = OptionValue.override(NestedOption0, false)) { 82 assertFalse(NestedOption0.getValue()); 83 } 84 try (OverrideScope s1 = OptionValue.override(NestedOption0, true)) { 85 assertTrue(NestedOption0.getValue()); 86 } 87 } 88 89 @Test 90 public void runDefaultTrue() { 91 Master1.setValue(true); 92 assertTrue(Master1.getValue()); 93 assertTrue(NestedOption1.getValue()); 94 // nested value unset 95 Master1.setValue(false); 96 assertFalse(Master1.getValue()); 97 assertFalse(NestedOption1.getValue()); 98 // set false 99 Master1.setValue(false); 100 NestedOption1.setValue(false); 101 assertFalse(Master1.getValue()); 102 assertFalse(NestedOption1.getValue()); 103 Master1.setValue(true); 104 assertTrue(Master1.getValue()); 105 assertFalse(NestedOption1.getValue()); 106 // set true 107 Master1.setValue(false); 108 NestedOption1.setValue(true); 109 assertFalse(Master1.getValue()); 110 assertTrue(NestedOption1.getValue()); 111 Master1.setValue(true); 112 assertTrue(Master1.getValue()); 113 assertTrue(NestedOption1.getValue()); 114 } 115 116 @Test 117 public void runDefaultFalse() { 118 Master2.setValue(true); 119 assertTrue(Master2.getValue()); 120 assertFalse(NestedOption2.getValue()); 121 // nested value unset 122 Master2.setValue(false); 123 assertFalse(Master2.getValue()); 124 assertFalse(NestedOption2.getValue()); 125 // set false 126 Master2.setValue(false); 127 NestedOption2.setValue(false); 128 assertFalse(Master2.getValue()); 129 assertFalse(NestedOption2.getValue()); 130 Master2.setValue(true); 131 assertTrue(Master2.getValue()); 132 assertFalse(NestedOption2.getValue()); 133 // set true 134 Master2.setValue(false); 135 NestedOption2.setValue(true); 136 assertFalse(Master2.getValue()); 137 assertTrue(NestedOption2.getValue()); 138 Master2.setValue(true); 139 assertTrue(Master2.getValue()); 140 assertTrue(NestedOption2.getValue()); 141 } 142 143 }