mirror of
https://github.com/electronicarts/CNC_TS_and_RA2_Mission_Editor.git
synced 2025-07-15 10:46:36 -04:00
Fix: now building node under house type is corrected, related function refactored .
This commit is contained in:
parent
ea4c214b04
commit
a91ff89091
12 changed files with 154 additions and 79 deletions
|
@ -1,31 +1,7 @@
|
|||
#include "stdafx.h"
|
||||
#include "StdAfx.h"
|
||||
#include "CIni_Test.h"
|
||||
#include "../MissionEditor/IniFile.h"
|
||||
|
||||
class IniTestHelper
|
||||
{
|
||||
std::string m_fileName;
|
||||
|
||||
void writeDownContent(const char* pContent) {
|
||||
std::ofstream iniFile(m_fileName.c_str());
|
||||
ASSERT(iniFile.is_open() == true);
|
||||
iniFile << pContent;
|
||||
iniFile.flush();
|
||||
iniFile.close();
|
||||
}
|
||||
|
||||
public:
|
||||
IniTestHelper(std::string&& name, const char* pContent) :
|
||||
m_fileName(std::move(name))
|
||||
{
|
||||
ASSERT(!m_fileName.empty());
|
||||
ASSERT(pContent != nullptr);
|
||||
writeDownContent(pContent);
|
||||
}
|
||||
~IniTestHelper() {
|
||||
remove(m_fileName.c_str());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST(CIniFileClass, LoadFileTest) {
|
||||
auto const fileName = "test.ini";
|
||||
|
|
28
UnitTest/CIni_Test.h
Normal file
28
UnitTest/CIni_Test.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
#include "StdAfx.h"
|
||||
|
||||
class IniTestHelper
|
||||
{
|
||||
std::string m_fileName;
|
||||
|
||||
void writeDownContent(const char* pContent) {
|
||||
std::ofstream iniFile(m_fileName.c_str());
|
||||
ASSERT(iniFile.is_open() == true);
|
||||
iniFile << pContent;
|
||||
iniFile.flush();
|
||||
iniFile.close();
|
||||
}
|
||||
|
||||
public:
|
||||
IniTestHelper(std::string&& name, const char* pContent) :
|
||||
m_fileName(std::move(name))
|
||||
{
|
||||
ASSERT(!m_fileName.empty());
|
||||
ASSERT(pContent != nullptr);
|
||||
writeDownContent(pContent);
|
||||
}
|
||||
~IniTestHelper() {
|
||||
remove(m_fileName.c_str());
|
||||
}
|
||||
|
||||
};
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
#include "stdafx.h"
|
||||
#include "StdAfx.h"
|
||||
#include "MissionEditorPackLib.h"
|
||||
#include "IniFile.h"
|
||||
#include "functions.h"
|
||||
#include "CIni_Test.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
@ -109,4 +112,75 @@ TEST(SerdeTest, OverlayDataPackSerde)
|
|||
|
||||
ASSERT_EQ(b64Input.size(), strlen(reinterpret_cast<char*>(encoded.get())));
|
||||
ASSERT_TRUE(0 == memcmp(encoded.get(), b64Input.data(), b64Input.size()));
|
||||
}
|
||||
|
||||
TEST(SerdeTest, HouseBuildingNodeTest)
|
||||
{
|
||||
ASSERT_EQ("000", GetNodeID(0));
|
||||
ASSERT_EQ("005", GetNodeID(5));
|
||||
ASSERT_EQ("010", GetNodeID(10));
|
||||
ASSERT_EQ("123", GetNodeID(123));
|
||||
}
|
||||
TEST(SerdeTest, HouseBuildingNodeDeleteTest)
|
||||
{
|
||||
auto const fileName = "test.ini";
|
||||
IniTestHelper helper(fileName, R"(
|
||||
[Russian1 House]
|
||||
IQ=5
|
||||
000=NALASR,86,63
|
||||
001=NALASR,89,64
|
||||
002=NALASR,83,64
|
||||
003=NARADR,71,48
|
||||
004=NAREFN,69,66
|
||||
005=NALASR,78,42
|
||||
006=NALASR,73,42
|
||||
007=NAFLAK,61,34
|
||||
008=NAFLAK,61,32
|
||||
009=NAFLAK,62,41
|
||||
010=TESLA,61,41
|
||||
011=NAFLAK,61,40
|
||||
012=NAPOWR,91,23
|
||||
013=NAFLAK,64,63
|
||||
014=NAFLAK,91,63
|
||||
015=NAPOWR,62,39
|
||||
016=TESLA,71,41
|
||||
017=NAHAND,76,57
|
||||
018=NAPOWR,65,37
|
||||
019=NALASR,83,50
|
||||
020=NAWEAP,63,59
|
||||
021=NAWEAP,63,54
|
||||
022=NALASR,77,24
|
||||
023=NAFLAK,81,63
|
||||
024=NALASR,79,24
|
||||
025=TESLA,81,24
|
||||
Edge=North
|
||||
Color=DarkRed
|
||||
Allies=C2 House,Russian1 House,Russian2 House,CivilianArmy House,Civilian1 House,Other1 House,Civilian2 House
|
||||
Country=Russian1
|
||||
Credits=600
|
||||
NodeCount=26
|
||||
TechLevel=5
|
||||
PercentBuilt=100
|
||||
PlayerControl=no
|
||||
|
||||
)");
|
||||
|
||||
CString houseName = "Russian1 House";
|
||||
CIniFile file;
|
||||
ASSERT_EQ(file.LoadFile(std::string(fileName)), 0);
|
||||
|
||||
// remove last
|
||||
DeleteBuildingNodeFrom(houseName, 25, file);
|
||||
ASSERT_EQ(file.GetInteger(houseName, "NodeCount"), 25);
|
||||
|
||||
// remove middle
|
||||
DeleteBuildingNodeFrom(houseName, 23, file);
|
||||
ASSERT_EQ(file.GetInteger(houseName, "NodeCount"), 24);
|
||||
ASSERT_EQ(file.GetString(houseName, GetNodeID(23)), "NALASR,79,24");
|
||||
|
||||
// remove first
|
||||
DeleteBuildingNodeFrom(houseName, 0, file);
|
||||
ASSERT_EQ(file.GetInteger(houseName, "NodeCount"), 23);
|
||||
ASSERT_EQ(file.GetString(houseName, GetNodeID(0)), "NALASR,89,64");
|
||||
ASSERT_EQ(file.GetString(houseName, GetNodeID(22)), "NALASR,79,24");
|
||||
}
|
|
@ -26,6 +26,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <afxwin.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
|
|
@ -148,6 +148,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\MissionEditor\IniFile.h" />
|
||||
<ClInclude Include="..\MissionEditor\INIMeta.h" />
|
||||
<ClInclude Include="CIni_Test.h" />
|
||||
<ClInclude Include="StdAfx.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -47,5 +47,8 @@
|
|||
<ClInclude Include="..\MissionEditor\INIMeta.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CIni_Test.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue