Electroneum
Loading...
Searching...
No Matches
EncodedStreamTest Class Reference
Inheritance diagram for EncodedStreamTest:
Collaboration diagram for EncodedStreamTest:

Public Member Functions

 EncodedStreamTest ()
virtual ~EncodedStreamTest ()
virtual void SetUp ()
virtual void TearDown ()
Public Member Functions inherited from testing::Test
virtual ~Test ()
virtual ~Test ()

Protected Member Functions

template<typename FileEncoding, typename MemoryEncoding>
void TestEncodedInputStream (const char *filename)
void TestAutoUTFInputStream (const char *filename, bool expectHasBOM)
template<typename FileEncoding, typename MemoryEncoding>
void TestEncodedOutputStream (const char *expectedFilename, bool putBOM)
void TestAutoUTFOutputStream (UTFType type, bool putBOM, const char *expectedFilename)
bool CompareFile (const char *filename, const char *expectedFilename)
bool CompareBufferFile (const char *actualBuffer, size_t actualLength, const char *expectedFilename)
Protected Member Functions inherited from testing::Test
 Test ()
 Test ()

Static Protected Member Functions

static FILE * Open (const char *filename)
static char * ReadFile (const char *filename, bool appendPath, size_t *outLength)

Protected Attributes

char * json_
size_t length_

Additional Inherited Members

Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
static void TearDownTestCase ()
static bool HasFatalFailure ()
static bool HasNonfatalFailure ()
static bool HasFailure ()
static void RecordProperty (const std::string &key, const std::string &value)
static void RecordProperty (const std::string &key, int value)
static void SetUpTestCase ()
static void TearDownTestCase ()
static bool HasFatalFailure ()
static bool HasNonfatalFailure ()
static bool HasFailure ()
static void RecordProperty (const std::string &key, const std::string &value)
static void RecordProperty (const std::string &key, int value)

Detailed Description

Definition at line 25 of file encodedstreamtest.cpp.

Constructor & Destructor Documentation

◆ EncodedStreamTest()

EncodedStreamTest::EncodedStreamTest ( )
inline

Definition at line 27 of file encodedstreamtest.cpp.

◆ ~EncodedStreamTest()

EncodedStreamTest::~EncodedStreamTest ( )
virtual

Definition at line 252 of file encodedstreamtest.cpp.

252{}

Member Function Documentation

◆ CompareBufferFile()

bool EncodedStreamTest::CompareBufferFile ( const char * actualBuffer,
size_t actualLength,
const char * expectedFilename )
inlineprotected

Definition at line 240 of file encodedstreamtest.cpp.

240 {
241 size_t expectedLength;
242 char* expectedBuffer = ReadFile(expectedFilename, true, &expectedLength);
243 bool ret = (expectedLength == actualLength) && memcmp(expectedBuffer, actualBuffer, actualLength) == 0;
244 free(expectedBuffer);
245 return ret;
246 }
static char * ReadFile(const char *filename, bool appendPath, size_t *outLength)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompareFile()

bool EncodedStreamTest::CompareFile ( const char * filename,
const char * expectedFilename )
inlineprotected

Definition at line 230 of file encodedstreamtest.cpp.

