mirror of
https://github.com/vgough/encfs.git
synced 2024-11-25 09:23:13 +01:00
59d74aea1f
git-subtree-dir: vendor/github.com/muflihun/easyloggingpp git-subtree-split: 850ea2a9f151ed648a989dda1cf44e503e45831f
60 lines
1.6 KiB
C
60 lines
1.6 KiB
C
#ifndef FILE_UTILS_TEST_H
|
|
#define FILE_UTILS_TEST_H
|
|
|
|
#include "test.h"
|
|
|
|
static const char* filename = "/tmp/files_utils_test";
|
|
static el::base::type::fstream_t* fs;
|
|
|
|
TEST(FileUtilsTest, NewFileStream) {
|
|
fs = File::newFileStream(filename);
|
|
EXPECT_NE(nullptr, fs);
|
|
EXPECT_TRUE(fs->is_open());
|
|
cleanFile(filename, fs);
|
|
}
|
|
|
|
TEST(FileUtilsTest, GetSizeOfFile) {
|
|
EXPECT_EQ(File::getSizeOfFile(fs), 0);
|
|
const char* data = "123";
|
|
(*fs) << data;
|
|
fs->flush();
|
|
EXPECT_EQ(File::getSizeOfFile(fs), strlen(data));
|
|
}
|
|
|
|
TEST(FileUtilsTest, PathExists) {
|
|
EXPECT_TRUE(File::pathExists(filename));
|
|
removeFile(filename);
|
|
EXPECT_FALSE(File::pathExists(filename));
|
|
}
|
|
|
|
TEST(FileUtilsTest, ExtractPathFromFilename) {
|
|
EXPECT_EQ("/this/is/path/on/unix/", File::extractPathFromFilename("/this/is/path/on/unix/file.txt"));
|
|
EXPECT_EQ("C:\\this\\is\\path\\on\\win\\", File::extractPathFromFilename("C:\\this\\is\\path\\on\\win\\file.txt", "\\"));
|
|
}
|
|
|
|
TEST(FileUtilsTest, CreatePath) {
|
|
const char* path = "/tmp/my/one/long/path";
|
|
EXPECT_FALSE(File::pathExists(path));
|
|
EXPECT_TRUE(File::createPath(path));
|
|
EXPECT_TRUE(File::pathExists(path));
|
|
removeFile(path);
|
|
EXPECT_FALSE(File::pathExists(path));
|
|
}
|
|
|
|
|
|
TEST(FileUtilsTest, BuildStrippedFilename) {
|
|
|
|
char buf[50] = "";
|
|
|
|
File::buildStrippedFilename("this_is_myfile.cc", buf, 50);
|
|
EXPECT_STREQ("this_is_myfile.cc", buf);
|
|
|
|
Str::clearBuff(buf, 20);
|
|
EXPECT_STREQ("", buf);
|
|
|
|
File::buildStrippedFilename("this_is_myfilename_with_more_than_50_characters.cc", buf, 50);
|
|
EXPECT_STREQ("..s_is_myfilename_with_more_than_50_characters.cc", buf);
|
|
}
|
|
|
|
#endif // FILE_UTILS_TEST_H
|