diff --git a/CMakeLists.txt b/CMakeLists.txt index fb3cda02e..31fb48a93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -960,8 +960,11 @@ add_custom_target(everything DEPENDS ${TARGETS_OWN}) if(GTEST_FOUND OR DOWNLOAD_GTEST) set_glob(TESTS GLOB src/test aio.cpp + fs.cpp strip_path_and_extension.cpp teehistorian.cpp + test.cpp + test.h thread.cpp ) set(TESTS_EXTRA diff --git a/src/base/system.c b/src/base/system.c index fbeb14397..7b8261182 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -435,8 +435,7 @@ unsigned io_write_newline(IOHANDLE io) int io_close(IOHANDLE io) { - fclose((FILE*)io); - return 1; + return fclose((FILE*)io) != 0; } int io_flush(IOHANDLE io) diff --git a/src/test/aio.cpp b/src/test/aio.cpp index c03f5908f..7a0f511e3 100644 --- a/src/test/aio.cpp +++ b/src/test/aio.cpp @@ -1,3 +1,4 @@ +#include "test.h" #include #include @@ -8,17 +9,12 @@ class Async : public ::testing::Test { protected: ASYNCIO *m_pAio; - char m_aFilename[64]; + CTestInfo m_Info; bool Delete; void SetUp() { - const ::testing::TestInfo *pTestInfo = - ::testing::UnitTest::GetInstance()->current_test_info(); - const char *pTestName = pTestInfo->name(); - - str_format(m_aFilename, sizeof(m_aFilename), "Async.%s-%d.tmp", pTestName, pid()); - IOHANDLE File = io_open(m_aFilename, IOFLAG_WRITE); + IOHANDLE File = io_open(m_Info.m_aFilename, IOFLAG_WRITE); ASSERT_TRUE(File); m_pAio = aio_new(File); Delete = false; @@ -28,7 +24,7 @@ protected: { if(Delete) { - fs_remove(m_aFilename); + fs_remove(m_Info.m_aFilename); } } @@ -44,7 +40,7 @@ protected: aio_free(m_pAio); char aBuf[BUF_SIZE]; - IOHANDLE File = io_open(m_aFilename, IOFLAG_READ); + IOHANDLE File = io_open(m_Info.m_aFilename, IOFLAG_READ); ASSERT_TRUE(File); int Read = io_read(File, aBuf, sizeof(aBuf)); io_close(File); diff --git a/src/test/fs.cpp b/src/test/fs.cpp new file mode 100644 index 000000000..fc10c7ed4 --- /dev/null +++ b/src/test/fs.cpp @@ -0,0 +1,14 @@ +#include "test.h" +#include + +#include + +TEST(Filesystem, CreateCloseDelete) +{ + CTestInfo Info; + + IOHANDLE File = io_open(Info.m_aFilename, IOFLAG_WRITE); + ASSERT_TRUE(File); + EXPECT_FALSE(io_close(File)); + EXPECT_FALSE(fs_remove(Info.m_aFilename)); +} diff --git a/src/test/test.cpp b/src/test/test.cpp new file mode 100644 index 000000000..463b93c0e --- /dev/null +++ b/src/test/test.cpp @@ -0,0 +1,12 @@ +#include "test.h" +#include + +#include + +CTestInfo::CTestInfo() +{ + const ::testing::TestInfo *pTestInfo = + ::testing::UnitTest::GetInstance()->current_test_info(); + str_format(m_aFilename, sizeof(m_aFilename), "%s.%s-%d.tmp", + pTestInfo->test_case_name(), pTestInfo->name(), pid()); +} diff --git a/src/test/test.h b/src/test/test.h new file mode 100644 index 000000000..71f13c9b0 --- /dev/null +++ b/src/test/test.h @@ -0,0 +1,9 @@ +#ifndef TEST_TEST_H +#define TEST_TEST_H +class CTestInfo +{ +public: + CTestInfo(); + char m_aFilename[64]; +}; +#endif // TEST_TEST_H