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 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64" 27 * @run junit jdk.vm.ci.options.test.NestedBooleanOptionValueTest 28 */ 29 30 package jdk.vm.ci.options.test; 31 32 import static jdk.vm.ci.options.test.NestedBooleanOptionValueTest.Options.*; 33 import static org.junit.Assert.*; 34 import jdk.vm.ci.options.*; 35 import jdk.vm.ci.options.OptionValue.*; 36 37 import org.junit.*; 38 39 public class NestedBooleanOptionValueTest { 40 41 public static class Options { 42 public static final OptionValue<Boolean> Master0 = new OptionValue<>(true); 43 public static final OptionValue<Boolean> NestedOption0 = new NestedBooleanOptionValue(Master0, true); 44 public static final OptionValue<Boolean> Master1 = new OptionValue<>(true); 45 public static final OptionValue<Boolean> NestedOption1 = new NestedBooleanOptionValue(Master1, true); 46 public static final OptionValue<Boolean> Master2 = new OptionValue<>(true); 47 public static final OptionValue<Boolean> NestedOption2 = new NestedBooleanOptionValue(Master2, false); 48 } 49 50 static final OptionDescriptor master0 = OptionDescriptor.create("Master0", Boolean.class, "", Options.class, "Master0", Master0); 51 static final OptionDescriptor nestedOption0 = OptionDescriptor.create("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0); 52 static final OptionDescriptor master1 = OptionDescriptor.create("Master1", Boolean.class, "", Options.class, "Master1", Master1); 53 static final OptionDescriptor nestedOption1 = OptionDescriptor.create("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1); 54 static final OptionDescriptor master2 = OptionDescriptor.create("Master2", Boolean.class, "", Options.class, "Master2", Master2); 55 static final OptionDescriptor nestedOption2 = OptionDescriptor.create("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2); 56 57 @SuppressWarnings("try") 58 @Test 59 public void runOverrides() { 60 assertTrue(Master0.getValue()); 61 assertTrue(NestedOption0.getValue()); 62 try (OverrideScope s1 = OptionValue.override(Master0, false)) { 63 assertFalse(Master0.getValue()); 64 assertFalse(NestedOption0.getValue()); 65 try (OverrideScope s2 = OptionValue.override(NestedOption0, false)) { 66 assertFalse(NestedOption0.getValue()); 67 } 68 try (OverrideScope s2 = OptionValue.override(NestedOption0, true)) { 69 assertTrue(NestedOption0.getValue()); 70 } 71 } 72 assertTrue(Master0.getValue()); 73 try (OverrideScope s1 = OptionValue.override(NestedOption0, false)) { 74 assertFalse(NestedOption0.getValue()); 75 } 76 try (OverrideScope s1 = OptionValue.override(NestedOption0, true)) { 77 assertTrue(NestedOption0.getValue()); 78 } 79 } 80 81 @Test 82 public void runDefaultTrue() { 83 Master1.setValue(true); 84 assertTrue(Master1.getValue()); 85 assertTrue(NestedOption1.getValue()); 86 // nested value unset 87 Master1.setValue(false); 88 assertFalse(Master1.getValue()); 89 assertFalse(NestedOption1.getValue()); 90 // set false 91 Master1.setValue(false); 92 NestedOption1.setValue(false); 93 assertFalse(Master1.getValue()); 94 assertFalse(NestedOption1.getValue()); 95 Master1.setValue(true); 96 assertTrue(Master1.getValue()); 97 assertFalse(NestedOption1.getValue()); 98 // set true 99 Master1.setValue(false); 100 NestedOption1.setValue(true); 101 assertFalse(Master1.getValue()); 102 assertTrue(NestedOption1.getValue()); 103 Master1.setValue(true); 104 assertTrue(Master1.getValue()); 105 assertTrue(NestedOption1.getValue()); 106 } 107 108 @Test 109 public void runDefaultFalse() { 110 Master2.setValue(true); 111 assertTrue(Master2.getValue()); 112 assertFalse(NestedOption2.getValue()); 113 // nested value unset 114 Master2.setValue(false); 115 assertFalse(Master2.getValue()); 116 assertFalse(NestedOption2.getValue()); 117 // set false 118 Master2.setValue(false); 119 NestedOption2.setValue(false); 120 assertFalse(Master2.getValue()); 121 assertFalse(NestedOption2.getValue()); 122 Master2.setValue(true); 123 assertTrue(Master2.getValue()); 124 assertFalse(NestedOption2.getValue()); 125 // set true 126 Master2.setValue(false); 127 NestedOption2.setValue(true); 128 assertFalse(Master2.getValue()); 129 assertTrue(NestedOption2.getValue()); 130 Master2.setValue(true); 131 assertTrue(Master2.getValue()); 132 assertTrue(NestedOption2.getValue()); 133 } 134 135 }