e26927b8e4badf2be5fe0740f8db275795231fe7
[feisty_meow.git] / kona / src / org / feistymeow / system / RegistryEditorTestCase.java
1 package org.feistymeow.system;\r
2 \r
3 import static org.junit.Assert.*;\r
4 import org.junit.*;\r
5 \r
6 import org.feistymeow.system.RegistryEditor;\r
7 \r
8 /**\r
9  * RegistryEditor junit tests.\r
10  * \r
11  * @author Chris Koeritz\r
12  *\r
13  */\r
14 public class RegistryEditorTestCase \r
15 {    \r
16         @Before\r
17         public void setUp() throws Exception \r
18         {\r
19         }\r
20 \r
21         @After\r
22         public void tearDown() throws Exception \r
23         {\r
24         }\r
25 \r
26         @Test\r
27         public void testCheckKey_missing() {\r
28                 // this key cannot exist, since we're not allowed to write at that\r
29                 // top level hive (as far as we know).\r
30                 assertFalse(RegistryEditor.checkKey("HKLM\\flaubert\\maximus"));\r
31         }\r
32 \r
33         @Test\r
34         public void testCheckKey_present() {\r
35                 // this key must always exist as far as we know.\r
36                 assertTrue(RegistryEditor.checkKey("HKLM\\Software"));\r
37         }\r
38 \r
39         @Test\r
40         public void testCheckKey_bad() {\r
41                 assertFalse(RegistryEditor.checkKey(null));\r
42         }\r
43 \r
44         @Test\r
45         public void testGetValue_present() {\r
46                 String PERSONAL_FOLDER_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";\r
47                 String PERSONAL_FOLDER_VALUE = "Personal";\r
48                 assertNotNull(RegistryEditor.getValue(PERSONAL_FOLDER_KEY, PERSONAL_FOLDER_VALUE,\r
49                                 RegistryEditor.STRING_TYPE)); \r
50         }\r
51 \r
52         @Test\r
53         public void testGetValue_missing() {\r
54                 String PERSONAL_FOLDER_KEY = "HKCU\\Flombix\\Gruntnork";\r
55                 String PERSONAL_FOLDER_VALUE = "Personalish";\r
56                 assertNull(RegistryEditor.getValue(PERSONAL_FOLDER_KEY, PERSONAL_FOLDER_VALUE,\r
57                                 RegistryEditor.STRING_TYPE)); \r
58         }\r
59 \r
60         @Test\r
61         public void testSetValueAndRemove_AllWork()\r
62         {\r
63                 String EXAMPLE_KEY_ROOT = "HKCU\\Software\\SpunkMaster5000";\r
64                 String EXAMPLE_KEY = EXAMPLE_KEY_ROOT + "\\traumix";\r
65                 String EXAMPLE_VALUE = "glonkish";\r
66                 String EXAMPLE_CONTENTS1 = "ralphWiggum!";\r
67                 String EXAMPLE_CONTENTS2 = "moeSzyslak?";\r
68 \r
69                 // first try deleting the value.  this should fail to start with.\r
70                 assertFalse(RegistryEditor.deleteValue(EXAMPLE_KEY, EXAMPLE_VALUE));\r
71                 // remove the entire key if present.\r
72                 assertFalse(RegistryEditor.deleteKey(EXAMPLE_KEY_ROOT));\r
73                 // now test that it really doesn't seem to be there.\r
74                 assertFalse(RegistryEditor.checkKey(EXAMPLE_KEY));\r
75 //System.out.println("now setting key [" + EXAMPLE_KEY + "] value [" + EXAMPLE_VALUE + "] to '" + EXAMPLE_CONTENTS1 + "'");\r
76                 // now try adding the example value.\r
77                 assertTrue(RegistryEditor.setValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE, EXAMPLE_CONTENTS1));\r
78                 // check that the contents are what we expect.\r
79                 assertEquals(RegistryEditor.getValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE),\r
80                                 EXAMPLE_CONTENTS1);\r
81                 // now change the value's contents to a new setting.\r
82                 assertTrue(RegistryEditor.setValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE, EXAMPLE_CONTENTS2));\r
83                 // make sure the update has succeeded.\r
84                 assertEquals(RegistryEditor.getValue(EXAMPLE_KEY, EXAMPLE_VALUE, RegistryEditor.STRING_TYPE),\r
85                                 EXAMPLE_CONTENTS2);\r
86                 // now whack the value we had added.\r
87                 assertTrue(RegistryEditor.deleteValue(EXAMPLE_KEY, EXAMPLE_VALUE));\r
88                 // now remove the entire key we added.\r
89                 assertTrue(RegistryEditor.deleteKey(EXAMPLE_KEY_ROOT));\r
90         }\r
91 \r
92 }\r
93 \r