230 {
231 size_t actualLength, expectedLength;
232 char* actualBuffer = ReadFile(filename, false, &actualLength);
233 char* expectedBuffer = ReadFile(expectedFilename, true, &expectedLength);
234 bool ret = (expectedLength == actualLength) && memcmp(expectedBuffer, actualBuffer, actualLength) == 0;
235 free(actualBuffer);
236 free(expectedBuffer);
237 return ret;
238 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Open()

FILE * EncodedStreamTest::Open ( const char * filename)
inlinestaticprotected

Definition at line 44 of file encodedstreamtest.cpp.

44 {
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 }
Here is the caller graph for this function:

◆ ReadFile()

char * EncodedStreamTest::ReadFile ( const char * filename,
bool appendPath,
size_t * outLength )
inlinestaticprotected

Definition at line 62 of file encodedstreamtest.cpp.

62 {
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 }
static FILE * Open(const char *filename)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetUp()

virtual void EncodedStreamTest::SetUp ( )
inlinevirtual

Reimplemented from testing::Test.

Definition at line 30 of file encodedstreamtest.cpp.

30 {
31 json_ = ReadFile("utf8.json", true, &length_);
32 }
Here is the call graph for this function:

◆ TearDown()

virtual void EncodedStreamTest::TearDown ( )
inlinevirtual

Reimplemented from testing::Test.

Definition at line 34 of file encodedstreamtest.cpp.

34 {
35 free(json_);
36 json_ = 0;
37 }

◆ TestAutoUTFInputStream()

void EncodedStreamTest::TestAutoUTFInputStream ( const char * filename,
bool expectHasBOM )
inlineprotected

Definition at line 121 of file encodedstreamtest.cpp.

121 {
122 // Test FileReadStream
123 {
124 char buffer[16];
125 FILE *fp = Open(filename);
126 ASSERT_TRUE(fp != 0);
127 FileReadStream fs(fp, buffer, sizeof(buffer));
128 AutoUTFInputStream<unsigned, FileReadStream> eis(fs);
129 EXPECT_EQ(expectHasBOM, eis.HasBOM());
131 while (eis.Peek() != '\0') {
132 unsigned expected, actual;
133 EXPECT_TRUE(UTF8<>::Decode(s, &expected));
135 EXPECT_EQ(expected, actual);
136 }
137 EXPECT_EQ('\0', s.Peek());
138 fclose(fp);
139 }
140
141 // Test MemoryStream
142 {
143 size_t size;
144 char* data = ReadFile(filename, true, &size);
145 MemoryStream ms(data, size);
146 AutoUTFInputStream<unsigned, MemoryStream> eis(ms);
147 EXPECT_EQ(expectHasBOM, eis.HasBOM());
149
150 while (eis.Peek() != '\0') {
151 unsigned expected, actual;
152 EXPECT_TRUE(UTF8<>::Decode(s, &expected));
154 EXPECT_EQ(expected, actual);
155 }
156 EXPECT_EQ('\0', s.Peek());
157 free(data);
158 EXPECT_EQ(size, eis.Tell());
159 }
160 }
GenericStringStream< UTF8< char > > StringStream
Definition fwd.h:49
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define EXPECT_TRUE(condition)
Definition gtest.h:1859
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
static RAPIDJSON_FORCEINLINE bool Decode(InputStream &is, unsigned *codepoint)
Definition encodings.h:637
static bool Decode(InputStream &is, unsigned *codepoint)
Definition encodings.h:146
Here is the call graph for this function:

◆ TestAutoUTFOutputStream()

void EncodedStreamTest::TestAutoUTFOutputStream ( UTFType type,
bool putBOM,
const char * expectedFilename )
inlineprotected

Definition at line 196 of file encodedstreamtest.cpp.

196 {
197 // Test FileWriteStream
198 {
199 char filename[L_tmpnam];
200 FILE* fp = TempFile(filename);
201
202 char buffer[16];
203 FileWriteStream os(fp, buffer, sizeof(buffer));
204 AutoUTFOutputStream<unsigned, FileWriteStream> eos(os, type, putBOM);
206 while (s.Peek() != '\0') {
207 bool success = Transcoder<UTF8<>, AutoUTF<unsigned> >::Transcode(s, eos);
208 EXPECT_TRUE(success);
209 }
210 eos.Flush();
211 fclose(fp);
212 EXPECT_TRUE(CompareFile(filename, expectedFilename));
213 remove(filename);
214 }
215
216 // Test MemoryBuffer
217 {
218 MemoryBuffer mb;
219 AutoUTFOutputStream<unsigned, MemoryBuffer> eos(mb, type, putBOM);
221 while (s.Peek() != '\0') {
222 bool success = Transcoder<UTF8<>, AutoUTF<unsigned> >::Transcode(s, eos);
223 EXPECT_TRUE(success);
224 }
225 eos.Flush();
226 EXPECT_TRUE(CompareBufferFile(mb.GetBuffer(), mb.GetSize(), expectedFilename));
227 }
228 }
bool CompareFile(const char *filename, const char *expectedFilename)
bool CompareBufferFile(const char *actualBuffer, size_t actualLength, const char *expectedFilename)
GenericMemoryBuffer< CrtAllocator > MemoryBuffer
Definition fwd.h:76
const Ch * GetBuffer() const
size_t GetSize() const
FILE * TempFile(char *filename)
Definition unittest.h:80
Here is the call graph for this function:

◆ TestEncodedInputStream()

template<typename FileEncoding, typename MemoryEncoding>
void EncodedStreamTest::TestEncodedInputStream ( const char * filename)
inlineprotected

Definition at line 81 of file encodedstreamtest.cpp.

81 {
82 // Test FileReadStream
83 {
84 char buffer[16];
85 FILE *fp = Open(filename);
86 ASSERT_TRUE(fp != 0);
87 FileReadStream fs(fp, buffer, sizeof(buffer));
88 EncodedInputStream<FileEncoding, FileReadStream> eis(fs);
90
91 while (eis.Peek() != '\0') {
92 unsigned expected, actual;
93 EXPECT_TRUE(UTF8<>::Decode(s, &expected));
94 EXPECT_TRUE(MemoryEncoding::Decode(eis, &actual));
95 EXPECT_EQ(expected, actual);
96 }
97 EXPECT_EQ('\0', s.Peek());
98 fclose(fp);
99 }
100
101 // Test MemoryStream
102 {
103 size_t size;
104 char* data = ReadFile(filename, true, &size);
105 MemoryStream ms(data, size);
106 EncodedInputStream<FileEncoding, MemoryStream> eis(ms);
108
109 while (eis.Peek() != '\0') {
110 unsigned expected, actual;
111 EXPECT_TRUE(UTF8<>::Decode(s, &expected));
112 EXPECT_TRUE(MemoryEncoding::Decode(eis, &actual));
113 EXPECT_EQ(expected, actual);
114 }
115 EXPECT_EQ('\0', s.Peek());
116 free(data);
117 EXPECT_EQ(size, eis.Tell());
118 }
119 }
Here is the call graph for this function:

◆ TestEncodedOutputStream()

template<typename FileEncoding, typename MemoryEncoding>
void EncodedStreamTest::TestEncodedOutputStream ( const char * expectedFilename,
bool putBOM )
inlineprotected

Definition at line 163 of file encodedstreamtest.cpp.

163 {
164 // Test FileWriteStream
165 {
166 char filename[L_tmpnam];
167 FILE* fp = TempFile(filename);
168 char buffer[16];
169 FileWriteStream os(fp, buffer, sizeof(buffer));
170 EncodedOutputStream<FileEncoding, FileWriteStream> eos(os, putBOM);
172 while (s.Peek() != '\0') {
173 bool success = Transcoder<UTF8<>, MemoryEncoding>::Transcode(s, eos);
174 EXPECT_TRUE(success);
175 }
176 eos.Flush();
177 fclose(fp);
178 EXPECT_TRUE(CompareFile(filename, expectedFilename));
179 remove(filename);
180 }
181
182 // Test MemoryBuffer
183 {
184 MemoryBuffer mb;
185 EncodedOutputStream<FileEncoding, MemoryBuffer> eos(mb, putBOM);
187 while (s.Peek() != '\0') {
188 bool success = Transcoder<UTF8<>, MemoryEncoding>::Transcode(s, eos);
189 EXPECT_TRUE(success);
190 }
191 eos.Flush();
192 EXPECT_TRUE(CompareBufferFile(mb.GetBuffer(), mb.GetSize(), expectedFilename));
193 }
194 }
Here is the call graph for this function:

Member Data Documentation

◆ json_

char* EncodedStreamTest::json_
protected

Definition at line 248 of file encodedstreamtest.cpp.

◆ length_

size_t EncodedStreamTest::length_
protected

Definition at line 249 of file encodedstreamtest.cpp.


The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/test/unittest/encodedstreamtest.cpp