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 56 57 58
|
#include <gtest/gtest.h>
#include "cpp-utils/tempfile/TempDir.h"
#include <fstream>
using ::testing::Test;
using std::ofstream;
using namespace cpputils;
namespace bf = boost::filesystem;
class TempDirTest: public Test {
public:
void EXPECT_ENTRY_COUNT(int expected, const bf::path &path) {
const int actual = CountEntries(path);
EXPECT_EQ(expected, actual);
}
int CountEntries(const bf::path &path) {
int count = 0;
for (bf::directory_iterator iter(path); iter != bf::directory_iterator(); ++iter) {
++count;
}
return count;
}
void CreateFile(const bf::path &path) {
const ofstream file(path.string().c_str());
}
};
TEST_F(TempDirTest, DirIsCreated) {
const TempDir dir;
EXPECT_TRUE(bf::exists(dir.path()));
EXPECT_TRUE(bf::is_directory(dir.path()));
}
TEST_F(TempDirTest, DirIsCreatedEmpty) {
const TempDir dir;
EXPECT_ENTRY_COUNT(0, dir.path());
}
TEST_F(TempDirTest, DirIsWriteable) {
const TempDir dir;
CreateFile(dir.path() / "myfile");
EXPECT_ENTRY_COUNT(1, dir.path());
}
TEST_F(TempDirTest, DirIsDeletedAfterUse) {
bf::path dirpath;
{
const TempDir dir;
dirpath = dir.path();
}
EXPECT_FALSE(bf::exists(dirpath));
}
|