10
10
#include < plist/Format/JSON.h>
11
11
#include < plist/Objects.h>
12
12
13
- using plist::Format::JSON;
14
- using plist::Format::Encoding;
15
- using plist::String;
13
+ using plist::Array;
16
14
using plist::Boolean;
15
+ using plist::Dictionary;
17
16
using plist::Integer;
18
17
using plist::Real;
19
- using plist::Dictionary;
20
- using plist::Array;
18
+ using plist::String;
19
+ using plist::Format::Encoding;
20
+ using plist::Format::JSON;
21
21
22
- static std::vector<uint8_t >
23
- Contents (std::string const &string)
24
- {
22
+ static std::vector<uint8_t > Contents (std::string const &string) {
25
23
return std::vector<uint8_t >(string.begin (), string.end ());
26
24
}
27
25
28
- TEST (JSON, Serialize)
29
- {
26
+ TEST (JSON, Serialize) {
30
27
auto dictionary = Dictionary::New ();
31
28
dictionary->set (" boolean" , Boolean::New (true ));
32
29
dictionary->set (" integer" , Integer::New (42 ));
33
30
dictionary->set (" real" , Real::New (3.14 ));
34
31
35
32
auto serialize = JSON::Serialize (dictionary.get (), JSON::Create ());
36
33
ASSERT_NE (serialize.first , nullptr );
37
- EXPECT_EQ (*serialize.first , Contents (" {\n\t\" boolean\" : true,\n\t\" integer\" : 42,\n\t\" real\" : 3.14\n }" ));
34
+ EXPECT_EQ (*serialize.first ,
35
+ Contents (" {\n\t\" boolean\" : true,\n\t\" integer\" : "
36
+ " 42,\n\t\" real\" : 3.14\n }" ));
38
37
}
39
38
40
- TEST (JSON, SerializeCollections)
41
- {
39
+ TEST (JSON, SerializeCollections) {
42
40
auto dict = Dictionary::New ();
43
41
dict->set (" one" , String::New (" 1" ));
44
42
dict->set (" two" , Integer::New (1 ));
@@ -53,11 +51,13 @@ TEST(JSON, SerializeCollections)
53
51
54
52
auto serialize = JSON::Serialize (dictionary.get (), JSON::Create ());
55
53
ASSERT_NE (serialize.first , nullptr );
56
- EXPECT_EQ (*serialize.first , Contents (" {\n\t\" dict\" : {\n\t\t\" one\" : \" 1\" ,\n\t\t\" two\" : 1\n\t },\n\t\" array\" : [\n\t\t\" test\" ,\n\t\t 99\n\t ]\n }" ));
54
+ EXPECT_EQ (
55
+ *serialize.first ,
56
+ Contents (" {\n\t\" dict\" : {\n\t\t\" one\" : \" 1\" ,\n\t\t\" two\" : "
57
+ " 1\n\t },\n\t\" array\" : [\n\t\t\" test\" ,\n\t\t 99\n\t ]\n }" ));
57
58
}
58
59
59
- TEST (JSON, String)
60
- {
60
+ TEST (JSON, String) {
61
61
auto contents = Contents (" \" str*ng\" " );
62
62
63
63
auto deserialize = JSON::Deserialize (contents, JSON::Create ());
@@ -69,11 +69,23 @@ TEST(JSON, String)
69
69
auto serialize = JSON::Serialize (deserialize.first .get (), JSON::Create ());
70
70
ASSERT_NE (serialize.first , nullptr );
71
71
EXPECT_EQ (*serialize.first , contents);
72
+
73
+ auto contents2 = Contents (" \" ©\" " );
74
+
75
+ auto deserialize2 = JSON::Deserialize (contents2, JSON::Create ());
76
+ ASSERT_NE (deserialize2.first , nullptr );
77
+
78
+ auto string2 = String::New (" ©" );
79
+ EXPECT_TRUE (deserialize2.first ->equals (string2.get ()));
80
+
81
+ auto serialize2 = JSON::Serialize (deserialize2.first .get (), JSON::Create ());
82
+ ASSERT_NE (serialize2.first , nullptr );
83
+ EXPECT_EQ (*serialize2.first , contents2);
72
84
}
73
85
74
- TEST (JSON, BooleanNumber)
75
- {
76
- auto contents = Contents ( " {\n\t\" boolean\" : true,\n\t\" integer\" : 42,\n\t\" real\" : 3.14\n }" );
86
+ TEST (JSON, BooleanNumber) {
87
+ auto contents = Contents (
88
+ " {\n\t\" boolean\" : true,\n\t\" integer\" : 42,\n\t\" real\" : 3.14\n }" );
77
89
78
90
auto deserialize = JSON::Deserialize (contents, JSON::Create ());
79
91
ASSERT_NE (deserialize.first , nullptr );
@@ -89,24 +101,21 @@ TEST(JSON, BooleanNumber)
89
101
EXPECT_EQ (*serialize.first , contents);
90
102
}
91
103
92
- TEST (JSON, Empty)
93
- {
104
+ TEST (JSON, Empty) {
94
105
auto contents = Contents (" \n\n " );
95
106
96
107
auto deserialize = JSON::Deserialize (contents, JSON::Create ());
97
108
ASSERT_EQ (deserialize.first , nullptr );
98
109
}
99
110
100
- TEST (JSON, SingleQuotes)
101
- {
111
+ TEST (JSON, SingleQuotes) {
102
112
/* Single quotes are not allowed in JSON. */
103
113
auto contents = Contents (" { 'one': 1 }" );
104
114
auto deserialize = JSON::Deserialize (contents, JSON::Create ());
105
115
EXPECT_EQ (deserialize.first , nullptr );
106
116
}
107
117
108
- TEST (JSON, Number)
109
- {
118
+ TEST (JSON, Number) {
110
119
/* Numbers can be zero. */
111
120
auto contents1 = Contents (" { \" key\" : 0 }" );
112
121
auto deserialize1 = JSON::Deserialize (contents1, JSON::Create ());
0 commit comments