From 54c4c8a3c957f3ab3a486328aac50acc442168af Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Thu, 22 Nov 2018 15:09:04 +0000 Subject: [PATCH] tests: Convert IniFile unit test to a GTest Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139 Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/14615 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/base/SConscript | 1 + .../initest.cc => base/inifiletest.cc} | 54 ++++++++++++------- src/unittest/SConscript | 1 - 3 files changed, 37 insertions(+), 19 deletions(-) rename src/{unittest/initest.cc => base/inifiletest.cc} (67%) 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 similarity index 67% rename from src/unittest/initest.cc rename to 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 #include -#include "base/cprintf.hh" +#include + #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') -- 2.30.2