rj_schema 0.2.6 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rj_schema/rapidjson/CMakeLists.txt +23 -1
  3. data/ext/rj_schema/rapidjson/appveyor.yml +49 -1
  4. data/ext/rj_schema/rapidjson/bin/types/alotofkeys.json +502 -0
  5. data/ext/rj_schema/rapidjson/bin/unittestschema/address.json +139 -0
  6. data/ext/rj_schema/rapidjson/bin/unittestschema/allOf_address.json +7 -0
  7. data/ext/rj_schema/rapidjson/bin/unittestschema/anyOf_address.json +7 -0
  8. data/ext/rj_schema/rapidjson/bin/unittestschema/idandref.json +69 -0
  9. data/ext/rj_schema/rapidjson/bin/unittestschema/oneOf_address.json +7 -0
  10. data/ext/rj_schema/rapidjson/doc/stream.md +7 -7
  11. data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +1 -1
  12. data/ext/rj_schema/rapidjson/doc/tutorial.md +15 -15
  13. data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +120 -0
  14. data/ext/rj_schema/rapidjson/example/traverseaspointer.cpp +39 -0
  15. data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +464 -56
  16. data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +1 -1
  17. data/ext/rj_schema/rapidjson/include/rapidjson/document.h +367 -72
  18. data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +1 -1
  19. data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +1 -1
  20. data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +49 -1
  21. data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +56 -1
  22. data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +1 -1
  23. data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +1 -1
  24. data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +1 -1
  25. data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +1 -1
  26. data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +4 -4
  27. data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +1 -1
  28. data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +1 -1
  29. data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +1 -1
  30. data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +1 -1
  31. data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +1 -1
  32. data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +1 -1
  33. data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +1 -1
  34. data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +1 -1
  35. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +15 -1
  36. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +1 -1
  37. data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +1 -1
  38. data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +1 -1
  39. data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +1 -1
  40. data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +1 -1
  41. data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +1 -1
  42. data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +69 -2
  43. data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +1 -1
  44. data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +77 -12
  45. data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +17 -9
  46. data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +558 -259
  47. data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +1 -1
  48. data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +1 -1
  49. data/ext/rj_schema/rapidjson/include/rapidjson/uri.h +466 -0
  50. data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +3 -3
  51. data/ext/rj_schema/rapidjson/readme.md +3 -3
  52. data/ext/rj_schema/rapidjson/readme.zh-cn.md +2 -2
  53. data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +1 -1
  54. data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +1 -1
  55. data/ext/rj_schema/rapidjson/test/perftest/perftest.h +6 -5
  56. data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +1 -1
  57. data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +21 -3
  58. data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +3 -0
  59. data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +194 -2
  60. data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +1 -1
  61. data/ext/rj_schema/rapidjson/test/unittest/clzlltest.cpp +34 -0
  62. data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +1 -1
  63. data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +3 -1
  64. data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +1 -1
  65. data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +1 -1
  66. data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +1 -1
  67. data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +1 -1
  68. data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +1 -1
  69. data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +1 -1
  70. data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +1 -1
  71. data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +1 -1
  72. data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +1 -1
  73. data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +1 -1
  74. data/ext/rj_schema/rapidjson/test/unittest/platformtest.cpp +40 -0
  75. data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +95 -3
  76. data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +1 -1
  77. data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +4 -1
  78. data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +1 -1
  79. data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +961 -81
  80. data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +1 -1
  81. data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +1 -1
  82. data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +1 -1
  83. data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +1 -1
  84. data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +1 -1
  85. data/ext/rj_schema/rapidjson/test/unittest/unittest.h +1 -1
  86. data/ext/rj_schema/rapidjson/test/unittest/uritest.cpp +718 -0
  87. data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +13 -3
  88. data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +1 -1
  89. data/ext/rj_schema/rj_schema.cpp +161 -17
  90. data/lib/rj_schema.rb +1 -1
  91. metadata +14 -3
