Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
namespacetest.cpp
Go to the documentation of this file.
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. All rights reserved.
4
//
5
// Licensed under the MIT License (the "License"); you may not use this file except
6
// in compliance with the License. You may obtain a copy of the License at
7
//
8
// http://opensource.org/licenses/MIT
9
//
10
// Unless required by applicable law or agreed to in writing, software distributed
11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
// specific language governing permissions and limitations under the License.
14
15
#include "
unittest.h
"
16
17
// test another instantiation of RapidJSON in a different namespace
18
19
#define RAPIDJSON_NAMESPACE my::rapid::json
20
#define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapid { namespace json {
21
#define RAPIDJSON_NAMESPACE_END } } }
22
23
// include lots of RapidJSON files
24
25
#include "
rapidjson/document.h
"
26
#include "
rapidjson/writer.h
"
27
#include "
rapidjson/filereadstream.h
"
28
#include "
rapidjson/filewritestream.h
"
29
#include "
rapidjson/encodedstream.h
"
30
#include "
rapidjson/stringbuffer.h
"
31
32
static
const
char
json
[] =
"{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}"
;
33
34
TEST
(NamespaceTest,Using) {
35
using namespace
RAPIDJSON_NAMESPACE
;
36
typedef
GenericDocument<UTF8<>
,
CrtAllocator
> DocumentType;
37
DocumentType doc;
38
39
doc.Parse(
json
);
40
EXPECT_TRUE
(!doc.HasParseError());
41
}
42
43
TEST
(NamespaceTest,Direct) {
44
typedef
RAPIDJSON_NAMESPACE::Document
Document
;
45
typedef
RAPIDJSON_NAMESPACE::Reader
Reader
;
46
typedef
RAPIDJSON_NAMESPACE::StringStream
StringStream
;
47
typedef
RAPIDJSON_NAMESPACE::StringBuffer
StringBuffer
;
48
typedef
RAPIDJSON_NAMESPACE::Writer<StringBuffer> WriterType;
49
50
StringStream
s(
json
);
51
StringBuffer
buffer;
52
WriterType writer(buffer);
53
buffer.
ShrinkToFit
();
54
Reader
reader;
55
reader.
Parse
(s, writer);
56
57
EXPECT_STREQ
(
json
, buffer.
GetString
());
58
EXPECT_EQ
(
sizeof
(
json
)-1, buffer.
GetSize
());
59
EXPECT_TRUE
(writer.IsComplete());
60
61
Document
doc;
62
doc.
Parse
(buffer.
GetString
());
63
EXPECT_TRUE
(!doc.
HasParseError
());
64
65
buffer.
Clear
();
66
writer.Reset(buffer);
67
doc.Accept(writer);
68
EXPECT_STREQ
(
json
, buffer.
GetString
());
69
EXPECT_TRUE
(writer.IsComplete());
70
}
CrtAllocator
C-runtime library allocator.
Definition
allocators.h:75
GenericDocument
A document for parsing JSON text as DOM.
Definition
document.h:2130
GenericDocument::HasParseError
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition
document.h:2394
GenericDocument::Parse
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion).
Definition
document.h:2331
GenericReader::Parse
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition
reader.h:557
GenericStringBuffer::ShrinkToFit
void ShrinkToFit()
Definition
stringbuffer.h:61
GenericStringBuffer::GetString
const Ch * GetString() const
Definition
stringbuffer.h:73
GenericStringBuffer::Clear
void Clear()
Definition
stringbuffer.h:60
GenericStringBuffer::GetSize
size_t GetSize() const
Get the size of string in bytes in the string buffer.
Definition
stringbuffer.h:82
document.h
Document
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition
document.h:2512
encodedstream.h
StringStream
GenericStringStream< UTF8< char > > StringStream
Definition
fwd.h:49
Reader
GenericReader< UTF8< char >, UTF8< char >, CrtAllocator > Reader
Definition
fwd.h:90
StringBuffer
GenericStringBuffer< UTF8< char >, CrtAllocator > StringBuffer
Definition
fwd.h:61
EXPECT_EQ
#define EXPECT_EQ(val1, val2)
Definition
gtest.h:1922
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition
gtest.h:1859
EXPECT_STREQ
#define EXPECT_STREQ(s1, s2)
Definition
gtest.h:1995
TEST
#define TEST(test_case_name, test_name)
Definition
gtest.h:2187
filereadstream.h
filewritestream.h
RAPIDJSON_NAMESPACE
#define RAPIDJSON_NAMESPACE
provide custom rapidjson namespace
Definition
rapidjson.h:118
stringbuffer.h
json
rapidjson::Document json
Definition
transport.cpp:49
unittest.h
writer.h
external
rapidjson
test
unittest
namespacetest.cpp
Generated on
for Electroneum by
1.17.0