-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_utils_test.cc
37 lines (28 loc) · 1014 Bytes
/
file_utils_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "file_utils.h"
using namespace reddit;
#include <gtest/gtest.h>
#include <string>
using std::string;
const char kHelloFile[] = "testing/hello.txt";
const char kHelloWorld[] = "Hello, world!\n";
const char kDoesntExist[] = "testing/doesnt.exist";
const char kTempFile[] = "testing/tmp.txt";
TEST(TestFileUtils, FileExists) {
EXPECT_TRUE(DoesFileExist(kHelloFile));
EXPECT_FALSE(DoesFileExist(kDoesntExist));
}
TEST(TestFileUtils, ReadFileToString) {
string hello_world = ReadFileToString(kHelloFile);
EXPECT_EQ(hello_world, kHelloWorld);
}
TEST(TestFileUtils, WriteStringToFile) {
EXPECT_FALSE(DoesFileExist(kTempFile));
WriteStringToFile(kTempFile, kHelloWorld);
string contents = ReadFileToString(kTempFile);
EXPECT_EQ(contents, kHelloWorld);
AppendStringToFile(kTempFile, kHelloWorld);
contents = ReadFileToString(kTempFile);
EXPECT_EQ(contents, string(kHelloWorld) + string(kHelloWorld));
DeleteFile(kTempFile);
EXPECT_FALSE(DoesFileExist(kTempFile));
}