Discussion:
[gem5-dev] Change in gem5/gem5[master]: tests: Convert IniFile unit test to a GTest
Giacomo Travaglini (Gerrit)
2018-11-26 17:23:03 UTC
Permalink
Giacomo Travaglini has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/14615


Change subject: tests: Convert IniFile unit test to a GTest
......................................................................

tests: Convert IniFile unit test to a GTest

Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139
Signed-off-by: Giacomo Travaglini <***@arm.com>
---
M src/base/SConscript
R src/base/initest.cc
M src/unittest/SConscript
3 files changed, 37 insertions(+), 19 deletions(-)



diff --git a/src/base/SConscript b/src/base/SConscript
index d84eba1..85413df 100644
--- a/src/base/SConscript
+++ b/src/base/SConscript
@@ -53,6 +53,7 @@
Source('hostinfo.cc')
Source('inet.cc')
Source('inifile.cc')
+GTest('initest', 'initest.cc', 'inifile.cc', 'str.cc')
Source('intmath.cc')
Source('logging.cc')
Source('match.cc')
diff --git a/src/unittest/initest.cc b/src/base/initest.cc
similarity index 67%
rename from src/unittest/initest.cc
rename to src/base/initest.cc
index 222fcab..d331905 100644
--- a/src/unittest/initest.cc
+++ b/src/base/initest.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 @@

};

-int
-main(int argc, char *argv[])
+TEST(Initest, MatchFound)
{
IniFile simConfigDB;
simConfigDB.load(iniFile);

- string value;
+ std::string value;

-#define FIND(C, E) \
- if (simConfigDB.find(C, E, value)) \
- cout << ">" << value << "<\n"; \
- else \
- cout << "Not Found!\n"
+ auto ret = simConfigDB.find("General", "Test2", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "bar");

- FIND("General", "Test2");
- FIND("Junk", "Test3");
- FIND("Junk", "Test4");
- FIND("General", "Test1");
- FIND("Junk2", "test3");
- FIND("General", "Test3");
+ ret = simConfigDB.find("Junk", "Test3", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "yo");

- cout << "\n";
+ ret = simConfigDB.find("Junk", "Test4", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "mama mia");

- simConfigDB.dump();
+ ret = simConfigDB.find("General", "Test1", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "BARasdf");

- return 0;
+ ret = simConfigDB.find("General", "Test3", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "89");
+}
+
+TEST(Initest, MatchNotFound)
+{
+ IniFile simConfigDB;
+ simConfigDB.load(iniFile);
+
+ std::string value;
+
+ auto ret = simConfigDB.find("Junk2", "test3", value);
+ ASSERT_FALSE(ret);
+
+ ret = simConfigDB.find("Junk", "test4", value);
+ ASSERT_FALSE(ret);
}
diff --git a/src/unittest/SConscript b/src/unittest/SConscript
index 3f65734..f437a1d 100644
--- a/src/unittest/SConscript
+++ b/src/unittest/SConscript
@@ -33,7 +33,6 @@
Source('unittest.cc')

UnitTest('cprintftime', 'cprintftime.cc')
-UnitTest('initest', 'initest.cc')
UnitTest('nmtest', 'nmtest.cc')
UnitTest('refcnttest', 'refcnttest.cc')
UnitTest('strnumtest', 'strnumtest.cc')
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/14615
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139
Gerrit-Change-Number: 14615
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini <***@arm.com>
Gerrit-MessageType: newchange
Giacomo Travaglini (Gerrit)
2018-11-27 13:40:19 UTC
Permalink
Hello Gabe Black, Jason Lowe-Power,

I'd like you to reexamine a change. Please visit

https://gem5-review.googlesource.com/c/public/gem5/+/14615

to look at the new patch set (#2).

Change subject: tests: Convert IniFile unit test to a GTest
......................................................................

tests: Convert IniFile unit test to a GTest

Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139
Signed-off-by: Giacomo Travaglini <***@arm.com>
---
M src/base/SConscript
R src/base/inifiletest.cc
M src/unittest/SConscript
3 files changed, 37 insertions(+), 19 deletions(-)
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/14615
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139
Gerrit-Change-Number: 14615
Gerrit-PatchSet: 2
Gerrit-Owner: Giacomo Travaglini <***@arm.com>
Gerrit-Reviewer: Gabe Black <***@google.com>
Gerrit-Reviewer: Giacomo Travaglini <***@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <***@lowepower.com>
Gerrit-MessageType: newpatchset
Giacomo Travaglini (Gerrit)
2018-11-28 09:54:18 UTC
Permalink
Giacomo Travaglini has submitted this change and it was merged. (
https://gem5-review.googlesource.com/c/public/gem5/+/14615 )

Change subject: tests: Convert IniFile unit test to a GTest
......................................................................

tests: Convert IniFile unit test to a GTest

Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139
Signed-off-by: Giacomo Travaglini <***@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/14615
Reviewed-by: Gabe Black <***@google.com>
Maintainer: Gabe Black <***@google.com>
---
M src/base/SConscript
R src/base/inifiletest.cc
M src/unittest/SConscript
3 files changed, 37 insertions(+), 19 deletions(-)

Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved



diff --git a/src/base/SConscript b/src/base/SConscript
index d84eba1..b0893a1 100644
--- a/src/base/SConscript
+++ b/src/base/SConscript
@@ -53,6 +53,7 @@
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 66%
rename from src/unittest/initest.cc
rename to src/base/inifiletest.cc
index 222fcab..d331905 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 @@

};

-int
-main(int argc, char *argv[])
+TEST(Initest, MatchFound)
{
IniFile simConfigDB;
simConfigDB.load(iniFile);

- string value;
+ std::string value;

-#define FIND(C, E) \
- if (simConfigDB.find(C, E, value)) \
- cout << ">" << value << "<\n"; \
- else \
- cout << "Not Found!\n"
+ auto ret = simConfigDB.find("General", "Test2", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "bar");

- FIND("General", "Test2");
- FIND("Junk", "Test3");
- FIND("Junk", "Test4");
- FIND("General", "Test1");
- FIND("Junk2", "test3");
- FIND("General", "Test3");
+ ret = simConfigDB.find("Junk", "Test3", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "yo");

- cout << "\n";
+ ret = simConfigDB.find("Junk", "Test4", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "mama mia");

- simConfigDB.dump();
+ ret = simConfigDB.find("General", "Test1", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "BARasdf");

- return 0;
+ ret = simConfigDB.find("General", "Test3", value);
+ ASSERT_TRUE(ret);
+ ASSERT_STREQ(value.c_str(), "89");
+}
+
+TEST(Initest, MatchNotFound)
+{
+ IniFile simConfigDB;
+ simConfigDB.load(iniFile);
+
+ std::string value;
+
+ auto ret = simConfigDB.find("Junk2", "test3", value);
+ ASSERT_FALSE(ret);
+
+ ret = simConfigDB.find("Junk", "test4", value);
+ ASSERT_FALSE(ret);
}
diff --git a/src/unittest/SConscript b/src/unittest/SConscript
index 3f65734..f437a1d 100644
--- a/src/unittest/SConscript
+++ b/src/unittest/SConscript
@@ -33,7 +33,6 @@
Source('unittest.cc')

UnitTest('cprintftime', 'cprintftime.cc')
-UnitTest('initest', 'initest.cc')
UnitTest('nmtest', 'nmtest.cc')
UnitTest('refcnttest', 'refcnttest.cc')
UnitTest('strnumtest', 'strnumtest.cc')
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/14615
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I47d6c9cbae21877420a15ffcf8489e3c26959139
Gerrit-Change-Number: 14615
Gerrit-PatchSet: 3
Gerrit-Owner: Giacomo Travaglini <***@arm.com>
Gerrit-Reviewer: Gabe Black <***@google.com>
Gerrit-Reviewer: Giacomo Travaglini <***@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <***@lowepower.com>
Gerrit-MessageType: merged
Loading...