fwdtest.cpp 5.7 KB

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