@@ -3,6 +3,7 @@ include(CheckCXXCompilerFlag)
3
3
  set(UNITTEST_SOURCES
4
4
  allocatorstest.cpp
5
5
  bigintegertest.cpp
6
+ clzlltest.cpp
6
7
  cursorstreamwrappertest.cpp
7
8
  documenttest.cpp
8
9
  dtoatest.cpp
@@ -15,6 +16,7 @@ set(UNITTEST_SOURCES
15
16
  jsoncheckertest.cpp
16
17
  namespacetest.cpp
17
18
  pointertest.cpp
19
+ platformtest.cpp
18
20
  prettywritertest.cpp
19
21
  ostreamwrappertest.cpp
20
22
  readertest.cpp
@@ -25,6 +27,7 @@ set(UNITTEST_SOURCES
25
27
  stringbuffertest.cpp
26
28
  strtodtest.cpp
27
29
  unittest.cpp
30
+ uritest.cpp
28
31
  valuetest.cpp
29
32
  writertest.cpp)
30
33
 
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -16,6 +16,11 @@
16
16
 
17
17
  #include "rapidjson/allocators.h"
18
18
 
19
+ #include <map>
20
+ #include <string>
21
+ #include <utility>
22
+ #include <functional>
23
+
19
24
  using namespace rapidjson;
20
25
 
21
26
  template <typename Allocator>
@@ -47,19 +52,206 @@ void TestAllocator(Allocator& a) {
47
52
  EXPECT_TRUE(a.Realloc(a.Malloc(1), 1, 0) == 0);
48
53
  }
49
54
 
55
+ struct TestStdAllocatorData {
56
+ TestStdAllocatorData(int &constructions, int &destructions) :
57
+ constructions_(&constructions),
58
+ destructions_(&destructions)
59
+ {
60
+ ++*constructions_;
61
+ }
62
+ TestStdAllocatorData(const TestStdAllocatorData& rhs) :
63
+ constructions_(rhs.constructions_),
64
+ destructions_(rhs.destructions_)
65
+ {
66
+ ++*constructions_;
67
+ }
68
+ TestStdAllocatorData& operator=(const TestStdAllocatorData& rhs)
69
+ {
70
+ this->~TestStdAllocatorData();
71
+ constructions_ = rhs.constructions_;
72
+ destructions_ = rhs.destructions_;
73
+ ++*constructions_;
74
+ return *this;
75
+ }
76
+ ~TestStdAllocatorData()
77
+ {
78
+ ++*destructions_;
79
+ }
80
+ private:
81
+ TestStdAllocatorData();
82
+ int *constructions_,
83
+ *destructions_;
84
+ };
85
+
86
+ template <typename Allocator>
87
+ void TestStdAllocator(const Allocator& a) {
88
+ #if RAPIDJSON_HAS_CXX17
89
+ typedef StdAllocator<bool, Allocator> BoolAllocator;
90
+ #else
91
+ typedef StdAllocator<void, Allocator> VoidAllocator;
92
+ typedef typename VoidAllocator::template rebind<bool>::other BoolAllocator;
93
+ #endif
94
+ BoolAllocator ba(a), ba2(a);
95
+ EXPECT_TRUE(ba == ba2);
96
+ EXPECT_FALSE(ba!= ba2);
97
+ ba.deallocate(ba.allocate());
98
+ EXPECT_TRUE(ba == ba2);
99
+ EXPECT_FALSE(ba != ba2);
100
+
101
+ unsigned long long ll = 0, *llp = &ll;
102
+ const unsigned long long cll = 0, *cllp = &cll;
103
+ StdAllocator<unsigned long long, Allocator> lla(a);
104
+ EXPECT_EQ(lla.address(ll), llp);
105
+ EXPECT_EQ(lla.address(cll), cllp);
106
+ EXPECT_TRUE(lla.max_size() > 0 && lla.max_size() <= SIZE_MAX / sizeof(unsigned long long));
107
+
108
+ int *arr;
109
+ StdAllocator<int, Allocator> ia(a);
110
+ arr = ia.allocate(10 * sizeof(int));
111
+ EXPECT_TRUE(arr != 0);
112
+ for (int i = 0; i < 10; ++i) {
113
+ arr[i] = 0x0f0f0f0f;
114
+ }
115
+ ia.deallocate(arr, 10);
116
+ arr = Malloc<int>(ia, 10);
117
+ EXPECT_TRUE(arr != 0);
118
+ for (int i = 0; i < 10; ++i) {
119
+ arr[i] = 0x0f0f0f0f;
120
+ }
121
+ arr = Realloc<int>(ia, arr, 10, 20);
122
+ EXPECT_TRUE(arr != 0);
123
+ for (int i = 0; i < 10; ++i) {
124
+ EXPECT_EQ(arr[i], 0x0f0f0f0f);
125
+ }
126
+ for (int i = 10; i < 20; i++) {
127
+ arr[i] = 0x0f0f0f0f;
128
+ }
129
+ Free<int>(ia, arr, 20);
130
+
131
+ int cons = 0, dest = 0;
132
+ StdAllocator<TestStdAllocatorData, Allocator> da(a);
133
+ for (int i = 1; i < 10; i++) {
134
+ TestStdAllocatorData *d = da.allocate();
135
+ EXPECT_TRUE(d != 0);
136
+
137
+ da.destroy(new(d) TestStdAllocatorData(cons, dest));
138
+ EXPECT_EQ(cons, i);
139
+ EXPECT_EQ(dest, i);
140
+
141
+ da.deallocate(d);
142
+ }
143
+
144
+ typedef StdAllocator<char, Allocator> CharAllocator;
145
+ typedef std::basic_string<char, std::char_traits<char>, CharAllocator> String;
146
+ #if RAPIDJSON_HAS_CXX11
147
+ String s(CharAllocator{a});
148
+ #else
149
+ CharAllocator ca(a);
150
+ String s(ca);
151
+ #endif
152
+ for (int i = 0; i < 26; i++) {
153
+ s.push_back(static_cast<char>('A' + i));
154
+ }
155
+ EXPECT_TRUE(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
156
+
157
+ typedef StdAllocator<std::pair<const int, bool>, Allocator> MapAllocator;
158
+ typedef std::map<int, bool, std::less<int>, MapAllocator> Map;
159
+ #if RAPIDJSON_HAS_CXX11
160
+ Map map(std::less<int>(), MapAllocator{a});
161
+ #else
162
+ MapAllocator ma(a);
163
+ Map map(std::less<int>(), ma);
164
+ #endif
165
+ for (int i = 0; i < 10; i++) {
166
+ map.insert(std::make_pair(i, (i % 2) == 0));
167
+ }
168
+ EXPECT_TRUE(map.size() == 10);
169
+ for (int i = 0; i < 10; i++) {
170
+ typename Map::iterator it = map.find(i);
171
+ EXPECT_TRUE(it != map.end());
172
+ EXPECT_TRUE(it->second == ((i % 2) == 0));
173
+ }
174
+ }
175
+
50
176
  TEST(Allocator, CrtAllocator) {
51
177
  CrtAllocator a;
178
+
52
179
  TestAllocator(a);
180
+ TestStdAllocator(a);
181
+
182
+ CrtAllocator a2;
183
+ EXPECT_TRUE(a == a2);
184
+ EXPECT_FALSE(a != a2);
185
+ a2.Free(a2.Malloc(1));
186
+ EXPECT_TRUE(a == a2);
187
+ EXPECT_FALSE(a != a2);
53
188
  }
54
189
 
55
190
  TEST(Allocator, MemoryPoolAllocator) {
56
- MemoryPoolAllocator<> a;
191
+ const size_t capacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY;
192
+ MemoryPoolAllocator<> a(capacity);
193
+
194
+ a.Clear(); // noop
195
+ EXPECT_EQ(a.Size(), 0u);
196
+ EXPECT_EQ(a.Capacity(), 0u);
197
+ EXPECT_EQ(a.Shared(), false);
198
+ {
199
+ MemoryPoolAllocator<> a2(a);
200
+ EXPECT_EQ(a2.Shared(), true);
201
+ EXPECT_EQ(a.Shared(), true);
202
+ EXPECT_TRUE(a == a2);
203
+ EXPECT_FALSE(a != a2);
204
+ a2.Free(a2.Malloc(1));
205
+ EXPECT_TRUE(a == a2);
206
+ EXPECT_FALSE(a != a2);
207
+ }
208
+ EXPECT_EQ(a.Shared(), false);
209
+ EXPECT_EQ(a.Capacity(), capacity);
210
+ EXPECT_EQ(a.Size(), 8u); // aligned
211
+ a.Clear();
212
+ EXPECT_EQ(a.Capacity(), 0u);
213
+ EXPECT_EQ(a.Size(), 0u);
214
+
57
215
  TestAllocator(a);
216
+ TestStdAllocator(a);
58
217
 
59
218
  for (size_t i = 1; i < 1000; i++) {
60
219
  EXPECT_TRUE(a.Malloc(i) != 0);
61
220
  EXPECT_LE(a.Size(), a.Capacity());
62
221
  }
222
+
223
+ CrtAllocator baseAllocator;
224
+ a = MemoryPoolAllocator<>(capacity, &baseAllocator);
225
+ EXPECT_EQ(a.Capacity(), 0u);
226
+ EXPECT_EQ(a.Size(), 0u);
227
+ a.Free(a.Malloc(1));
228
+ EXPECT_EQ(a.Capacity(), capacity);
229
+ EXPECT_EQ(a.Size(), 8u); // aligned
230
+
231
+ {
232
+ a.Clear();
233
+ const size_t bufSize = 1024;
234
+ char *buffer = (char *)a.Malloc(bufSize);
235
+ MemoryPoolAllocator<> aligned_a(buffer, bufSize);
236
+ EXPECT_TRUE(aligned_a.Capacity() > 0 && aligned_a.Capacity() <= bufSize);
237
+ EXPECT_EQ(aligned_a.Size(), 0u);
238
+ aligned_a.Free(aligned_a.Malloc(1));
239
+ EXPECT_TRUE(aligned_a.Capacity() > 0 && aligned_a.Capacity() <= bufSize);
240
+ EXPECT_EQ(aligned_a.Size(), 8u); // aligned
241
+ }
242
+
243
+ {
244
+ a.Clear();
245
+ const size_t bufSize = 1024;
246
+ char *buffer = (char *)a.Malloc(bufSize);
247
+ RAPIDJSON_ASSERT(bufSize % sizeof(void*) == 0);
248
+ MemoryPoolAllocator<> unaligned_a(buffer + 1, bufSize - 1);
249
+ EXPECT_TRUE(unaligned_a.Capacity() > 0 && unaligned_a.Capacity() <= bufSize - sizeof(void*));
250
+ EXPECT_EQ(unaligned_a.Size(), 0u);
251
+ unaligned_a.Free(unaligned_a.Malloc(1));
252
+ EXPECT_TRUE(unaligned_a.Capacity() > 0 && unaligned_a.Capacity() <= bufSize - sizeof(void*));
253
+ EXPECT_EQ(unaligned_a.Size(), 8u); // aligned
254
+ }
63
255
  }
64
256
 
65
257
  TEST(Allocator, Alignment) {
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -0,0 +1,34 @@
1
+ // Tencent is pleased to support the open source community by making RapidJSON available.
2
+ //
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
+ //
5
+ // Licensed under the MIT License (the "License"); you may not use this file except
6
+ // in compliance with the License. You may obtain a copy of the License at
7
+ //
8
+ // http://opensource.org/licenses/MIT
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software distributed
11
+ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
+ // specific language governing permissions and limitations under the License.
14
+
15
+ #include "unittest.h"
16
+ #include "rapidjson/internal/clzll.h"
17
+
18
+ #ifdef __GNUC__
19
+ RAPIDJSON_DIAG_PUSH
20
+ #endif
21
+
22
+ using namespace rapidjson::internal;
23
+
24
+ TEST(clzll, normal) {
25
+ EXPECT_EQ(clzll(1), 63U);
26
+ EXPECT_EQ(clzll(2), 62U);
27
+ EXPECT_EQ(clzll(12), 60U);
28
+ EXPECT_EQ(clzll(0x0000000080000001UL), 32U);
29
+ EXPECT_EQ(clzll(0x8000000000000001UL), 0U);
30
+ }
31
+
32
+ #ifdef __GNUC__
33
+ RAPIDJSON_DIAG_POP
34
+ #endif
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -325,6 +325,8 @@ TEST(Document, Swap) {
325
325
  EXPECT_TRUE(d1.IsNull());
326
326
 
327
327
  // reset document, including allocator
328
+ // so clear o before so that it doesnt contain dangling elements
329
+ o.Clear();
328
330
  Document().Swap(d2);
329
331
  EXPECT_TRUE(d2.IsNull());
330
332
  EXPECT_NE(&d2.GetAllocator(), &a);
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -0,0 +1,40 @@
1
+ // Tencent is pleased to support the open source community by making RapidJSON available.
2
+ //
3
+ // Copyright (C) 2021 THL A29 Limited, a Tencent company, and Milo Yip.
4
+ //
5
+ // Licensed under the MIT License (the "License"); you may not use this file except
6
+ // in compliance with the License. You may obtain a copy of the License at
7
+ //
8
+ // http://opensource.org/licenses/MIT
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software distributed
11
+ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
+ // specific language governing permissions and limitations under the License.
14
+
15
+ #include "unittest.h"
16
+
17
+ // see https://github.com/Tencent/rapidjson/issues/1448
18
+ // including windows.h on purpose to provoke a compile time problem as GetObject is a
19
+ // macro that gets defined when windows.h is included
20
+ #ifdef _WIN32
21
+ #include <windows.h>
22
+ #endif
23
+
24
+ #include "rapidjson/document.h"
25
+ #undef GetObject
26
+
27
+ using namespace rapidjson;
28
+
29
+ TEST(Platform, GetObject) {
30
+ Document doc;
31
+ doc.Parse(" { \"object\" : { \"pi\": 3.1416} } ");
32
+ EXPECT_TRUE(doc.IsObject());
33
+ EXPECT_TRUE(doc.HasMember("object"));
34
+ const Document::ValueType& o = doc["object"];
35
+ EXPECT_TRUE(o.IsObject());
36
+ Value::ConstObject sub = o.GetObject();
37
+ EXPECT_TRUE(sub.HasMember("pi"));
38
+ Value::ConstObject sub2 = o.GetObj();
39
+ EXPECT_TRUE(sub2.HasMember("pi"));
40
+ }
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -475,7 +475,9 @@ TEST(Pointer, CopyConstructor) {
475
475
  EXPECT_EQ(1u, q.GetTokens()[1].length);
476
476
  EXPECT_STREQ("0", q.GetTokens()[1].name);
477
477
  EXPECT_EQ(0u, q.GetTokens()[1].index);
478
- EXPECT_EQ(&p.GetAllocator(), &q.GetAllocator());
478
+
479
+ // Copied pointer needs to have its own allocator
480
+ EXPECT_NE(&p.GetAllocator(), &q.GetAllocator());
479
481
  }
480
482
 
481
483
  // Static tokens
@@ -648,6 +650,52 @@ TEST(Pointer, Create) {
648
650
  }
649
651
  }
650
652
 
653
+ static const char kJsonIds[] = "{\n"
654
+ " \"id\": \"/root/\","
655
+ " \"foo\":[\"bar\", \"baz\", {\"id\": \"inarray\", \"child\": 1}],\n"
656
+ " \"int\" : 2,\n"
657
+ " \"str\" : \"val\",\n"
658
+ " \"obj\": {\"id\": \"inobj\", \"child\": 3},\n"
659
+ " \"jbo\": {\"id\": true, \"child\": 4}\n"
660
+ "}";
661
+
662
+
663
+ TEST(Pointer, GetUri) {
664
+ CrtAllocator allocator;
665
+ Document d;
666
+ d.Parse(kJsonIds);
667
+ Pointer::UriType doc("http://doc");
668
+ Pointer::UriType root("http://doc/root/");
669
+ Pointer::UriType empty = Pointer::UriType();
670
+
671
+ EXPECT_TRUE(Pointer("").GetUri(d, doc) == doc);
672
+ EXPECT_TRUE(Pointer("/foo").GetUri(d, doc) == root);
673
+ EXPECT_TRUE(Pointer("/foo/0").GetUri(d, doc) == root);
674
+ EXPECT_TRUE(Pointer("/foo/2").GetUri(d, doc) == root);
675
+ EXPECT_TRUE(Pointer("/foo/2/child").GetUri(d, doc) == Pointer::UriType("http://doc/root/inarray"));
676
+ EXPECT_TRUE(Pointer("/int").GetUri(d, doc) == root);
677
+ EXPECT_TRUE(Pointer("/str").GetUri(d, doc) == root);
678
+ EXPECT_TRUE(Pointer("/obj").GetUri(d, doc) == root);
679
+ EXPECT_TRUE(Pointer("/obj/child").GetUri(d, doc) == Pointer::UriType("http://doc/root/inobj"));
680
+ EXPECT_TRUE(Pointer("/jbo").GetUri(d, doc) == root);
681
+ EXPECT_TRUE(Pointer("/jbo/child").GetUri(d, doc) == root); // id not string
682
+
683
+ size_t unresolvedTokenIndex;
684
+ EXPECT_TRUE(Pointer("/abc").GetUri(d, doc, &unresolvedTokenIndex, &allocator) == empty); // Out of boundary
685
+ EXPECT_EQ(0u, unresolvedTokenIndex);
686
+ EXPECT_TRUE(Pointer("/foo/3").GetUri(d, doc, &unresolvedTokenIndex, &allocator) == empty); // Out of boundary
687
+ EXPECT_EQ(1u, unresolvedTokenIndex);
688
+ EXPECT_TRUE(Pointer("/foo/a").GetUri(d, doc, &unresolvedTokenIndex, &allocator) == empty); // "/foo" is an array, cannot query by "a"
689
+ EXPECT_EQ(1u, unresolvedTokenIndex);
690
+ EXPECT_TRUE(Pointer("/foo/0/0").GetUri(d, doc, &unresolvedTokenIndex, &allocator) == empty); // "/foo/0" is an string, cannot further query
691
+ EXPECT_EQ(2u, unresolvedTokenIndex);
692
+ EXPECT_TRUE(Pointer("/foo/0/a").GetUri(d, doc, &unresolvedTokenIndex, &allocator) == empty); // "/foo/0" is an string, cannot further query
693
+ EXPECT_EQ(2u, unresolvedTokenIndex);
694
+
695
+ Pointer::Token tokens[] = { { "foo ...", 3, kPointerInvalidIndex } };
696
+ EXPECT_TRUE(Pointer(tokens, 1).GetUri(d, doc) == root);
697
+ }
698
+
651
699
  TEST(Pointer, Get) {
652
700
  Document d;
653
701
  d.Parse(kJson);
@@ -664,7 +712,8 @@ TEST(Pointer, Get) {
664
712
  EXPECT_EQ(&d["k\"l"], Pointer("/k\"l").Get(d));
665
713
  EXPECT_EQ(&d[" "], Pointer("/ ").Get(d));
666
714
  EXPECT_EQ(&d["m~n"], Pointer("/m~0n").Get(d));
667
- EXPECT_TRUE(Pointer("/abc").Get(d) == 0);
715
+
716
+ EXPECT_TRUE(Pointer("/abc").Get(d) == 0); // Out of boundary
668
717
  size_t unresolvedTokenIndex;
669
718
  EXPECT_TRUE(Pointer("/foo/2").Get(d, &unresolvedTokenIndex) == 0); // Out of boundary
670
719
  EXPECT_EQ(1u, unresolvedTokenIndex);
@@ -1529,6 +1578,38 @@ TEST(Pointer, Ambiguity) {
1529
1578
  }
1530
1579
  }
1531
1580
 
1581
+ TEST(Pointer, ResolveOnObject) {
1582
+ Document d;
1583
+ EXPECT_FALSE(d.Parse("{\"a\": 123}").HasParseError());
1584
+
1585
+ {
1586
+ Value::ConstObject o = static_cast<const Document&>(d).GetObject();
1587
+ EXPECT_EQ(123, Pointer("/a").Get(o)->GetInt());
1588
+ }
1589
+
1590
+ {
1591
+ Value::Object o = d.GetObject();
1592
+ Pointer("/a").Set(o, 456, d.GetAllocator());
1593
+ EXPECT_EQ(456, Pointer("/a").Get(o)->GetInt());
1594
+ }
1595
+ }
1596
+
1597
+ TEST(Pointer, ResolveOnArray) {
1598
+ Document d;
1599
+ EXPECT_FALSE(d.Parse("[1, 2, 3]").HasParseError());
1600
+
1601
+ {
1602
+ Value::ConstArray a = static_cast<const Document&>(d).GetArray();
1603
+ EXPECT_EQ(2, Pointer("/1").Get(a)->GetInt());
1604
+ }
1605
+
1606
+ {
1607
+ Value::Array a = d.GetArray();
1608
+ Pointer("/1").Set(a, 123, d.GetAllocator());
1609
+ EXPECT_EQ(123, Pointer("/1").Get(a)->GetInt());
1610
+ }
1611
+ }
1612
+
1532
1613
  TEST(Pointer, LessThan) {
1533
1614
  static const struct {
1534
1615
  const char *str;
@@ -1636,3 +1717,14 @@ TEST(Pointer, Issue483) {
1636
1717
  value.SetString(mystr.c_str(), static_cast<SizeType>(mystr.length()), document.GetAllocator());
1637
1718
  myjson::Pointer(path.c_str()).Set(document, value, document.GetAllocator());
1638
1719
  }
1720
+
1721
+ TEST(Pointer, Issue1899) {
1722
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
1723
+ PointerType p;
1724
+ PointerType q = p.Append("foo");
1725
+ EXPECT_TRUE(PointerType("/foo") == q);
1726
+ q = q.Append(1234);
1727
+ EXPECT_TRUE(PointerType("/foo/1234") == q);
1728
+ q = q.Append("");
1729
+ EXPECT_TRUE(PointerType("/foo/1234/") == q);
1730
+ }
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at
@@ -944,6 +944,9 @@ TEST(Reader, ParseString_Error) {
944
944
  TEST_STRING_ERROR(kParseErrorStringUnicodeSurrogateInvalid, "[\"\\uD800X\"]", 2u, 8u);
945
945
  TEST_STRING_ERROR(kParseErrorStringUnicodeSurrogateInvalid, "[\"\\uD800\\uFFFF\"]", 2u, 14u);
946
946
 
947
+ // Single low surrogate pair in string is invalid.
948
+ TEST_STRING_ERROR(kParseErrorStringUnicodeSurrogateInvalid, "[\"\\udc4d\"]", 2u, 8u);
949
+
947
950
  // Missing a closing quotation mark in string.
948
951
  TEST_STRING_ERROR(kParseErrorStringMissQuotationMark, "[\"Test]", 7u, 7u);
949
952
 
@@ -1,6 +1,6 @@
1
1
  // Tencent is pleased to support the open source community by making RapidJSON available.
2
2
  //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
4
  //
5
5
  // Licensed under the MIT License (the "License"); you may not use this file except
6
6
  // in compliance with the License. You may obtain a copy of the License at