[PATCH] reg/tests: Add data tests for the 'copy' command

Hugh McMaster hugh.mcmaster at outlook.com
Thu May 13 07:36:56 CDT 2021


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/reg/tests/copy.c     | 136 ++++++++++++++++++++++++++++++++++
 programs/reg/tests/export.c   |  30 ++++----
 programs/reg/tests/reg_test.h |   7 ++
 3 files changed, 158 insertions(+), 15 deletions(-)

diff --git a/programs/reg/tests/copy.c b/programs/reg/tests/copy.c
index 0d245dae4da..7126b00d50e 100644
--- a/programs/reg/tests/copy.c
+++ b/programs/reg/tests/copy.c
@@ -122,6 +122,140 @@ static void test_command_syntax(void)
     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
 }
 
+static void test_copy_empty_key(void)
+{
+    DWORD r;
+
+    delete_tree(HKEY_CURRENT_USER, COPY_SRC);
+    verify_key_nonexist(HKEY_CURRENT_USER, COPY_SRC);
+
+    delete_tree(HKEY_CURRENT_USER, KEY_BASE);
+    verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
+
+    add_key(HKEY_CURRENT_USER, COPY_SRC, NULL);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
+
+    todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
+
+    todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
+
+    todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
+}
+
+static void test_copy_simple_data(void)
+{
+    HKEY hkey;
+    DWORD r, dword;
+
+    delete_tree(HKEY_CURRENT_USER, COPY_SRC);
+    verify_key_nonexist(HKEY_CURRENT_USER, COPY_SRC);
+
+    delete_tree(HKEY_CURRENT_USER, KEY_BASE);
+    verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
+
+    add_key(HKEY_CURRENT_USER, COPY_SRC, &hkey);
+
+    dword = 0x100;
+    add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
+    add_value(hkey, "String", REG_SZ, "Your text here...", 18);
+    close_key(hkey);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
+
+    todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
+
+    todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
+
+    todo_wine delete_key(HKEY_CURRENT_USER, KEY_BASE);
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
+
+
+    run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine verify_key(HKEY_CURRENT_USER, KEY_BASE);
+
+    run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
+    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    todo_wine ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
+}
+
 START_TEST(copy)
 {
     DWORD r;
@@ -132,4 +266,6 @@ START_TEST(copy)
     }
 
     test_command_syntax();
+    test_copy_empty_key();
+    test_copy_simple_data();
 }
diff --git a/programs/reg/tests/export.c b/programs/reg/tests/export.c
index daf42f66e3e..27d70b6a663 100644
--- a/programs/reg/tests/export.c
+++ b/programs/reg/tests/export.c
@@ -18,9 +18,8 @@
 
 #include "reg_test.h"
 
-#define compare_export(f,e,todo) compare_export_(__FILE__,__LINE__,f,e,todo)
-static BOOL compare_export_(const char *file, unsigned line, const char *filename,
-                            const char *expected, DWORD todo)
+BOOL compare_export_(const char *file, unsigned line, const char *filename,
+                     const char *expected, DWORD todo)
 {
     FILE *fp;
     long file_size;
@@ -64,6 +63,17 @@ error:
     return FALSE;
 }
 
+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";
+
+const char *simple_data_test =
+    "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
+    "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
+    "\"DWORD\"=dword:00000100\r\n"
+    "\"String\"=\"Your text here...\"\r\n\r\n";
+
+
 /* Unit tests */
 
 static void test_export(void)
@@ -73,16 +83,6 @@ static void test_export(void)
     HKEY hkey, subkey;
     BYTE hex[4], buffer[8];
 
-    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";
-
-    const char *simple_test =
-        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
-        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
-        "\"DWORD\"=dword:00000100\r\n"
-        "\"String\"=\"Your text here...\"\r\n\r\n";
-
     const char *complex_test =
         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
@@ -243,12 +243,12 @@ static void test_export(void)
 
     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
-    ok(compare_export("file.reg", simple_test, 0), "compare_export() failed\n");
+    ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
 
     /* Test whether a .reg file extension is required when exporting */
     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " foo /y", &r);
     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
-    ok(compare_export("foo", simple_test, 0), "compare_export() failed\n");
+    ok(compare_export("foo", simple_data_test, 0), "compare_export() failed\n");
 
     /* Test registry export with a complex data structure */
     add_key(hkey, "Subkey1", &subkey);
diff --git a/programs/reg/tests/reg_test.h b/programs/reg/tests/reg_test.h
index 6718e91096f..3f4677a7a69 100644
--- a/programs/reg/tests/reg_test.h
+++ b/programs/reg/tests/reg_test.h
@@ -74,6 +74,13 @@ void add_value_(const char *file, unsigned line, HKEY hkey, const char *name,
 #define delete_value(k,n) delete_value_(__FILE__,__LINE__,k,n)
 void delete_value_(const char *file, unsigned line, const HKEY hkey, const char *name);
 
+/* export.c */
+#define compare_export(f,e,todo) compare_export_(__FILE__,__LINE__,f,e,todo)
+BOOL compare_export_(const char *file, unsigned line, const char *filename,
+                     const char *expected, DWORD todo);
+extern const char *empty_key_test;
+extern const char *simple_data_test;
+
 /* import.c */
 #define test_import_str(c,r) import_reg(__FILE__,__LINE__,c,FALSE,r)
 #define test_import_wstr(c,r) import_reg(__FILE__,__LINE__,c,TRUE,r)
-- 
2.31.1




More information about the wine-devel mailing list