22 static const char kJson[] =
"{\n" 23 " \"foo\":[\"bar\", \"baz\"],\n" 37 EXPECT_TRUE(p.IsValid());
38 EXPECT_EQ(0u, p.GetTokenCount());
44 EXPECT_TRUE(p.IsValid());
45 EXPECT_EQ(0u, p.GetTokenCount());
50 EXPECT_TRUE(p.IsValid());
51 EXPECT_EQ(1u, p.GetTokenCount());
52 EXPECT_EQ(0u, p.GetTokens()[0].length);
53 EXPECT_STREQ(
"", p.GetTokens()[0].name);
59 EXPECT_TRUE(p.IsValid());
60 EXPECT_EQ(1u, p.GetTokenCount());
61 EXPECT_EQ(3u, p.GetTokens()[0].length);
62 EXPECT_STREQ(
"foo", p.GetTokens()[0].name);
66 #if RAPIDJSON_HAS_STDSTRING 69 EXPECT_TRUE(p.IsValid());
70 EXPECT_EQ(1u, p.GetTokenCount());
71 EXPECT_EQ(3u, p.GetTokens()[0].length);
72 EXPECT_STREQ(
"foo", p.GetTokens()[0].name);
79 EXPECT_TRUE(p.IsValid());
80 EXPECT_EQ(2u, p.GetTokenCount());
81 EXPECT_EQ(3u, p.GetTokens()[0].length);
82 EXPECT_STREQ(
"foo", p.GetTokens()[0].name);
84 EXPECT_EQ(1u, p.GetTokens()[1].length);
85 EXPECT_STREQ(
"0", p.GetTokens()[1].name);
86 EXPECT_EQ(0u, p.GetTokens()[1].index);
92 EXPECT_TRUE(p.IsValid());
93 EXPECT_EQ(1u, p.GetTokenCount());
94 EXPECT_EQ(3u, p.GetTokens()[0].length);
95 EXPECT_STREQ(
"a/b", p.GetTokens()[0].name);
101 EXPECT_TRUE(p.IsValid());
102 EXPECT_EQ(1u, p.GetTokenCount());
103 EXPECT_EQ(3u, p.GetTokens()[0].length);
104 EXPECT_STREQ(
"m~n", p.GetTokens()[0].name);
110 EXPECT_TRUE(p.IsValid());
111 EXPECT_EQ(1u, p.GetTokenCount());
112 EXPECT_EQ(0u, p.GetTokens()[0].length);
113 EXPECT_STREQ(
"", p.GetTokens()[0].name);
119 EXPECT_TRUE(p.IsValid());
120 EXPECT_EQ(2u, p.GetTokenCount());
121 EXPECT_EQ(0u, p.GetTokens()[0].length);
122 EXPECT_STREQ(
"", p.GetTokens()[0].name);
123 EXPECT_EQ(1u, p.GetTokens()[1].length);
124 EXPECT_STREQ(
"a", p.GetTokens()[1].name);
130 EXPECT_TRUE(p.IsValid());
131 EXPECT_EQ(1u, p.GetTokenCount());
132 EXPECT_EQ(2u, p.GetTokens()[0].length);
133 EXPECT_EQ(
'\0', p.GetTokens()[0].name[0]);
134 EXPECT_EQ(
'\0', p.GetTokens()[0].name[1]);
135 EXPECT_EQ(
'\0', p.GetTokens()[0].name[2]);
141 EXPECT_TRUE(p.IsValid());
142 EXPECT_EQ(1u, p.GetTokenCount());
143 EXPECT_STREQ(
"123", p.GetTokens()[0].name);
144 EXPECT_EQ(123u, p.GetTokens()[0].index);
150 EXPECT_TRUE(p.IsValid());
151 EXPECT_EQ(1u, p.GetTokenCount());
152 EXPECT_STREQ(
"01", p.GetTokens()[0].name);
159 EXPECT_TRUE(p.IsValid());
160 EXPECT_EQ(1u, p.GetTokenCount());
161 EXPECT_STREQ(
"4294967296", p.GetTokens()[0].name);
168 EXPECT_FALSE(p.IsValid());
170 EXPECT_EQ(0u, p.GetParseErrorOffset());
176 EXPECT_FALSE(p.IsValid());
178 EXPECT_EQ(2u, p.GetParseErrorOffset());
184 EXPECT_FALSE(p.IsValid());
186 EXPECT_EQ(2u, p.GetParseErrorOffset());
193 EXPECT_TRUE(p.IsValid());
194 EXPECT_EQ(0u, p.GetTokenCount());
199 EXPECT_TRUE(p.IsValid());
200 EXPECT_EQ(1u, p.GetTokenCount());
201 EXPECT_EQ(3u, p.GetTokens()[0].length);
202 EXPECT_STREQ(
"foo", p.GetTokens()[0].name);
207 EXPECT_TRUE(p.IsValid());
208 EXPECT_EQ(2u, p.GetTokenCount());
209 EXPECT_EQ(3u, p.GetTokens()[0].length);
210 EXPECT_STREQ(
"foo", p.GetTokens()[0].name);
211 EXPECT_EQ(1u, p.GetTokens()[1].length);
212 EXPECT_STREQ(
"0", p.GetTokens()[1].name);
213 EXPECT_EQ(0u, p.GetTokens()[1].index);
219 EXPECT_TRUE(p.IsValid());
220 EXPECT_EQ(1u, p.GetTokenCount());
221 EXPECT_EQ(3u, p.GetTokens()[0].length);
222 EXPECT_STREQ(
"a/b", p.GetTokens()[0].name);
228 EXPECT_TRUE(p.IsValid());
229 EXPECT_EQ(1u, p.GetTokenCount());
230 EXPECT_EQ(3u, p.GetTokens()[0].length);
231 EXPECT_STREQ(
"m~n", p.GetTokens()[0].name);
237 EXPECT_TRUE(p.IsValid());
238 EXPECT_EQ(1u, p.GetTokenCount());
239 EXPECT_EQ(0u, p.GetTokens()[0].length);
240 EXPECT_STREQ(
"", p.GetTokens()[0].name);
246 EXPECT_TRUE(p.IsValid());
247 EXPECT_EQ(2u, p.GetTokenCount());
248 EXPECT_EQ(0u, p.GetTokens()[0].length);
249 EXPECT_STREQ(
"", p.GetTokens()[0].name);
250 EXPECT_EQ(1u, p.GetTokens()[1].length);
251 EXPECT_STREQ(
"a", p.GetTokens()[1].name);
257 EXPECT_TRUE(p.IsValid());
258 EXPECT_EQ(1u, p.GetTokenCount());
259 EXPECT_EQ(2u, p.GetTokens()[0].length);
260 EXPECT_EQ(
'\0', p.GetTokens()[0].name[0]);
261 EXPECT_EQ(
'\0', p.GetTokens()[0].name[1]);
262 EXPECT_EQ(
'\0', p.GetTokens()[0].name[2]);
267 EXPECT_STREQ(
"c%d",
Pointer(
"#/c%25d").GetTokens()[0].name);
268 EXPECT_STREQ(
"e^f",
Pointer(
"#/e%5Ef").GetTokens()[0].name);
269 EXPECT_STREQ(
"g|h",
Pointer(
"#/g%7Ch").GetTokens()[0].name);
270 EXPECT_STREQ(
"i\\j",
Pointer(
"#/i%5Cj").GetTokens()[0].name);
271 EXPECT_STREQ(
"k\"l",
Pointer(
"#/k%22l").GetTokens()[0].name);
272 EXPECT_STREQ(
" ",
Pointer(
"#/%20").GetTokens()[0].name);
278 EXPECT_TRUE(p.IsValid());
279 EXPECT_EQ(1u, p.GetTokenCount());
280 EXPECT_STREQ(
"123", p.GetTokens()[0].name);
281 EXPECT_EQ(123u, p.GetTokens()[0].index);
287 EXPECT_TRUE(p.IsValid());
288 EXPECT_EQ(1u, p.GetTokenCount());
289 EXPECT_STREQ(
"01", p.GetTokens()[0].name);
296 EXPECT_TRUE(p.IsValid());
297 EXPECT_EQ(1u, p.GetTokenCount());
298 EXPECT_STREQ(
"4294967296", p.GetTokens()[0].name);
305 EXPECT_TRUE(p.IsValid());
306 EXPECT_EQ(1u, p.GetTokenCount());
307 EXPECT_STREQ(
"\xC2\xA2", p.GetTokens()[0].name);
313 EXPECT_TRUE(p.IsValid());
314 EXPECT_EQ(1u, p.GetTokenCount());
315 EXPECT_EQ(
static_cast<UTF16<>::Ch>(0x00A2), p.GetTokens()[0].name[0]);
316 EXPECT_EQ(1u, p.GetTokens()[0].length);
322 EXPECT_TRUE(p.IsValid());
323 EXPECT_EQ(1u, p.GetTokenCount());
324 EXPECT_EQ(
static_cast<UTF16<>::Ch>(0x20AC), p.GetTokens()[0].name[0]);
325 EXPECT_EQ(1u, p.GetTokens()[0].length);
331 EXPECT_FALSE(p.IsValid());
333 EXPECT_EQ(1u, p.GetParseErrorOffset());
339 EXPECT_FALSE(p.IsValid());
341 EXPECT_EQ(3u, p.GetParseErrorOffset());
347 EXPECT_FALSE(p.IsValid());
349 EXPECT_EQ(3u, p.GetParseErrorOffset());
355 EXPECT_FALSE(p.IsValid());
357 EXPECT_EQ(2u, p.GetParseErrorOffset());
363 EXPECT_FALSE(p.IsValid());
365 EXPECT_EQ(2u, p.GetParseErrorOffset());
371 EXPECT_FALSE(p.IsValid());
373 EXPECT_EQ(2u, p.GetParseErrorOffset());
379 EXPECT_FALSE(p.IsValid());
381 EXPECT_EQ(2u, p.GetParseErrorOffset());
387 EXPECT_FALSE(p.IsValid());
389 EXPECT_EQ(2u, p.GetParseErrorOffset());
395 EXPECT_FALSE(p.IsValid());
397 EXPECT_EQ(2u, p.GetParseErrorOffset());
403 const char* sources[] = {
421 for (
size_t i = 0; i <
sizeof(sources) /
sizeof(sources[0]); i++) {
429 EXPECT_TRUE(p.StringifyUriFragment(s2));
430 Pointer p2(s2.GetString(), s2.GetSize());
431 EXPECT_TRUE(p2.IsValid());
432 EXPECT_TRUE(p == p2);
439 EXPECT_FALSE(p.StringifyUriFragment(s));
444 #define NAME(s) { s, static_cast<SizeType>(sizeof(s) / sizeof(s[0]) - 1), kPointerInvalidIndex } 445 #define INDEX(i) { #i, static_cast<SizeType>(sizeof(#i) - 1), i } 453 Pointer p(kTokens,
sizeof(kTokens) /
sizeof(kTokens[0]));
454 EXPECT_TRUE(p.IsValid());
455 EXPECT_EQ(2u, p.GetTokenCount());
456 EXPECT_EQ(3u, p.GetTokens()[0].length);
457 EXPECT_STREQ(
"foo", p.GetTokens()[0].name);
458 EXPECT_EQ(1u, p.GetTokens()[1].length);
459 EXPECT_STREQ(
"0", p.GetTokens()[1].name);
460 EXPECT_EQ(0u, p.GetTokens()[1].index);
467 EXPECT_TRUE(q.IsValid());
468 EXPECT_EQ(2u, q.GetTokenCount());
469 EXPECT_EQ(3u, q.GetTokens()[0].length);
470 EXPECT_STREQ(
"foo", q.GetTokens()[0].name);
471 EXPECT_EQ(1u, q.GetTokens()[1].length);
472 EXPECT_STREQ(
"0", q.GetTokens()[1].name);
473 EXPECT_EQ(0u, q.GetTokens()[1].index);
478 Pointer p(kTokens,
sizeof(kTokens) /
sizeof(kTokens[0]));
480 EXPECT_TRUE(q.IsValid());
481 EXPECT_EQ(2u, q.GetTokenCount());
482 EXPECT_EQ(3u, q.GetTokens()[0].length);
483 EXPECT_STREQ(
"foo", q.GetTokens()[0].name);
484 EXPECT_EQ(1u, q.GetTokens()[1].length);
485 EXPECT_STREQ(
"0", q.GetTokens()[1].name);
486 EXPECT_EQ(0u, q.GetTokens()[1].index);
495 EXPECT_TRUE(q.IsValid());
496 EXPECT_EQ(2u, q.GetTokenCount());
497 EXPECT_EQ(3u, q.GetTokens()[0].length);
498 EXPECT_STREQ(
"foo", q.GetTokens()[0].name);
499 EXPECT_EQ(1u, q.GetTokens()[1].length);
500 EXPECT_STREQ(
"0", q.GetTokens()[1].name);
501 EXPECT_EQ(0u, q.GetTokens()[1].index);
503 EXPECT_TRUE(q.IsValid());
504 EXPECT_EQ(2u, q.GetTokenCount());
505 EXPECT_EQ(3u, q.GetTokens()[0].length);
506 EXPECT_STREQ(
"foo", q.GetTokens()[0].name);
507 EXPECT_EQ(1u, q.GetTokens()[1].length);
508 EXPECT_STREQ(
"0", q.GetTokens()[1].name);
509 EXPECT_EQ(0u, q.GetTokens()[1].index);
514 Pointer p(kTokens,
sizeof(kTokens) /
sizeof(kTokens[0]));
517 EXPECT_TRUE(q.IsValid());
518 EXPECT_EQ(2u, q.GetTokenCount());
519 EXPECT_EQ(3u, q.GetTokens()[0].length);
520 EXPECT_STREQ(
"foo", q.GetTokens()[0].name);
521 EXPECT_EQ(1u, q.GetTokens()[1].length);
522 EXPECT_STREQ(
"0", q.GetTokens()[1].name);
523 EXPECT_EQ(0u, q.GetTokens()[1].index);
531 EXPECT_TRUE(
Pointer(
"/foo") == q);
533 EXPECT_TRUE(
Pointer(
"/foo/1234") == q);
535 EXPECT_TRUE(
Pointer(
"/foo/1234/") == q);
541 EXPECT_TRUE(
Pointer(
"/foo") == q);
543 EXPECT_TRUE(
Pointer(
"/foo/1234") == q);
545 EXPECT_TRUE(
Pointer(
"/foo/1234/") == q);
548 #if RAPIDJSON_HAS_STDSTRING 552 EXPECT_TRUE(
Pointer(
"/foo") == q);
581 EXPECT_EQ(&d[
"foo"], v);
585 EXPECT_EQ(&d[
"foo"][0], v);
589 EXPECT_EQ(&d[
"foo"][1], v);
597 EXPECT_EQ(&d[
"foo"][2][
"-"], v);
603 EXPECT_EQ(&d[
"foo"][3], v);
609 EXPECT_EQ(&d[
"foo"][4], v);
617 EXPECT_EQ(&d,
Pointer(
"").Get(d));
618 EXPECT_EQ(&d[
"foo"],
Pointer(
"/foo").Get(d));
619 EXPECT_EQ(&d[
"foo"][0],
Pointer(
"/foo/0").Get(d));
620 EXPECT_EQ(&d[
""],
Pointer(
"/").Get(d));
621 EXPECT_EQ(&d[
"a/b"],
Pointer(
"/a~1b").Get(d));
622 EXPECT_EQ(&d[
"c%d"],
Pointer(
"/c%d").Get(d));
623 EXPECT_EQ(&d[
"e^f"],
Pointer(
"/e^f").Get(d));
624 EXPECT_EQ(&d[
"g|h"],
Pointer(
"/g|h").Get(d));
625 EXPECT_EQ(&d[
"i\\j"],
Pointer(
"/i\\j").Get(d));
626 EXPECT_EQ(&d[
"k\"l"],
Pointer(
"/k\"l").Get(d));
627 EXPECT_EQ(&d[
" "],
Pointer(
"/ ").Get(d));
628 EXPECT_EQ(&d[
"m~n"],
Pointer(
"/m~0n").Get(d));
629 EXPECT_TRUE(
Pointer(
"/abc").Get(d) == 0);
630 size_t unresolvedTokenIndex;
631 EXPECT_TRUE(
Pointer(
"/foo/2").Get(d, &unresolvedTokenIndex) == 0);
632 EXPECT_EQ(1, unresolvedTokenIndex);
633 EXPECT_TRUE(
Pointer(
"/foo/a").Get(d, &unresolvedTokenIndex) == 0);
634 EXPECT_EQ(1, unresolvedTokenIndex);
635 EXPECT_TRUE(
Pointer(
"/foo/0/0").Get(d, &unresolvedTokenIndex) == 0);
636 EXPECT_EQ(2, unresolvedTokenIndex);
637 EXPECT_TRUE(
Pointer(
"/foo/0/a").Get(d, &unresolvedTokenIndex) == 0);
638 EXPECT_EQ(2, unresolvedTokenIndex);
647 const Value v(
"qux");
648 EXPECT_TRUE(
Value(
"bar") ==
Pointer(
"/foo/0").GetWithDefault(d, v, a));
649 EXPECT_TRUE(
Value(
"baz") ==
Pointer(
"/foo/1").GetWithDefault(d, v, a));
650 EXPECT_TRUE(
Value(
"qux") ==
Pointer(
"/foo/2").GetWithDefault(d, v, a));
651 EXPECT_TRUE(
Value(
"last") ==
Pointer(
"/foo/-").GetWithDefault(d,
Value(
"last").Move(), a));
652 EXPECT_STREQ(
"last", d[
"foo"][3].GetString());
654 EXPECT_TRUE(
Pointer(
"/foo/null").GetWithDefault(d,
Value().Move(), a).IsNull());
655 EXPECT_TRUE(
Pointer(
"/foo/null").GetWithDefault(d,
"x", a).IsNull());
658 EXPECT_EQ(-1,
Pointer(
"/foo/int").GetWithDefault(d, -1, a).GetInt());
659 EXPECT_EQ(-1,
Pointer(
"/foo/int").GetWithDefault(d, -2, a).GetInt());
660 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(d, 0x87654321, a).GetUint());
661 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(d, 0x12345678, a).GetUint());
664 EXPECT_EQ(i64,
Pointer(
"/foo/int64").GetWithDefault(d, i64, a).GetInt64());
665 EXPECT_EQ(i64,
Pointer(
"/foo/int64").GetWithDefault(d, i64 + 1, a).GetInt64());
668 EXPECT_EQ(u64,
Pointer(
"/foo/uint64").GetWithDefault(d, u64, a).GetUint64());
669 EXPECT_EQ(u64,
Pointer(
"/foo/uint64").GetWithDefault(d, u64 - 1, a).GetUint64());
671 EXPECT_TRUE(
Pointer(
"/foo/true").GetWithDefault(d,
true, a).IsTrue());
672 EXPECT_TRUE(
Pointer(
"/foo/true").GetWithDefault(d,
false, a).IsTrue());
674 EXPECT_TRUE(
Pointer(
"/foo/false").GetWithDefault(d,
false, a).IsFalse());
675 EXPECT_TRUE(
Pointer(
"/foo/false").GetWithDefault(d,
true, a).IsFalse());
678 EXPECT_STREQ(
"Hello",
Pointer(
"/foo/hello").GetWithDefault(d,
"Hello", a).GetString());
683 strcpy(buffer,
"World");
684 EXPECT_STREQ(
"World",
Pointer(
"/foo/world").GetWithDefault(d, buffer, a).GetString());
685 memset(buffer, 0,
sizeof(buffer));
689 #if RAPIDJSON_HAS_STDSTRING 690 EXPECT_STREQ(
"C++",
Pointer(
"/foo/C++").GetWithDefault(d, std::string(
"C++"), a).GetString());
699 const Value v(
"qux");
700 EXPECT_TRUE(
Value(
"bar") ==
Pointer(
"/foo/0").GetWithDefault(d, v));
701 EXPECT_TRUE(
Value(
"baz") ==
Pointer(
"/foo/1").GetWithDefault(d, v));
702 EXPECT_TRUE(
Value(
"qux") ==
Pointer(
"/foo/2").GetWithDefault(d, v));
703 EXPECT_TRUE(
Value(
"last") ==
Pointer(
"/foo/-").GetWithDefault(d,
Value(
"last").Move()));
704 EXPECT_STREQ(
"last", d[
"foo"][3].GetString());
706 EXPECT_TRUE(
Pointer(
"/foo/null").GetWithDefault(d,
Value().Move()).IsNull());
707 EXPECT_TRUE(
Pointer(
"/foo/null").GetWithDefault(d,
"x").IsNull());
710 EXPECT_EQ(-1,
Pointer(
"/foo/int").GetWithDefault(d, -1).GetInt());
711 EXPECT_EQ(-1,
Pointer(
"/foo/int").GetWithDefault(d, -2).GetInt());
712 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(d, 0x87654321).GetUint());
713 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(d, 0x12345678).GetUint());
716 EXPECT_EQ(i64,
Pointer(
"/foo/int64").GetWithDefault(d, i64).GetInt64());
717 EXPECT_EQ(i64,
Pointer(
"/foo/int64").GetWithDefault(d, i64 + 1).GetInt64());
720 EXPECT_EQ(u64,
Pointer(
"/foo/uint64").GetWithDefault(d, u64).GetUint64());
721 EXPECT_EQ(u64,
Pointer(
"/foo/uint64").GetWithDefault(d, u64 - 1).GetUint64());
723 EXPECT_TRUE(
Pointer(
"/foo/true").GetWithDefault(d,
true).IsTrue());
724 EXPECT_TRUE(
Pointer(
"/foo/true").GetWithDefault(d,
false).IsTrue());
726 EXPECT_TRUE(
Pointer(
"/foo/false").GetWithDefault(d,
false).IsFalse());
727 EXPECT_TRUE(
Pointer(
"/foo/false").GetWithDefault(d,
true).IsFalse());
730 EXPECT_STREQ(
"Hello",
Pointer(
"/foo/hello").GetWithDefault(d,
"Hello").GetString());
735 strcpy(buffer,
"World");
736 EXPECT_STREQ(
"World",
Pointer(
"/foo/world").GetWithDefault(d, buffer).GetString());
737 memset(buffer, 0,
sizeof(buffer));
741 #if RAPIDJSON_HAS_STDSTRING 742 EXPECT_STREQ(
"C++",
Pointer(
"/foo/C++").GetWithDefault(d, std::string(
"C++")).GetString());
753 EXPECT_EQ(123, d[
"foo"][0].GetInt());
756 EXPECT_EQ(456, d[
"foo"][2].GetInt());
762 const Value foo(d[
"foo"], a);
763 Pointer(
"/clone").Set(d, foo, a);
767 Pointer(
"/foo/int").Set(d, -1, a);
770 Pointer(
"/foo/uint").Set(d, 0x87654321, a);
774 Pointer(
"/foo/int64").Set(d, i64, a);
778 Pointer(
"/foo/uint64").Set(d, u64, a);
781 Pointer(
"/foo/true").Set(d,
true, a);
784 Pointer(
"/foo/false").Set(d,
false, a);
788 Pointer(
"/foo/hello").Set(d,
"Hello", a);
794 strcpy(buffer,
"World");
795 Pointer(
"/foo/world").Set(d, buffer, a);
796 memset(buffer, 0,
sizeof(buffer));
800 #if RAPIDJSON_HAS_STDSTRING 801 Pointer(
"/foo/c++").Set(d, std::string(
"C++"), a);
812 EXPECT_EQ(123, d[
"foo"][0].GetInt());
815 EXPECT_EQ(456, d[
"foo"][2].GetInt());
826 Pointer(
"/foo/int").Set(d, -1);
829 Pointer(
"/foo/uint").Set(d, 0x87654321);
833 Pointer(
"/foo/int64").Set(d, i64);
837 Pointer(
"/foo/uint64").Set(d, u64);
840 Pointer(
"/foo/true").Set(d,
true);
843 Pointer(
"/foo/false").Set(d,
false);
847 Pointer(
"/foo/hello").Set(d,
"Hello");
853 strcpy(buffer,
"World");
854 Pointer(
"/foo/world").Set(d, buffer);
855 memset(buffer, 0,
sizeof(buffer));
859 #if RAPIDJSON_HAS_STDSTRING 860 Pointer(
"/foo/c++").Set(d, std::string(
"C++"));
870 EXPECT_STREQ(
"baz", d[
"foo"][0].GetString());
871 EXPECT_STREQ(
"bar", d[
"foo"][1].GetString());
878 EXPECT_STREQ(
"baz", d[
"foo"][0].GetString());
879 EXPECT_STREQ(
"bar", d[
"foo"][1].GetString());
886 EXPECT_FALSE(
Pointer(
"").Erase(d));
887 EXPECT_FALSE(
Pointer(
"/nonexist").Erase(d));
888 EXPECT_FALSE(
Pointer(
"/nonexist/nonexist").Erase(d));
889 EXPECT_FALSE(
Pointer(
"/foo/nonexist").Erase(d));
890 EXPECT_FALSE(
Pointer(
"/foo/nonexist/nonexist").Erase(d));
891 EXPECT_FALSE(
Pointer(
"/foo/0/nonexist").Erase(d));
892 EXPECT_FALSE(
Pointer(
"/foo/0/nonexist/nonexist").Erase(d));
893 EXPECT_FALSE(
Pointer(
"/foo/2/nonexist").Erase(d));
894 EXPECT_TRUE(
Pointer(
"/foo/0").Erase(d));
895 EXPECT_EQ(1u, d[
"foo"].Size());
896 EXPECT_STREQ(
"baz", d[
"foo"][0].GetString());
897 EXPECT_TRUE(
Pointer(
"/foo/0").Erase(d));
898 EXPECT_TRUE(d[
"foo"].Empty());
899 EXPECT_TRUE(
Pointer(
"/foo").Erase(d));
900 EXPECT_TRUE(
Pointer(
"/foo").Get(d) == 0);
904 EXPECT_TRUE(
Pointer(
"/a/0/b/0").Get(d) != 0);
905 EXPECT_TRUE(
Pointer(
"/a/0/b/0").Erase(d));
906 EXPECT_TRUE(
Pointer(
"/a/0/b/0").Get(d) == 0);
908 EXPECT_TRUE(
Pointer(
"/a/0/b").Get(d) != 0);
909 EXPECT_TRUE(
Pointer(
"/a/0/b").Erase(d));
910 EXPECT_TRUE(
Pointer(
"/a/0/b").Get(d) == 0);
912 EXPECT_TRUE(
Pointer(
"/a/0").Get(d) != 0);
913 EXPECT_TRUE(
Pointer(
"/a/0").Erase(d));
914 EXPECT_TRUE(
Pointer(
"/a/0").Get(d) == 0);
916 EXPECT_TRUE(
Pointer(
"/a").Get(d) != 0);
917 EXPECT_TRUE(
Pointer(
"/a").Erase(d));
918 EXPECT_TRUE(
Pointer(
"/a").Get(d) == 0);
927 EXPECT_EQ(&d[
"foo"][0], &v);
931 EXPECT_EQ(&d[
"foo"][1], &v);
940 EXPECT_EQ(&d[
"foo"][0], &v);
944 EXPECT_EQ(&d[
"foo"][1], &v);
955 size_t unresolvedTokenIndex;
957 EXPECT_EQ(1, unresolvedTokenIndex);
959 EXPECT_EQ(1, unresolvedTokenIndex);
961 EXPECT_EQ(2, unresolvedTokenIndex);
963 EXPECT_EQ(2, unresolvedTokenIndex);
971 EXPECT_EQ(1, unresolvedTokenIndex);
973 EXPECT_EQ(1, unresolvedTokenIndex);
975 EXPECT_EQ(2, unresolvedTokenIndex);
977 EXPECT_EQ(2, unresolvedTokenIndex);
986 const Value v(
"qux");
992 EXPECT_STREQ(
"last", d[
"foo"][3].GetString());
1023 strcpy(buffer,
"World");
1025 memset(buffer, 0,
sizeof(buffer));
1029 #if RAPIDJSON_HAS_STDSTRING 1039 const Value v(
"qux");
1045 EXPECT_STREQ(
"last", d[
"foo"][3].GetString());
1076 strcpy(buffer,
"World");
1078 memset(buffer, 0,
sizeof(buffer));
1082 #if RAPIDJSON_HAS_STDSTRING 1091 const Value v(
"qux");
1097 EXPECT_STREQ(
"last", d[
"foo"][3].GetString());
1128 strcpy(buffer,
"World");
1130 memset(buffer, 0,
sizeof(buffer));
1134 #if RAPIDJSON_HAS_STDSTRING 1143 const Value v(
"qux");
1149 EXPECT_STREQ(
"last", d[
"foo"][3].GetString());
1180 strcpy(buffer,
"World");
1182 memset(buffer, 0,
sizeof(buffer));
1186 #if RAPIDJSON_HAS_STDSTRING 1198 EXPECT_EQ(123, d[
"foo"][0].GetInt());
1236 strcpy(buffer,
"World");
1238 memset(buffer, 0,
sizeof(buffer));
1242 #if RAPIDJSON_HAS_STDSTRING 1255 EXPECT_EQ(123, d[
"foo"][0].GetInt());
1293 strcpy(buffer,
"World");
1295 memset(buffer, 0,
sizeof(buffer));
1299 #if RAPIDJSON_HAS_STDSTRING 1311 EXPECT_EQ(123, d[
"foo"][0].GetInt());
1349 strcpy(buffer,
"World");
1351 memset(buffer, 0,
sizeof(buffer));
1355 #if RAPIDJSON_HAS_STDSTRING 1367 EXPECT_EQ(123, d[
"foo"][0].GetInt());
1405 strcpy(buffer,
"World");
1407 memset(buffer, 0,
sizeof(buffer));
1411 #if RAPIDJSON_HAS_STDSTRING 1422 EXPECT_STREQ(
"baz", d[
"foo"][0].GetString());
1423 EXPECT_STREQ(
"bar", d[
"foo"][1].GetString());
1426 EXPECT_STREQ(
"bar", d[
"foo"][0].GetString());
1427 EXPECT_STREQ(
"baz", d[
"foo"][1].GetString());
1434 EXPECT_STREQ(
"baz", d[
"foo"][0].GetString());
1435 EXPECT_STREQ(
"bar", d[
"foo"][1].GetString());
1438 EXPECT_STREQ(
"bar", d[
"foo"][0].GetString());
1439 EXPECT_STREQ(
"baz", d[
"foo"][1].GetString());
1447 EXPECT_FALSE(
Pointer(
"/foo/nonexist").Erase(d));
1449 EXPECT_EQ(1u, d[
"foo"].Size());
1450 EXPECT_STREQ(
"baz", d[
"foo"][0].GetString());
1452 EXPECT_TRUE(d[
"foo"].Empty());
1454 EXPECT_TRUE(
Pointer(
"/foo").Get(d) == 0);
1462 EXPECT_FALSE(
Pointer(
"/foo/nonexist").Erase(d));
1464 EXPECT_EQ(1u, d[
"foo"].Size());
1465 EXPECT_STREQ(
"baz", d[
"foo"][0].GetString());
1467 EXPECT_TRUE(d[
"foo"].Empty());
1469 EXPECT_TRUE(
Pointer(
"/foo").Get(d) == 0);
1475 d.
Parse(
"{\"0\" : [123]}");
1476 EXPECT_EQ(123,
Pointer(
"/0/0").Get(d)->GetInt());
1478 EXPECT_EQ(456,
Pointer(
"/0/a").Get(d)->GetInt());
1484 EXPECT_EQ(123,
Pointer(
"/0/0").Get(d)->GetInt());
1486 EXPECT_EQ(123,
Pointer(
"/0/0").Get(d)->GetInt());
1487 EXPECT_EQ(456,
Pointer(
"/0/1").Get(d)->GetInt());
1497 static const bool kNeedFree =
true;
1498 void *
Malloc(
size_t _size) {
return malloc(_size); }
1499 void *
Realloc(
void *_org_p,
size_t _org_size,
size_t _new_size) { (void)_org_size;
return realloc(_org_p, _new_size); }
1500 static void Free(
void *_p) {
return free(_p); }
1503 typedef rapidjson::GenericDocument<
1505 rapidjson::MemoryPoolAllocator< MyAllocator >,
1509 typedef rapidjson::GenericPointer<
1510 ::myjson::Document::ValueType,
1514 typedef ::myjson::Document::ValueType
Value;
1519 std::string mystr, path;
1522 value.SetString(mystr.c_str(),
static_cast<SizeType>(mystr.length()), document.GetAllocator());
1523 myjson::Pointer(path.c_str()).Set(document, value, document.GetAllocator());
TEST(Pointer, DefaultConstructor)
T::ValueType & GetValueByPointerWithDefault(T &root, const GenericPointer< typename T::ValueType > &pointer, const typename T::ValueType &defaultValue, typename T::AllocatorType &a)
::myjson::Document::ValueType Value
static const Pointer::Token kTokens[]
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
const Ch * GetString() const
Invalid percent encoding in URI fragment.
static void Free(void *_p)
static RAPIDJSON_NAMESPACE_BEGIN const SizeType kPointerInvalidIndex
Represents an invalid index in GenericPointer::Token.
T::ValueType & SwapValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
A token is the basic units of internal representation.
A token must begin with a '/'.
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
void * Realloc(void *_org_p, size_t _org_size, size_t _new_size)
rapidjson::GenericDocument< rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator< MyAllocator >, MyAllocator > Document
unsigned __int64 uint64_t
Allocator & GetAllocator()
Get the allocator of this document.
rapidjson::GenericPointer< ::myjson::Document::ValueType, MyAllocator > Pointer
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
T::ValueType & CreateValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::AllocatorType &a)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
const GenericPointer< typename T::ValueType > T2 value
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Append a token and return a new Pointer.
bool EraseValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer)
bool Stringify(OutputStream &os) const
Stringify to string or URI fragment representation.
static const char kJson[]
void * Malloc(size_t _size)
A character must percent encoded in URI fragment.
T::ValueType & SetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
T::ValueType * GetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, size_t *unresolvedTokenIndex=0)
bool HasParseError() const
Whether a parse error has occured in the last parsing.