-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy path_test_registry_util.cpp
More file actions
179 lines (148 loc) · 4.25 KB
/
_test_registry_util.cpp
File metadata and controls
179 lines (148 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**----------------------------------------------------------------------------
* _test_registry_util.cpp
*-----------------------------------------------------------------------------
*
*-----------------------------------------------------------------------------
* All rights reserved by Noh,Yonghwan (fixbrain@gmail.com, unsorted@msn.com)
*-----------------------------------------------------------------------------
* 2014:9:24 21:10 created
**---------------------------------------------------------------------------*/
#include "stdafx.h"
#include "_MyLib/src/RegistryUtil.h"
/**
* @brief
* @param
* @see
* @remarks
* @code
* @endcode
* @return
**/
bool test_registry_util()
{
// Create key
HKEY key = RUCreateKey(HKEY_CURRENT_USER, L"_test_key", false);
if (NULL == key) return false;
RegCloseKey(key);
// key created ?
if (true != RUIsKeyExists(HKEY_CURRENT_USER, L"_test_key")) return false;
// write dword value
key = RUOpenKey(HKEY_CURRENT_USER, L"_test_key", false);
_ASSERTE(nullptr != key);
_ASSERTE(true == RUWriteDword(key, L"TestValue", 1000));
// write string
_ASSERTE(true == RUSetString(key, L"TestValueString", L"abc"));
// read dword value
_ASSERTE(1000 == RUReadDword(key, L"TestValue", 0));
std::wstring str;
_ASSERTE(true == RUReadString(key, L"TestValueString", str));
_ASSERTE(0 == str.compare(L"abc"));
// Delete DWORD Value
_ASSERTE(true == RUDeleteValue(key, L"TestValue"));
uint64_t test64 = 1234567890;
// Write QWORD Value
_ASSERTE(true == RUWriteQword(key, L"test_Qword", test64));
// Read QWORD Value
_ASSERTE(test64 == RUReadQword(key, L"test_Qword", 0));
// Delete key
// -- key 내부의 value 들도 함께 삭제됨
_ASSERTE(true == RUDeleteKey(HKEY_CURRENT_USER, L"_test_key", true));
return true;
}
bool
reg_key_callback(
_In_ uint32_t index,
_In_ const wchar_t* base_name,
_In_ const wchar_t* sub_key_name,
_In_ const wchar_t* class_name,
_In_ DWORD_PTR tag
)
{
UNREFERENCED_PARAMETER(base_name);
UNREFERENCED_PARAMETER(tag);
log_dbg
"index = %u, sub_key_name = %ws, class_name = %ws",
index, sub_key_name, class_name
log_end;
return true;
}
bool
reg_value_callback(
_In_ uint32_t index,
_In_ uint32_t value_type,
_In_ const wchar_t* value_name,
_In_ uint32_t value_data_size,
_In_ const uint8_t* value_data,
_In_ DWORD_PTR tag
)
{
UNREFERENCED_PARAMETER(index);
UNREFERENCED_PARAMETER(value_type);
UNREFERENCED_PARAMETER(value_data_size);
UNREFERENCED_PARAMETER(value_data);
UNREFERENCED_PARAMETER(tag);
log_dbg
"value name=%ws",
value_name
log_end;
return true;
}
bool test_read_mouted_device()
{
// HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices 키 오픈
HKEY key = RUOpenKey(HKEY_LOCAL_MACHINE, L"SYSTEM\\MountedDevices", true);
if (NULL == key)
{
log_err "RUOpenKey( HKLM\\SYSTEM\\MountedDevices ) failed." log_end;
return false;
}
reg_enum_key_values(key,
nullptr,
reg_key_callback,
NULL,
reg_value_callback,
NULL);
RegCloseKey(key);
return true;
}
bool test_set_binary_data()
{
uint8_t value[] = { 0x00,0x01,0x02,0x03,0x04,0x00,0x01,0x02,0x03,0x04,0x00,0x01,0x02,0x03,0x04 };
HKEY key = RUOpenKey(HKEY_CURRENT_USER, L"Environment", false);
_ASSERTE(nullptr != key);
_ASSERTE(true == RUSetBinaryData(key, L"ExtToReg", (uint8_t*)&value, sizeof(value)));
RUCloseKey(key);
return true;
}
bool test_reg_multi_value()
{
_mem_check_begin
{
// Create key
hkey_ptr reg_key(RUCreateKey(HKEY_CURRENT_USER,
L"test_key",
false),
[](HKEY key) {
if (nullptr != key)
{
RUCloseKey(key);
}
});
_ASSERTE(nullptr != reg_key.get());
std::vector<std::wstring> set_vec;
set_vec.push_back(L"Hello");
set_vec.push_back(L"World");
_ASSERTE(true == RUSetMultiString(reg_key.get(), L"TestValue", set_vec));
std::vector<std::wstring> read_vec;
_ASSERTE(true == RUReadMultiString(reg_key.get(), L"TestValue", read_vec));
for (DWORD i = 0; i < set_vec.size(); ++i)
{
_ASSERTE(0 == read_vec.at(i).compare(set_vec.at(i).c_str()));
}
// Delete key
// -- key 내부의 value 들도 함께 삭제됨
_ASSERTE(true == RUDeleteKey(HKEY_CURRENT_USER, L"test_key", true));
}
_mem_check_end;
return true;
}