25static const char kJson[] =
"{\n"
26" \"foo\":[\"bar\", \"baz\"],\n"
57 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
66 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
69 #if RAPIDJSON_HAS_STDSTRING
76 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
86 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
156 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
165 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
293 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
302 EXPECT_EQ(kPointerInvalidIndex,
p.GetTokens()[0].index);
406 const char* sources[] = {
424 for (
size_t i = 0; i <
sizeof(sources) /
sizeof(sources[0]); i++) {
447#define NAME(s) { s, static_cast<SizeType>(sizeof(s) / sizeof(s[0]) - 1), kPointerInvalidIndex }
448#define INDEX(i) { #i, static_cast<SizeType>(sizeof(#i) - 1), i }
456 Pointer p(kTokens,
sizeof(kTokens) /
sizeof(kTokens[0]));
478 EXPECT_EQ(&
p.GetAllocator(), &q.GetAllocator());
483 Pointer p(kTokens,
sizeof(kTokens) /
sizeof(kTokens[0]));
508 EXPECT_NE(&
p.GetAllocator(), &q.GetAllocator());
509 q =
static_cast<const Pointer &
>(q);
517 EXPECT_NE(&
p.GetAllocator(), &q.GetAllocator());
522 Pointer p(kTokens,
sizeof(kTokens) /
sizeof(kTokens[0]));
540 EXPECT_EQ(&q.GetAllocator(), &
p.GetAllocator());
553 EXPECT_EQ(&
p.GetAllocator(), &q.GetAllocator());
586#if RAPIDJSON_HAS_STDSTRING
589 Pointer q =
p.Append(std::string(
"foo"));
668 size_t unresolvedTokenIndex;
685 const Value v(
"qux");
698 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(
d, 0x87654321,
a).GetUint());
699 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(
d, 0x12345678,
a).GetUint());
721 strcpy(buffer,
"World");
723 memset(buffer, 0,
sizeof(buffer));
727#if RAPIDJSON_HAS_STDSTRING
737 const Value v(
"qux");
750 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(
d, 0x87654321).GetUint());
751 EXPECT_EQ(0x87654321,
Pointer(
"/foo/uint").GetWithDefault(
d, 0x12345678).GetUint());
773 strcpy(buffer,
"World");
775 memset(buffer, 0,
sizeof(buffer));
779#if RAPIDJSON_HAS_STDSTRING
808 Pointer(
"/foo/uint").Set(
d, 0x87654321,
a);
826 Pointer(
"/foo/hello").Set(
d,
"Hello",
a);
832 strcpy(buffer,
"World");
834 memset(buffer, 0,
sizeof(buffer));
838#if RAPIDJSON_HAS_STDSTRING
839 Pointer(
"/foo/c++").Set(
d, std::string(
"C++"),
a);
867 Pointer(
"/foo/uint").Set(
d, 0x87654321);
881 Pointer(
"/foo/false").Set(
d,
false);
885 Pointer(
"/foo/hello").Set(
d,
"Hello");
891 strcpy(buffer,
"World");
892 Pointer(
"/foo/world").Set(
d, buffer);
893 memset(buffer, 0,
sizeof(buffer));
897#if RAPIDJSON_HAS_STDSTRING
898 Pointer(
"/foo/c++").Set(
d, std::string(
"C++"));
993 size_t unresolvedTokenIndex;
1024 const Value v(
"qux");
1061 strcpy(buffer,
"World");
1063 memset(buffer, 0,
sizeof(buffer));
1067#if RAPIDJSON_HAS_STDSTRING
1077 const Value v(
"qux");
1114 strcpy(buffer,
"World");
1116 memset(buffer, 0,
sizeof(buffer));
1120#if RAPIDJSON_HAS_STDSTRING
1129 const Value v(
"qux");
1166 strcpy(buffer,
"World");
1168 memset(buffer, 0,
sizeof(buffer));
1172#if RAPIDJSON_HAS_STDSTRING
1181 const Value v(
"qux");
1218 strcpy(buffer,
"World");
1220 memset(buffer, 0,
sizeof(buffer));
1224#if RAPIDJSON_HAS_STDSTRING
1274 strcpy(buffer,
"World");
1276 memset(buffer, 0,
sizeof(buffer));
1280#if RAPIDJSON_HAS_STDSTRING
1331 strcpy(buffer,
"World");
1333 memset(buffer, 0,
sizeof(buffer));
1337#if RAPIDJSON_HAS_STDSTRING
1387 strcpy(buffer,
"World");
1389 memset(buffer, 0,
sizeof(buffer));
1393#if RAPIDJSON_HAS_STDSTRING
1443 strcpy(buffer,
"World");
1445 memset(buffer, 0,
sizeof(buffer));
1449#if RAPIDJSON_HAS_STDSTRING
1513 d.Parse(
"{\"0\" : [123]}");
1530 static const struct {
1541 {
"/e/f~g",
false },
1542 {
"/d/2/zz",
true },
1545 {
"/e/f~~g",
false },
1546 {
"/e/f~0g",
true },
1547 {
"/e/f~1g",
true },
1551 static const char *ordered_pointers[] = {
1571 typedef std::multimap<PointerType, size_t> PointerMap;
1573 PointerMap::iterator it;
1574 AllocatorType allocator;
1577 EXPECT_EQ(
sizeof(pointers) /
sizeof(pointers[0]),
1578 sizeof(ordered_pointers) /
sizeof(ordered_pointers[0]));
1580 for (i = 0; i <
sizeof(pointers) /
sizeof(pointers[0]); ++i) {
1581 it = map.insert(PointerMap::value_type(PointerType(pointers[i].str, &allocator), i));
1582 if (!it->first.IsValid()) {
1587 for (i = 0, it = map.begin(); it != map.end(); ++it, ++i) {
1588 EXPECT_TRUE(it->second <
sizeof(pointers) /
sizeof(pointers[0]));
1589 EXPECT_EQ(it->first.IsValid(), pointers[it->second].valid);
1590 EXPECT_TRUE(i <
sizeof(ordered_pointers) /
sizeof(ordered_pointers[0]));
1591 EXPECT_EQ(it->first.IsValid(), !!ordered_pointers[i]);
1592 if (it->first.IsValid()) {
1593 std::stringstream ss;
1596 EXPECT_EQ(ss.str(), pointers[it->second].str);
1597 EXPECT_EQ(ss.str(), ordered_pointers[i]);
1609 void *
Malloc(
size_t _size) {
return malloc(_size); }
1610 void *
Realloc(
void *_org_p,
size_t _org_size,
size_t _new_size) { (void)_org_size;
return realloc(_org_p, _new_size); }
1611 static void Free(
void *_p) {
return free(_p); }
1614typedef rapidjson::GenericDocument<
1616 rapidjson::MemoryPoolAllocator< MyAllocator >,
1620typedef rapidjson::GenericPointer<
1621 ::myjson::Document::ValueType,
1625typedef ::myjson::Document::ValueType
Value;
1630 std::string mystr, path;
1633 value.SetString(mystr.c_str(),
static_cast<SizeType>(mystr.length()), document.GetAllocator());
C-runtime library allocator.
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Append a token and return a new Pointer.
GenericPointer & Swap(GenericPointer &other) RAPIDJSON_NOEXCEPT
Swap the content of this pointer with an other.
const Ch * GetString() const
size_t GetSize() const
Get the size of string in bytes in the string buffer.
Default memory allocator used by the parser and DOM.
static void Free(void *_p)
void * Realloc(void *_org_p, size_t _org_size, size_t _new_size)
static const bool kNeedFree
void * Malloc(size_t _size)
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
GenericPointer< Value, CrtAllocator > Pointer
@ kPointerParseErrorInvalidEscape
Invalid escape.
@ kPointerParseErrorTokenMustBeginWithSolidus
A token must begin with a '/'.
@ kPointerParseErrorCharacterMustPercentEncode
A character must percent encoded in URI fragment.
@ kPointerParseErrorInvalidPercentEncoding
Invalid percent encoding in URI fragment.
#define EXPECT_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
rapidjson::GenericPointer< ::myjson::Document::ValueType, MyAllocator > Pointer
::myjson::Document::ValueType Value
rapidjson::GenericDocument< rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator< MyAllocator >, MyAllocator > Document
void swap(picojson::value &x, picojson::value &y)
T::ValueType & SwapValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
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 EraseValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer)
T::ValueType & CreateValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::AllocatorType &a)
T::ValueType & GetValueByPointerWithDefault(T &root, const GenericPointer< typename T::ValueType > &pointer, const typename T::ValueType &defaultValue, typename T::AllocatorType &a)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
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.
unsigned __int64 uint64_t
A token is the basic units of internal representation.
memset(pInfo->slotDescription, ' ', 64)