summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Travaglini <giacomo.travaglini@arm.com>2018-11-22 15:09:04 +0000
committerGiacomo Travaglini <giacomo.travaglini@arm.com>2018-11-28 09:54:16 +0000
commit54c4c8a3c957f3ab3a486328aac50acc442168af (patch)
treeba261731da43581a758834b1b3e8fc0a26eedfa8
parent529c07c1c53b484e1876decb3d4d808f289096b5 (diff)
downloadgem5-54c4c8a3c957f3ab3a486328aac50acc442168af.tar.xz
tests: Convert IniFile unit test to a GTest
Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/c/14615 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r--src/base/SConscript1
-rw-r--r--src/base/inifiletest.cc (renamed from src/unittest/initest.cc)54
-rw-r--r--src/unittest/SConscript1
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')