Add CTestInfo class, add test for create-close-remove process

This commit is contained in:
heinrich5991 2017-10-23 00:13:53 +02:00
parent d6bcc4fe01
commit b463197348
6 changed files with 44 additions and 11 deletions

View file

@ -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

View file

@ -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)

View file

@ -1,3 +1,4 @@
#include "test.h"
#include <gtest/gtest.h>
#include <base/system.h>
@ -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);

14
src/test/fs.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "test.h"
#include <gtest/gtest.h>
#include <base/system.h>
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));
}

12
src/test/test.cpp Normal file
View file

@ -0,0 +1,12 @@
#include "test.h"
#include <gtest/gtest.h>
#include <base/system.h>
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());
}

9
src/test/test.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef TEST_TEST_H
#define TEST_TEST_H
class CTestInfo
{
public:
CTestInfo();
char m_aFilename[64];
};
#endif // TEST_TEST_H