11// LAF Base Library
2- // Copyright (c) 2024 Igara Studio S.A.
2+ // Copyright (c) 2024-2025 Igara Studio S.A.
33// Copyright (c) 2017 David Capello
44//
55// This file is released under the terms of the MIT license.
@@ -33,8 +33,8 @@ TEST(Registry, OpenKey)
3333TEST (Registry, CreateKey)
3434{
3535 try {
36- hkey k = hkey::current_user ();
37- k = k .create (" Software\\ Classes\\ .laf-base-test-extension" );
36+ hkey hkcu = hkey::current_user ();
37+ hkey k = hkcu .create (" Software\\ Classes\\ .laf-base-test-extension" );
3838 k.string (" " , " testing" );
3939 k.string (" A" , " value A" );
4040 k.string (" B" , " value B" );
@@ -49,7 +49,46 @@ TEST(Registry, CreateKey)
4949 // We cannot use k.delete_tree("") because it does delete the
5050 // whole tree, but leaves the root key untouched.
5151
52- hkey::current_user ().delete_tree (" Software\\ Classes\\ .laf-base-test-extension" );
52+ hkcu.delete_tree (" Software\\ Classes\\ .laf-base-test-extension" );
53+ }
54+ catch (Win32Exception& ex) {
55+ printf (" Win32Exception: %s\n Error Code: %d\n " , ex.what (), ex.errorCode ());
56+ throw ;
57+ }
58+ catch (const std::exception& ex) {
59+ printf (" std::exception: %s\n " , ex.what ());
60+ throw ;
61+ }
62+ }
63+
64+ TEST (Registry, DeleteValue)
65+ {
66+ try {
67+ hkey hkcu = hkey::current_user ();
68+ hkey k = hkcu.create (" Software\\ Classes\\ .laf-base-test-delete-value" );
69+ k.string (" A" , " value A" );
70+ k.string (" B" , " " );
71+ k.dword (" C" , 2 );
72+
73+ EXPECT_TRUE (k.exists (" A" ));
74+ EXPECT_TRUE (k.exists (" B" ));
75+ EXPECT_TRUE (k.exists (" C" ));
76+ EXPECT_EQ (" value A" , k.string (" A" ));
77+ EXPECT_EQ (" " , k.string (" B" ));
78+ EXPECT_EQ (2 , k.dword (" C" ));
79+
80+ k.delete_value (" A" );
81+ k.delete_value (" B" );
82+ k.delete_value (" C" );
83+
84+ EXPECT_FALSE (k.exists (" A" ));
85+ EXPECT_FALSE (k.exists (" B" ));
86+ EXPECT_FALSE (k.exists (" C" ));
87+ EXPECT_EQ (" " , k.string (" A" ));
88+ EXPECT_EQ (" " , k.string (" B" ));
89+ EXPECT_EQ (0 , k.dword (" C" ));
90+
91+ hkcu.delete_tree (" Software\\ Classes\\ .laf-base-test-delete-value" );
5392 }
5493 catch (Win32Exception& ex) {
5594 printf (" Win32Exception: %s\n Error Code: %d\n " , ex.what (), ex.errorCode ());
0 commit comments