forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONTest.h
More file actions
133 lines (113 loc) · 3 KB
/
JSONTest.h
File metadata and controls
133 lines (113 loc) · 3 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
//
// JSONTest.h
//
// Definition of the JSONTest class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef JSONTest_INCLUDED
#define JSONTest_INCLUDED
#include "Poco/JSON/JSON.h"
#include "Poco/CppUnit/TestCase.h"
#include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h"
#include "Poco/JSON/Query.h"
#include "Poco/JSON/JSONException.h"
#include "Poco/JSON/Stringifier.h"
#include "Poco/JSON/ParseHandler.h"
#include "Poco/JSON/PrintHandler.h"
#include "Poco/JSON/Template.h"
#include <sstream>
class JSONTest: public CppUnit::TestCase
{
public:
JSONTest(const std::string& name);
~JSONTest();
void testNullProperty();
void testTrueProperty();
void testFalseProperty();
void testNumberProperty();
void testUnsignedNumberProperty();
#if defined(POCO_HAVE_INT64)
void testNumber64Property();
void testUnsignedNumber64Property();
#endif
void testStringProperty();
void testEmptyObject();
void testEmptyPropertyName();
void testComplexObject();
void testDoubleProperty();
void testDouble2Property();
void testDouble3Property();
void testObjectProperty();
void testObjectArray();
void testArrayOfObjects();
void testEmptyArray();
void testNestedArray();
void testNullElement();
void testTrueElement();
void testFalseElement();
void testNumberElement();
void testStringElement();
void testEmptyObjectElement();
void testDoubleElement();
void testSetArrayElement();
void testOptValue();
void testQuery();
void testComment();
void testPrintHandler();
void testStringify();
void testStringifyPreserveOrder();
void testValidJanssonFiles();
void testInvalidJanssonFiles();
void testTemplate();
void testUnicode();
void testInvalidUnicodeJanssonFiles();
void testSmallBuffer();
void testEscape0();
void testNonEscapeUnicode();
void testEscapeUnicode();
void testCopy();
void testMove();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
std::string getTestFilesPath(const std::string& type);
template <typename T>
void testNumber(T number)
{
std::ostringstream os;
os << "{ \"test\" : " << number << " }";
std::string json = os.str();
Poco::JSON::Parser parser;
Poco::Dynamic::Var result;
try
{
result = parser.parse(json);
}
catch (Poco::JSON::JSONException& jsone)
{
std::cout << jsone.message() << std::endl;
assertTrue (false);
}
assertTrue (result.type() == typeid(Poco::JSON::Object::Ptr));
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
Poco::Dynamic::Var test = object->get("test");
assertTrue (test.isNumeric());
T value = test;
assertTrue (value == number);
Poco::DynamicStruct ds = *object;
assertTrue (!ds["test"].isEmpty());
assertTrue (ds["test"].isNumeric());
assertTrue (ds["test"] == number);
const Poco::DynamicStruct& rds = *object;
assertTrue (!rds["test"].isEmpty());
assertTrue (rds["test"].isNumeric());
assertTrue (rds["test"] == number);
}
};
#endif // JSONTest_INCLUDED