Electroneum
Loading...
Searching...
No Matches
filestreamtest.cpp File Reference
Include dependency graph for filestreamtest.cpp:

Go to the source code of this file.

Classes

class  FileStreamTest

Functions

 TEST_F (FileStreamTest, FileReadStream)
 TEST_F (FileStreamTest, FileWriteStream)

Function Documentation

◆ TEST_F() [1/2]

Definition at line 71 of file filestreamtest.cpp.

71 {
72 FILE *fp = fopen(filename_, "rb");
73 ASSERT_TRUE(fp != 0);
74 char buffer[65536];
75 FileReadStream s(fp, buffer, sizeof(buffer));
76
77 for (size_t i = 0; i < length_; i++) {
78 EXPECT_EQ(json_[i], s.Peek());
79 EXPECT_EQ(json_[i], s.Peek()); // 2nd time should be the same
80 EXPECT_EQ(json_[i], s.Take());
81 }
82
83 EXPECT_EQ(length_, s.Tell());
84 EXPECT_EQ('\0', s.Peek());
85
86 fclose(fp);
87}
File byte stream for input using fread().
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
Here is the call graph for this function:

◆ TEST_F() [2/2]

Definition at line 89 of file filestreamtest.cpp.

89 {
90 char filename[L_tmpnam];
91 FILE* fp = TempFile(filename);
92
93 char buffer[65536];
94 FileWriteStream os(fp, buffer, sizeof(buffer));
95 for (size_t i = 0; i < length_; i++)
96 os.Put(json_[i]);
97 os.Flush();
98 fclose(fp);
99
100 // Read it back to verify
101 fp = fopen(filename, "rb");
102 FileReadStream is(fp, buffer, sizeof(buffer));
103
104 for (size_t i = 0; i < length_; i++)
105 EXPECT_EQ(json_[i], is.Take());
106
107 EXPECT_EQ(length_, is.Tell());
108 fclose(fp);
109
110 //std::cout << filename << std::endl;
111 remove(filename);
112}
Wrapper of C file stream for output using fwrite().
FILE * TempFile(char *filename)
Definition unittest.h:80
Here is the call graph for this function: