| 23 | using namespace rapidjson; |
| 24 | |
| 25 | class EncodedStreamTest : public ::testing::Test { |
| 26 | public: |
| 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 | |
| 39 | private: |
| 40 | EncodedStreamTest(const EncodedStreamTest&); |
| 41 | EncodedStreamTest& operator=(const EncodedStreamTest&); |
| 42 | |
| 43 | protected: |
| 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 |
nothing calls this directly
no outgoing calls
no test coverage detected