MCPcopy Create free account
hub / github.com/Tencent/rapidjson / EncodedStreamTest

Class EncodedStreamTest

test/unittest/encodedstreamtest.cpp:25–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23using namespace rapidjson;
24
25class EncodedStreamTest : public ::testing::Test {
26public:
27 EncodedStreamTest() : json_(), length_() {}
28 virtual ~EncodedStreamTest();
29
30 virtual void SetUp() {
31 json_ = ReadFile("utf8.json", true, &length_);
32 }
33
34 virtual void TearDown() {
35 free(json_);
36 json_ = 0;
37 }
38
39private:
40 EncodedStreamTest(const EncodedStreamTest&);
41 EncodedStreamTest& operator=(const EncodedStreamTest&);
42
43protected:
44 static FILE* Open(const char* filename) {
45 const char *paths[] = {
46 "encodings",
47 "bin/encodings",
48 "../bin/encodings",
49 "../../bin/encodings",
50 "../../../bin/encodings"
51 };
52 char buffer[1024];
53 for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
54 sprintf(buffer, "%s/%s", paths[i], filename);
55 FILE *fp = fopen(buffer, "rb");
56 if (fp)
57 return fp;
58 }
59 return 0;
60 }
61
62 static char *ReadFile(const char* filename, bool appendPath, size_t* outLength) {
63 FILE *fp = appendPath ? Open(filename) : fopen(filename, "rb");
64
65 if (!fp) {
66 *outLength = 0;
67 return 0;
68 }
69
70 fseek(fp, 0, SEEK_END);
71 *outLength = static_cast<size_t>(ftell(fp));
72 fseek(fp, 0, SEEK_SET);
73 char* buffer = static_cast<char*>(malloc(*outLength + 1));
74 size_t readLength = fread(buffer, 1, *outLength, fp);
75 buffer[readLength] = '\0';
76 fclose(fp);
77 return buffer;
78 }
79
80 template <typename FileEncoding, typename MemoryEncoding>
81 void TestEncodedInputStream(const char* filename) {
82 // Test FileReadStream

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected