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 // Using forward declared types here.
18 
19 #include "rapidjson/fwd.h"
20 
21 #ifdef __GNUC__
22 RAPIDJSON_DIAG_PUSH
23 RAPIDJSON_DIAG_OFF(effc++)
24 #endif
25 
26 using namespace rapidjson;
27 
28 struct Foo {
29     Foo();
30     ~Foo();
31 
32     // encodings.h
33     UTF8<char>* utf8;
34     UTF16<wchar_t>* utf16;
35     UTF16BE<wchar_t>* utf16be;
36     UTF16LE<wchar_t>* utf16le;
37     UTF32<unsigned>* utf32;
38     UTF32BE<unsigned>* utf32be;
39     UTF32LE<unsigned>* utf32le;
40     ASCII<char>* ascii;
41     AutoUTF<unsigned>* autoutf;
42     Transcoder<UTF8<char>, UTF8<char> >* transcoder;
43 
44     // allocators.h
45     CrtAllocator* crtallocator;
46     MemoryPoolAllocator<CrtAllocator>* memorypoolallocator;
47 
48     // stream.h
49     StringStream* stringstream;
50     InsituStringStream* insitustringstream;
51 
52     // stringbuffer.h
53     StringBuffer* stringbuffer;
54 
55     // // filereadstream.h
56     // FileReadStream* filereadstream;
57 
58     // // filewritestream.h
59     // FileWriteStream* filewritestream;
60 
61     // memorybuffer.h
62     MemoryBuffer* memorybuffer;
63 
64     // memorystream.h
65     MemoryStream* memorystream;
66 
67     // reader.h
68     BaseReaderHandler<UTF8<char>, void>* basereaderhandler;
69     Reader* reader;
70 
71     // writer.h
72     Writer<StringBuffer, UTF8<char>, UTF8<char>, CrtAllocator, 0>* writer;
73 
74     // prettywriter.h
75     PrettyWriter<StringBuffer, UTF8<char>, UTF8<char>, CrtAllocator, 0>* prettywriter;
76 
77     // document.h
78     Value* value;
79     Document* document;
80 
81     // pointer.h
82     Pointer* pointer;
83 
84     // schema.h
85     SchemaDocument* schemadocument;
86     SchemaValidator* schemavalidator;
87 
88     // char buffer[16];
89 };
90 
91 // Using type definitions here.
92 
93 #include "rapidjson/stringbuffer.h"
94 #include "rapidjson/filereadstream.h"
95 #include "rapidjson/filewritestream.h"
96 #include "rapidjson/memorybuffer.h"
97 #include "rapidjson/memorystream.h"
98 #include "rapidjson/document.h" // -> reader.h
99 #include "rapidjson/writer.h"
100 #include "rapidjson/prettywriter.h"
101 #include "rapidjson/schema.h"   // -> pointer.h
102 
Foo()103 Foo::Foo() :
104     // encodings.h
105     utf8(RAPIDJSON_NEW(UTF8<>)),
106     utf16(RAPIDJSON_NEW(UTF16<>)),
107     utf16be(RAPIDJSON_NEW(UTF16BE<>)),
108     utf16le(RAPIDJSON_NEW(UTF16LE<>)),
109     utf32(RAPIDJSON_NEW(UTF32<>)),
110     utf32be(RAPIDJSON_NEW(UTF32BE<>)),
111     utf32le(RAPIDJSON_NEW(UTF32LE<>)),
112     ascii(RAPIDJSON_NEW(ASCII<>)),
113     autoutf(RAPIDJSON_NEW(AutoUTF<unsigned>)),
114     transcoder(RAPIDJSON_NEW((Transcoder<UTF8<>, UTF8<> >))),
115 
116     // allocators.h
117     crtallocator(RAPIDJSON_NEW(CrtAllocator)),
118     memorypoolallocator(RAPIDJSON_NEW(MemoryPoolAllocator<>)),
119 
120     // stream.h
121     stringstream(RAPIDJSON_NEW(StringStream(0))),
122     insitustringstream(RAPIDJSON_NEW(InsituStringStream(0))),
123 
124     // stringbuffer.h
125     stringbuffer(RAPIDJSON_NEW(StringBuffer)),
126 
127     // // filereadstream.h
128     // filereadstream(RAPIDJSON_NEW(FileReadStream(stdout, buffer, sizeof(buffer)))),
129 
130     // // filewritestream.h
131     // filewritestream(RAPIDJSON_NEW(FileWriteStream(stdout, buffer, sizeof(buffer)))),
132 
133     // memorybuffer.h
134     memorybuffer(RAPIDJSON_NEW(MemoryBuffer)),
135 
136     // memorystream.h
137     memorystream(RAPIDJSON_NEW(MemoryStream(0, 0))),
138 
139     // reader.h
140     basereaderhandler(RAPIDJSON_NEW((BaseReaderHandler<UTF8<>, void>))),
141     reader(RAPIDJSON_NEW(Reader)),
142 
143     // writer.h
144     writer(RAPIDJSON_NEW((Writer<StringBuffer>))),
145 
146     // prettywriter.h
147     prettywriter(RAPIDJSON_NEW((PrettyWriter<StringBuffer>))),
148 
149     // document.h
150     value(RAPIDJSON_NEW(Value)),
151     document(RAPIDJSON_NEW(Document)),
152 
153     // pointer.h
154     pointer(RAPIDJSON_NEW(Pointer)),
155 
156     // schema.h
157     schemadocument(RAPIDJSON_NEW(SchemaDocument(*document))),
158     schemavalidator(RAPIDJSON_NEW(SchemaValidator(*schemadocument)))
159 {
160 
161 }
162 
~Foo()163 Foo::~Foo() {
164     // encodings.h
165     RAPIDJSON_DELETE(utf8);
166     RAPIDJSON_DELETE(utf16);
167     RAPIDJSON_DELETE(utf16be);
168     RAPIDJSON_DELETE(utf16le);
169     RAPIDJSON_DELETE(utf32);
170     RAPIDJSON_DELETE(utf32be);
171     RAPIDJSON_DELETE(utf32le);
172     RAPIDJSON_DELETE(ascii);
173     RAPIDJSON_DELETE(autoutf);
174     RAPIDJSON_DELETE(transcoder);
175 
176     // allocators.h
177     RAPIDJSON_DELETE(crtallocator);
178     RAPIDJSON_DELETE(memorypoolallocator);
179 
180     // stream.h
181     RAPIDJSON_DELETE(stringstream);
182     RAPIDJSON_DELETE(insitustringstream);
183 
184     // stringbuffer.h
185     RAPIDJSON_DELETE(stringbuffer);
186 
187     // // filereadstream.h
188     // RAPIDJSON_DELETE(filereadstream);
189 
190     // // filewritestream.h
191     // RAPIDJSON_DELETE(filewritestream);
192 
193     // memorybuffer.h
194     RAPIDJSON_DELETE(memorybuffer);
195 
196     // memorystream.h
197     RAPIDJSON_DELETE(memorystream);
198 
199     // reader.h
200     RAPIDJSON_DELETE(basereaderhandler);
201     RAPIDJSON_DELETE(reader);
202 
203     // writer.h
204     RAPIDJSON_DELETE(writer);
205 
206     // prettywriter.h
207     RAPIDJSON_DELETE(prettywriter);
208 
209     // document.h
210     RAPIDJSON_DELETE(value);
211     RAPIDJSON_DELETE(document);
212 
213     // pointer.h
214     RAPIDJSON_DELETE(pointer);
215 
216     // schema.h
217     RAPIDJSON_DELETE(schemadocument);
218     RAPIDJSON_DELETE(schemavalidator);
219 }
220 
TEST(Fwd,Fwd)221 TEST(Fwd, Fwd) {
222     Foo f;
223 }
224 
225 #ifdef __GNUC__
226 RAPIDJSON_DIAG_POP
227 #endif
228