001/* 002 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package jdk.internal.jvmci.options.test; 024 025import static jdk.internal.jvmci.options.test.NestedBooleanOptionValueTest.Options.*; 026import static org.junit.Assert.*; 027import jdk.internal.jvmci.options.*; 028import jdk.internal.jvmci.options.OptionValue.*; 029 030import org.junit.*; 031 032public class NestedBooleanOptionValueTest { 033 034 public static class Options { 035 public static final OptionValue<Boolean> Master0 = new OptionValue<>(true); 036 public static final OptionValue<Boolean> NestedOption0 = new NestedBooleanOptionValue(Master0, true); 037 public static final OptionValue<Boolean> Master1 = new OptionValue<>(true); 038 public static final OptionValue<Boolean> NestedOption1 = new NestedBooleanOptionValue(Master1, true); 039 public static final OptionValue<Boolean> Master2 = new OptionValue<>(true); 040 public static final OptionValue<Boolean> NestedOption2 = new NestedBooleanOptionValue(Master2, false); 041 } 042 043 static final OptionDescriptor master0 = new OptionDescriptor("Master0", Boolean.class, "", Options.class, "Master0", Master0); 044 static final OptionDescriptor nestedOption0 = new OptionDescriptor("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0); 045 static final OptionDescriptor master1 = new OptionDescriptor("Master1", Boolean.class, "", Options.class, "Master1", Master1); 046 static final OptionDescriptor nestedOption1 = new OptionDescriptor("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1); 047 static final OptionDescriptor master2 = new OptionDescriptor("Master2", Boolean.class, "", Options.class, "Master2", Master2); 048 static final OptionDescriptor nestedOption2 = new OptionDescriptor("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2); 049 050 @Test 051 public void runOverrides() { 052 assertTrue(Master0.getValue()); 053 assertTrue(NestedOption0.getValue()); 054 try (OverrideScope s1 = OptionValue.override(Master0, false)) { 055 assertFalse(Master0.getValue()); 056 assertFalse(NestedOption0.getValue()); 057 try (OverrideScope s2 = OptionValue.override(NestedOption0, false)) { 058 assertFalse(NestedOption0.getValue()); 059 } 060 try (OverrideScope s2 = OptionValue.override(NestedOption0, true)) { 061 assertTrue(NestedOption0.getValue()); 062 } 063 } 064 assertTrue(Master0.getValue()); 065 try (OverrideScope s1 = OptionValue.override(NestedOption0, false)) { 066 assertFalse(NestedOption0.getValue()); 067 } 068 try (OverrideScope s1 = OptionValue.override(NestedOption0, true)) { 069 assertTrue(NestedOption0.getValue()); 070 } 071 } 072 073 @Test 074 public void runDefaultTrue() { 075 Master1.setValue(true); 076 assertTrue(Master1.getValue()); 077 assertTrue(NestedOption1.getValue()); 078 // nested value unset 079 Master1.setValue(false); 080 assertFalse(Master1.getValue()); 081 assertFalse(NestedOption1.getValue()); 082 // set false 083 Master1.setValue(false); 084 NestedOption1.setValue(false); 085 assertFalse(Master1.getValue()); 086 assertFalse(NestedOption1.getValue()); 087 Master1.setValue(true); 088 assertTrue(Master1.getValue()); 089 assertFalse(NestedOption1.getValue()); 090 // set true 091 Master1.setValue(false); 092 NestedOption1.setValue(true); 093 assertFalse(Master1.getValue()); 094 assertTrue(NestedOption1.getValue()); 095 Master1.setValue(true); 096 assertTrue(Master1.getValue()); 097 assertTrue(NestedOption1.getValue()); 098 } 099 100 @Test 101 public void runDefaultFalse() { 102 Master2.setValue(true); 103 assertTrue(Master2.getValue()); 104 assertFalse(NestedOption2.getValue()); 105 // nested value unset 106 Master2.setValue(false); 107 assertFalse(Master2.getValue()); 108 assertFalse(NestedOption2.getValue()); 109 // set false 110 Master2.setValue(false); 111 NestedOption2.setValue(false); 112 assertFalse(Master2.getValue()); 113 assertFalse(NestedOption2.getValue()); 114 Master2.setValue(true); 115 assertTrue(Master2.getValue()); 116 assertFalse(NestedOption2.getValue()); 117 // set true 118 Master2.setValue(false); 119 NestedOption2.setValue(true); 120 assertFalse(Master2.getValue()); 121 assertTrue(NestedOption2.getValue()); 122 Master2.setValue(true); 123 assertTrue(Master2.getValue()); 124 assertTrue(NestedOption2.getValue()); 125 } 126 127}