forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameValueCollectionTest.cpp
More file actions
128 lines (94 loc) · 2.46 KB
/
NameValueCollectionTest.cpp
File metadata and controls
128 lines (94 loc) · 2.46 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
//
// NameValueCollectionTest.cpp
//
// $Id: //poco/1.4/Net/testsuite/src/NameValueCollectionTest.cpp#1 $
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "NameValueCollectionTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Net/NameValueCollection.h"
#include "Poco/Exception.h"
using Poco::Net::NameValueCollection;
using Poco::NotFoundException;
NameValueCollectionTest::NameValueCollectionTest(const std::string& name): CppUnit::TestCase(name)
{
}
NameValueCollectionTest::~NameValueCollectionTest()
{
}
void NameValueCollectionTest::testNameValueCollection()
{
NameValueCollection nvc;
assert (nvc.empty());
assert (nvc.size() == 0);
nvc.set("name", "value");
assert (!nvc.empty());
assert (nvc["name"] == "value");
assert (nvc["Name"] == "value");
nvc.set("name2", "value2");
assert (nvc.get("name2") == "value2");
assert (nvc.get("NAME2") == "value2");
assert (nvc.size() == 2);
try
{
std::string value = nvc.get("name3");
fail("not found - must throw");
}
catch (NotFoundException&)
{
}
try
{
std::string value = nvc["name3"];
fail("not found - must throw");
}
catch (NotFoundException&)
{
}
assert (nvc.get("name", "default") == "value");
assert (nvc.get("name3", "default") == "default");
assert (nvc.has("name"));
assert (nvc.has("name2"));
assert (!nvc.has("name3"));
nvc.add("name3", "value3");
assert (nvc.get("name3") == "value3");
nvc.add("name3", "value31");
NameValueCollection::ConstIterator it = nvc.find("Name3");
assert (it != nvc.end());
std::string v1 = it->second;
assert (it->first == "name3");
++it;
assert (it != nvc.end());
std::string v2 = it->second;
assert (it->first == "name3");
assert ((v1 == "value3" && v2 == "value31") || (v1 == "value31" && v2 == "value3"));
nvc.erase("name3");
assert (!nvc.has("name3"));
assert (nvc.find("name3") == nvc.end());
it = nvc.begin();
assert (it != nvc.end());
++it;
assert (it != nvc.end());
++it;
assert (it == nvc.end());
nvc.clear();
assert (nvc.empty());
assert (nvc.size() == 0);
}
void NameValueCollectionTest::setUp()
{
}
void NameValueCollectionTest::tearDown()
{
}
CppUnit::Test* NameValueCollectionTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NameValueCollectionTest");
CppUnit_addTest(pSuite, NameValueCollectionTest, testNameValueCollection);
return pSuite;
}