1*1e76060aSYuxiao Zhang #include "../file-io.hpp"
2*1e76060aSYuxiao Zhang 
3*1e76060aSYuxiao Zhang #include <stdio.h>
4*1e76060aSYuxiao Zhang #include <sys/file.h>
5*1e76060aSYuxiao Zhang #include <unistd.h>
6*1e76060aSYuxiao Zhang 
7*1e76060aSYuxiao Zhang #include <fstream>
8*1e76060aSYuxiao Zhang #include <iostream>
9*1e76060aSYuxiao Zhang #include <string>
10*1e76060aSYuxiao Zhang 
11*1e76060aSYuxiao Zhang #include <gtest/gtest.h>
12*1e76060aSYuxiao Zhang 
TEST(TestFileIO,TestFileReadWrite)13*1e76060aSYuxiao Zhang TEST(TestFileIO, TestFileReadWrite)
14*1e76060aSYuxiao Zhang {
15*1e76060aSYuxiao Zhang     std::string testFile = "./tmp_test_file";
16*1e76060aSYuxiao Zhang 
17*1e76060aSYuxiao Zhang     std::string testStatus, testStatusUpdated;
18*1e76060aSYuxiao Zhang 
19*1e76060aSYuxiao Zhang     testStatus.push_back(2);
20*1e76060aSYuxiao Zhang     testStatus.append("image downloading in progress");
21*1e76060aSYuxiao Zhang 
22*1e76060aSYuxiao Zhang     testStatusUpdated.push_back(0);
23*1e76060aSYuxiao Zhang     testStatusUpdated.append("finished netboot");
24*1e76060aSYuxiao Zhang 
25*1e76060aSYuxiao Zhang     fileWrite(testFile, testStatus);
26*1e76060aSYuxiao Zhang 
27*1e76060aSYuxiao Zhang     EXPECT_TRUE(testStatus == fileRead(testFile));
28*1e76060aSYuxiao Zhang 
29*1e76060aSYuxiao Zhang     fileWrite(testFile, testStatusUpdated);
30*1e76060aSYuxiao Zhang 
31*1e76060aSYuxiao Zhang     EXPECT_TRUE(testStatusUpdated == fileRead(testFile));
32*1e76060aSYuxiao Zhang 
33*1e76060aSYuxiao Zhang     remove(testFile.c_str());
34*1e76060aSYuxiao Zhang }
35