rj_schema 0.2.5 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rj_schema/rapidjson/CMakeLists.txt +23 -1
- data/ext/rj_schema/rapidjson/appveyor.yml +49 -1
- data/ext/rj_schema/rapidjson/bin/types/alotofkeys.json +502 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/address.json +139 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/allOf_address.json +7 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/anyOf_address.json +7 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/idandref.json +69 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/oneOf_address.json +7 -0
- data/ext/rj_schema/rapidjson/doc/stream.md +7 -7
- data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +1 -1
- data/ext/rj_schema/rapidjson/doc/tutorial.md +15 -15
- data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +120 -0
- data/ext/rj_schema/rapidjson/example/traverseaspointer.cpp +39 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +464 -56
- data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/document.h +367 -72
- data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +49 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +56 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +4 -4
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +15 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +69 -2
- data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +77 -12
- data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +17 -9
- data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +558 -259
- data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/uri.h +466 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +3 -3
- data/ext/rj_schema/rapidjson/readme.md +3 -3
- data/ext/rj_schema/rapidjson/readme.zh-cn.md +2 -2
- data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/perftest.h +6 -5
- data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +21 -3
- data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +3 -0
- data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +194 -2
- data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/clzlltest.cpp +34 -0
- data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +3 -1
- data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/platformtest.cpp +40 -0
- data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +95 -3
- data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +4 -1
- data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +961 -81
- data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/unittest.h +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/uritest.cpp +718 -0
- data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +13 -3
- data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +1 -1
- data/ext/rj_schema/rj_schema.cpp +162 -18
- data/lib/rj_schema.rb +1 -1
- metadata +14 -3
@@ -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.
|
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
|
@@ -283,6 +283,8 @@ public:
|
|
283
283
|
os_->Flush();
|
284
284
|
}
|
285
285
|
|
286
|
+
static const size_t kDefaultLevelDepth = 32;
|
287
|
+
|
286
288
|
protected:
|
287
289
|
//! Information for each nested level
|
288
290
|
struct Level {
|
@@ -291,8 +293,6 @@ protected:
|
|
291
293
|
bool inArray; //!< true if in array, otherwise in object
|
292
294
|
};
|
293
295
|
|
294
|
-
static const size_t kDefaultLevelDepth = 32;
|
295
|
-
|
296
296
|
bool WriteNull() {
|
297
297
|
PutReserve(*os_, 4);
|
298
298
|
PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); return true;
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Tencent is pleased to support the open source community by making RapidJSON available.
|
8
8
|
|
9
|
-
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
9
|
+
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
10
10
|
|
11
11
|
* [RapidJSON GitHub](https://github.com/Tencent/rapidjson/)
|
12
12
|
* RapidJSON Documentation
|
@@ -196,7 +196,7 @@ You can copy and paste the license summary from below.
|
|
196
196
|
```
|
197
197
|
Tencent is pleased to support the open source community by making RapidJSON available.
|
198
198
|
|
199
|
-
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
199
|
+
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
200
200
|
|
201
201
|
Licensed under the MIT License (the "License"); you may not use this file except
|
202
202
|
in compliance with the License. You may obtain a copy of the License at
|
@@ -207,4 +207,4 @@ Unless required by applicable law or agreed to in writing, software distributed
|
|
207
207
|
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
208
208
|
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
209
209
|
specific language governing permissions and limitations under the License.
|
210
|
-
```
|
210
|
+
```
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Tencent is pleased to support the open source community by making RapidJSON available.
|
8
8
|
|
9
|
-
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
9
|
+
Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
10
10
|
|
11
11
|
* [RapidJSON GitHub](https://github.com/Tencent/rapidjson/)
|
12
12
|
* RapidJSON 文档
|
@@ -149,4 +149,4 @@ int main() {
|
|
149
149
|
* [prettyauto](https://github.com/Tencent/rapidjson/blob/master/example/prettyauto/prettyauto.cpp): [pretty](https://github.com/Tencent/rapidjson/blob/master/example/pretty/pretty.cpp) 的修改版本,可自动处理任何 UTF 编码的 JSON。
|
150
150
|
* [parsebyparts](https://github.com/Tencent/rapidjson/blob/master/example/parsebyparts/parsebyparts.cpp): 这例子中的 `AsyncDocumentParser` 类使用 C++ 线程来逐段解析 JSON。
|
151
151
|
* [filterkey](https://github.com/Tencent/rapidjson/blob/master/example/filterkey/filterkey.cpp): 移取使用者指定的键值的命令行工具。
|
152
|
-
* [filterkeydom](https://github.com/Tencent/rapidjson/blob/master/example/filterkey/filterkey.cpp): 如上的工具,但展示如何使用生成器(generator)去填充一个 `Document`。
|
152
|
+
* [filterkeydom](https://github.com/Tencent/rapidjson/blob/master/example/filterkey/filterkey.cpp): 如上的工具,但展示如何使用生成器(generator)去填充一个 `Document`。
|
@@ -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.
|
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.
|
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.
|
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
|
@@ -130,7 +130,8 @@ public:
|
|
130
130
|
"integers.json",
|
131
131
|
"mixed.json",
|
132
132
|
"nulls.json",
|
133
|
-
"paragraphs.json"
|
133
|
+
"paragraphs.json",
|
134
|
+
"alotofkeys.json"
|
134
135
|
};
|
135
136
|
|
136
137
|
for (size_t j = 0; j < sizeof(typesfilenames) / sizeof(typesfilenames[0]); j++) {
|
@@ -158,7 +159,7 @@ public:
|
|
158
159
|
free(whitespace_);
|
159
160
|
json_ = 0;
|
160
161
|
whitespace_ = 0;
|
161
|
-
for (size_t i = 0; i <
|
162
|
+
for (size_t i = 0; i < 8; i++) {
|
162
163
|
free(types_[i]);
|
163
164
|
types_[i] = 0;
|
164
165
|
}
|
@@ -174,8 +175,8 @@ protected:
|
|
174
175
|
size_t length_;
|
175
176
|
char *whitespace_;
|
176
177
|
size_t whitespace_length_;
|
177
|
-
char *types_[
|
178
|
-
size_t typesLength_[
|
178
|
+
char *types_[8];
|
179
|
+
size_t typesLength_[8];
|
179
180
|
|
180
181
|
static const size_t kTrialCount = 1000;
|
181
182
|
};
|
@@ -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.
|
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.
|
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
|
@@ -26,6 +26,7 @@
|
|
26
26
|
#include "rapidjson/memorystream.h"
|
27
27
|
|
28
28
|
#include <fstream>
|
29
|
+
#include <vector>
|
29
30
|
|
30
31
|
#ifdef RAPIDJSON_SSE2
|
31
32
|
#define SIMD_SUFFIX(name) name##_SSE2
|
@@ -52,7 +53,7 @@ public:
|
|
52
53
|
// Parse as a document
|
53
54
|
EXPECT_FALSE(doc_.Parse(json_).HasParseError());
|
54
55
|
|
55
|
-
for (size_t i = 0; i <
|
56
|
+
for (size_t i = 0; i < 8; i++)
|
56
57
|
EXPECT_FALSE(typesDoc_[i].Parse(types_[i]).HasParseError());
|
57
58
|
}
|
58
59
|
|
@@ -68,7 +69,7 @@ private:
|
|
68
69
|
protected:
|
69
70
|
char *temp_;
|
70
71
|
Document doc_;
|
71
|
-
Document typesDoc_[
|
72
|
+
Document typesDoc_[8];
|
72
73
|
};
|
73
74
|
|
74
75
|
TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler)) {
|
@@ -335,6 +336,23 @@ TEST_F(RapidJson, DocumentAccept) {
|
|
335
336
|
}
|
336
337
|
}
|
337
338
|
|
339
|
+
TEST_F(RapidJson, DocumentFind) {
|
340
|
+
typedef Document::ValueType ValueType;
|
341
|
+
typedef ValueType::ConstMemberIterator ConstMemberIterator;
|
342
|
+
const Document &doc = typesDoc_[7]; // alotofkeys.json
|
343
|
+
if (doc.IsObject()) {
|
344
|
+
std::vector<const ValueType*> keys;
|
345
|
+
for (ConstMemberIterator it = doc.MemberBegin(); it != doc.MemberEnd(); ++it) {
|
346
|
+
keys.push_back(&it->name);
|
347
|
+
}
|
348
|
+
for (size_t i = 0; i < kTrialCount; i++) {
|
349
|
+
for (size_t j = 0; j < keys.size(); j++) {
|
350
|
+
EXPECT_TRUE(doc.FindMember(*keys[j]) != doc.MemberEnd());
|
351
|
+
}
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
338
356
|
struct NullStream {
|
339
357
|
typedef char Ch;
|
340
358
|
|
@@ -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.
|
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 = ≪
|
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
|
-
|
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.
|
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
|