Wire Sysio Wire Sysion 1.0.0
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, FileReadStream_Peek4)
 
 TEST_F (FileStreamTest, FileWriteStream)
 

Function Documentation

◆ TEST_F() [1/3]

Definition at line 90 of file filestreamtest.cpp.

90 {
91 FILE *fp = fopen(filename_, "rb");
92 ASSERT_TRUE(fp != 0);
93 char buffer[65536];
94 FileReadStream s(fp, buffer, sizeof(buffer));
95
96 for (size_t i = 0; i < length_; i++) {
97 EXPECT_EQ(json_[i], s.Peek());
98 EXPECT_EQ(json_[i], s.Peek()); // 2nd time should be the same
99 EXPECT_EQ(json_[i], s.Take());
100 }
101
102 EXPECT_EQ(length_, s.Tell());
103 EXPECT_EQ('\0', s.Peek());
104
105 fclose(fp);
106}
File byte stream for input using fread().
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954
#define ASSERT_TRUE(condition)
Definition gtest.h:1901
char * s

◆ TEST_F() [2/3]

TEST_F ( FileStreamTest ,
FileReadStream_Peek4  )

Definition at line 108 of file filestreamtest.cpp.

108 {
109 FILE *fp = fopen(abcde_, "rb");
110 ASSERT_TRUE(fp != 0);
111 char buffer[4];
112 FileReadStream s(fp, buffer, sizeof(buffer));
113
114 const char* c = s.Peek4();
115 for (int i = 0; i < 4; i++)
116 EXPECT_EQ('a' + i, c[i]);
117 EXPECT_EQ(0u, s.Tell());
118
119 for (int i = 0; i < 5; i++) {
120 EXPECT_EQ(static_cast<size_t>(i), s.Tell());
121 EXPECT_EQ('a' + i, s.Peek());
122 EXPECT_EQ('a' + i, s.Peek());
123 EXPECT_EQ('a' + i, s.Take());
124 }
125 EXPECT_EQ(5u, s.Tell());
126 EXPECT_EQ(0, s.Peek());
127 EXPECT_EQ(0, s.Take());
128
129 fclose(fp);
130}

◆ TEST_F() [3/3]

Definition at line 132 of file filestreamtest.cpp.

132 {
133 char filename[L_tmpnam];
134 FILE* fp = TempFile(filename);
135
136 char buffer[65536];
137 FileWriteStream os(fp, buffer, sizeof(buffer));
138 for (size_t i = 0; i < length_; i++)
139 os.Put(json_[i]);
140 os.Flush();
141 fclose(fp);
142
143 // Read it back to verify
144 fp = fopen(filename, "rb");
145 FileReadStream is(fp, buffer, sizeof(buffer));
146
147 for (size_t i = 0; i < length_; i++)
148 EXPECT_EQ(json_[i], is.Take());
149
150 EXPECT_EQ(length_, is.Tell());
151 fclose(fp);
152
153 //std::cout << filename << std::endl;
154 remove(filename);
155}
Wrapper of C file stream for output using fwrite().
os_t os
bool remove(const path &p)
FILE * TempFile(char *filename)
Definition unittest.h:80
Here is the call graph for this function: