rj_schema 0.2.6 → 1.0.0
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/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/oneOf_address.json +7 -0
- data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +118 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +5 -5
- data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/document.h +17 -12
- 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 +1 -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 +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +17 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +17 -9
- data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +311 -159
- 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/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 +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +1 -0
- data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +1 -1
- 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 +1 -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/pointertest.cpp +33 -1
- 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 +593 -78
- 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/valuetest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +1 -1
- data/ext/rj_schema/rj_schema.cpp +160 -16
- data/lib/rj_schema.rb +1 -1
- metadata +8 -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -1529,6 +1529,38 @@ TEST(Pointer, Ambiguity) {
|
|
1529
1529
|
}
|
1530
1530
|
}
|
1531
1531
|
|
1532
|
+
TEST(Pointer, ResolveOnObject) {
|
1533
|
+
Document d;
|
1534
|
+
EXPECT_FALSE(d.Parse("{\"a\": 123}").HasParseError());
|
1535
|
+
|
1536
|
+
{
|
1537
|
+
Value::ConstObject o = static_cast<const Document&>(d).GetObject();
|
1538
|
+
EXPECT_EQ(123, Pointer("/a").Get(o)->GetInt());
|
1539
|
+
}
|
1540
|
+
|
1541
|
+
{
|
1542
|
+
Value::Object o = d.GetObject();
|
1543
|
+
Pointer("/a").Set(o, 456, d.GetAllocator());
|
1544
|
+
EXPECT_EQ(456, Pointer("/a").Get(o)->GetInt());
|
1545
|
+
}
|
1546
|
+
}
|
1547
|
+
|
1548
|
+
TEST(Pointer, ResolveOnArray) {
|
1549
|
+
Document d;
|
1550
|
+
EXPECT_FALSE(d.Parse("[1, 2, 3]").HasParseError());
|
1551
|
+
|
1552
|
+
{
|
1553
|
+
Value::ConstArray a = static_cast<const Document&>(d).GetArray();
|
1554
|
+
EXPECT_EQ(2, Pointer("/1").Get(a)->GetInt());
|
1555
|
+
}
|
1556
|
+
|
1557
|
+
{
|
1558
|
+
Value::Array a = d.GetArray();
|
1559
|
+
Pointer("/1").Set(a, 123, d.GetAllocator());
|
1560
|
+
EXPECT_EQ(123, Pointer("/1").Get(a)->GetInt());
|
1561
|
+
}
|
1562
|
+
}
|
1563
|
+
|
1532
1564
|
TEST(Pointer, LessThan) {
|
1533
1565
|
static const struct {
|
1534
1566
|
const char *str;
|
@@ -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
|
@@ -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.
|
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
|
@@ -12,10 +12,14 @@
|
|
12
12
|
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
13
|
// specific language governing permissions and limitations under the License.
|
14
14
|
|
15
|
+
#define RAPIDJSON_SCHEMA_VERBOSE 0
|
16
|
+
|
15
17
|
#include "unittest.h"
|
16
18
|
#include "rapidjson/schema.h"
|
17
19
|
#include "rapidjson/stringbuffer.h"
|
18
20
|
#include "rapidjson/writer.h"
|
21
|
+
#include "rapidjson/error/error.h"
|
22
|
+
#include "rapidjson/error/en.h"
|
19
23
|
|
20
24
|
#ifdef __clang__
|
21
25
|
RAPIDJSON_DIAG_PUSH
|
@@ -114,11 +118,18 @@ TEST(SchemaValidator, Hasher) {
|
|
114
118
|
EXPECT_FALSE(d.HasParseError());\
|
115
119
|
EXPECT_TRUE(expected == d.Accept(validator));\
|
116
120
|
EXPECT_TRUE(expected == validator.IsValid());\
|
121
|
+
ValidateErrorCode code = validator.GetInvalidSchemaCode();\
|
122
|
+
if (expected) {\
|
123
|
+
EXPECT_TRUE(code == kValidateErrorNone);\
|
124
|
+
EXPECT_TRUE(validator.GetInvalidSchemaKeyword() == 0);\
|
125
|
+
}\
|
117
126
|
if ((expected) && !validator.IsValid()) {\
|
118
127
|
StringBuffer sb;\
|
119
128
|
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);\
|
120
129
|
printf("Invalid schema: %s\n", sb.GetString());\
|
121
130
|
printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());\
|
131
|
+
printf("Invalid code: %d\n", code);\
|
132
|
+
printf("Invalid message: %s\n", GetValidateError_En(code));\
|
122
133
|
sb.Clear();\
|
123
134
|
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);\
|
124
135
|
printf("Invalid document: %s\n", sb.GetString());\
|
@@ -131,19 +142,23 @@ TEST(SchemaValidator, Hasher) {
|
|
131
142
|
|
132
143
|
#define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error) \
|
133
144
|
{\
|
134
|
-
INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, SchemaValidator, Pointer) \
|
145
|
+
INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, kValidateDefaultFlags, SchemaValidator, Pointer) \
|
135
146
|
}
|
136
147
|
|
137
148
|
#define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, \
|
138
|
-
SchemaValidatorType, PointerType) \
|
149
|
+
flags, SchemaValidatorType, PointerType) \
|
139
150
|
{\
|
140
151
|
SchemaValidatorType validator(schema);\
|
152
|
+
validator.SetValidateFlags(flags);\
|
141
153
|
Document d;\
|
142
154
|
/*printf("\n%s\n", json);*/\
|
143
155
|
d.Parse(json);\
|
144
156
|
EXPECT_FALSE(d.HasParseError());\
|
145
|
-
|
157
|
+
d.Accept(validator);\
|
146
158
|
EXPECT_FALSE(validator.IsValid());\
|
159
|
+
ValidateErrorCode code = validator.GetInvalidSchemaCode();\
|
160
|
+
ASSERT_TRUE(code != kValidateErrorNone);\
|
161
|
+
ASSERT_TRUE(strcmp(GetValidateError_En(code), "Unknown error.") != 0);\
|
147
162
|
if (validator.GetInvalidSchemaPointer() != PointerType(invalidSchemaPointer)) {\
|
148
163
|
StringBuffer sb;\
|
149
164
|
validator.GetInvalidSchemaPointer().Stringify(sb);\
|
@@ -191,6 +206,7 @@ TEST(SchemaValidator, MultiType) {
|
|
191
206
|
VALIDATE(s, "\"Life, the universe, and everything\"", true);
|
192
207
|
INVALIDATE(s, "[\"Life\", \"the universe\", \"and everything\"]", "", "type", "",
|
193
208
|
"{ \"type\": {"
|
209
|
+
" \"errorCode\": 20,"
|
194
210
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
195
211
|
" \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
|
196
212
|
"}}");
|
@@ -203,7 +219,7 @@ TEST(SchemaValidator, Enum_Typed) {
|
|
203
219
|
|
204
220
|
VALIDATE(s, "\"red\"", true);
|
205
221
|
INVALIDATE(s, "\"blue\"", "", "enum", "",
|
206
|
-
"{ \"enum\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
222
|
+
"{ \"enum\": { \"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
207
223
|
}
|
208
224
|
|
209
225
|
TEST(SchemaValidator, Enum_Typless) {
|
@@ -215,7 +231,7 @@ TEST(SchemaValidator, Enum_Typless) {
|
|
215
231
|
VALIDATE(s, "null", true);
|
216
232
|
VALIDATE(s, "42", true);
|
217
233
|
INVALIDATE(s, "0", "", "enum", "",
|
218
|
-
"{ \"enum\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
234
|
+
"{ \"enum\": { \"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
219
235
|
}
|
220
236
|
|
221
237
|
TEST(SchemaValidator, Enum_InvalidType) {
|
@@ -226,6 +242,7 @@ TEST(SchemaValidator, Enum_InvalidType) {
|
|
226
242
|
VALIDATE(s, "\"red\"", true);
|
227
243
|
INVALIDATE(s, "null", "", "type", "",
|
228
244
|
"{ \"type\": {"
|
245
|
+
" \"errorCode\": 20,"
|
229
246
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
230
247
|
" \"expected\": [\"string\"], \"actual\": \"null\""
|
231
248
|
"}}");
|
@@ -239,9 +256,12 @@ TEST(SchemaValidator, AllOf) {
|
|
239
256
|
|
240
257
|
VALIDATE(s, "\"ok\"", true);
|
241
258
|
INVALIDATE(s, "\"too long\"", "", "allOf", "",
|
242
|
-
"{ \"
|
243
|
-
" \"
|
244
|
-
"
|
259
|
+
"{ \"allOf\": {"
|
260
|
+
" \"errors\": ["
|
261
|
+
" {},"
|
262
|
+
" {\"maxLength\": {\"errorCode\": 6, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", \"expected\": 5, \"actual\": \"too long\"}}"
|
263
|
+
" ],"
|
264
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
245
265
|
"}}");
|
246
266
|
}
|
247
267
|
{
|
@@ -251,8 +271,12 @@ TEST(SchemaValidator, AllOf) {
|
|
251
271
|
|
252
272
|
VALIDATE(s, "\"No way\"", false);
|
253
273
|
INVALIDATE(s, "-1", "", "allOf", "",
|
254
|
-
"{ \"
|
255
|
-
" \"
|
274
|
+
"{ \"allOf\": {"
|
275
|
+
" \"errors\": ["
|
276
|
+
" {\"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\", \"errorCode\": 20, \"expected\": [\"string\"], \"actual\": \"integer\"}},"
|
277
|
+
" {}"
|
278
|
+
" ],"
|
279
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
256
280
|
"}}");
|
257
281
|
}
|
258
282
|
}
|
@@ -266,13 +290,16 @@ TEST(SchemaValidator, AnyOf) {
|
|
266
290
|
VALIDATE(s, "42", true);
|
267
291
|
INVALIDATE(s, "{ \"Not a\": \"string or number\" }", "", "anyOf", "",
|
268
292
|
"{ \"anyOf\": {"
|
293
|
+
" \"errorCode\": 24,"
|
269
294
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
|
270
295
|
" \"errors\": ["
|
271
296
|
" { \"type\": {"
|
297
|
+
" \"errorCode\": 20,"
|
272
298
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/0\","
|
273
299
|
" \"expected\": [\"string\"], \"actual\": \"object\""
|
274
300
|
" }},"
|
275
301
|
" { \"type\": {"
|
302
|
+
" \"errorCode\": 20,"
|
276
303
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/1\","
|
277
304
|
" \"expected\": [\"number\"], \"actual\": \"object\""
|
278
305
|
" }}"
|
@@ -289,20 +316,23 @@ TEST(SchemaValidator, OneOf) {
|
|
289
316
|
VALIDATE(s, "9", true);
|
290
317
|
INVALIDATE(s, "2", "", "oneOf", "",
|
291
318
|
"{ \"oneOf\": {"
|
319
|
+
" \"errorCode\": 21,"
|
292
320
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
293
321
|
" \"errors\": ["
|
294
322
|
" { \"multipleOf\": {"
|
323
|
+
" \"errorCode\": 1,"
|
295
324
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/0\","
|
296
325
|
" \"expected\": 5, \"actual\": 2"
|
297
326
|
" }},"
|
298
327
|
" { \"multipleOf\": {"
|
328
|
+
" \"errorCode\": 1,"
|
299
329
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/1\","
|
300
330
|
" \"expected\": 3, \"actual\": 2"
|
301
331
|
" }}"
|
302
332
|
" ]"
|
303
333
|
"}}");
|
304
334
|
INVALIDATE(s, "15", "", "oneOf", "",
|
305
|
-
"{ \"oneOf\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"errors\": [{}, {}]}}");
|
335
|
+
"{ \"oneOf\": { \"errorCode\": 22, \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"errors\": [{}, {}]}}");
|
306
336
|
}
|
307
337
|
|
308
338
|
TEST(SchemaValidator, Not) {
|
@@ -313,7 +343,7 @@ TEST(SchemaValidator, Not) {
|
|
313
343
|
VALIDATE(s, "42", true);
|
314
344
|
VALIDATE(s, "{ \"key\": \"value\" }", true);
|
315
345
|
INVALIDATE(s, "\"I am a string\"", "", "not", "",
|
316
|
-
"{ \"not\": { \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
346
|
+
"{ \"not\": { \"errorCode\": 25, \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
|
317
347
|
}
|
318
348
|
|
319
349
|
TEST(SchemaValidator, Ref) {
|
@@ -378,10 +408,12 @@ TEST(SchemaValidator, Ref_AllOf) {
|
|
378
408
|
SchemaDocument s(sd);
|
379
409
|
|
380
410
|
INVALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"} }", "/properties/shipping_address", "allOf", "/shipping_address",
|
381
|
-
"{ \"
|
382
|
-
" \"
|
383
|
-
"
|
384
|
-
"
|
411
|
+
"{ \"allOf\": {"
|
412
|
+
" \"errors\": ["
|
413
|
+
" {},"
|
414
|
+
" {\"required\": {\"errorCode\": 15, \"instanceRef\": \"#/shipping_address\", \"schemaRef\": \"#/properties/shipping_address/allOf/1\", \"missing\": [\"type\"]}}"
|
415
|
+
" ],"
|
416
|
+
" \"errorCode\":23,\"instanceRef\":\"#/shipping_address\",\"schemaRef\":\"#/properties/shipping_address\""
|
385
417
|
"}}");
|
386
418
|
VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\", \"type\": \"business\"} }", true);
|
387
419
|
}
|
@@ -394,26 +426,31 @@ TEST(SchemaValidator, String) {
|
|
394
426
|
VALIDATE(s, "\"I'm a string\"", true);
|
395
427
|
INVALIDATE(s, "42", "", "type", "",
|
396
428
|
"{ \"type\": {"
|
429
|
+
" \"errorCode\": 20,"
|
397
430
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
398
431
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
399
432
|
"}}");
|
400
433
|
INVALIDATE(s, "2147483648", "", "type", "",
|
401
434
|
"{ \"type\": {"
|
435
|
+
" \"errorCode\": 20,"
|
402
436
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
403
437
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
404
438
|
"}}"); // 2^31 can only be fit in unsigned
|
405
439
|
INVALIDATE(s, "-2147483649", "", "type", "",
|
406
440
|
"{ \"type\": {"
|
441
|
+
" \"errorCode\": 20,"
|
407
442
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
408
443
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
409
444
|
"}}"); // -2^31 - 1 can only be fit in int64_t
|
410
445
|
INVALIDATE(s, "4294967296", "", "type", "",
|
411
446
|
"{ \"type\": {"
|
447
|
+
" \"errorCode\": 20,"
|
412
448
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
413
449
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
414
450
|
"}}"); // 2^32 can only be fit in int64_t
|
415
451
|
INVALIDATE(s, "3.1415926", "", "type", "",
|
416
452
|
"{ \"type\": {"
|
453
|
+
" \"errorCode\": 20,"
|
417
454
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
418
455
|
" \"expected\": [\"string\"], \"actual\": \"number\""
|
419
456
|
"}}");
|
@@ -426,6 +463,7 @@ TEST(SchemaValidator, String_LengthRange) {
|
|
426
463
|
|
427
464
|
INVALIDATE(s, "\"A\"", "", "minLength", "",
|
428
465
|
"{ \"minLength\": {"
|
466
|
+
" \"errorCode\": 7,"
|
429
467
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
430
468
|
" \"expected\": 2, \"actual\": \"A\""
|
431
469
|
"}}");
|
@@ -433,6 +471,7 @@ TEST(SchemaValidator, String_LengthRange) {
|
|
433
471
|
VALIDATE(s, "\"ABC\"", true);
|
434
472
|
INVALIDATE(s, "\"ABCD\"", "", "maxLength", "",
|
435
473
|
"{ \"maxLength\": {"
|
474
|
+
" \"errorCode\": 6,"
|
436
475
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
437
476
|
" \"expected\": 3, \"actual\": \"ABCD\""
|
438
477
|
"}}");
|
@@ -448,11 +487,13 @@ TEST(SchemaValidator, String_Pattern) {
|
|
448
487
|
VALIDATE(s, "\"(888)555-1212\"", true);
|
449
488
|
INVALIDATE(s, "\"(888)555-1212 ext. 532\"", "", "pattern", "",
|
450
489
|
"{ \"pattern\": {"
|
490
|
+
" \"errorCode\": 8,"
|
451
491
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
452
492
|
" \"actual\": \"(888)555-1212 ext. 532\""
|
453
493
|
"}}");
|
454
494
|
INVALIDATE(s, "\"(800)FLOWERS\"", "", "pattern", "",
|
455
495
|
"{ \"pattern\": {"
|
496
|
+
" \"errorCode\": 8,"
|
456
497
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
457
498
|
" \"actual\": \"(800)FLOWERS\""
|
458
499
|
"}}");
|
@@ -482,11 +523,13 @@ TEST(SchemaValidator, Integer) {
|
|
482
523
|
VALIDATE(s, "4294967296", true); // 2^32 can only be fit in int64_t
|
483
524
|
INVALIDATE(s, "3.1415926", "", "type", "",
|
484
525
|
"{ \"type\": {"
|
526
|
+
" \"errorCode\": 20,"
|
485
527
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
486
528
|
" \"expected\": [\"integer\"], \"actual\": \"number\""
|
487
529
|
"}}");
|
488
530
|
INVALIDATE(s, "\"42\"", "", "type", "",
|
489
531
|
"{ \"type\": {"
|
532
|
+
" \"errorCode\": 20,"
|
490
533
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
491
534
|
" \"expected\": [\"integer\"], \"actual\": \"string\""
|
492
535
|
"}}");
|
@@ -499,6 +542,7 @@ TEST(SchemaValidator, Integer_Range) {
|
|
499
542
|
|
500
543
|
INVALIDATE(s, "-1", "", "minimum", "",
|
501
544
|
"{ \"minimum\": {"
|
545
|
+
" \"errorCode\": 4,"
|
502
546
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
503
547
|
" \"expected\": 0, \"actual\": -1"
|
504
548
|
"}}");
|
@@ -507,11 +551,13 @@ TEST(SchemaValidator, Integer_Range) {
|
|
507
551
|
VALIDATE(s, "99", true);
|
508
552
|
INVALIDATE(s, "100", "", "maximum", "",
|
509
553
|
"{ \"maximum\": {"
|
554
|
+
" \"errorCode\": 3,"
|
510
555
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
511
556
|
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
|
512
557
|
"}}");
|
513
558
|
INVALIDATE(s, "101", "", "maximum", "",
|
514
559
|
"{ \"maximum\": {"
|
560
|
+
" \"errorCode\": 3,"
|
515
561
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
516
562
|
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101"
|
517
563
|
"}}");
|
@@ -524,6 +570,7 @@ TEST(SchemaValidator, Integer_Range64Boundary) {
|
|
524
570
|
|
525
571
|
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
526
572
|
"{ \"minimum\": {"
|
573
|
+
" \"errorCode\": 4,"
|
527
574
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
528
575
|
" \"expected\": -9223372036854775807, \"actual\": -9223372036854775808"
|
529
576
|
"}}");
|
@@ -536,11 +583,13 @@ TEST(SchemaValidator, Integer_Range64Boundary) {
|
|
536
583
|
VALIDATE(s, "9223372036854775806", true);
|
537
584
|
INVALIDATE(s, "9223372036854775807", "", "maximum", "",
|
538
585
|
"{ \"maximum\": {"
|
586
|
+
" \"errorCode\": 2,"
|
539
587
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
540
588
|
" \"expected\": 9223372036854775806, \"actual\": 9223372036854775807"
|
541
589
|
"}}");
|
542
590
|
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
543
591
|
"{ \"maximum\": {"
|
592
|
+
" \"errorCode\": 2,"
|
544
593
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
545
594
|
" \"expected\": 9223372036854775806, \"actual\": 18446744073709551615"
|
546
595
|
"}}"); // uint64_t max
|
@@ -553,36 +602,43 @@ TEST(SchemaValidator, Integer_RangeU64Boundary) {
|
|
553
602
|
|
554
603
|
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
555
604
|
"{ \"minimum\": {"
|
605
|
+
" \"errorCode\": 4,"
|
556
606
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
557
607
|
" \"expected\": 9223372036854775808, \"actual\": -9223372036854775808"
|
558
608
|
"}}");
|
559
609
|
INVALIDATE(s, "9223372036854775807", "", "minimum", "",
|
560
610
|
"{ \"minimum\": {"
|
611
|
+
" \"errorCode\": 4,"
|
561
612
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
562
613
|
" \"expected\": 9223372036854775808, \"actual\": 9223372036854775807"
|
563
614
|
"}}");
|
564
615
|
INVALIDATE(s, "-2147483648", "", "minimum", "",
|
565
616
|
"{ \"minimum\": {"
|
617
|
+
" \"errorCode\": 4,"
|
566
618
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
567
619
|
" \"expected\": 9223372036854775808, \"actual\": -2147483648"
|
568
620
|
"}}"); // int min
|
569
621
|
INVALIDATE(s, "0", "", "minimum", "",
|
570
622
|
"{ \"minimum\": {"
|
623
|
+
" \"errorCode\": 4,"
|
571
624
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
572
625
|
" \"expected\": 9223372036854775808, \"actual\": 0"
|
573
626
|
"}}");
|
574
627
|
INVALIDATE(s, "2147483647", "", "minimum", "",
|
575
628
|
"{ \"minimum\": {"
|
629
|
+
" \"errorCode\": 4,"
|
576
630
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
577
631
|
" \"expected\": 9223372036854775808, \"actual\": 2147483647"
|
578
632
|
"}}"); // int max
|
579
633
|
INVALIDATE(s, "2147483648", "", "minimum", "",
|
580
634
|
"{ \"minimum\": {"
|
635
|
+
" \"errorCode\": 4,"
|
581
636
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
582
637
|
" \"expected\": 9223372036854775808, \"actual\": 2147483648"
|
583
638
|
"}}"); // unsigned first
|
584
639
|
INVALIDATE(s, "4294967295", "", "minimum", "",
|
585
640
|
"{ \"minimum\": {"
|
641
|
+
" \"errorCode\": 4,"
|
586
642
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
587
643
|
" \"expected\": 9223372036854775808, \"actual\": 4294967295"
|
588
644
|
"}}"); // unsigned max
|
@@ -590,6 +646,7 @@ TEST(SchemaValidator, Integer_RangeU64Boundary) {
|
|
590
646
|
VALIDATE(s, "18446744073709551614", true);
|
591
647
|
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
592
648
|
"{ \"maximum\": {"
|
649
|
+
" \"errorCode\": 2,"
|
593
650
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
594
651
|
" \"expected\": 18446744073709551614, \"actual\": 18446744073709551615"
|
595
652
|
"}}");
|
@@ -602,6 +659,7 @@ TEST(SchemaValidator, Integer_Range64BoundaryExclusive) {
|
|
602
659
|
|
603
660
|
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
604
661
|
"{ \"minimum\": {"
|
662
|
+
" \"errorCode\": 5,"
|
605
663
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
606
664
|
" \"expected\": -9223372036854775808, \"exclusiveMinimum\": true, "
|
607
665
|
" \"actual\": -9223372036854775808"
|
@@ -610,6 +668,7 @@ TEST(SchemaValidator, Integer_Range64BoundaryExclusive) {
|
|
610
668
|
VALIDATE(s, "18446744073709551614", true);
|
611
669
|
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
612
670
|
"{ \"maximum\": {"
|
671
|
+
" \"errorCode\": 3,"
|
613
672
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
614
673
|
" \"expected\": 18446744073709551615, \"exclusiveMaximum\": true, "
|
615
674
|
" \"actual\": 18446744073709551615"
|
@@ -627,11 +686,13 @@ TEST(SchemaValidator, Integer_MultipleOf) {
|
|
627
686
|
VALIDATE(s, "20", true);
|
628
687
|
INVALIDATE(s, "23", "", "multipleOf", "",
|
629
688
|
"{ \"multipleOf\": {"
|
689
|
+
" \"errorCode\": 1,"
|
630
690
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
631
691
|
" \"expected\": 10, \"actual\": 23"
|
632
692
|
"}}");
|
633
693
|
INVALIDATE(s, "-23", "", "multipleOf", "",
|
634
694
|
"{ \"multipleOf\": {"
|
695
|
+
" \"errorCode\": 1,"
|
635
696
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
636
697
|
" \"expected\": 10, \"actual\": -23"
|
637
698
|
"}}");
|
@@ -646,6 +707,7 @@ TEST(SchemaValidator, Integer_MultipleOf64Boundary) {
|
|
646
707
|
VALIDATE(s, "18446744073709551615", true);
|
647
708
|
INVALIDATE(s, "18446744073709551614", "", "multipleOf", "",
|
648
709
|
"{ \"multipleOf\": {"
|
710
|
+
" \"errorCode\": 1,"
|
649
711
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
650
712
|
" \"expected\": 18446744073709551615, \"actual\": 18446744073709551614"
|
651
713
|
"}}");
|
@@ -658,6 +720,7 @@ TEST(SchemaValidator, Number_Range) {
|
|
658
720
|
|
659
721
|
INVALIDATE(s, "-1", "", "minimum", "",
|
660
722
|
"{ \"minimum\": {"
|
723
|
+
" \"errorCode\": 4,"
|
661
724
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
662
725
|
" \"expected\": 0, \"actual\": -1"
|
663
726
|
"}}");
|
@@ -668,16 +731,19 @@ TEST(SchemaValidator, Number_Range) {
|
|
668
731
|
VALIDATE(s, "99.9", true);
|
669
732
|
INVALIDATE(s, "100", "", "maximum", "",
|
670
733
|
"{ \"maximum\": {"
|
734
|
+
" \"errorCode\": 3,"
|
671
735
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
672
736
|
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
|
673
737
|
"}}");
|
674
738
|
INVALIDATE(s, "100.0", "", "maximum", "",
|
675
739
|
"{ \"maximum\": {"
|
740
|
+
" \"errorCode\": 3,"
|
676
741
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
677
742
|
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100.0"
|
678
743
|
"}}");
|
679
744
|
INVALIDATE(s, "101.5", "", "maximum", "",
|
680
745
|
"{ \"maximum\": {"
|
746
|
+
" \"errorCode\": 3,"
|
681
747
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
682
748
|
" \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101.5"
|
683
749
|
"}}");
|
@@ -690,11 +756,13 @@ TEST(SchemaValidator, Number_RangeInt) {
|
|
690
756
|
|
691
757
|
INVALIDATE(s, "-101", "", "minimum", "",
|
692
758
|
"{ \"minimum\": {"
|
759
|
+
" \"errorCode\": 4,"
|
693
760
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
694
761
|
" \"expected\": -100, \"actual\": -101"
|
695
762
|
"}}");
|
696
763
|
INVALIDATE(s, "-100.1", "", "minimum", "",
|
697
764
|
"{ \"minimum\": {"
|
765
|
+
" \"errorCode\": 4,"
|
698
766
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
699
767
|
" \"expected\": -100, \"actual\": -100.1"
|
700
768
|
"}}");
|
@@ -702,46 +770,55 @@ TEST(SchemaValidator, Number_RangeInt) {
|
|
702
770
|
VALIDATE(s, "-2", true);
|
703
771
|
INVALIDATE(s, "-1", "", "maximum", "",
|
704
772
|
"{ \"maximum\": {"
|
773
|
+
" \"errorCode\": 3,"
|
705
774
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
706
775
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -1"
|
707
776
|
"}}");
|
708
777
|
INVALIDATE(s, "-0.9", "", "maximum", "",
|
709
778
|
"{ \"maximum\": {"
|
779
|
+
" \"errorCode\": 3,"
|
710
780
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
711
781
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -0.9"
|
712
782
|
"}}");
|
713
783
|
INVALIDATE(s, "0", "", "maximum", "",
|
714
784
|
"{ \"maximum\": {"
|
785
|
+
" \"errorCode\": 3,"
|
715
786
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
716
787
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 0"
|
717
788
|
"}}");
|
718
789
|
INVALIDATE(s, "2147483647", "", "maximum", "",
|
719
790
|
"{ \"maximum\": {"
|
791
|
+
" \"errorCode\": 3,"
|
720
792
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
721
793
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
|
722
794
|
"}}"); // int max
|
723
795
|
INVALIDATE(s, "2147483648", "", "maximum", "",
|
724
796
|
"{ \"maximum\": {"
|
797
|
+
" \"errorCode\": 3,"
|
725
798
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
726
799
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
|
727
800
|
"}}"); // unsigned first
|
728
801
|
INVALIDATE(s, "4294967295", "", "maximum", "",
|
729
802
|
"{ \"maximum\": {"
|
803
|
+
" \"errorCode\": 3,"
|
730
804
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
731
805
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
|
732
806
|
"}}"); // unsigned max
|
733
807
|
INVALIDATE(s, "9223372036854775808", "", "maximum", "",
|
734
808
|
"{ \"maximum\": {"
|
809
|
+
" \"errorCode\": 3,"
|
735
810
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
736
811
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
|
737
812
|
"}}");
|
738
813
|
INVALIDATE(s, "18446744073709551614", "", "maximum", "",
|
739
814
|
"{ \"maximum\": {"
|
815
|
+
" \"errorCode\": 3,"
|
740
816
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
741
817
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
|
742
818
|
"}}");
|
743
819
|
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
744
820
|
"{ \"maximum\": {"
|
821
|
+
" \"errorCode\": 3,"
|
745
822
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
746
823
|
" \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
|
747
824
|
"}}");
|
@@ -754,16 +831,19 @@ TEST(SchemaValidator, Number_RangeDouble) {
|
|
754
831
|
|
755
832
|
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
756
833
|
"{ \"minimum\": {"
|
834
|
+
" \"errorCode\": 4,"
|
757
835
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
758
836
|
" \"expected\": 0.1, \"actual\": -9223372036854775808"
|
759
837
|
"}}");
|
760
838
|
INVALIDATE(s, "-2147483648", "", "minimum", "",
|
761
839
|
"{ \"minimum\": {"
|
840
|
+
" \"errorCode\": 4,"
|
762
841
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
763
842
|
" \"expected\": 0.1, \"actual\": -2147483648"
|
764
843
|
"}}"); // int min
|
765
844
|
INVALIDATE(s, "-1", "", "minimum", "",
|
766
845
|
"{ \"minimum\": {"
|
846
|
+
" \"errorCode\": 4,"
|
767
847
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
768
848
|
" \"expected\": 0.1, \"actual\": -1"
|
769
849
|
"}}");
|
@@ -773,51 +853,61 @@ TEST(SchemaValidator, Number_RangeDouble) {
|
|
773
853
|
VALIDATE(s, "100", true);
|
774
854
|
INVALIDATE(s, "101", "", "maximum", "",
|
775
855
|
"{ \"maximum\": {"
|
856
|
+
" \"errorCode\": 3,"
|
776
857
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
777
858
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101"
|
778
859
|
"}}");
|
779
860
|
INVALIDATE(s, "101.5", "", "maximum", "",
|
780
861
|
"{ \"maximum\": {"
|
862
|
+
" \"errorCode\": 3,"
|
781
863
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
782
864
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101.5"
|
783
865
|
"}}");
|
784
866
|
INVALIDATE(s, "18446744073709551614", "", "maximum", "",
|
785
867
|
"{ \"maximum\": {"
|
868
|
+
" \"errorCode\": 3,"
|
786
869
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
787
870
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
|
788
871
|
"}}");
|
789
872
|
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
790
873
|
"{ \"maximum\": {"
|
874
|
+
" \"errorCode\": 3,"
|
791
875
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
792
876
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
|
793
877
|
"}}");
|
794
878
|
INVALIDATE(s, "2147483647", "", "maximum", "",
|
795
879
|
"{ \"maximum\": {"
|
880
|
+
" \"errorCode\": 3,"
|
796
881
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
797
882
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
|
798
883
|
"}}"); // int max
|
799
884
|
INVALIDATE(s, "2147483648", "", "maximum", "",
|
800
885
|
"{ \"maximum\": {"
|
886
|
+
" \"errorCode\": 3,"
|
801
887
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
802
888
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
|
803
889
|
"}}"); // unsigned first
|
804
890
|
INVALIDATE(s, "4294967295", "", "maximum", "",
|
805
891
|
"{ \"maximum\": {"
|
892
|
+
" \"errorCode\": 3,"
|
806
893
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
807
894
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
|
808
895
|
"}}"); // unsigned max
|
809
896
|
INVALIDATE(s, "9223372036854775808", "", "maximum", "",
|
810
897
|
"{ \"maximum\": {"
|
898
|
+
" \"errorCode\": 3,"
|
811
899
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
812
900
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
|
813
901
|
"}}");
|
814
902
|
INVALIDATE(s, "18446744073709551614", "", "maximum", "",
|
815
903
|
"{ \"maximum\": {"
|
904
|
+
" \"errorCode\": 3,"
|
816
905
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
817
906
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
|
818
907
|
"}}");
|
819
908
|
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
820
909
|
"{ \"maximum\": {"
|
910
|
+
" \"errorCode\": 3,"
|
821
911
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
822
912
|
" \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
|
823
913
|
"}}");
|
@@ -830,31 +920,37 @@ TEST(SchemaValidator, Number_RangeDoubleU64Boundary) {
|
|
830
920
|
|
831
921
|
INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
|
832
922
|
"{ \"minimum\": {"
|
923
|
+
" \"errorCode\": 4,"
|
833
924
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
834
925
|
" \"expected\": 9223372036854775808.0, \"actual\": -9223372036854775808"
|
835
926
|
"}}");
|
836
927
|
INVALIDATE(s, "-2147483648", "", "minimum", "",
|
837
928
|
"{ \"minimum\": {"
|
929
|
+
" \"errorCode\": 4,"
|
838
930
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
839
931
|
" \"expected\": 9223372036854775808.0, \"actual\": -2147483648"
|
840
932
|
"}}"); // int min
|
841
933
|
INVALIDATE(s, "0", "", "minimum", "",
|
842
934
|
"{ \"minimum\": {"
|
935
|
+
" \"errorCode\": 4,"
|
843
936
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
844
937
|
" \"expected\": 9223372036854775808.0, \"actual\": 0"
|
845
938
|
"}}");
|
846
939
|
INVALIDATE(s, "2147483647", "", "minimum", "",
|
847
940
|
"{ \"minimum\": {"
|
941
|
+
" \"errorCode\": 4,"
|
848
942
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
849
943
|
" \"expected\": 9223372036854775808.0, \"actual\": 2147483647"
|
850
944
|
"}}"); // int max
|
851
945
|
INVALIDATE(s, "2147483648", "", "minimum", "",
|
852
946
|
"{ \"minimum\": {"
|
947
|
+
" \"errorCode\": 4,"
|
853
948
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
854
949
|
" \"expected\": 9223372036854775808.0, \"actual\": 2147483648"
|
855
950
|
"}}"); // unsigned first
|
856
951
|
INVALIDATE(s, "4294967295", "", "minimum", "",
|
857
952
|
"{ \"minimum\": {"
|
953
|
+
" \"errorCode\": 4,"
|
858
954
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
859
955
|
" \"expected\": 9223372036854775808.0, \"actual\": 4294967295"
|
860
956
|
"}}"); // unsigned max
|
@@ -862,6 +958,7 @@ TEST(SchemaValidator, Number_RangeDoubleU64Boundary) {
|
|
862
958
|
VALIDATE(s, "18446744073709540000", true);
|
863
959
|
INVALIDATE(s, "18446744073709551615", "", "maximum", "",
|
864
960
|
"{ \"maximum\": {"
|
961
|
+
" \"errorCode\": 2,"
|
865
962
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
866
963
|
" \"expected\": 18446744073709550000.0, \"actual\": 18446744073709551615"
|
867
964
|
"}}");
|
@@ -878,28 +975,33 @@ TEST(SchemaValidator, Number_MultipleOf) {
|
|
878
975
|
VALIDATE(s, "20", true);
|
879
976
|
INVALIDATE(s, "23", "", "multipleOf", "",
|
880
977
|
"{ \"multipleOf\": {"
|
978
|
+
" \"errorCode\": 1,"
|
881
979
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
882
980
|
" \"expected\": 10.0, \"actual\": 23"
|
883
981
|
"}}");
|
884
982
|
INVALIDATE(s, "-2147483648", "", "multipleOf", "",
|
885
983
|
"{ \"multipleOf\": {"
|
984
|
+
" \"errorCode\": 1,"
|
886
985
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
887
986
|
" \"expected\": 10.0, \"actual\": -2147483648"
|
888
987
|
"}}"); // int min
|
889
988
|
VALIDATE(s, "-2147483640", true);
|
890
989
|
INVALIDATE(s, "2147483647", "", "multipleOf", "",
|
891
990
|
"{ \"multipleOf\": {"
|
991
|
+
" \"errorCode\": 1,"
|
892
992
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
893
993
|
" \"expected\": 10.0, \"actual\": 2147483647"
|
894
994
|
"}}"); // int max
|
895
995
|
INVALIDATE(s, "2147483648", "", "multipleOf", "",
|
896
996
|
"{ \"multipleOf\": {"
|
997
|
+
" \"errorCode\": 1,"
|
897
998
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
898
999
|
" \"expected\": 10.0, \"actual\": 2147483648"
|
899
1000
|
"}}"); // unsigned first
|
900
1001
|
VALIDATE(s, "2147483650", true);
|
901
1002
|
INVALIDATE(s, "4294967295", "", "multipleOf", "",
|
902
1003
|
"{ \"multipleOf\": {"
|
1004
|
+
" \"errorCode\": 1,"
|
903
1005
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
904
1006
|
" \"expected\": 10.0, \"actual\": 4294967295"
|
905
1007
|
"}}"); // unsigned max
|
@@ -915,6 +1017,7 @@ TEST(SchemaValidator, Number_MultipleOfOne) {
|
|
915
1017
|
VALIDATE(s, "42.0", true);
|
916
1018
|
INVALIDATE(s, "3.1415926", "", "multipleOf", "",
|
917
1019
|
"{ \"multipleOf\": {"
|
1020
|
+
" \"errorCode\": 1,"
|
918
1021
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
919
1022
|
" \"expected\": 1, \"actual\": 3.1415926"
|
920
1023
|
"}}");
|
@@ -929,11 +1032,13 @@ TEST(SchemaValidator, Object) {
|
|
929
1032
|
VALIDATE(s, "{\"Sun\":1.9891e30,\"Jupiter\":1.8986e27,\"Saturn\":5.6846e26,\"Neptune\":10.243e25,\"Uranus\":8.6810e25,\"Earth\":5.9736e24,\"Venus\":4.8685e24,\"Mars\":6.4185e23,\"Mercury\":3.3022e23,\"Moon\":7.349e22,\"Pluto\":1.25e22}", true);
|
930
1033
|
INVALIDATE(s, "[\"An\", \"array\", \"not\", \"an\", \"object\"]", "", "type", "",
|
931
1034
|
"{ \"type\": {"
|
1035
|
+
" \"errorCode\": 20,"
|
932
1036
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
933
1037
|
" \"expected\": [\"object\"], \"actual\": \"array\""
|
934
1038
|
"}}");
|
935
1039
|
INVALIDATE(s, "\"Not an object\"", "", "type", "",
|
936
1040
|
"{ \"type\": {"
|
1041
|
+
" \"errorCode\": 20,"
|
937
1042
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
938
1043
|
" \"expected\": [\"object\"], \"actual\": \"string\""
|
939
1044
|
"}}");
|
@@ -956,12 +1061,14 @@ TEST(SchemaValidator, Object_Properties) {
|
|
956
1061
|
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
|
957
1062
|
INVALIDATE(s, "{ \"number\": \"1600\", \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", "/properties/number", "type", "/number",
|
958
1063
|
"{ \"type\": {"
|
1064
|
+
" \"errorCode\": 20,"
|
959
1065
|
" \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
|
960
1066
|
" \"expected\": [\"number\"], \"actual\": \"string\""
|
961
1067
|
"}}");
|
962
1068
|
INVALIDATE(s, "{ \"number\": \"One\", \"street_name\": \"Microsoft\", \"street_type\": \"Way\" }",
|
963
1069
|
"/properties/number", "type", "/number",
|
964
1070
|
"{ \"type\": {"
|
1071
|
+
" \"errorCode\": 20,"
|
965
1072
|
" \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
|
966
1073
|
" \"expected\": [\"number\"], \"actual\": \"string\""
|
967
1074
|
"}}"); // fail fast
|
@@ -990,6 +1097,7 @@ TEST(SchemaValidator, Object_AdditionalPropertiesBoolean) {
|
|
990
1097
|
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
|
991
1098
|
INVALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", "", "additionalProperties", "/direction",
|
992
1099
|
"{ \"additionalProperties\": {"
|
1100
|
+
" \"errorCode\": 16,"
|
993
1101
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
994
1102
|
" \"disallowed\": \"direction\""
|
995
1103
|
"}}");
|
@@ -1015,6 +1123,7 @@ TEST(SchemaValidator, Object_AdditionalPropertiesObject) {
|
|
1015
1123
|
VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", true);
|
1016
1124
|
INVALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"office_number\": 201 }", "/additionalProperties", "type", "/office_number",
|
1017
1125
|
"{ \"type\": {"
|
1126
|
+
" \"errorCode\": 20,"
|
1018
1127
|
" \"instanceRef\": \"#/office_number\", \"schemaRef\": \"#/additionalProperties\","
|
1019
1128
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1020
1129
|
"}}");
|
@@ -1039,11 +1148,13 @@ TEST(SchemaValidator, Object_Required) {
|
|
1039
1148
|
VALIDATE(s, "{ \"name\": \"William Shakespeare\", \"email\" : \"bill@stratford-upon-avon.co.uk\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\", \"authorship\" : \"in question\"}", true);
|
1040
1149
|
INVALIDATE(s, "{ \"name\": \"William Shakespeare\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\" }", "", "required", "",
|
1041
1150
|
"{ \"required\": {"
|
1151
|
+
" \"errorCode\": 15,"
|
1042
1152
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1043
1153
|
" \"missing\": [\"email\"]"
|
1044
1154
|
"}}");
|
1045
1155
|
INVALIDATE(s, "{}", "", "required", "",
|
1046
1156
|
"{ \"required\": {"
|
1157
|
+
" \"errorCode\": 15,"
|
1047
1158
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1048
1159
|
" \"missing\": [\"name\", \"email\"]"
|
1049
1160
|
"}}");
|
@@ -1067,11 +1178,13 @@ TEST(SchemaValidator, Object_Required_PassWithDefault) {
|
|
1067
1178
|
VALIDATE(s, "{ \"email\" : \"bill@stratford-upon-avon.co.uk\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\", \"authorship\" : \"in question\"}", true);
|
1068
1179
|
INVALIDATE(s, "{ \"name\": \"William Shakespeare\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\" }", "", "required", "",
|
1069
1180
|
"{ \"required\": {"
|
1181
|
+
" \"errorCode\": 15,"
|
1070
1182
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1071
1183
|
" \"missing\": [\"email\"]"
|
1072
1184
|
"}}");
|
1073
1185
|
INVALIDATE(s, "{}", "", "required", "",
|
1074
1186
|
"{ \"required\": {"
|
1187
|
+
" \"errorCode\": 15,"
|
1075
1188
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1076
1189
|
" \"missing\": [\"email\"]"
|
1077
1190
|
"}}");
|
@@ -1084,11 +1197,13 @@ TEST(SchemaValidator, Object_PropertiesRange) {
|
|
1084
1197
|
|
1085
1198
|
INVALIDATE(s, "{}", "", "minProperties", "",
|
1086
1199
|
"{ \"minProperties\": {"
|
1200
|
+
" \"errorCode\": 14,"
|
1087
1201
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1088
1202
|
" \"expected\": 2, \"actual\": 0"
|
1089
1203
|
"}}");
|
1090
1204
|
INVALIDATE(s, "{\"a\":0}", "", "minProperties", "",
|
1091
1205
|
"{ \"minProperties\": {"
|
1206
|
+
" \"errorCode\": 14,"
|
1092
1207
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1093
1208
|
" \"expected\": 2, \"actual\": 1"
|
1094
1209
|
"}}");
|
@@ -1096,6 +1211,7 @@ TEST(SchemaValidator, Object_PropertiesRange) {
|
|
1096
1211
|
VALIDATE(s, "{\"a\":0,\"b\":1,\"c\":2}", true);
|
1097
1212
|
INVALIDATE(s, "{\"a\":0,\"b\":1,\"c\":2,\"d\":3}", "", "maxProperties", "",
|
1098
1213
|
"{ \"maxProperties\": {"
|
1214
|
+
" \"errorCode\": 13,"
|
1099
1215
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
|
1100
1216
|
" \"expected\": 3, \"actual\": 4"
|
1101
1217
|
"}}");
|
@@ -1123,8 +1239,15 @@ TEST(SchemaValidator, Object_PropertyDependencies) {
|
|
1123
1239
|
"\"billing_address\": \"555 Debtor's Lane\" }", true);
|
1124
1240
|
INVALIDATE(s, "{ \"name\": \"John Doe\", \"credit_card\": 5555555555555555 }", "", "dependencies", "",
|
1125
1241
|
"{ \"dependencies\": {"
|
1242
|
+
" \"errorCode\": 18,"
|
1126
1243
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1127
|
-
" \"errors\": {
|
1244
|
+
" \"errors\": {"
|
1245
|
+
" \"credit_card\": {"
|
1246
|
+
" \"required\": {"
|
1247
|
+
" \"errorCode\": 15,"
|
1248
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/credit_card\","
|
1249
|
+
" \"missing\": [\"cvv_code\", \"billing_address\"]"
|
1250
|
+
" } } }"
|
1128
1251
|
"}}");
|
1129
1252
|
VALIDATE(s, "{ \"name\": \"John Doe\"}", true);
|
1130
1253
|
VALIDATE(s, "{ \"name\": \"John Doe\", \"cvv_code\": 777, \"billing_address\": \"555 Debtor's Lane\" }", true);
|
@@ -1154,10 +1277,12 @@ TEST(SchemaValidator, Object_SchemaDependencies) {
|
|
1154
1277
|
VALIDATE(s, "{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555,\"billing_address\" : \"555 Debtor's Lane\"}", true);
|
1155
1278
|
INVALIDATE(s, "{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555 }", "", "dependencies", "",
|
1156
1279
|
"{ \"dependencies\": {"
|
1280
|
+
" \"errorCode\": 18,"
|
1157
1281
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1158
1282
|
" \"errors\": {"
|
1159
1283
|
" \"credit_card\": {"
|
1160
1284
|
" \"required\": {"
|
1285
|
+
" \"errorCode\": 15,"
|
1161
1286
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/credit_card\","
|
1162
1287
|
" \"missing\": [\"billing_address\"]"
|
1163
1288
|
" } } }"
|
@@ -1182,18 +1307,20 @@ TEST(SchemaValidator, Object_PatternProperties) {
|
|
1182
1307
|
VALIDATE(s, "{ \"I_0\": 42 }", true);
|
1183
1308
|
INVALIDATE(s, "{ \"S_0\": 42 }", "", "patternProperties", "/S_0",
|
1184
1309
|
"{ \"type\": {"
|
1310
|
+
" \"errorCode\": 20,"
|
1185
1311
|
" \"instanceRef\": \"#/S_0\", \"schemaRef\": \"#/patternProperties/%5ES_\","
|
1186
1312
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1187
1313
|
"}}");
|
1188
1314
|
INVALIDATE(s, "{ \"I_42\": \"This is a string\" }", "", "patternProperties", "/I_42",
|
1189
1315
|
"{ \"type\": {"
|
1316
|
+
" \"errorCode\": 20,"
|
1190
1317
|
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
|
1191
1318
|
" \"expected\": [\"integer\"], \"actual\": \"string\""
|
1192
1319
|
"}}");
|
1193
1320
|
VALIDATE(s, "{ \"keyword\": \"value\" }", true);
|
1194
1321
|
}
|
1195
1322
|
|
1196
|
-
TEST(SchemaValidator,
|
1323
|
+
TEST(SchemaValidator, Object_PatternProperties_ErrorConflict) {
|
1197
1324
|
Document sd;
|
1198
1325
|
sd.Parse(
|
1199
1326
|
"{"
|
@@ -1209,9 +1336,11 @@ TEST(SchemaValidator, Object_PattternProperties_ErrorConflict) {
|
|
1209
1336
|
INVALIDATE(s, "{ \"I_30\": 7 }", "", "patternProperties", "/I_30",
|
1210
1337
|
"{ \"multipleOf\": ["
|
1211
1338
|
" {"
|
1339
|
+
" \"errorCode\": 1,"
|
1212
1340
|
" \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/%5EI_\","
|
1213
1341
|
" \"expected\": 5, \"actual\": 7"
|
1214
1342
|
" }, {"
|
1343
|
+
" \"errorCode\": 1,"
|
1215
1344
|
" \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/30%24\","
|
1216
1345
|
" \"expected\": 6, \"actual\": 7"
|
1217
1346
|
" }"
|
@@ -1236,22 +1365,25 @@ TEST(SchemaValidator, Object_Properties_PatternProperties) {
|
|
1236
1365
|
VALIDATE(s, "{ \"I_42\": 78 }", true);
|
1237
1366
|
INVALIDATE(s, "{ \"I_42\": 42 }", "", "patternProperties", "/I_42",
|
1238
1367
|
"{ \"minimum\": {"
|
1368
|
+
" \"errorCode\": 4,"
|
1239
1369
|
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
|
1240
1370
|
" \"expected\": 73, \"actual\": 42"
|
1241
1371
|
"}}");
|
1242
1372
|
INVALIDATE(s, "{ \"I_42\": 7 }", "", "patternProperties", "/I_42",
|
1243
1373
|
"{ \"minimum\": {"
|
1374
|
+
" \"errorCode\": 4,"
|
1244
1375
|
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
|
1245
1376
|
" \"expected\": 73, \"actual\": 7"
|
1246
1377
|
" },"
|
1247
1378
|
" \"multipleOf\": {"
|
1379
|
+
" \"errorCode\": 1,"
|
1248
1380
|
" \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
|
1249
1381
|
" \"expected\": 6, \"actual\": 7"
|
1250
1382
|
" }"
|
1251
1383
|
"}");
|
1252
1384
|
}
|
1253
1385
|
|
1254
|
-
TEST(SchemaValidator,
|
1386
|
+
TEST(SchemaValidator, Object_PatternProperties_AdditionalPropertiesObject) {
|
1255
1387
|
Document sd;
|
1256
1388
|
sd.Parse(
|
1257
1389
|
"{"
|
@@ -1271,10 +1403,35 @@ TEST(SchemaValidator, Object_PatternProperties_AdditionalProperties) {
|
|
1271
1403
|
VALIDATE(s, "{ \"keyword\": \"value\" }", true);
|
1272
1404
|
INVALIDATE(s, "{ \"keyword\": 42 }", "/additionalProperties", "type", "/keyword",
|
1273
1405
|
"{ \"type\": {"
|
1406
|
+
" \"errorCode\": 20,"
|
1274
1407
|
" \"instanceRef\": \"#/keyword\", \"schemaRef\": \"#/additionalProperties\","
|
1275
1408
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1276
1409
|
"}}");
|
1277
1410
|
}
|
1411
|
+
|
1412
|
+
// Replaces test Issue285 and tests failure as well as success
|
1413
|
+
TEST(SchemaValidator, Object_PatternProperties_AdditionalPropertiesBoolean) {
|
1414
|
+
Document sd;
|
1415
|
+
sd.Parse(
|
1416
|
+
"{"
|
1417
|
+
" \"type\": \"object\","
|
1418
|
+
" \"patternProperties\": {"
|
1419
|
+
" \"^S_\": { \"type\": \"string\" },"
|
1420
|
+
" \"^I_\": { \"type\": \"integer\" }"
|
1421
|
+
" },"
|
1422
|
+
" \"additionalProperties\": false"
|
1423
|
+
"}");
|
1424
|
+
SchemaDocument s(sd);
|
1425
|
+
|
1426
|
+
VALIDATE(s, "{ \"S_25\": \"This is a string\" }", true);
|
1427
|
+
VALIDATE(s, "{ \"I_0\": 42 }", true);
|
1428
|
+
INVALIDATE(s, "{ \"keyword\": \"value\" }", "", "additionalProperties", "/keyword",
|
1429
|
+
"{ \"additionalProperties\": {"
|
1430
|
+
" \"errorCode\": 16,"
|
1431
|
+
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1432
|
+
" \"disallowed\": \"keyword\""
|
1433
|
+
"}}");
|
1434
|
+
}
|
1278
1435
|
#endif
|
1279
1436
|
|
1280
1437
|
TEST(SchemaValidator, Array) {
|
@@ -1286,6 +1443,7 @@ TEST(SchemaValidator, Array) {
|
|
1286
1443
|
VALIDATE(s, "[3, \"different\", { \"types\" : \"of values\" }]", true);
|
1287
1444
|
INVALIDATE(s, "{\"Not\": \"an array\"}", "", "type", "",
|
1288
1445
|
"{ \"type\": {"
|
1446
|
+
" \"errorCode\": 20,"
|
1289
1447
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1290
1448
|
" \"expected\": [\"array\"], \"actual\": \"object\""
|
1291
1449
|
"}}");
|
@@ -1305,6 +1463,7 @@ TEST(SchemaValidator, Array_ItemsList) {
|
|
1305
1463
|
VALIDATE(s, "[1, 2, 3, 4, 5]", true);
|
1306
1464
|
INVALIDATE(s, "[1, 2, \"3\", 4, 5]", "/items", "type", "/2",
|
1307
1465
|
"{ \"type\": {"
|
1466
|
+
" \"errorCode\": 20,"
|
1308
1467
|
" \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items\","
|
1309
1468
|
" \"expected\": [\"number\"], \"actual\": \"string\""
|
1310
1469
|
"}}");
|
@@ -1337,14 +1496,16 @@ TEST(SchemaValidator, Array_ItemsTuple) {
|
|
1337
1496
|
|
1338
1497
|
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]", true);
|
1339
1498
|
INVALIDATE(s, "[24, \"Sussex\", \"Drive\"]", "/items/2", "enum", "/2",
|
1340
|
-
"{ \"enum\": { \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items/2\" }}");
|
1499
|
+
"{ \"enum\": { \"errorCode\": 19, \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items/2\" }}");
|
1341
1500
|
INVALIDATE(s, "[\"Palais de l'Elysee\"]", "/items/0", "type", "/0",
|
1342
1501
|
"{ \"type\": {"
|
1502
|
+
" \"errorCode\": 20,"
|
1343
1503
|
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
|
1344
1504
|
" \"expected\": [\"number\"], \"actual\": \"string\""
|
1345
1505
|
"}}");
|
1346
1506
|
INVALIDATE(s, "[\"Twenty-four\", \"Sussex\", \"Drive\"]", "/items/0", "type", "/0",
|
1347
1507
|
"{ \"type\": {"
|
1508
|
+
" \"errorCode\": 20,"
|
1348
1509
|
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
|
1349
1510
|
" \"expected\": [\"number\"], \"actual\": \"string\""
|
1350
1511
|
"}}"); // fail fast
|
@@ -1352,7 +1513,7 @@ TEST(SchemaValidator, Array_ItemsTuple) {
|
|
1352
1513
|
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]", true);
|
1353
1514
|
}
|
1354
1515
|
|
1355
|
-
TEST(SchemaValidator,
|
1516
|
+
TEST(SchemaValidator, Array_AdditionalItems) {
|
1356
1517
|
Document sd;
|
1357
1518
|
sd.Parse(
|
1358
1519
|
"{"
|
@@ -1379,8 +1540,9 @@ TEST(SchemaValidator, Array_AdditionalItmes) {
|
|
1379
1540
|
|
1380
1541
|
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]", true);
|
1381
1542
|
VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\"]", true);
|
1382
|
-
INVALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]", "", "
|
1543
|
+
INVALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]", "", "additionalItems", "/4",
|
1383
1544
|
"{ \"additionalItems\": {"
|
1545
|
+
" \"errorCode\": 12,"
|
1384
1546
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1385
1547
|
" \"disallowed\": 4"
|
1386
1548
|
"}}");
|
@@ -1393,11 +1555,13 @@ TEST(SchemaValidator, Array_ItemsRange) {
|
|
1393
1555
|
|
1394
1556
|
INVALIDATE(s, "[]", "", "minItems", "",
|
1395
1557
|
"{ \"minItems\": {"
|
1558
|
+
" \"errorCode\": 10,"
|
1396
1559
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1397
1560
|
" \"expected\": 2, \"actual\": 0"
|
1398
1561
|
"}}");
|
1399
1562
|
INVALIDATE(s, "[1]", "", "minItems", "",
|
1400
1563
|
"{ \"minItems\": {"
|
1564
|
+
" \"errorCode\": 10,"
|
1401
1565
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1402
1566
|
" \"expected\": 2, \"actual\": 1"
|
1403
1567
|
"}}");
|
@@ -1405,6 +1569,7 @@ TEST(SchemaValidator, Array_ItemsRange) {
|
|
1405
1569
|
VALIDATE(s, "[1, 2, 3]", true);
|
1406
1570
|
INVALIDATE(s, "[1, 2, 3, 4]", "", "maxItems", "",
|
1407
1571
|
"{ \"maxItems\": {"
|
1572
|
+
" \"errorCode\": 9,"
|
1408
1573
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1409
1574
|
" \"expected\": 3, \"actual\": 4"
|
1410
1575
|
"}}");
|
@@ -1418,11 +1583,13 @@ TEST(SchemaValidator, Array_UniqueItems) {
|
|
1418
1583
|
VALIDATE(s, "[1, 2, 3, 4, 5]", true);
|
1419
1584
|
INVALIDATE(s, "[1, 2, 3, 3, 4]", "", "uniqueItems", "/3",
|
1420
1585
|
"{ \"uniqueItems\": {"
|
1586
|
+
" \"errorCode\": 11,"
|
1421
1587
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1422
1588
|
" \"duplicates\": [2, 3]"
|
1423
1589
|
"}}");
|
1424
1590
|
INVALIDATE(s, "[1, 2, 3, 3, 3]", "", "uniqueItems", "/3",
|
1425
1591
|
"{ \"uniqueItems\": {"
|
1592
|
+
" \"errorCode\": 11,"
|
1426
1593
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1427
1594
|
" \"duplicates\": [2, 3]"
|
1428
1595
|
"}}"); // fail fast
|
@@ -1438,11 +1605,13 @@ TEST(SchemaValidator, Boolean) {
|
|
1438
1605
|
VALIDATE(s, "false", true);
|
1439
1606
|
INVALIDATE(s, "\"true\"", "", "type", "",
|
1440
1607
|
"{ \"type\": {"
|
1608
|
+
" \"errorCode\": 20,"
|
1441
1609
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1442
1610
|
" \"expected\": [\"boolean\"], \"actual\": \"string\""
|
1443
1611
|
"}}");
|
1444
1612
|
INVALIDATE(s, "0", "", "type", "",
|
1445
1613
|
"{ \"type\": {"
|
1614
|
+
" \"errorCode\": 20,"
|
1446
1615
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1447
1616
|
" \"expected\": [\"boolean\"], \"actual\": \"integer\""
|
1448
1617
|
"}}");
|
@@ -1456,16 +1625,19 @@ TEST(SchemaValidator, Null) {
|
|
1456
1625
|
VALIDATE(s, "null", true);
|
1457
1626
|
INVALIDATE(s, "false", "", "type", "",
|
1458
1627
|
"{ \"type\": {"
|
1628
|
+
" \"errorCode\": 20,"
|
1459
1629
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1460
1630
|
" \"expected\": [\"null\"], \"actual\": \"boolean\""
|
1461
1631
|
"}}");
|
1462
1632
|
INVALIDATE(s, "0", "", "type", "",
|
1463
1633
|
"{ \"type\": {"
|
1634
|
+
" \"errorCode\": 20,"
|
1464
1635
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1465
1636
|
" \"expected\": [\"null\"], \"actual\": \"integer\""
|
1466
1637
|
"}}");
|
1467
1638
|
INVALIDATE(s, "\"\"", "", "type", "",
|
1468
1639
|
"{ \"type\": {"
|
1640
|
+
" \"errorCode\": 20,"
|
1469
1641
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1470
1642
|
" \"expected\": [\"null\"], \"actual\": \"string\""
|
1471
1643
|
"}}");
|
@@ -1481,11 +1653,13 @@ TEST(SchemaValidator, ObjectInArray) {
|
|
1481
1653
|
VALIDATE(s, "[\"a\"]", true);
|
1482
1654
|
INVALIDATE(s, "[1]", "/items", "type", "/0",
|
1483
1655
|
"{ \"type\": {"
|
1656
|
+
" \"errorCode\": 20,"
|
1484
1657
|
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
|
1485
1658
|
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1486
1659
|
"}}");
|
1487
1660
|
INVALIDATE(s, "[{}]", "/items", "type", "/0",
|
1488
1661
|
"{ \"type\": {"
|
1662
|
+
" \"errorCode\": 20,"
|
1489
1663
|
" \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
|
1490
1664
|
" \"expected\": [\"string\"], \"actual\": \"object\""
|
1491
1665
|
"}}");
|
@@ -1508,6 +1682,7 @@ TEST(SchemaValidator, MultiTypeInObject) {
|
|
1508
1682
|
VALIDATE(s, "{ \"tel\": \"123-456\" }", true);
|
1509
1683
|
INVALIDATE(s, "{ \"tel\": true }", "/properties/tel", "type", "/tel",
|
1510
1684
|
"{ \"type\": {"
|
1685
|
+
" \"errorCode\": 20,"
|
1511
1686
|
" \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
|
1512
1687
|
" \"expected\": [\"string\", \"integer\"], \"actual\": \"boolean\""
|
1513
1688
|
"}}");
|
@@ -1530,6 +1705,7 @@ TEST(SchemaValidator, MultiTypeWithObject) {
|
|
1530
1705
|
VALIDATE(s, "{ \"tel\": 999 }", true);
|
1531
1706
|
INVALIDATE(s, "{ \"tel\": \"fail\" }", "/properties/tel", "type", "/tel",
|
1532
1707
|
"{ \"type\": {"
|
1708
|
+
" \"errorCode\": 20,"
|
1533
1709
|
" \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
|
1534
1710
|
" \"expected\": [\"integer\"], \"actual\": \"string\""
|
1535
1711
|
"}}");
|
@@ -1550,48 +1726,71 @@ TEST(SchemaValidator, AllOf_Nested) {
|
|
1550
1726
|
VALIDATE(s, "\"ok\"", true);
|
1551
1727
|
VALIDATE(s, "\"OK\"", true);
|
1552
1728
|
INVALIDATE(s, "\"okay\"", "", "allOf", "",
|
1553
|
-
"{ \"
|
1554
|
-
" \"
|
1729
|
+
"{ \"allOf\": {"
|
1730
|
+
" \"errors\": ["
|
1731
|
+
" {},{},"
|
1732
|
+
" { \"allOf\": {"
|
1733
|
+
" \"errors\": ["
|
1734
|
+
" {},"
|
1735
|
+
" { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\" }}"
|
1736
|
+
" ],"
|
1737
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
|
1738
|
+
" }}],"
|
1739
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
1555
1740
|
"}}");
|
1556
1741
|
INVALIDATE(s, "\"o\"", "", "allOf", "",
|
1557
|
-
"{ \"
|
1558
|
-
"
|
1559
|
-
" \"expected\": 2, \"
|
1742
|
+
"{ \"allOf\": {"
|
1743
|
+
" \"errors\": ["
|
1744
|
+
" { \"minLength\": {\"actual\": \"o\", \"expected\": 2, \"errorCode\": 7, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\" }},"
|
1745
|
+
" {},{}"
|
1746
|
+
" ],"
|
1747
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
1560
1748
|
"}}");
|
1561
1749
|
INVALIDATE(s, "\"n\"", "", "allOf", "",
|
1562
|
-
"{ \"
|
1563
|
-
" \"
|
1564
|
-
"
|
1565
|
-
"
|
1566
|
-
"
|
1567
|
-
"
|
1568
|
-
"
|
1569
|
-
"
|
1570
|
-
"
|
1750
|
+
"{ \"allOf\": {"
|
1751
|
+
" \"errors\": ["
|
1752
|
+
" { \"minLength\": {\"actual\": \"n\", \"expected\": 2, \"errorCode\": 7, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\" }},"
|
1753
|
+
" {},"
|
1754
|
+
" { \"allOf\": {"
|
1755
|
+
" \"errors\": ["
|
1756
|
+
" { \"enum\": {\"errorCode\": 19 ,\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"}},"
|
1757
|
+
" { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}}"
|
1758
|
+
" ],"
|
1759
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
|
1760
|
+
" }}"
|
1761
|
+
" ],"
|
1762
|
+
" \"errorCode\":23,\"instanceRef\":\"#\",\"schemaRef\":\"#\""
|
1763
|
+
"}}");
|
1571
1764
|
INVALIDATE(s, "\"too long\"", "", "allOf", "",
|
1572
|
-
"{ \"
|
1573
|
-
" \"
|
1574
|
-
"
|
1575
|
-
"
|
1576
|
-
"
|
1577
|
-
"
|
1578
|
-
"
|
1579
|
-
"
|
1580
|
-
"
|
1765
|
+
"{ \"allOf\": {"
|
1766
|
+
" \"errors\": ["
|
1767
|
+
" {},"
|
1768
|
+
" { \"maxLength\": {\"actual\": \"too long\", \"expected\": 5, \"errorCode\": 6, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\" }},"
|
1769
|
+
" { \"allOf\": {"
|
1770
|
+
" \"errors\": ["
|
1771
|
+
" { \"enum\": {\"errorCode\": 19 ,\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"}},"
|
1772
|
+
" { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}}"
|
1773
|
+
" ],"
|
1774
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
|
1775
|
+
" }}"
|
1776
|
+
" ],"
|
1777
|
+
" \"errorCode\":23,\"instanceRef\":\"#\",\"schemaRef\":\"#\""
|
1778
|
+
"}}");
|
1581
1779
|
INVALIDATE(s, "123", "", "allOf", "",
|
1582
|
-
"{ \"
|
1583
|
-
"
|
1584
|
-
" \"expected\": [\"string\"], \"actual\": \"integer\""
|
1585
|
-
"
|
1586
|
-
"
|
1587
|
-
"
|
1588
|
-
"
|
1589
|
-
"
|
1590
|
-
"
|
1591
|
-
"
|
1592
|
-
"
|
1593
|
-
"
|
1594
|
-
"
|
1780
|
+
"{ \"allOf\": {"
|
1781
|
+
" \"errors\": ["
|
1782
|
+
" {\"type\": {\"expected\": [\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\"}},"
|
1783
|
+
" {\"type\": {\"expected\": [\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\"}},"
|
1784
|
+
" { \"allOf\": {"
|
1785
|
+
" \"errors\": ["
|
1786
|
+
" { \"enum\": {\"errorCode\": 19 ,\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"}},"
|
1787
|
+
" { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}}"
|
1788
|
+
" ],"
|
1789
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
|
1790
|
+
" }}"
|
1791
|
+
" ],"
|
1792
|
+
" \"errorCode\":23,\"instanceRef\":\"#\",\"schemaRef\":\"#\""
|
1793
|
+
"}}");
|
1595
1794
|
}
|
1596
1795
|
|
1597
1796
|
TEST(SchemaValidator, EscapedPointer) {
|
@@ -1606,6 +1805,7 @@ TEST(SchemaValidator, EscapedPointer) {
|
|
1606
1805
|
SchemaDocument s(sd);
|
1607
1806
|
INVALIDATE(s, "{\"~/\":true}", "/properties/~0~1", "type", "/~0~1",
|
1608
1807
|
"{ \"type\": {"
|
1808
|
+
" \"errorCode\": 20,"
|
1609
1809
|
" \"instanceRef\": \"#/~0~1\", \"schemaRef\": \"#/properties/~0~1\","
|
1610
1810
|
" \"expected\": [\"number\"], \"actual\": \"boolean\""
|
1611
1811
|
"}}");
|
@@ -1650,11 +1850,14 @@ TEST(SchemaValidator, ValidateMetaSchema) {
|
|
1650
1850
|
ASSERT_FALSE(d.HasParseError());
|
1651
1851
|
SchemaDocument sd(d);
|
1652
1852
|
SchemaValidator validator(sd);
|
1653
|
-
|
1853
|
+
d.Accept(validator);
|
1854
|
+
if (!validator.IsValid()) {
|
1654
1855
|
StringBuffer sb;
|
1655
1856
|
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
|
1656
1857
|
printf("Invalid schema: %s\n", sb.GetString());
|
1657
1858
|
printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
|
1859
|
+
printf("Invalid code: %d\n", validator.GetInvalidSchemaCode());
|
1860
|
+
printf("Invalid message: %s\n", GetValidateError_En(validator.GetInvalidSchemaCode()));
|
1658
1861
|
sb.Clear();
|
1659
1862
|
validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
|
1660
1863
|
printf("Invalid document: %s\n", sb.GetString());
|
@@ -1681,7 +1884,8 @@ TEST(SchemaValidator, ValidateMetaSchema_UTF16) {
|
|
1681
1884
|
ASSERT_FALSE(d.HasParseError());
|
1682
1885
|
SD sd(d);
|
1683
1886
|
SV validator(sd);
|
1684
|
-
|
1887
|
+
d.Accept(validator);
|
1888
|
+
if (!validator.IsValid()) {
|
1685
1889
|
GenericStringBuffer<UTF16<> > sb;
|
1686
1890
|
validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
|
1687
1891
|
wprintf(L"Invalid schema: %ls\n", sb.GetString());
|
@@ -1709,13 +1913,15 @@ public:
|
|
1709
1913
|
"jsonschema/remotes/integer.json",
|
1710
1914
|
"jsonschema/remotes/subSchemas.json",
|
1711
1915
|
"jsonschema/remotes/folder/folderInteger.json",
|
1712
|
-
"draft-04/schema"
|
1916
|
+
"draft-04/schema",
|
1917
|
+
"unittestschema/address.json"
|
1713
1918
|
};
|
1714
1919
|
const char* uris[kCount] = {
|
1715
1920
|
"http://localhost:1234/integer.json",
|
1716
1921
|
"http://localhost:1234/subSchemas.json",
|
1717
1922
|
"http://localhost:1234/folder/folderInteger.json",
|
1718
|
-
"http://json-schema.org/draft-04/schema"
|
1923
|
+
"http://json-schema.org/draft-04/schema",
|
1924
|
+
"http://localhost:1234/address.json"
|
1719
1925
|
};
|
1720
1926
|
|
1721
1927
|
for (size_t i = 0; i < kCount; i++) {
|
@@ -1757,7 +1963,7 @@ private:
|
|
1757
1963
|
RemoteSchemaDocumentProvider(const RemoteSchemaDocumentProvider&);
|
1758
1964
|
RemoteSchemaDocumentProvider& operator=(const RemoteSchemaDocumentProvider&);
|
1759
1965
|
|
1760
|
-
static const size_t kCount =
|
1966
|
+
static const size_t kCount = 5;
|
1761
1967
|
SchemaDocumentType* sd_[kCount];
|
1762
1968
|
typename DocumentType::AllocatorType documentAllocator_;
|
1763
1969
|
typename SchemaDocumentType::AllocatorType schemaAllocator_;
|
@@ -1826,6 +2032,7 @@ TEST(SchemaValidator, TestSuite) {
|
|
1826
2032
|
ADD_FAILURE();
|
1827
2033
|
}
|
1828
2034
|
else {
|
2035
|
+
//printf("json test suite file %s parsed ok\n", filename);
|
1829
2036
|
GenericDocument<UTF8<>, MemoryPoolAllocator<>, MemoryPoolAllocator<> > d(&documentAllocator, 1024, &documentStackAllocator);
|
1830
2037
|
d.Parse(json);
|
1831
2038
|
if (d.HasParseError()) {
|
@@ -1846,11 +2053,14 @@ TEST(SchemaValidator, TestSuite) {
|
|
1846
2053
|
bool expected = (*testItr)["valid"].GetBool();
|
1847
2054
|
testCount++;
|
1848
2055
|
validator.Reset();
|
1849
|
-
|
2056
|
+
data.Accept(validator);
|
2057
|
+
bool actual = validator.IsValid();
|
1850
2058
|
if (expected != actual)
|
1851
2059
|
printf("Fail: %30s \"%s\" \"%s\"\n", filename, description1, description2);
|
1852
|
-
else
|
2060
|
+
else {
|
2061
|
+
//printf("Passed: %30s \"%s\" \"%s\"\n", filename, description1, description2);
|
1853
2062
|
passCount++;
|
2063
|
+
}
|
1854
2064
|
}
|
1855
2065
|
}
|
1856
2066
|
//printf("%zu %zu %zu\n", documentAllocator.Size(), schemaAllocator.Size(), validatorAllocator.Size());
|
@@ -1865,8 +2075,8 @@ TEST(SchemaValidator, TestSuite) {
|
|
1865
2075
|
jsonAllocator.Clear();
|
1866
2076
|
}
|
1867
2077
|
printf("%d / %d passed (%2d%%)\n", passCount, testCount, passCount * 100 / testCount);
|
1868
|
-
|
1869
|
-
|
2078
|
+
// if (passCount != testCount)
|
2079
|
+
// ADD_FAILURE();
|
1870
2080
|
}
|
1871
2081
|
|
1872
2082
|
TEST(SchemaValidatingReader, Simple) {
|
@@ -1897,12 +2107,14 @@ TEST(SchemaValidatingReader, Invalid) {
|
|
1897
2107
|
EXPECT_FALSE(reader.IsValid());
|
1898
2108
|
EXPECT_EQ(kParseErrorTermination, reader.GetParseResult().Code());
|
1899
2109
|
EXPECT_STREQ("maxLength", reader.GetInvalidSchemaKeyword());
|
2110
|
+
EXPECT_TRUE(reader.GetInvalidSchemaCode() == kValidateErrorMaxLength);
|
1900
2111
|
EXPECT_TRUE(reader.GetInvalidSchemaPointer() == SchemaDocument::PointerType(""));
|
1901
2112
|
EXPECT_TRUE(reader.GetInvalidDocumentPointer() == SchemaDocument::PointerType(""));
|
1902
2113
|
EXPECT_TRUE(d.IsNull());
|
1903
2114
|
Document e;
|
1904
2115
|
e.Parse(
|
1905
2116
|
"{ \"maxLength\": {"
|
2117
|
+
" \"errorCode\": 6,"
|
1906
2118
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1907
2119
|
" \"expected\": 3, \"actual\": \"ABCD\""
|
1908
2120
|
"}}");
|
@@ -1933,9 +2145,11 @@ TEST(SchemaValidatingWriter, Simple) {
|
|
1933
2145
|
EXPECT_FALSE(validator.IsValid());
|
1934
2146
|
EXPECT_TRUE(validator.GetInvalidSchemaPointer() == SchemaDocument::PointerType(""));
|
1935
2147
|
EXPECT_TRUE(validator.GetInvalidDocumentPointer() == SchemaDocument::PointerType(""));
|
2148
|
+
EXPECT_TRUE(validator.GetInvalidSchemaCode() == kValidateErrorMaxLength);
|
1936
2149
|
Document e;
|
1937
2150
|
e.Parse(
|
1938
2151
|
"{ \"maxLength\": {"
|
2152
|
+
" \"errorCode\": 6,"
|
1939
2153
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1940
2154
|
" \"expected\": 3, \"actual\": \"ABCD\""
|
1941
2155
|
"}}");
|
@@ -1963,6 +2177,7 @@ TEST(Schema, Issue552) {
|
|
1963
2177
|
VALIDATE(s, "\"Life, the universe, and everything\"", true);
|
1964
2178
|
INVALIDATE(s, "[\"Life\", \"the universe\", \"and everything\"]", "", "type", "",
|
1965
2179
|
"{ \"type\": {"
|
2180
|
+
" \"errorCode\": 20,"
|
1966
2181
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1967
2182
|
" \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
|
1968
2183
|
"}}");
|
@@ -1978,6 +2193,7 @@ TEST(SchemaValidator, Issue608) {
|
|
1978
2193
|
VALIDATE(s, "{\"a\" : null, \"b\": null}", true);
|
1979
2194
|
INVALIDATE(s, "{\"a\" : null, \"a\" : null}", "", "required", "",
|
1980
2195
|
"{ \"required\": {"
|
2196
|
+
" \"errorCode\": 15,"
|
1981
2197
|
" \"instanceRef\": \"#\", \"schemaRef\": \"#\","
|
1982
2198
|
" \"missing\": [\"b\"]"
|
1983
2199
|
"}}");
|
@@ -1991,13 +2207,6 @@ TEST(SchemaValidator, Issue728_AllOfRef) {
|
|
1991
2207
|
VALIDATE(s, "{\"key1\": \"abc\", \"key2\": \"def\"}", true);
|
1992
2208
|
}
|
1993
2209
|
|
1994
|
-
TEST(SchemaValidator, Issue825) {
|
1995
|
-
Document sd;
|
1996
|
-
sd.Parse("{\"type\": \"object\", \"additionalProperties\": false, \"patternProperties\": {\"^i\": { \"type\": \"string\" } } }");
|
1997
|
-
SchemaDocument s(sd);
|
1998
|
-
VALIDATE(s, "{ \"item\": \"hello\" }", true);
|
1999
|
-
}
|
2000
|
-
|
2001
2210
|
TEST(SchemaValidator, Issue1017_allOfHandler) {
|
2002
2211
|
Document sd;
|
2003
2212
|
sd.Parse("{\"allOf\": [{\"type\": \"object\",\"properties\": {\"cyanArray2\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}}},{\"type\": \"object\",\"properties\": {\"blackArray\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}},\"required\": [ \"blackArray\" ]}]}");
|
@@ -2027,19 +2236,25 @@ TEST(SchemaValidator, Ref_remote) {
|
|
2027
2236
|
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
|
2028
2237
|
INVALIDATE_(s, "null", "/integer", "type", "",
|
2029
2238
|
"{ \"type\": {"
|
2239
|
+
" \"errorCode\": 20,"
|
2030
2240
|
" \"instanceRef\": \"#\","
|
2031
2241
|
" \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
|
2032
2242
|
" \"expected\": [\"integer\"], \"actual\": \"null\""
|
2033
2243
|
"}}",
|
2034
|
-
SchemaValidatorType, PointerType);
|
2244
|
+
kValidateDefaultFlags, SchemaValidatorType, PointerType);
|
2035
2245
|
}
|
2036
2246
|
|
2037
2247
|
TEST(SchemaValidator, Ref_remote_issue1210) {
|
2038
2248
|
class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider {
|
2039
2249
|
SchemaDocument** collection;
|
2040
2250
|
|
2041
|
-
|
2042
|
-
|
2251
|
+
// Dummy private copy constructor & assignment operator.
|
2252
|
+
// Function bodies added so that they compile in MSVC 2019.
|
2253
|
+
SchemaDocumentProvider(const SchemaDocumentProvider&) : collection(NULL) {
|
2254
|
+
}
|
2255
|
+
SchemaDocumentProvider& operator=(const SchemaDocumentProvider&) {
|
2256
|
+
return *this;
|
2257
|
+
}
|
2043
2258
|
|
2044
2259
|
public:
|
2045
2260
|
SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { }
|
@@ -2067,6 +2282,306 @@ TEST(SchemaValidator, Ref_remote_issue1210) {
|
|
2067
2282
|
VALIDATE(sx, "{\"country\":\"US\"}", true);
|
2068
2283
|
}
|
2069
2284
|
|
2285
|
+
// Test that when kValidateContinueOnErrorFlag is set, all errors are reported.
|
2286
|
+
TEST(SchemaValidator, ContinueOnErrors) {
|
2287
|
+
CrtAllocator allocator;
|
2288
|
+
char* schema = ReadFile("unittestschema/address.json", allocator);
|
2289
|
+
Document sd;
|
2290
|
+
sd.Parse(schema);
|
2291
|
+
ASSERT_FALSE(sd.HasParseError());
|
2292
|
+
SchemaDocument s(sd);
|
2293
|
+
VALIDATE(s, "{\"version\": 1.0, \"address\": {\"number\": 24, \"street1\": \"The Woodlands\", \"street3\": \"Ham\", \"city\": \"Romsey\", \"area\": \"Kent\", \"country\": \"UK\", \"postcode\": \"SO51 0GP\"}, \"phones\": [\"0111-222333\", \"0777-666888\"], \"names\": [\"Fred\", \"Bloggs\"]}", true);
|
2294
|
+
INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
|
2295
|
+
"{ \"multipleOf\": {"
|
2296
|
+
" \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
|
2297
|
+
" },"
|
2298
|
+
" \"minimum\": {"
|
2299
|
+
" \"errorCode\": 5, \"instanceRef\": \"#/address/number\", \"schemaRef\": \"#/definitions/positiveInt_type\", \"expected\": 0, \"actual\": 0, \"exclusiveMinimum\": true"
|
2300
|
+
" },"
|
2301
|
+
" \"type\": ["
|
2302
|
+
" {\"expected\": [\"null\", \"string\"], \"actual\": \"boolean\", \"errorCode\": 20, \"instanceRef\": \"#/address/street2\", \"schemaRef\": \"#/definitions/address_type/properties/street2\"},"
|
2303
|
+
" {\"expected\": [\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#/extra/S_xxx\", \"schemaRef\": \"#/properties/extra/patternProperties/%5ES_\"}"
|
2304
|
+
" ],"
|
2305
|
+
" \"maxLength\": {"
|
2306
|
+
" \"actual\": \"RomseyTownFC\", \"expected\": 10, \"errorCode\": 6, \"instanceRef\": \"#/address/city\", \"schemaRef\": \"#/definitions/address_type/properties/city\""
|
2307
|
+
" },"
|
2308
|
+
" \"anyOf\": {"
|
2309
|
+
" \"errors\":["
|
2310
|
+
" {\"pattern\": {\"actual\": \"999ABC\", \"errorCode\": 8, \"instanceRef\": \"#/address/postcode\", \"schemaRef\": \"#/definitions/address_type/properties/postcode/anyOf/0\"}},"
|
2311
|
+
" {\"pattern\": {\"actual\": \"999ABC\", \"errorCode\": 8, \"instanceRef\": \"#/address/postcode\", \"schemaRef\": \"#/definitions/address_type/properties/postcode/anyOf/1\"}}"
|
2312
|
+
" ],"
|
2313
|
+
" \"errorCode\": 24, \"instanceRef\": \"#/address/postcode\", \"schemaRef\": \"#/definitions/address_type/properties/postcode\""
|
2314
|
+
" },"
|
2315
|
+
" \"allOf\": {"
|
2316
|
+
" \"errors\":["
|
2317
|
+
" {\"enum\":{\"errorCode\":19,\"instanceRef\":\"#/address/country\",\"schemaRef\":\"#/definitions/country_type\"}}"
|
2318
|
+
" ],"
|
2319
|
+
" \"errorCode\":23,\"instanceRef\":\"#/address/country\",\"schemaRef\":\"#/definitions/address_type/properties/country\""
|
2320
|
+
" },"
|
2321
|
+
" \"minItems\": {"
|
2322
|
+
" \"actual\": 0, \"expected\": 1, \"errorCode\": 10, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\""
|
2323
|
+
" },"
|
2324
|
+
" \"additionalProperties\": {"
|
2325
|
+
" \"disallowed\": \"planet\", \"errorCode\": 16, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
2326
|
+
" },"
|
2327
|
+
" \"required\": {"
|
2328
|
+
" \"missing\": [\"street1\"], \"errorCode\": 15, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\""
|
2329
|
+
" }"
|
2330
|
+
"}",
|
2331
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2332
|
+
INVALIDATE_(s, "{\"address\": {\"number\": 200, \"street1\": {}, \"street3\": null, \"city\": \"Rom\", \"area\": \"Dorset\", \"postcode\": \"SO51 0GP\"}, \"phones\": [\"0111-222333\", \"0777-666888\", \"0777-666888\"], \"names\": [\"Fred\", \"S\", \"M\", \"Bloggs\"]}", "#", "errors", "#",
|
2333
|
+
"{ \"maximum\": {"
|
2334
|
+
" \"errorCode\": 3, \"instanceRef\": \"#/address/number\", \"schemaRef\": \"#/definitions/positiveInt_type\", \"expected\": 100, \"actual\": 200, \"exclusiveMaximum\": true"
|
2335
|
+
" },"
|
2336
|
+
" \"type\": {"
|
2337
|
+
" \"expected\": [\"string\"], \"actual\": \"object\", \"errorCode\": 20, \"instanceRef\": \"#/address/street1\", \"schemaRef\": \"#/definitions/address_type/properties/street1\""
|
2338
|
+
" },"
|
2339
|
+
" \"not\": {"
|
2340
|
+
" \"errorCode\": 25, \"instanceRef\": \"#/address/street3\", \"schemaRef\": \"#/definitions/address_type/properties/street3\""
|
2341
|
+
" },"
|
2342
|
+
" \"minLength\": {"
|
2343
|
+
" \"actual\": \"Rom\", \"expected\": 4, \"errorCode\": 7, \"instanceRef\": \"#/address/city\", \"schemaRef\": \"#/definitions/address_type/properties/city\""
|
2344
|
+
" },"
|
2345
|
+
" \"maxItems\": {"
|
2346
|
+
" \"actual\": 3, \"expected\": 2, \"errorCode\": 9, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\""
|
2347
|
+
" },"
|
2348
|
+
" \"uniqueItems\": {"
|
2349
|
+
" \"duplicates\": [1, 2], \"errorCode\": 11, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\""
|
2350
|
+
" },"
|
2351
|
+
" \"minProperties\": {\"actual\": 6, \"expected\": 7, \"errorCode\": 14, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\""
|
2352
|
+
" },"
|
2353
|
+
" \"additionalItems\": ["
|
2354
|
+
" {\"disallowed\": 2, \"errorCode\": 12, \"instanceRef\": \"#/names\", \"schemaRef\": \"#/properties/names\"},"
|
2355
|
+
" {\"disallowed\": 3, \"errorCode\": 12, \"instanceRef\": \"#/names\", \"schemaRef\": \"#/properties/names\"}"
|
2356
|
+
" ],"
|
2357
|
+
" \"dependencies\": {"
|
2358
|
+
" \"errors\": {"
|
2359
|
+
" \"address\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/address\"}},"
|
2360
|
+
" \"names\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/names\"}}"
|
2361
|
+
" },"
|
2362
|
+
" \"errorCode\": 18, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
2363
|
+
" },"
|
2364
|
+
" \"oneOf\": {"
|
2365
|
+
" \"errors\": ["
|
2366
|
+
" {\"enum\": {\"errorCode\": 19, \"instanceRef\": \"#/address/area\", \"schemaRef\": \"#/definitions/county_type\"}},"
|
2367
|
+
" {\"enum\": {\"errorCode\": 19, \"instanceRef\": \"#/address/area\", \"schemaRef\": \"#/definitions/province_type\"}}"
|
2368
|
+
" ],"
|
2369
|
+
" \"errorCode\": 21, \"instanceRef\": \"#/address/area\", \"schemaRef\": \"#/definitions/address_type/properties/area\""
|
2370
|
+
" }"
|
2371
|
+
"}",
|
2372
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2373
|
+
|
2374
|
+
CrtAllocator::Free(schema);
|
2375
|
+
}
|
2376
|
+
|
2377
|
+
// Test that when kValidateContinueOnErrorFlag is set, it is not propagated to oneOf sub-validator so we only get the first error.
|
2378
|
+
TEST(SchemaValidator, ContinueOnErrors_OneOf) {
|
2379
|
+
typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
|
2380
|
+
RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
|
2381
|
+
CrtAllocator allocator;
|
2382
|
+
char* schema = ReadFile("unittestschema/oneOf_address.json", allocator);
|
2383
|
+
Document sd;
|
2384
|
+
sd.Parse(schema);
|
2385
|
+
ASSERT_FALSE(sd.HasParseError());
|
2386
|
+
SchemaDocumentType s(sd, 0, 0, &provider);
|
2387
|
+
typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
|
2388
|
+
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
|
2389
|
+
INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
|
2390
|
+
"{ \"oneOf\": {"
|
2391
|
+
" \"errors\": [{"
|
2392
|
+
" \"multipleOf\": {"
|
2393
|
+
" \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"http://localhost:1234/address.json#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
|
2394
|
+
" }"
|
2395
|
+
" }],"
|
2396
|
+
" \"errorCode\": 21, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
2397
|
+
" }"
|
2398
|
+
"}",
|
2399
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidatorType, PointerType);
|
2400
|
+
CrtAllocator::Free(schema);
|
2401
|
+
}
|
2402
|
+
|
2403
|
+
// Test that when kValidateContinueOnErrorFlag is set, it is not propagated to allOf sub-validator so we only get the first error.
|
2404
|
+
TEST(SchemaValidator, ContinueOnErrors_AllOf) {
|
2405
|
+
typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
|
2406
|
+
RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
|
2407
|
+
CrtAllocator allocator;
|
2408
|
+
char* schema = ReadFile("unittestschema/allOf_address.json", allocator);
|
2409
|
+
Document sd;
|
2410
|
+
sd.Parse(schema);
|
2411
|
+
ASSERT_FALSE(sd.HasParseError());
|
2412
|
+
SchemaDocumentType s(sd, 0, 0, &provider);
|
2413
|
+
typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
|
2414
|
+
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
|
2415
|
+
INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
|
2416
|
+
"{ \"allOf\": {"
|
2417
|
+
" \"errors\": [{"
|
2418
|
+
" \"multipleOf\": {"
|
2419
|
+
" \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"http://localhost:1234/address.json#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
|
2420
|
+
" }"
|
2421
|
+
" }],"
|
2422
|
+
" \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
2423
|
+
" }"
|
2424
|
+
"}",
|
2425
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidatorType, PointerType);
|
2426
|
+
CrtAllocator::Free(schema);
|
2427
|
+
}
|
2428
|
+
|
2429
|
+
// Test that when kValidateContinueOnErrorFlag is set, it is not propagated to anyOf sub-validator so we only get the first error.
|
2430
|
+
TEST(SchemaValidator, ContinueOnErrors_AnyOf) {
|
2431
|
+
typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
|
2432
|
+
RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
|
2433
|
+
CrtAllocator allocator;
|
2434
|
+
char* schema = ReadFile("unittestschema/anyOf_address.json", allocator);
|
2435
|
+
Document sd;
|
2436
|
+
sd.Parse(schema);
|
2437
|
+
ASSERT_FALSE(sd.HasParseError());
|
2438
|
+
SchemaDocumentType s(sd, 0, 0, &provider);
|
2439
|
+
typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
|
2440
|
+
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
|
2441
|
+
INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
|
2442
|
+
"{ \"anyOf\": {"
|
2443
|
+
" \"errors\": [{"
|
2444
|
+
" \"multipleOf\": {"
|
2445
|
+
" \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"http://localhost:1234/address.json#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
|
2446
|
+
" }"
|
2447
|
+
" }],"
|
2448
|
+
" \"errorCode\": 24, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
2449
|
+
" }"
|
2450
|
+
"}",
|
2451
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidatorType, PointerType);
|
2452
|
+
|
2453
|
+
CrtAllocator::Free(schema);
|
2454
|
+
}
|
2455
|
+
|
2456
|
+
// Test that when kValidateContinueOnErrorFlag is set, arrays with uniqueItems:true are correctly processed when an item is invalid.
|
2457
|
+
// This tests that we don't blow up if a hasher does not get created.
|
2458
|
+
TEST(SchemaValidator, ContinueOnErrors_UniqueItems) {
|
2459
|
+
CrtAllocator allocator;
|
2460
|
+
char* schema = ReadFile("unittestschema/address.json", allocator);
|
2461
|
+
Document sd;
|
2462
|
+
sd.Parse(schema);
|
2463
|
+
ASSERT_FALSE(sd.HasParseError());
|
2464
|
+
SchemaDocument s(sd);
|
2465
|
+
VALIDATE(s, "{\"phones\":[\"12-34\",\"56-78\"]}", true);
|
2466
|
+
INVALIDATE_(s, "{\"phones\":[\"12-34\",\"12-34\"]}", "#", "errors", "#",
|
2467
|
+
"{\"uniqueItems\": {\"duplicates\": [0,1], \"errorCode\": 11, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\"}}",
|
2468
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2469
|
+
INVALIDATE_(s, "{\"phones\":[\"ab-34\",\"cd-78\"]}", "#", "errors", "#",
|
2470
|
+
"{\"pattern\": ["
|
2471
|
+
" {\"actual\": \"ab-34\", \"errorCode\": 8, \"instanceRef\": \"#/phones/0\", \"schemaRef\": \"#/definitions/phone_type\"},"
|
2472
|
+
" {\"actual\": \"cd-78\", \"errorCode\": 8, \"instanceRef\": \"#/phones/1\", \"schemaRef\": \"#/definitions/phone_type\"}"
|
2473
|
+
"]}",
|
2474
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2475
|
+
CrtAllocator::Free(schema);
|
2476
|
+
}
|
2477
|
+
|
2478
|
+
// Test that when kValidateContinueOnErrorFlag is set, an enum field is correctly processed when it has an invalid value.
|
2479
|
+
// This tests that we don't blow up if a hasher does not get created.
|
2480
|
+
TEST(SchemaValidator, ContinueOnErrors_Enum) {
|
2481
|
+
CrtAllocator allocator;
|
2482
|
+
char* schema = ReadFile("unittestschema/address.json", allocator);
|
2483
|
+
Document sd;
|
2484
|
+
sd.Parse(schema);
|
2485
|
+
ASSERT_FALSE(sd.HasParseError());
|
2486
|
+
SchemaDocument s(sd);
|
2487
|
+
VALIDATE(s, "{\"gender\":\"M\"}", true);
|
2488
|
+
INVALIDATE_(s, "{\"gender\":\"X\"}", "#", "errors", "#",
|
2489
|
+
"{\"enum\": {\"errorCode\": 19, \"instanceRef\": \"#/gender\", \"schemaRef\": \"#/properties/gender\"}}",
|
2490
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2491
|
+
INVALIDATE_(s, "{\"gender\":1}", "#", "errors", "#",
|
2492
|
+
"{\"type\": {\"expected\":[\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#/gender\", \"schemaRef\": \"#/properties/gender\"}}",
|
2493
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2494
|
+
CrtAllocator::Free(schema);
|
2495
|
+
}
|
2496
|
+
|
2497
|
+
// Test that when kValidateContinueOnErrorFlag is set, an array appearing for an object property is handled
|
2498
|
+
// This tests that we don't blow up when there is a type mismatch.
|
2499
|
+
TEST(SchemaValidator, ContinueOnErrors_RogueArray) {
|
2500
|
+
CrtAllocator allocator;
|
2501
|
+
char* schema = ReadFile("unittestschema/address.json", allocator);
|
2502
|
+
Document sd;
|
2503
|
+
sd.Parse(schema);
|
2504
|
+
ASSERT_FALSE(sd.HasParseError());
|
2505
|
+
SchemaDocument s(sd);
|
2506
|
+
INVALIDATE_(s, "{\"address\":[{\"number\": 0}]}", "#", "errors", "#",
|
2507
|
+
"{\"type\": {\"expected\":[\"object\"], \"actual\": \"array\", \"errorCode\": 20, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\"},"
|
2508
|
+
" \"dependencies\": {"
|
2509
|
+
" \"errors\": {"
|
2510
|
+
" \"address\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/address\"}}"
|
2511
|
+
" },\"errorCode\": 18, \"instanceRef\": \"#\", \"schemaRef\": \"#\"}}",
|
2512
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2513
|
+
CrtAllocator::Free(schema);
|
2514
|
+
}
|
2515
|
+
|
2516
|
+
// Test that when kValidateContinueOnErrorFlag is set, an object appearing for an array property is handled
|
2517
|
+
// This tests that we don't blow up when there is a type mismatch.
|
2518
|
+
TEST(SchemaValidator, ContinueOnErrors_RogueObject) {
|
2519
|
+
CrtAllocator allocator;
|
2520
|
+
char* schema = ReadFile("unittestschema/address.json", allocator);
|
2521
|
+
Document sd;
|
2522
|
+
sd.Parse(schema);
|
2523
|
+
ASSERT_FALSE(sd.HasParseError());
|
2524
|
+
SchemaDocument s(sd);
|
2525
|
+
INVALIDATE_(s, "{\"phones\":{\"number\": 0}}", "#", "errors", "#",
|
2526
|
+
"{\"type\": {\"expected\":[\"array\"], \"actual\": \"object\", \"errorCode\": 20, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\"}}",
|
2527
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2528
|
+
CrtAllocator::Free(schema);
|
2529
|
+
}
|
2530
|
+
|
2531
|
+
// Test that when kValidateContinueOnErrorFlag is set, a string appearing for an array or object property is handled
|
2532
|
+
// This tests that we don't blow up when there is a type mismatch.
|
2533
|
+
TEST(SchemaValidator, ContinueOnErrors_RogueString) {
|
2534
|
+
CrtAllocator allocator;
|
2535
|
+
char* schema = ReadFile("unittestschema/address.json", allocator);
|
2536
|
+
Document sd;
|
2537
|
+
sd.Parse(schema);
|
2538
|
+
ASSERT_FALSE(sd.HasParseError());
|
2539
|
+
SchemaDocument s(sd);
|
2540
|
+
INVALIDATE_(s, "{\"address\":\"number\"}", "#", "errors", "#",
|
2541
|
+
"{\"type\": {\"expected\":[\"object\"], \"actual\": \"string\", \"errorCode\": 20, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\"},"
|
2542
|
+
" \"dependencies\": {"
|
2543
|
+
" \"errors\": {"
|
2544
|
+
" \"address\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/address\"}}"
|
2545
|
+
" },\"errorCode\": 18, \"instanceRef\": \"#\", \"schemaRef\": \"#\"}}",
|
2546
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2547
|
+
INVALIDATE_(s, "{\"phones\":\"number\"}", "#", "errors", "#",
|
2548
|
+
"{\"type\": {\"expected\":[\"array\"], \"actual\": \"string\", \"errorCode\": 20, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\"}}",
|
2549
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2550
|
+
CrtAllocator::Free(schema);
|
2551
|
+
}
|
2552
|
+
|
2553
|
+
// Test that when kValidateContinueOnErrorFlag is set, an incorrect simple type with a sub-schema is handled correctly.
|
2554
|
+
// This tests that we don't blow up when there is a type mismatch but there is a sub-schema present
|
2555
|
+
TEST(SchemaValidator, ContinueOnErrors_Issue2) {
|
2556
|
+
Document sd;
|
2557
|
+
sd.Parse("{\"type\":\"string\", \"anyOf\":[{\"maxLength\":2}]}");
|
2558
|
+
ASSERT_FALSE(sd.HasParseError());
|
2559
|
+
SchemaDocument s(sd);
|
2560
|
+
VALIDATE(s, "\"AB\"", true);
|
2561
|
+
INVALIDATE_(s, "\"ABC\"", "#", "errors", "#",
|
2562
|
+
"{ \"anyOf\": {"
|
2563
|
+
" \"errors\": [{"
|
2564
|
+
" \"maxLength\": {"
|
2565
|
+
" \"errorCode\": 6, \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/0\", \"expected\": 2, \"actual\": \"ABC\""
|
2566
|
+
" }"
|
2567
|
+
" }],"
|
2568
|
+
" \"errorCode\": 24, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
|
2569
|
+
" }"
|
2570
|
+
"}",
|
2571
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2572
|
+
// Invalid type
|
2573
|
+
INVALIDATE_(s, "333", "#", "errors", "#",
|
2574
|
+
"{ \"type\": {"
|
2575
|
+
" \"errorCode\": 20, \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"expected\": [\"string\"], \"actual\": \"integer\""
|
2576
|
+
" }"
|
2577
|
+
"}",
|
2578
|
+
kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
|
2579
|
+
}
|
2580
|
+
|
2581
|
+
TEST(SchemaValidator, Schema_UnknownError) {
|
2582
|
+
ASSERT_TRUE(SchemaValidator::SchemaType::GetValidateErrorKeyword(kValidateErrors).GetString() == std::string("null"));
|
2583
|
+
}
|
2584
|
+
|
2070
2585
|
#if defined(_MSC_VER) || defined(__clang__)
|
2071
2586
|
RAPIDJSON_DIAG_POP
|
2072
2587
|
#endif
|