Hugh McMaster : regedit/tests: Test registry export with an empty key.

Alexandre Julliard julliard at winehq.org
Mon Sep 25 16:34:31 CDT 2017


Module: wine
Branch: master
Commit: fd4ce9a0efa72f5cf0770a9cc342502e667ba5b6
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fd4ce9a0efa72f5cf0770a9cc342502e667ba5b6

Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date:   Mon Sep 25 06:58:20 2017 +0000

regedit/tests: Test registry export with an empty key.

Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/regedit/tests/regedit.c | 81 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 80 insertions(+), 1 deletion(-)

diff --git a/programs/regedit/tests/regedit.c b/programs/regedit/tests/regedit.c
index 8b0b085..d64a590 100644
--- a/programs/regedit/tests/regedit.c
+++ b/programs/regedit/tests/regedit.c
@@ -17,7 +17,7 @@
  */
 
 #include <windows.h>
-
+#include <stdio.h>
 #include "wine/test.h"
 
 #define lok ok_(__FILE__,line)
@@ -166,6 +166,16 @@ static void verify_key_nonexist_(unsigned line, HKEY key_base, const char *subke
         RegCloseKey(hkey);
 }
 
+#define add_key(k,p,s) add_key_(__LINE__,k,p,s)
+static void add_key_(unsigned line, const HKEY hkey, const char *path, HKEY *subkey)
+{
+    LONG lr;
+
+    lr = RegCreateKeyExA(hkey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
+                         KEY_READ|KEY_WRITE, NULL, subkey, NULL);
+    lok(lr == ERROR_SUCCESS, "RegCreateKeyExA failed: %d\n", lr);
+}
+
 #define delete_key(k,p) delete_key_(__LINE__,k,p)
 static void delete_key_(unsigned line, const HKEY hkey, const char *path)
 {
@@ -3264,6 +3274,74 @@ static void test_value_deletion_unicode(void)
     delete_key(HKEY_CURRENT_USER, KEY_BASE);
 }
 
+#define compare_export(f,e) compare_export_(__LINE__,f,e)
+static BOOL compare_export_(unsigned line, const char *filename, const char *expected)
+{
+    FILE *fp;
+    long file_size;
+    WCHAR *fbuf = NULL, *wstr = NULL;
+    size_t len;
+    BOOL ret = FALSE;
+
+    fp = fopen(filename, "rb");
+    if (!fp) return FALSE;
+
+    if (fseek(fp, 0, SEEK_END)) goto error;
+    file_size = ftell(fp);
+    if (file_size == -1) goto error;
+    rewind(fp);
+
+    fbuf = HeapAlloc(GetProcessHeap(), 0, file_size + sizeof(WCHAR));
+    if (!fbuf) goto error;
+
+    fread(fbuf, file_size, 1, fp);
+    fbuf[file_size/sizeof(WCHAR)] = 0;
+    fclose(fp);
+
+    len = MultiByteToWideChar(CP_UTF8, 0, expected, -1, NULL, 0);
+    wstr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+    if (!wstr) goto exit;
+    MultiByteToWideChar(CP_UTF8, 0, expected, -1, wstr, len);
+
+    lok(!lstrcmpW(fbuf, wstr), "export data does not match expected data\n");
+    ret = TRUE;
+
+exit:
+    HeapFree(GetProcessHeap(), 0, fbuf);
+    HeapFree(GetProcessHeap(), 0, wstr);
+    return ret;
+
+error:
+    fclose(fp);
+    return FALSE;
+}
+
+static void test_export(void)
+{
+    LONG lr;
+    HKEY hkey;
+
+    const char *empty_key_test =
+        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
+        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n\r\n";
+
+    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
+    ok(lr == ERROR_SUCCESS || lr == ERROR_FILE_NOT_FOUND, "RegDeleteKeyA failed: %d\n", lr);
+
+    /* Test registry export with an empty key */
+    add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
+
+    run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
+    ok(compare_export("file.reg", empty_key_test), "compare_export() failed\n");
+
+    lr = DeleteFileA("file.reg");
+    ok(lr, "DeleteFile failed: %u\n", GetLastError());
+
+    RegCloseKey(hkey);
+
+    delete_key(HKEY_CURRENT_USER, KEY_BASE);
+}
+
 START_TEST(regedit)
 {
     if(!exec_import_str("REGEDIT4\r\n\r\n")){
@@ -3285,4 +3363,5 @@ START_TEST(regedit)
     test_key_creation_and_deletion_unicode();
     test_value_deletion();
     test_value_deletion_unicode();
+    test_export();
 }




More information about the wine-cvs mailing list