Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vvromanov committed Dec 5, 2024
1 parent 0323ce7 commit d335178
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bool get_file_size(const char *name, size_t &size) {
if (errno != ENOENT) {
log_write(LOG_LEVEL_ERR_ERRNO, "stat call failed for file %s", name);
}
size = 0;
return false;
}
size = structstat.st_size;
Expand Down
14 changes: 7 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ find_package(ZLIB REQUIRED)

add_executable(${TARGET}
Convert.cpp
Dictionary_test.cpp
DumpUtilsTest.cpp
FileUtils_Test.cpp
Log_test.cpp
ShmBufferEx_Test.cpp
ShmBase_Test.cpp
ShmBuffer_Test.cpp
ShmBufferEx_Test.cpp
SysInfo.cpp
TestCounter.cpp
TestCountersInit.cpp
TestCounters.cpp
ShmBase_Test.cpp
FileUtils_Test.cpp
Dictionary_test.cpp
TestCountersInit.cpp
TestTimeUtils.cpp
DumpUtilsTest.cpp
SysInfo.cpp
TestUptime.cpp
)

Expand Down
35 changes: 34 additions & 1 deletion tests/FileUtils_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,45 @@ TEST(FileUtils, FileNotExists) {


TEST(FileUtils, FileNotExistsInvalid) {
remove(TEST_FILE);
EXPECT_FALSE(is_file_exists(""));
EXPECT_FALSE(is_file_exists(TEST_FILE_INVALID));
EXPECT_FALSE(is_file_exists("../../../../../../../../../some_file.txt"));
}

TEST(FileUtils, FileSize) {
FILE* fp = fopen(TEST_FILE, "ab+");
fclose(fp);
size_t size=123;
EXPECT_TRUE(get_file_size(TEST_FILE, size));
EXPECT_EQ(0, size);
fp = fopen(TEST_FILE, "ab+");
fwrite("0123456789", 1, 10, fp);
fclose(fp);
EXPECT_TRUE(get_file_size(TEST_FILE, size));
EXPECT_EQ(10, size);
}

TEST(FileUtils, FileSizeNotExists) {
remove(TEST_FILE);
size_t size = 123;
EXPECT_FALSE(get_file_size(TEST_FILE, size));
EXPECT_EQ(0, size);
}

TEST(FileUtils, FileSizeInvalid) {
size_t size = 123;
EXPECT_FALSE(get_file_size("", size));
EXPECT_EQ(0, size);

size = 123;
EXPECT_FALSE(get_file_size(TEST_FILE_INVALID, size));
EXPECT_EQ(0, size);

size = 123;
EXPECT_FALSE(get_file_size("../../../../../../../../../some_file.txt", size));
EXPECT_EQ(0, size);
}

TEST(FileUtils, DirExists) {
EXPECT_TRUE(is_dir_exists("."));
EXPECT_TRUE(is_dir_exists("/"));
Expand Down

0 comments on commit d335178

Please sign in to comment.