[DEV] add testunit for FSNode & add sub display in debug for etest

This commit is contained in:
Edouard DUPIN 2017-09-12 22:47:30 +02:00
parent 5a245687f6
commit d8a6c0a9a9
5 changed files with 49 additions and 6 deletions

View File

@ -10,6 +10,7 @@
#include <elog/elog.hpp> #include <elog/elog.hpp>
#include <echrono/Steady.hpp> #include <echrono/Steady.hpp>
#include <echrono/Duration.hpp> #include <echrono/Duration.hpp>
#include <etk/os/FSNode.hpp>
static int32_t nbTimeInit = 0; static int32_t nbTimeInit = 0;
@ -75,7 +76,7 @@ static etk::Vector<etest::GenericTest*> getListFiltered() {
} }
static void listAllTest() { static void listAllTest() {
ETEST_ERROR("We have " << getListOfTest().size() << " tests:"); ETEST_PRINT("We have " << getListOfTest().size() << " tests:");
etk::Vector<etk::String> listGroup = getListGroup(); etk::Vector<etk::String> listGroup = getListGroup();
for (auto &itGroup: listGroup) { for (auto &itGroup: listGroup) {
ETEST_PRINT("Group: " << itGroup); ETEST_PRINT("Group: " << itGroup);
@ -95,6 +96,7 @@ void etest::init(int32_t _argc, const char** _argv) {
} }
nbTimeInit++; nbTimeInit++;
elog::init(_argc, _argv); elog::init(_argc, _argv);
etk::initDefaultFolder("ewolApplNoName");
ETEST_INFO("ETEST system init (BEGIN) "); ETEST_INFO("ETEST system init (BEGIN) ");
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
etk::String data = _argv[iii]; etk::String data = _argv[iii];
@ -116,7 +118,6 @@ void etest::init(int32_t _argc, const char** _argv) {
} else if (data.startWith("--etest-filter=") == true) { } else if (data.startWith("--etest-filter=") == true) {
etk::String filter = &data[15]; etk::String filter = &data[15];
ETEST_PRINT(" Filter: " << filter); ETEST_PRINT(" Filter: " << filter);
ETEST_ERROR("plop:" << filter);
etk::Vector<etk::String> tmp = filter.split("."); etk::Vector<etk::String> tmp = filter.split(".");
if (tmp.size() == 1) { if (tmp.size() == 1) {
// Filter only the groups // Filter only the groups

View File

@ -151,6 +151,7 @@ namespace etest {
#define EXPECT_EQ(element, result) \ #define EXPECT_EQ(element, result) \
do { \ do { \
ETEST_DEBUG(" [ SUB-RUN ] EXPECT_EQ(" << #element << ", " << #result << ");"); \
bool ETEST_VARIABLE_TMP_res = ((element) == (result)); \ bool ETEST_VARIABLE_TMP_res = ((element) == (result)); \
if (etest::g_currentTest == nullptr) { \ if (etest::g_currentTest == nullptr) { \
ETEST_CRITICAL("Not in a test"); \ ETEST_CRITICAL("Not in a test"); \
@ -162,10 +163,12 @@ namespace etest {
#result, \ #result, \
__LINE__); \ __LINE__); \
} \ } \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} while (false) } while (false)
#define EXPECT_NE(element, result) \ #define EXPECT_NE(element, result) \
do { \ do { \
ETEST_DEBUG(" [ SUB-RUN ] EXPECT_NE(" << #element << ", " << #result << ");"); \
bool ETEST_VARIABLE_TMP_res = ((element) != (result)); \ bool ETEST_VARIABLE_TMP_res = ((element) != (result)); \
if (etest::g_currentTest == nullptr) { \ if (etest::g_currentTest == nullptr) { \
ETEST_CRITICAL("Not in a test"); \ ETEST_CRITICAL("Not in a test"); \
@ -177,10 +180,12 @@ namespace etest {
#result, \ #result, \
__LINE__); \ __LINE__); \
} \ } \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} while (false) } while (false)
#define EXPECT_FLOAT_EQ(element, result) \ #define EXPECT_FLOAT_EQ(element, result) \
do { \ do { \
ETEST_DEBUG(" [ SUB-RUN ] EXPECT_FLOAT_EQ(" << #element << ", " << #result << ");"); \
float ETEST_VARIABLE_TMP_res2 = (element) - (result); \ float ETEST_VARIABLE_TMP_res2 = (element) - (result); \
bool ETEST_VARIABLE_TMP_res = false; \ bool ETEST_VARIABLE_TMP_res = false; \
if (ETEST_VARIABLE_TMP_res2 < 0.00001f && ETEST_VARIABLE_TMP_res2 > -0.00001f) { \ if (ETEST_VARIABLE_TMP_res2 < 0.00001f && ETEST_VARIABLE_TMP_res2 > -0.00001f) { \
@ -196,6 +201,7 @@ namespace etest {
#result, \ #result, \
__LINE__); \ __LINE__); \
} \ } \
ETEST_DEBUG(" [ SUB-DONE ]"); \
} while (false) } while (false)

View File

@ -49,5 +49,6 @@ def configure(target, my_module):
'etest', 'etest',
'test-debug' 'test-debug'
]) ])
my_module.copy_path('data/*')
return True return True

View File

@ -12,14 +12,11 @@
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/os/FSNode.hpp>
#include <etest/etest.hpp> #include <etest/etest.hpp>
int main(int argc, const char *argv[]) { int main(int argc, const char *argv[]) {
// init test engine: // init test engine:
etest::init(argc, argv); etest::init(argc, argv);
// the only one init for etk:
etk::init(argc, argv);
etk::initDefaultFolder("ewolApplNoName");
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@ -11,6 +11,44 @@
#include <etk/os/FSNode.hpp> #include <etk/os/FSNode.hpp>
#define NAME "FSNode" #define NAME "FSNode"
TEST(TestEtkFSNode, checkDATAFilePresent) {
etk::String fileName("DATA:filePresent.txt");
etk::FSNode myNodeTest1(fileName);
EXPECT_EQ(myNodeTest1.getNameFile(), "filePresent.txt");
EXPECT_EQ(myNodeTest1.exist(), true);
bool ret = myNodeTest1.fileOpenRead();
EXPECT_EQ(ret, true);
etk::String data;
ret = myNodeTest1.fileGets(data);
EXPECT_EQ(ret, true);
EXPECT_EQ(data, "plop");
ret = myNodeTest1.fileClose();
EXPECT_EQ(ret, true);
}
TEST(TestEtkFSNode, checkDATAFileEmpty) {
etk::String fileName("DATA:fileEmpty.txt");
etk::FSNode myNodeTest1(fileName);
EXPECT_EQ(myNodeTest1.getNameFile(), "fileEmpty.txt");
EXPECT_EQ(myNodeTest1.exist(), true);
bool ret = myNodeTest1.fileOpenRead();
EXPECT_EQ(ret, true);
etk::String data;
ret = myNodeTest1.fileGets(data);
EXPECT_EQ(ret, false);
EXPECT_EQ(data, "");
ret = myNodeTest1.fileClose();
EXPECT_EQ(ret, true);
}
TEST(TestEtkFSNode, checkDATAFileNotPresent) {
etk::String fileName("DATA:fileNotPresent.txt");
etk::FSNode myNodeTest1(fileName);
EXPECT_EQ(myNodeTest1.getNameFile(), "fileNotPresent.txt");
EXPECT_EQ(myNodeTest1.exist(), false);
}
TEST(TestEtkFSNode, checkType) { TEST(TestEtkFSNode, checkType) {
etk::String fileName("USERDATA:myFileTest.txt"); etk::String fileName("USERDATA:myFileTest.txt");
etk::FSNode myNodeTest1(fileName); etk::FSNode myNodeTest1(fileName);