diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/base/SConscript | 1 | ||||
-rw-r--r-- | src/base/inifiletest.cc (renamed from src/unittest/initest.cc) | 54 | ||||
-rw-r--r-- | src/unittest/SConscript | 1 |
3 files changed, 37 insertions, 19 deletions
diff --git a/src/base/SConscript b/src/base/SConscript index d84eba14c..b0893a145 100644 --- a/src/base/SConscript +++ b/src/base/SConscript @@ -53,6 +53,7 @@ Source('framebuffer.cc') Source('hostinfo.cc') Source('inet.cc') Source('inifile.cc') +GTest('inifiletest', 'inifiletest.cc', 'inifile.cc', 'str.cc') Source('intmath.cc') Source('logging.cc') Source('match.cc') diff --git a/src/unittest/initest.cc b/src/base/inifiletest.cc index 222fcabae..d33190580 100644 --- a/src/unittest/initest.cc +++ b/src/base/inifiletest.cc @@ -1,4 +1,7 @@ /* + * Copyright (c) 2018 ARM Limited + * All rights reserved + * * Copyright (c) 2002-2005 The Regents of The University of Michigan * All rights reserved. * @@ -34,7 +37,8 @@ #include <string> #include <vector> -#include "base/cprintf.hh" +#include <gtest/gtest.h> + #include "base/inifile.hh" using namespace std; @@ -63,30 +67,44 @@ Test4+=mia }; -int -main(int argc, char *argv[]) +TEST(Initest, MatchFound) { IniFile simConfigDB; simConfigDB.load(iniFile); - string value; + std::string value; + + auto ret = simConfigDB.find("General", "Test2", value); + ASSERT_TRUE(ret); + ASSERT_STREQ(value.c_str(), "bar"); + + ret = simConfigDB.find("Junk", "Test3", value); + ASSERT_TRUE(ret); + ASSERT_STREQ(value.c_str(), "yo"); + + ret = simConfigDB.find("Junk", "Test4", value); + ASSERT_TRUE(ret); + ASSERT_STREQ(value.c_str(), "mama mia"); -#define FIND(C, E) \ - if (simConfigDB.find(C, E, value)) \ - cout << ">" << value << "<\n"; \ - else \ - cout << "Not Found!\n" + ret = simConfigDB.find("General", "Test1", value); + ASSERT_TRUE(ret); + ASSERT_STREQ(value.c_str(), "BARasdf"); - FIND("General", "Test2"); - FIND("Junk", "Test3"); - FIND("Junk", "Test4"); - FIND("General", "Test1"); - FIND("Junk2", "test3"); - FIND("General", "Test3"); + ret = simConfigDB.find("General", "Test3", value); + ASSERT_TRUE(ret); + ASSERT_STREQ(value.c_str(), "89"); +} + +TEST(Initest, MatchNotFound) +{ + IniFile simConfigDB; + simConfigDB.load(iniFile); - cout << "\n"; + std::string value; - simConfigDB.dump(); + auto ret = simConfigDB.find("Junk2", "test3", value); + ASSERT_FALSE(ret); - return 0; + ret = simConfigDB.find("Junk", "test4", value); + ASSERT_FALSE(ret); } diff --git a/src/unittest/SConscript b/src/unittest/SConscript index 3f657345f..f437a1dda 100644 --- a/src/unittest/SConscript +++ b/src/unittest/SConscript @@ -33,7 +33,6 @@ Import('*') Source('unittest.cc') UnitTest('cprintftime', 'cprintftime.cc') -UnitTest('initest', 'initest.cc') UnitTest('nmtest', 'nmtest.cc') UnitTest('refcnttest', 'refcnttest.cc') UnitTest('strnumtest', 'strnumtest.cc') |