From 9c4efce3d49e385d0d59e8085374b5a1d1e17647 Mon Sep 17 00:00:00 2001 From: Michael Putters Date: Thu, 12 Dec 2013 00:12:10 +0100 Subject: [PATCH] Added tests for WindowRegistry.getValueNames --- src/main/cpp/win.cpp | 4 ++-- .../platform/WindowsRegistryTest.groovy | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/cpp/win.cpp b/src/main/cpp/win.cpp index 9cc8f84..d08617e 100755 --- a/src/main/cpp/win.cpp +++ b/src/main/cpp/win.cpp @@ -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); diff --git a/src/test/groovy/net/rubygrapefruit/platform/WindowsRegistryTest.groovy b/src/test/groovy/net/rubygrapefruit/platform/WindowsRegistryTest.groovy index bf5057f..a7b3898 100644 --- a/src/test/groovy/net/rubygrapefruit/platform/WindowsRegistryTest.groovy +++ b/src/test/groovy/net/rubygrapefruit/platform/WindowsRegistryTest.groovy @@ -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./ + } }