Example #1
0
 public void testRegistrySetGetExpandableStringValue() {
   Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
   Advapi32Util.registrySetExpandableStringValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue", "Temp is %TEMP%");
   assertEquals(
       "Temp is %TEMP%",
       Advapi32Util.registryGetExpandableStringValue(
           WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue"));
   assertTrue(
       Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue"));
   Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
 }
Example #2
0
 public void testRegistryGetValues() {
   String uu = new String("A" + "\\u00ea" + "\\u00f1" + "\\u00fc" + "C");
   Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
   Advapi32Util.registrySetIntValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "FourtyTwo" + uu, 42);
   Advapi32Util.registrySetStringValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "42" + uu, "FourtyTwo" + uu);
   Advapi32Util.registrySetExpandableStringValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "ExpandableString", "%TEMP%");
   byte[] dataWritten = {0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF};
   Advapi32Util.registrySetBinaryValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "DeadBeef", dataWritten);
   String[] stringsWritten = {"Hello", "World", "Hello World", uu};
   Advapi32Util.registrySetStringArray(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringArray", stringsWritten);
   String[] emptyArray = new String[0];
   Advapi32Util.registrySetStringArray(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyStringArray", emptyArray);
   Advapi32Util.registrySetBinaryValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyBinary", new byte[0]);
   TreeMap<String, Object> values =
       Advapi32Util.registryGetValues(WinReg.HKEY_CURRENT_USER, "Software\\JNA");
   assertEquals(7, values.keySet().size());
   assertEquals("FourtyTwo" + uu, values.get("42" + uu));
   assertEquals(42, values.get("FourtyTwo" + uu));
   assertEquals("%TEMP%", values.get("ExpandableString"));
   byte[] dataRead = (byte[]) values.get("DeadBeef");
   assertEquals(dataWritten.length, dataRead.length);
   for (int i = 0; i < dataWritten.length; i++) {
     assertEquals(dataWritten[i], dataRead[i]);
   }
   String[] stringsRead = (String[]) values.get("StringArray");
   assertEquals(stringsWritten.length, stringsRead.length);
   for (int i = 0; i < stringsWritten.length; i++) {
     assertEquals(stringsWritten[i], stringsRead[i]);
   }
   stringsRead = (String[]) values.get("EmptyStringArray");
   assertEquals(0, stringsRead.length);
   Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
 }