forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinRegistryTest.cpp
More file actions
130 lines (100 loc) · 2.93 KB
/
WinRegistryTest.cpp
File metadata and controls
130 lines (100 loc) · 2.93 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
//
// WinRegistryTest.cpp
//
// $Id: //poco/1.4/Util/testsuite/src/WinRegistryTest.cpp#1 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "WinRegistryTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Util/WinRegistryKey.h"
#include "Poco/Environment.h"
#include "Poco/Exception.h"
#undef min
#undef max
#include <limits>
#if defined(POCO_HAVE_INT64)
using Poco::Int64;
#endif
using Poco::Util::WinRegistryKey;
using Poco::Environment;
WinRegistryTest::WinRegistryTest(const std::string& name): CppUnit::TestCase(name)
{
}
WinRegistryTest::~WinRegistryTest()
{
}
void WinRegistryTest::testRegistry()
{
WinRegistryKey regKey("HKEY_CURRENT_USER\\Software\\Applied Informatics\\Test");
if (regKey.exists()) regKey.deleteKey();
assert (!regKey.exists());
regKey.setString("name1", "value1");
assert (regKey.getString("name1") == "value1");
regKey.setString("name1", "Value1");
assert (regKey.getString("name1") == "Value1");
regKey.setString("name2", "value2");
assert (regKey.getString("name2") == "value2");
assert (regKey.exists("name1"));
assert (regKey.exists("name2"));
assert (regKey.exists());
WinRegistryKey regKeyRO("HKEY_CURRENT_USER\\Software\\Applied Informatics\\Test", true);
assert (regKeyRO.getString("name1") == "Value1");
try
{
regKeyRO.setString("name1", "newValue1");
}
catch (Poco::Exception& exc)
{
std::string msg = exc.displayText();
}
assert (regKey.getString("name1") == "Value1");
WinRegistryKey::Values vals;
regKey.values(vals);
assert (vals.size() == 2);
assert (vals[0] == "name1" || vals[0] == "name2");
assert (vals[1] == "name1" || vals[1] == "name2");
assert (vals[0] != vals[1]);
Environment::set("FOO", "bar");
regKey.setStringExpand("name3", "%FOO%");
assert (regKey.getStringExpand("name3") == "bar");
regKey.setInt("name4", 42);
assert (regKey.getInt("name4") == 42);
assert (regKey.exists("name4"));
regKey.deleteValue("name4");
assert (!regKey.exists("name4"));
#if defined(POCO_HAVE_INT64)
regKey.setInt64("name5", std::numeric_limits<Int64>::max());
assert (regKey.getInt64("name5") == std::numeric_limits<Int64>::max());
assert (regKey.exists("name5"));
regKey.deleteValue("name5");
assert (!regKey.exists("name5"));
#endif
const int dataSize = 127;
std::vector<char> data(dataSize);
for (int i = 0; i < dataSize; ++i)
data[i] = rand() % 256;
regKey.setBinary("binary", data);
assert (regKey.getBinary("binary") == data);
assert (regKey.exists("binary"));
regKey.deleteValue("binary");
assert (!regKey.exists("binary"));
regKey.deleteKey();
assert (!regKey.exists());
}
void WinRegistryTest::setUp()
{
}
void WinRegistryTest::tearDown()
{
}
CppUnit::Test* WinRegistryTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WinRegistryTest");
CppUnit_addTest(pSuite, WinRegistryTest, testRegistry);
return pSuite;
}