Ciro Santilli has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/37975 )
Change subject: sim: add test for IniFile::visitSection
......................................................................
sim: add test for IniFile::visitSection
iniFile was used as a global variable, and thee tests were relying on
MatchNotFound running after MatchFound, which would first empty the
istringstream.
Therefore, the only way to reuse that test file was to rewind
istringstream. Since this is a bit ugly, and it is better practice not to
rely on a specific test order, this commit instead creates a separate
istringstream per test.
Change-Id: If3cf5ef74ba7dfaf2f90b55acd1c3a8bdda04947
---
M src/base/inifile.test.cc
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/src/base/inifile.test.cc b/src/base/inifile.test.cc
index 0d1600e..0cabb55 100644
--- a/src/base/inifile.test.cc
+++ b/src/base/inifile.test.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 ARM Limited
+ * Copyright (c) 2018, 2020 ARM Limited
* All rights reserved
*
* Copyright (c) 2002-2005 The Regents of The University of Michigan
@@ -29,20 +29,27 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-copy"
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#pragma GCC diagnostic pop
#include <fstream>
#include <iostream>
#include <string>
+#include <utility>
#include <vector>
#include "base/inifile.hh"
using namespace std;
+using testing::ElementsAre;
+using testing::Pair;
namespace {
-std::istringstream iniFile(R"ini_file(
+const char *iniFileString = R"ini_file(
[General]
Test1=BARasdf
Test2=bar
@@ -60,14 +67,13 @@
[Junk]
Test4+=mia
-)ini_file");
-
-};
+)ini_file";
TEST(Initest, MatchFound)
{
IniFile simConfigDB;
- simConfigDB.load(iniFile);
+ std::istringstream is{iniFileString};
+ simConfigDB.load(is);
std::string value;
@@ -95,7 +101,8 @@
TEST(Initest, MatchNotFound)
{
IniFile simConfigDB;
- simConfigDB.load(iniFile);
+ std::istringstream is;
+ simConfigDB.load(is);
std::string value;
@@ -105,3 +112,20 @@
ret = simConfigDB.find("Junk", "test4", value);
ASSERT_FALSE(ret);
}
+
+TEST(Initest, visitSection)
+{
+ IniFile simConfigDB;
+ std::istringstream is{iniFileString};
+ simConfigDB.load(is);
+ std::vector<std::pair<std::string, std::string>> keys_values;
+ simConfigDB.visitSection("Junk", [&](std::string key, std::string
value)
+ {
+ keys_values.emplace_back(key, value);
+ });
+ ASSERT_THAT(keys_values, ElementsAre(
+ Pair("Test4", "mama mia"),
+ Pair("Test3", "yo")
+ ));
+}
+}
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/37975
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: If3cf5ef74ba7dfaf2f90b55acd1c3a8bdda04947
Gerrit-Change-Number: 37975
Gerrit-PatchSet: 1
Gerrit-Owner: Ciro Santilli <ciro.santi...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s