Example #1
0
 public void testRegistryDeleteValue() {
   Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
   Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 42);
   assertTrue(
       Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue"));
   Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue");
   assertFalse(
       Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue"));
   Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
 }
Example #2
0
 public void testRegistryValueExists() {
   assertFalse(
       Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, "Software\\Microsoft", ""));
   assertFalse(
       Advapi32Util.registryValueExists(
           WinReg.HKEY_LOCAL_MACHINE, "Software\\Microsoft", "KeyDoesNotExist"));
   assertTrue(
       Advapi32Util.registryValueExists(
           WinReg.HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control", "SystemBootDevice"));
 }
Example #3
0
 public void testRegistrySetGetLongValue() {
   Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
   Advapi32Util.registrySetLongValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "LongValue", 1234L);
   assertEquals(
       1234L,
       Advapi32Util.registryGetLongValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "LongValue"));
   assertTrue(
       Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "LongValue"));
   Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
 }
Example #4
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 #5
0
 public void testRegistrySetGetStringValue() {
   Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
   Advapi32Util.registrySetStringValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue", "Hello World");
   assertEquals(
       "Hello World",
       Advapi32Util.registryGetStringValue(
           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 #6
0
 public void testRegistrySetGetBinaryValue() {
   byte[] data = {0x00, 0x01, 0x02};
   Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
   Advapi32Util.registrySetBinaryValue(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue", data);
   byte[] read =
       Advapi32Util.registryGetBinaryValue(
           WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue");
   assertEquals(data.length, read.length);
   for (int i = 0; i < data.length; i++) {
     assertEquals(data[i], read[i]);
   }
   assertTrue(
       Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue"));
   Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
 }
Example #7
0
 public void testRegistrySetGetStringArray() {
   Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
   String[] dataWritten = {"Hello", "World"};
   Advapi32Util.registrySetStringArray(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue", dataWritten);
   assertTrue(
       Advapi32Util.registryValueExists(
           WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue"));
   String[] dataRead =
       Advapi32Util.registryGetStringArray(
           WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue");
   assertEquals(dataWritten.length, dataRead.length);
   for (int i = 0; i < dataRead.length; i++) {
     assertEquals(dataWritten[i], dataRead[i]);
   }
   dataWritten = new String[0];
   Advapi32Util.registrySetStringArray(
       WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyMultiString", dataWritten);
   dataRead =
       Advapi32Util.registryGetStringArray(
           WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyMultiString");
   assertEquals(0, dataRead.length);
   Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
 }