Added tests for WindowRegistry.getValueNames

This commit is contained in:
Michael Putters
2013-12-12 00:12:10 +01:00
parent 45dc2bc7be
commit 9c4efce3d4
2 changed files with 16 additions and 2 deletions

View File

@@ -556,8 +556,8 @@ Java_net_rubygrapefruit_platform_internal_jni_WindowsRegistryFunctions_getSubkey
JNIEXPORT jboolean JNICALL
Java_net_rubygrapefruit_platform_internal_jni_WindowsRegistryFunctions_getValueNames(JNIEnv *env, jclass target, jint keyNum, jstring subkey, jobject names, jobject result) {
wchar_t* subkeyStr = java_to_wchar(env, subkey, result);
jclass subkeys_class = env->GetObjectClass(names);
jmethodID method = env->GetMethodID(subkeys_class, "add", "(Ljava/lang/Object;)Z");
jclass names_class = env->GetObjectClass(names);
jmethodID method = env->GetMethodID(names_class, "add", "(Ljava/lang/Object;)Z");
HKEY key;
LONG retval = RegOpenKeyExW(get_key_from_ordinal(keyNum), subkeyStr, 0, KEY_READ, &key);

View File

@@ -47,4 +47,18 @@ class WindowsRegistryTest extends Specification {
def e = thrown(MissingRegistryEntryException)
e.message == /Could not list the subkeys of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./
}
def "can read value names"() {
expect:
windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Microsoft\Windows NT\CurrentVersion/).flatten().contains("CurrentVersion")
}
def "cannot read value names of key that does not exist"() {
when:
windowsRegistry.getValueNames(WindowsRegistry.Key.HKEY_LOCAL_MACHINE, /SOFTWARE\Unknown/)
then:
def e = thrown(MissingRegistryEntryException)
e.message == /Could not list the value names of registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Unknown' as it does not exist./
}
}