[Scummvm-git-logs] scummvm master -> a74b08197320be362401d77e1940788773aaf222
mduggan
noreply at scummvm.org
Fri Mar 25 09:17:58 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
a74b081973 TEST: Add more tests for Common::INIFile
Commit: a74b08197320be362401d77e1940788773aaf222
https://github.com/scummvm/scummvm/commit/a74b08197320be362401d77e1940788773aaf222
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2022-03-25T18:16:07+09:00
Commit Message:
TEST: Add more tests for Common::INIFile
My initial tests were quite minimal as I was trying to fix the build. Now more
of the basic INIFile functionality is tested.
Changed paths:
test/common/ini-file.h
diff --git a/test/common/ini-file.h b/test/common/ini-file.h
index d3a6a418930..5cf1ed92f04 100644
--- a/test/common/ini-file.h
+++ b/test/common/ini-file.h
@@ -14,22 +14,74 @@ class IniFileTestSuite : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(sections.size(), 0);
}
- void test_simple_ini_file() {
- const unsigned char data[] = "[s]\nabc=1\ndef=xyz";
- Common::MemoryReadStream ms(data, sizeof(data));
+ void test_simple_ini_file() {
+ static const unsigned char inistr[] = "#comment\n[s]\nabc=1\ndef=xyz";
+ Common::MemoryReadStream ms(inistr, sizeof(inistr));
Common::INIFile inifile;
bool result = inifile.loadFromStream(ms);
TS_ASSERT(result);
+ Common::INIFile::SectionList sections = inifile.getSections();
+ TS_ASSERT_EQUALS(sections.size(), 1);
+
TS_ASSERT(inifile.hasSection("s"));
TS_ASSERT(inifile.hasKey("abc", "s"));
Common::String val;
TS_ASSERT(inifile.getKey("abc", "s", val));
TS_ASSERT_EQUALS(val, "1");
+ TS_ASSERT(inifile.getKey("def", "s", val));
+ TS_ASSERT_EQUALS(val, "xyz");
inifile.setKey("abc", "s", "newval");
TS_ASSERT(inifile.getKey("abc", "s", val));
TS_ASSERT_EQUALS(val, "newval");
}
+
+ void test_multisection_ini_file() {
+ static const unsigned char inistr[] = "[s]\nabc=1\ndef=xyz\n#comment=no\n[empty]\n\n[s2]\nabc=2";
+ Common::MemoryReadStream ms(inistr, sizeof(inistr));
+ Common::INIFile inifile;
+ bool result = inifile.loadFromStream(ms);
+ TS_ASSERT(result);
+
+ Common::INIFile::SectionList sections = inifile.getSections();
+ TS_ASSERT_EQUALS(sections.size(), 3);
+
+ TS_ASSERT(inifile.hasSection("s"));
+ TS_ASSERT(inifile.hasSection("empty"));
+ TS_ASSERT(inifile.hasSection("s2"));
+ TS_ASSERT(inifile.hasKey("abc", "s"));
+ TS_ASSERT(inifile.hasKey("abc", "s2"));
+
+ Common::String val;
+ TS_ASSERT(inifile.getKey("abc", "s", val));
+ TS_ASSERT_EQUALS(val, "1");
+ TS_ASSERT(inifile.getKey("abc", "s2", val));
+ TS_ASSERT_EQUALS(val, "2");
+ }
+
+ void test_modify_ini_file() {
+ Common::INIFile inifile;
+
+ TS_ASSERT(!inifile.hasSection("s"));
+ inifile.addSection("s");
+ TS_ASSERT(inifile.hasSection("s"));
+
+ inifile.setKey("k", "s", "val");
+ TS_ASSERT(inifile.hasKey("k", "s"));
+
+ inifile.setKey("k2", "s", "val2");
+ TS_ASSERT(inifile.hasKey("k2", "s"));
+ inifile.removeKey("k2", "s");
+ TS_ASSERT(!inifile.hasKey("k2", "s"));
+
+ inifile.renameSection("s", "t");
+ TS_ASSERT(!inifile.hasSection("s"));
+ TS_ASSERT(inifile.hasSection("t"));
+ TS_ASSERT(inifile.hasKey("k", "t"));
+
+ inifile.removeSection("t");
+ TS_ASSERT(!inifile.hasSection("t"));
+ }
};
More information about the Scummvm-git-logs
mailing list