Mercurial > hg > truffle
comparison graal/com.oracle.jvmci.options.test/src/com/oracle/jvmci/options/test/TestOptionValue.java @ 21554:b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 26 May 2015 23:21:15 +0200 |
parents | graal/com.oracle.graal.options.test/src/com/oracle/graal/options/test/TestOptionValue.java@bb85b81258a0 |
children |
comparison
equal
deleted
inserted
replaced
21553:0910a9497b02 | 21554:b1530a6cce8c |
---|---|
1 /* | |
2 * Copyright (c) 2013, 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 package com.oracle.jvmci.options.test; | |
24 | |
25 import static com.oracle.jvmci.options.test.TestOptionValue.Options.*; | |
26 import static org.junit.Assert.*; | |
27 | |
28 import java.util.*; | |
29 | |
30 import org.junit.*; | |
31 | |
32 import com.oracle.jvmci.options.*; | |
33 import com.oracle.jvmci.options.OptionValue.OverrideScope; | |
34 | |
35 public class TestOptionValue { | |
36 | |
37 public static class Options { | |
38 public static final OptionValue<Boolean> Stable = new StableOptionValue<>(true); | |
39 public static final OptionValue<String> Mutable = new OptionValue<>("original"); | |
40 public static final OptionValue<String> SecondMutable = new OptionValue<>("second"); | |
41 } | |
42 | |
43 static final OptionDescriptor stable = new OptionDescriptor("Stable", Boolean.class, "", Options.class, "Stable", Stable); | |
44 static final OptionDescriptor mutable = new OptionDescriptor("Mutable", String.class, "", Options.class, "Mutable", Mutable); | |
45 static final OptionDescriptor secondMutable = new OptionDescriptor("SecondMutable", String.class, "", Options.class, "SecondMutable", SecondMutable); | |
46 | |
47 @Test | |
48 public void testMutable() { | |
49 assertEquals("original", Mutable.getValue()); | |
50 try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { | |
51 assertEquals("override1", Mutable.getValue()); | |
52 try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { | |
53 assertEquals("override2", Mutable.getValue()); | |
54 } | |
55 assertEquals("override1", Mutable.getValue()); | |
56 try (OverrideScope s3 = OptionValue.override(Mutable, "override3")) { | |
57 assertEquals("override3", Mutable.getValue()); | |
58 } | |
59 assertEquals("override1", Mutable.getValue()); | |
60 } | |
61 assertEquals("original", Mutable.getValue()); | |
62 try (OverrideScope s1 = OptionValue.override(Mutable, "original")) { | |
63 assertEquals("original", Mutable.getValue()); | |
64 } | |
65 } | |
66 | |
67 @Test | |
68 public void testMultiple() { | |
69 assertEquals("original", Mutable.getValue()); | |
70 assertEquals("second", SecondMutable.getValue()); | |
71 try (OverrideScope s1 = OptionValue.override(Mutable, "override1", SecondMutable, "secondOverride1")) { | |
72 assertEquals("override1", Mutable.getValue()); | |
73 assertEquals("secondOverride1", SecondMutable.getValue()); | |
74 try (OverrideScope s2 = OptionValue.override(Mutable, "override2", SecondMutable, "secondOverride2")) { | |
75 assertEquals("override2", Mutable.getValue()); | |
76 assertEquals("secondOverride2", SecondMutable.getValue()); | |
77 } | |
78 assertEquals("override1", Mutable.getValue()); | |
79 assertEquals("secondOverride1", SecondMutable.getValue()); | |
80 try (OverrideScope s3 = OptionValue.override(Mutable, "override3", SecondMutable, "secondOverride3")) { | |
81 assertEquals("override3", Mutable.getValue()); | |
82 assertEquals("secondOverride3", SecondMutable.getValue()); | |
83 } | |
84 assertEquals("override1", Mutable.getValue()); | |
85 assertEquals("secondOverride1", SecondMutable.getValue()); | |
86 } | |
87 assertEquals("original", Mutable.getValue()); | |
88 assertEquals("second", SecondMutable.getValue()); | |
89 try (OverrideScope s1 = OptionValue.override(Mutable, "original", SecondMutable, "second")) { | |
90 assertEquals("original", Mutable.getValue()); | |
91 assertEquals("second", SecondMutable.getValue()); | |
92 } | |
93 } | |
94 | |
95 @Test | |
96 public void testStable() { | |
97 assertTrue(Stable.getValue()); | |
98 try (OverrideScope s = OptionValue.override(Stable, false)) { | |
99 fail("cannot override stable option"); | |
100 } catch (IllegalArgumentException e) { | |
101 // expected | |
102 } | |
103 } | |
104 | |
105 @Test | |
106 public void toStringTest() { | |
107 assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=original", Mutable.toString()); | |
108 try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { | |
109 assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=override1", Mutable.toString()); | |
110 try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { | |
111 assertEquals("com.oracle.jvmci.options.test.TestOptionValue$Options.Mutable=override2", Mutable.toString()); | |
112 } | |
113 } | |
114 } | |
115 | |
116 @Test | |
117 public void getValuesTest() { | |
118 assertEquals(Arrays.asList("original"), Mutable.getValues(null)); | |
119 assertEquals(Arrays.asList(true), Stable.getValues(null)); | |
120 try (OverrideScope s1 = OptionValue.override(Mutable, "override1")) { | |
121 assertEquals(Arrays.asList("override1", "original"), Mutable.getValues(null)); | |
122 try (OverrideScope s2 = OptionValue.override(Mutable, "override2")) { | |
123 assertEquals(Arrays.asList("override2", "override1", "original"), Mutable.getValues(null)); | |
124 } | |
125 } | |
126 } | |
127 } |