summaryrefslogtreecommitdiffhomepage
path: root/tests/test-file.cpp
blob: 7c3b752e2c05c476878a115ae9d7db23775bd9cf (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <gtest/gtest.h>

#include "file.h"

#include <filesystem>
#include <fstream>
#include <iostream>

namespace fs = std::filesystem;

namespace {
 const fs::path testFilename{"testfile.txt"};
} // namespace

class FileTest: public ::testing::Test
{
protected:
 FileTest(){
 }

 ~FileTest() override{
 }

 void SetUp() override
 {
  std::error_code ec;
  fs::remove(testFilename, ec);
 }

 void TearDown() override
 {
  std::error_code ec;
  fs::remove(testFilename, ec);
 }

};

TEST_F(FileTest, getFile)
{
 {
  std::ofstream of(testFilename, std::ios::binary);
  of << "abc";
 }

 std::string s{Reichwein::File::getFile(testFilename)};

 EXPECT_EQ(s, "abc");
}

TEST_F(FileTest, getFile_proc)
{
 std::string s{Reichwein::File::getFile("/proc/cmdline")};

 EXPECT_GT(s.size(), 0);
}