From fcd5b6b37f5a95b218a9f02e970e1d03093881ff Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Thu, 11 Apr 2024 23:23:05 -0400 Subject: [PATCH] some ini adjustment related to UT . --- MissionEditor/IniFile.cpp | 16 ---------------- MissionEditor/IniFile.h | 18 ++++++++++++++---- MissionEditor/IniHelper.h | 1 + UnitTest/CIni_Test.cpp | 1 + 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/MissionEditor/IniFile.cpp b/MissionEditor/IniFile.cpp index 8154b2d..b803447 100644 --- a/MissionEditor/IniFile.cpp +++ b/MissionEditor/IniFile.cpp @@ -41,19 +41,6 @@ using namespace std; const CIniFileSection CIniFile::EmptySection; const CString CIniFileSection::EmptyValue; -bool SortDummy::operator()(const CString& x, const CString& y) const -{ - // the length is more important than spelling (numbers!!!)... - if (x.GetLength() < y.GetLength()) return true; - if (x.GetLength() == y.GetLength()) - { - if (x < y) return true; - } - - return false; - -} - typedef map::iterator CIniI; typedef map::iterator SI; typedef map::iterator SII; @@ -159,14 +146,11 @@ WORD CIniFile::InsertFile(const std::string& filename, const char* Section, BOOL CString name = cLine.substr(0, equals).c_str(); CString value = cLine.substr(equals + 1, cLine.size() - equals - 1).c_str(); - int cuValueIndex = sections[cSec].Size(); - if (bNoSpaces) { name.Trim(); value.Trim(); } - sections[cSec].SetString(name, value); } } diff --git a/MissionEditor/IniFile.h b/MissionEditor/IniFile.h index 30f17a5..e86334f 100644 --- a/MissionEditor/IniFile.h +++ b/MissionEditor/IniFile.h @@ -38,22 +38,32 @@ #include #include "IniHelper.h" - using namespace std; class SortDummy { public: - bool operator() (const CString&, const CString&) const; + bool operator()(const CString& x, const CString& y) const + { + // the length is more important than spelling (numbers!!!)... + if (x.GetLength() < y.GetLength()) { + return true; + } + if (x.GetLength() == y.GetLength()) { + if (x < y) { + return true; + } + } + return false; + } }; class CIniFileSection { -public: - static const CString EmptyValue; +public: CIniFileSection(); virtual ~CIniFileSection(); diff --git a/MissionEditor/IniHelper.h b/MissionEditor/IniHelper.h index 8cb29be..868e6c4 100644 --- a/MissionEditor/IniHelper.h +++ b/MissionEditor/IniHelper.h @@ -59,6 +59,7 @@ public: { char buffer[0x100]; _itoa_s(origin, buffer, 10); + buffer[sizeof buffer - 1] = '\0'; return buffer; } }; \ No newline at end of file diff --git a/UnitTest/CIni_Test.cpp b/UnitTest/CIni_Test.cpp index 8bdb7ac..2ca6754 100644 --- a/UnitTest/CIni_Test.cpp +++ b/UnitTest/CIni_Test.cpp @@ -19,6 +19,7 @@ AllowUnidirectionalTunnels=yes CIniFile file; ASSERT_EQ(file.LoadFile(std::string(testIni)), 0); + remove(testIni); EXPECT_EQ(true, file.GetBool("Debug","AllowTunnels")); } \ No newline at end of file