Fix warnings in vs2015 when building tests.

Reviewed by: @Angen, @Itms
Differential Revision: https://code.wildfiregames.com/D1678
This was SVN commit r22048.
This commit is contained in:
Stan 2019-01-12 16:23:47 +00:00
parent c7485492c5
commit 43758bcb92
5 changed files with 226 additions and 281 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2017 Wildfire Games. /* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -189,124 +189,121 @@ void CMapWriter::WriteXML(const VfsPath& filename,
CPostprocManager* pPostproc, CPostprocManager* pPostproc,
CSimulation2* pSimulation2) CSimulation2* pSimulation2)
{ {
XML_Start(); XMLWriter_File xmlMapFile;
{ {
XML_Element("Scenario"); XMLWriter_Element scenarioTag(xmlMapFile, "Scenario");
XML_Attribute("version", (int)FILE_VERSION); scenarioTag.Attribute("version", static_cast<int>(FILE_VERSION));
ENSURE(pSimulation2); ENSURE(pSimulation2);
CSimulation2& sim = *pSimulation2; CSimulation2& sim = *pSimulation2;
if (!sim.GetStartupScript().empty()) if (!sim.GetStartupScript().empty())
{ {
XML_Element("Script"); XMLWriter_Element scriptTag(xmlMapFile, "Script");
XML_CDATA(sim.GetStartupScript().c_str()); scriptTag.Text(sim.GetStartupScript().c_str(), true);
} }
{ {
XML_Element("Environment"); XMLWriter_Element environmentTag(xmlMapFile, "Environment");
environmentTag.Setting("SkySet", pSkyMan->GetSkySet());
XML_Setting("SkySet", pSkyMan->GetSkySet());
{ {
XML_Element("SunColor"); XMLWriter_Element sunColorTag(xmlMapFile, "SunColor");
XML_Attribute("r", pLightEnv->m_SunColor.X); // yes, it's X/Y/Z... sunColorTag.Attribute("r", pLightEnv->m_SunColor.X); // yes, it's X/Y/Z...
XML_Attribute("g", pLightEnv->m_SunColor.Y); sunColorTag.Attribute("g", pLightEnv->m_SunColor.Y);
XML_Attribute("b", pLightEnv->m_SunColor.Z); sunColorTag.Attribute("b", pLightEnv->m_SunColor.Z);
} }
{ {
XML_Element("SunElevation"); XMLWriter_Element SunElevationTag(xmlMapFile, "SunElevation");
XML_Attribute("angle", pLightEnv->m_Elevation); SunElevationTag.Attribute("angle", pLightEnv->m_Elevation);
} }
{ {
XML_Element("SunRotation"); XMLWriter_Element sunRotationTag(xmlMapFile, "SunRotation");
XML_Attribute("angle", pLightEnv->m_Rotation); sunRotationTag.Attribute("angle", pLightEnv->m_Rotation);
} }
{ {
XML_Element("TerrainAmbientColor"); XMLWriter_Element terrainAmbientColorTag(xmlMapFile, "TerrainAmbientColor");
XML_Attribute("r", pLightEnv->m_TerrainAmbientColor.X); terrainAmbientColorTag.Attribute("r", pLightEnv->m_TerrainAmbientColor.X);
XML_Attribute("g", pLightEnv->m_TerrainAmbientColor.Y); terrainAmbientColorTag.Attribute("g", pLightEnv->m_TerrainAmbientColor.Y);
XML_Attribute("b", pLightEnv->m_TerrainAmbientColor.Z); terrainAmbientColorTag.Attribute("b", pLightEnv->m_TerrainAmbientColor.Z);
} }
{ {
XML_Element("UnitsAmbientColor"); XMLWriter_Element unitsAmbientColorTag(xmlMapFile, "UnitsAmbientColor");
XML_Attribute("r", pLightEnv->m_UnitsAmbientColor.X); unitsAmbientColorTag.Attribute("r", pLightEnv->m_UnitsAmbientColor.X);
XML_Attribute("g", pLightEnv->m_UnitsAmbientColor.Y); unitsAmbientColorTag.Attribute("g", pLightEnv->m_UnitsAmbientColor.Y);
XML_Attribute("b", pLightEnv->m_UnitsAmbientColor.Z); unitsAmbientColorTag.Attribute("b", pLightEnv->m_UnitsAmbientColor.Z);
} }
{ {
XML_Element("Fog"); XMLWriter_Element fogTag(xmlMapFile, "Fog");
XML_Setting("FogFactor", pLightEnv->m_FogFactor); fogTag.Setting("FogFactor", pLightEnv->m_FogFactor);
XML_Setting("FogThickness", pLightEnv->m_FogMax); fogTag.Setting("FogThickness", pLightEnv->m_FogMax);
{ {
XML_Element("FogColor"); XMLWriter_Element fogColorTag(xmlMapFile, "FogColor");
XML_Attribute("r", pLightEnv->m_FogColor.X); fogColorTag.Attribute("r", pLightEnv->m_FogColor.X);
XML_Attribute("g", pLightEnv->m_FogColor.Y); fogColorTag.Attribute("g", pLightEnv->m_FogColor.Y);
XML_Attribute("b", pLightEnv->m_FogColor.Z); fogColorTag.Attribute("b", pLightEnv->m_FogColor.Z);
} }
} }
{ {
XML_Element("Water"); XMLWriter_Element waterTag(xmlMapFile, "Water");
{ {
XML_Element("WaterBody"); XMLWriter_Element waterBodyTag(xmlMapFile, "WaterBody");
CmpPtr<ICmpWaterManager> cmpWaterManager(sim, SYSTEM_ENTITY); CmpPtr<ICmpWaterManager> cmpWaterManager(sim, SYSTEM_ENTITY);
ENSURE(cmpWaterManager); ENSURE(cmpWaterManager);
XML_Setting("Type", pWaterMan->m_WaterType); waterBodyTag.Setting("Type", pWaterMan->m_WaterType);
{ {
XML_Element("Color"); XMLWriter_Element colorTag(xmlMapFile, "Color");
XML_Attribute("r", pWaterMan->m_WaterColor.r); colorTag.Attribute("r", pWaterMan->m_WaterColor.r);
XML_Attribute("g", pWaterMan->m_WaterColor.g); colorTag.Attribute("g", pWaterMan->m_WaterColor.g);
XML_Attribute("b", pWaterMan->m_WaterColor.b); colorTag.Attribute("b", pWaterMan->m_WaterColor.b);
} }
{ {
XML_Element("Tint"); XMLWriter_Element tintTag(xmlMapFile, "Tint");
XML_Attribute("r", pWaterMan->m_WaterTint.r); tintTag.Attribute("r", pWaterMan->m_WaterTint.r);
XML_Attribute("g", pWaterMan->m_WaterTint.g); tintTag.Attribute("g", pWaterMan->m_WaterTint.g);
XML_Attribute("b", pWaterMan->m_WaterTint.b); tintTag.Attribute("b", pWaterMan->m_WaterTint.b);
} }
XML_Setting("Height", cmpWaterManager->GetExactWaterLevel(0, 0)); waterBodyTag.Setting("Height", cmpWaterManager->GetExactWaterLevel(0, 0));
XML_Setting("Waviness", pWaterMan->m_Waviness); waterBodyTag.Setting("Waviness", pWaterMan->m_Waviness);
XML_Setting("Murkiness", pWaterMan->m_Murkiness); waterBodyTag.Setting("Murkiness", pWaterMan->m_Murkiness);
XML_Setting("WindAngle", pWaterMan->m_WindAngle); waterBodyTag.Setting("WindAngle", pWaterMan->m_WindAngle);
} }
} }
{ {
XML_Element("Postproc"); XMLWriter_Element postProcTag(xmlMapFile, "Postproc");
{ {
XML_Setting("Brightness", pLightEnv->m_Brightness); postProcTag.Setting("Brightness", pLightEnv->m_Brightness);
XML_Setting("Contrast", pLightEnv->m_Contrast); postProcTag.Setting("Contrast", pLightEnv->m_Contrast);
XML_Setting("Saturation", pLightEnv->m_Saturation); postProcTag.Setting("Saturation", pLightEnv->m_Saturation);
XML_Setting("Bloom", pLightEnv->m_Bloom); postProcTag.Setting("Bloom", pLightEnv->m_Bloom);
XML_Setting("PostEffect", pPostproc->GetPostEffect()); postProcTag.Setting("PostEffect", pPostproc->GetPostEffect());
} }
} }
} }
{ {
XML_Element("Camera"); XMLWriter_Element cameraTag(xmlMapFile, "Camera");
{ {
XML_Element("Position"); XMLWriter_Element positionTag(xmlMapFile, "Position");
CVector3D pos = pCamera->m_Orientation.GetTranslation(); CVector3D pos = pCamera->m_Orientation.GetTranslation();
XML_Attribute("x", pos.X); positionTag.Attribute("x", pos.X);
XML_Attribute("y", pos.Y); positionTag.Attribute("y", pos.Y);
XML_Attribute("z", pos.Z); positionTag.Attribute("z", pos.Z);
} }
CVector3D in = pCamera->m_Orientation.GetIn(); CVector3D in = pCamera->m_Orientation.GetIn();
// Convert to spherical coordinates // Convert to spherical coordinates
float rotation = atan2(in.X, in.Z); float rotation = atan2(in.X, in.Z);
float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - (float)M_PI/2; float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - static_cast<float>(M_PI / 2);
{ {
XML_Element("Rotation"); XMLWriter_Element rotationTag(xmlMapFile, "Rotation");
XML_Attribute("angle", rotation); rotationTag.Attribute("angle", rotation);
} }
{ {
XML_Element("Declination"); XMLWriter_Element declinationTag(xmlMapFile, "Declination");
XML_Attribute("angle", declination); declinationTag.Attribute("angle", declination);
} }
} }
@ -314,14 +311,13 @@ void CMapWriter::WriteXML(const VfsPath& filename,
std::string settings = sim.GetMapSettingsString(); std::string settings = sim.GetMapSettingsString();
if (!settings.empty()) if (!settings.empty())
{ {
XML_Element("ScriptSettings"); XMLWriter_Element scriptSettingsTag(xmlMapFile, "ScriptSettings");
XML_CDATA(("\n" + settings + "\n").c_str()); scriptSettingsTag.Text(("\n" + settings + "\n").c_str(), true);
} }
} }
{ {
XML_Element("Entities"); XMLWriter_Element entitiesTag(xmlMapFile, "Entities");
CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY); CmpPtr<ICmpTemplateManager> cmpTemplateManager(sim, SYSTEM_ENTITY);
ENSURE(cmpTemplateManager); ENSURE(cmpTemplateManager);
@ -336,14 +332,14 @@ void CMapWriter::WriteXML(const VfsPath& filename,
if (ENTITY_IS_LOCAL(ent)) if (ENTITY_IS_LOCAL(ent))
continue; continue;
XML_Element("Entity"); XMLWriter_Element entityTag(xmlMapFile, "Entity");
XML_Attribute("uid", ent); entityTag.Attribute("uid", ent);
XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(ent)); entityTag.Setting("Template", cmpTemplateManager->GetCurrentTemplateName(ent));
CmpPtr<ICmpOwnership> cmpOwnership(sim, ent); CmpPtr<ICmpOwnership> cmpOwnership(sim, ent);
if (cmpOwnership) if (cmpOwnership)
XML_Setting("Player", (int)cmpOwnership->GetOwner()); entityTag.Setting("Player", static_cast<int>(cmpOwnership->GetOwner()));
CmpPtr<ICmpPosition> cmpPosition(sim, ent); CmpPtr<ICmpPosition> cmpPosition(sim, ent);
if (cmpPosition) if (cmpPosition)
@ -354,14 +350,14 @@ void CMapWriter::WriteXML(const VfsPath& filename,
CFixedVector3D rot = cmpPosition->GetRotation(); CFixedVector3D rot = cmpPosition->GetRotation();
{ {
XML_Element("Position"); XMLWriter_Element positionTag(xmlMapFile, "Position");
XML_Attribute("x", pos.X); positionTag.Attribute("x", pos.X);
XML_Attribute("z", pos.Z); positionTag.Attribute("z", pos.Z);
// TODO: height offset etc // TODO: height offset etc
} }
{ {
XML_Element("Orientation"); XMLWriter_Element orientationTag(xmlMapFile, "Orientation");
XML_Attribute("y", rot.Y); orientationTag.Attribute("y", rot.Y);
// TODO: X, Z maybe // TODO: X, Z maybe
} }
} }
@ -379,22 +375,22 @@ void CMapWriter::WriteXML(const VfsPath& filename,
// Don't waste space writing the default control groups. // Don't waste space writing the default control groups.
if (group != ent || group2 != INVALID_ENTITY) if (group != ent || group2 != INVALID_ENTITY)
{ {
XML_Element("Obstruction"); XMLWriter_Element obstructionTag(xmlMapFile, "Obstruction");
if (group != ent) if (group != ent)
XML_Attribute("group", group); obstructionTag.Attribute("group", group);
if (group2 != INVALID_ENTITY) if (group2 != INVALID_ENTITY)
XML_Attribute("group2", group2); obstructionTag.Attribute("group2", group2);
} }
} }
CmpPtr<ICmpVisual> cmpVisual(sim, ent); CmpPtr<ICmpVisual> cmpVisual(sim, ent);
if (cmpVisual) if (cmpVisual)
{ {
u32 seed = cmpVisual->GetActorSeed(); entity_id_t seed = static_cast<entity_id_t>(cmpVisual->GetActorSeed());
if (seed != (u32)ent) if (seed != ent)
{ {
XML_Element("Actor"); XMLWriter_Element actorTag(xmlMapFile, "Actor");
XML_Attribute("seed", seed); actorTag.Attribute("seed",seed);
} }
// TODO: variation/selection strings // TODO: variation/selection strings
} }
@ -407,7 +403,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
{ {
const std::map<CStrW, CCinemaPath>& paths = cmpCinemaManager->GetPaths(); const std::map<CStrW, CCinemaPath>& paths = cmpCinemaManager->GetPaths();
std::map<CStrW, CCinemaPath>::const_iterator it = paths.begin(); std::map<CStrW, CCinemaPath>::const_iterator it = paths.begin();
XML_Element("Paths"); XMLWriter_Element pathsTag(xmlMapFile, "Paths");
for ( ; it != paths.end(); ++it ) for ( ; it != paths.end(); ++it )
{ {
@ -416,12 +412,12 @@ void CMapWriter::WriteXML(const VfsPath& filename,
const std::vector<SplineData>& target_nodes = it->second.GetTargetSpline().GetAllNodes(); const std::vector<SplineData>& target_nodes = it->second.GetTargetSpline().GetAllNodes();
const CCinemaData* data = it->second.GetData(); const CCinemaData* data = it->second.GetData();
XML_Element("Path"); XMLWriter_Element pathTag(xmlMapFile, "Path");
XML_Attribute("name", data->m_Name); pathTag.Attribute("name", data->m_Name);
XML_Attribute("timescale", timescale); pathTag.Attribute("timescale", timescale);
XML_Attribute("orientation", data->m_Orientation); pathTag.Attribute("orientation", data->m_Orientation);
XML_Attribute("mode", data->m_Mode); pathTag.Attribute("mode", data->m_Mode);
XML_Attribute("style", data->m_Style); pathTag.Attribute("style", data->m_Style);
struct SEvent struct SEvent
{ {
@ -460,23 +456,23 @@ void CMapWriter::WriteXML(const VfsPath& filename,
std::sort(events.begin(), events.end()); std::sort(events.begin(), events.end());
for (size_t i = 0; i < events.size();) for (size_t i = 0; i < events.size();)
{ {
XML_Element("Node"); XMLWriter_Element nodeTag(xmlMapFile, "Node");
fixed deltatime = i > 0 ? (events[i].time - events[i - 1].time) : fixed::Zero(); fixed deltatime = i > 0 ? (events[i].time - events[i - 1].time) : fixed::Zero();
XML_Attribute("deltatime", deltatime); nodeTag.Attribute("deltatime", deltatime);
size_t j = i; size_t j = i;
for (; j < events.size() && events[j].time == events[i].time; ++j) for (; j < events.size() && events[j].time == events[i].time; ++j)
{ {
// Types: Position/Rotation/Target // Types: Position/Rotation/Target
XML_Element(events[j].type); XMLWriter_Element eventTypeTag(xmlMapFile, events[j].type);
XML_Attribute("x", events[j].value.X); eventTypeTag.Attribute("x", events[j].value.X);
XML_Attribute("y", events[j].value.Y); eventTypeTag.Attribute("y", events[j].value.Y);
XML_Attribute("z", events[j].value.Z); eventTypeTag.Attribute("z", events[j].value.Z);
} }
i = j; i = j;
} }
} }
} }
} }
if (!XML_StoreVFS(g_VFS, filename)) if (!xmlMapFile.StoreVFS(g_VFS, filename))
LOGERROR("Failed to write map '%s'", filename.string8()); LOGERROR("Failed to write map '%s'", filename.string8());
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games. /* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -128,10 +128,10 @@ bool CShaderManager::NewProgram(const char* name, const CShaderDefines& baseDefi
TIMER_ACCRUE(tc_ShaderValidation); TIMER_ACCRUE(tc_ShaderValidation);
// Serialize the XMB data and pass it to the validator // Serialize the XMB data and pass it to the validator
XML_Start(); XMLWriter_File shaderFile;
XML_SetPrettyPrint(false); shaderFile.SetPrettyPrint(false);
XML_WriteXMB(XeroFile); shaderFile.XMB(XeroFile);
bool ok = CXeromyces::ValidateEncoded("shader", wstring_from_utf8(name), XML_GetOutput()); bool ok = CXeromyces::ValidateEncoded("shader", wstring_from_utf8(name), shaderFile.GetOutput());
if (!ok) if (!ok)
return false; return false;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games. /* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -19,88 +19,47 @@
#define INCLUDED_XMLWRITER #define INCLUDED_XMLWRITER
/* /*
*
System for writing simple XML files, with human-readable formatting. *System for writing simple XML files, with human-readable formatting.
*
Example usage: *Example usage:
*
XML_Start(); * XMLWriter_File exampleFile;
* {
{ * XMLWriter_Element scenarioTag (exampleFile,"Scenario");
XML_Element("Scenario"); * {
{ * XMLWriter_Element entitiesTag (exampleFile,"Entities");
XML_Element("Entities"); * for (...)
for (...) * {
{ * XMLWriter_Element entityTag (exampleFile,"Entity");
XML_Element("Entity"); * {
* XMLWriter_Element templateTag (exampleFile,"Template");
{ * templateTag.Text(entity.name);
XML_Element("Template"); * }
XML_Text(entity.name); * // Or equivalently:
} * templateTag.Setting("Template", entity.name);
// Or equivalently: * {
XML_Setting("Template", entity.name); * XMLWriter_Element positionTag (exampleFile,"Position");
* positionTag.Attribute("x", entity.x);
{ * positionTag.Attribute("y", entity.y);
XML_Element("Position"); * positionTag.Attribute("z", entity.z);
XML_Attribute("x", entity.x); * }
XML_Attribute("y", entity.y); * {
XML_Attribute("z", entity.z); * XMLWriter_Element orientationTag (exampleFile,"Orientation");
} * orientationTag.Attribute("angle", entity.angle);
* }
{ * }
XML_Element("Orientation"); * }
XML_Attribute("angle", entity.angle); * }
} * exampleFile.StoreVFS(g_VFS, "/test.xml");
} *
} * In general, "{ XML_Element(name); ... }" means "<name> ... </name>" -- the
} * scoping braces are important to indicate where an element ends. If you don't put
* them the tag won't be closed until the object's destructor is called, usually
Handle h = vfs_open("/test.xml", FILE_WRITE|FILE_NO_AIO); * when it goes out of scope.
XML_StoreVFS(h); * xml_element_.Attribute/xml_element_.Setting are templated. To support more types, alter the
* end of XMLWriter.cpp.
In general, "{ XML_Element(name); ... }" means "<name> ... </name>" -- the */
scoping braces are important to indicate where an element ends.
XML_Attribute/XML_Setting are templated. To support more types, alter the
end of XMLWriter.cpp.
*/
// Starts generating a new XML file.
#define XML_Start() XMLWriter_File xml_file_
// Set pretty printing (newlines, tabs). Defaults to true.
#define XML_SetPrettyPrint(enabled) xml_file_.SetPrettyPrint(false)
// Add a comment to the XML file: <!-- text -->
#define XML_Comment(text) xml_file_.Comment(text)
// Start a new element: <name ...>
#define XML_Element(name) XMLWriter_Element xml_element_ (xml_file_, name)
// Add text to the interior of the current element: <...>text</...>
#define XML_Text(text) xml_element_.Text(text, false)
// Add CDATA-escaped text to the interior of the current element: <...><![CDATA[text]]></...>
#define XML_CDATA(text) xml_element_.Text(text, true)
// Add an attribute to the current element: <... name="value" ...>
#define XML_Attribute(name, value) xml_element_.Attribute(name, value)
// Add a 'setting': <name>value</name>
#define XML_Setting(name, value) xml_element_.Setting(name, value)
#define XML_WriteXMB(xero) xml_file_.XMB(xero)
// Create a VFS file from the XML data.
// Returns true on success, false (and logs an error) on failure.
#define XML_StoreVFS(vfs, pathname) xml_file_.StoreVFS(vfs, pathname)
// Returns the contents of the XML file as a UTF-8 byte stream in a const CStr&
// string. (Use CStr::FromUTF8 to get a Unicode string back.)
#define XML_GetOutput() xml_file_.GetOutput()
#include "ps/CStr.h" #include "ps/CStr.h"
#include "lib/file/vfs/vfs.h" #include "lib/file/vfs/vfs.h"

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games. /* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -24,42 +24,41 @@ class TestXmlWriter : public CxxTest::TestSuite
public: public:
void test1() void test1()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Root"); XMLWriter_Element rootTag(testFile, "Root");
{ {
XML_Comment("Comment test."); testFile.Comment("Comment test.");
XML_Comment("Comment test again."); testFile.Comment("Comment test again.");
{ {
XML_Element("a"); XMLWriter_Element testTag1(testFile, "a");
XML_Attribute("one", 1); testTag1.Attribute("one", 1);
XML_Attribute("two", "TWO"); testTag1.Attribute("two", "TWO");
XML_Text("b"); testTag1.Text("b", false);
XML_Text(" (etc)"); testTag1.Text(" (etc)", false);
} }
{ {
XML_Element("c"); XMLWriter_Element testTag2(testFile, "c");
XML_Text("d"); testTag2.Text("d", false);
} }
XML_Setting("c2", "d2"); rootTag.Setting("c2", "d2");
{ {
XML_Element("e"); XMLWriter_Element testTag3(testFile, "e");
{ {
{ {
XML_Element("f"); XMLWriter_Element testTag4(testFile, "f");
XML_Text("g"); testTag4.Text("g", false);
} }
{ {
XML_Element("h"); XMLWriter_Element testTag5(testFile, "h");
} }
{ {
XML_Element("i"); XMLWriter_Element testTag6(testFile, "i");
XML_Attribute("j", 1.23); testTag6.Attribute("j", 1.23);
{ {
XML_Element("k"); XMLWriter_Element testTag7(testFile, "k");
XML_Attribute("l", 2.34); testTag7.Attribute("l", 2.34);
XML_Text("m"); testTag7.Text("m", false);
} }
} }
} }
@ -67,7 +66,7 @@ public:
} }
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"\n" "\n"
@ -85,25 +84,24 @@ public:
"\t\t</i>\n" "\t\t</i>\n"
"\t</e>\n" "\t</e>\n"
"</Root>" "</Root>"
); );
} }
void test_basic() void test_basic()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Test"); XMLWriter_Element testTag1(testFile, "Test");
{ {
XML_Element("example"); XMLWriter_Element testTag2(testFile, "example");
{ {
XML_Element("content"); XMLWriter_Element testTag3(testFile, "content");
XML_Text("text"); testTag3.Text("text", false);
} }
} }
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"\n" "\n"
@ -112,133 +110,126 @@ public:
"\t\t<content>text</content>\n" "\t\t<content>text</content>\n"
"\t</example>\n" "\t</example>\n"
"</Test>" "</Test>"
); );
} }
void test_nonpretty() void test_nonpretty()
{ {
XML_Start(); XMLWriter_File testFile;
XML_SetPrettyPrint(false); testFile.SetPrettyPrint(false);
{ {
XML_Element("Test"); XMLWriter_Element testTag1(testFile, "Test");
{ {
XML_Element("example"); XMLWriter_Element testTag2(testFile, "example");
{ {
XML_Element("content"); XMLWriter_Element testTag3(testFile, "content");
XML_Text("text"); testTag3.Text("text", false);
} }
} }
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Test><example><content>text</content></example></Test>" "<Test><example><content>text</content></example></Test>"
); );
} }
void test_text() void test_text()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Test"); XMLWriter_Element rootTag(testFile, "Test");
XML_Text("a"); rootTag.Text("a", false);
XML_Text("b"); rootTag.Text("b", false);
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"\n" "\n"
"<Test>ab</Test>" "<Test>ab</Test>"
); );
} }
void test_utf8() void test_utf8()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Test"); XMLWriter_Element rootTag(testFile, "Test");
{ {
const wchar_t text[] = { 0x0251, 0 }; const wchar_t text[] = { 0x0251, 0 };
XML_Text(text); rootTag.Text(text, false);
} }
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"
"<Test>\xC9\x91</Test>" "<Test>\xC9\x91</Test>"
); );
} }
void test_attr_escape() void test_attr_escape()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Test"); XMLWriter_Element rootTag(testFile, "Test");
XML_Attribute("example", "abc > ]]> < & \"\" "); rootTag.Attribute("example", "abc > ]]> < & \"\" ");
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"
"<Test example=\"abc > ]]> &lt; &amp; &quot;&quot; \"/>" "<Test example=\"abc > ]]> &lt; &amp; &quot;&quot; \"/>"
); );
} }
void test_chardata_escape() void test_chardata_escape()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Test"); XMLWriter_Element rootTag(testFile, "Test");
XML_Text("abc > ]]> < & \"\" "); rootTag.Text("abc > ]]> < & \"\" ", false);
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"
"<Test>abc > ]]&gt; &lt; &amp; \"\" </Test>" "<Test>abc > ]]&gt; &lt; &amp; \"\" </Test>"
); );
} }
void test_cdata_escape() void test_cdata_escape()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Test"); XMLWriter_Element rootTag(testFile, "Test");
XML_CDATA("abc > ]]> < & \"\" "); rootTag.Text("abc > ]]> < & \"\" ", true);
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"
"<Test><![CDATA[abc > ]]>]]&gt;<![CDATA[ < & \"\" ]]></Test>" "<Test><![CDATA[abc > ]]>]]&gt;<![CDATA[ < & \"\" ]]></Test>"
); );
} }
void test_comment_escape() void test_comment_escape()
{ {
XML_Start(); XMLWriter_File testFile;
{ {
XML_Element("Test"); XMLWriter_Element rootTag(testFile, "Test");
XML_Comment("test - -- --- ---- test"); testFile.Comment("test - -- --- ---- test");
} }
CStr output = XML_GetOutput(); CStr output = testFile.GetOutput();
TS_ASSERT_STR_EQUALS(output, TS_ASSERT_STR_EQUALS(output,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"
"<Test>\n" "<Test>\n"
"\t<!-- test - \xE2\x80\x90\xE2\x80\x90 \xE2\x80\x90\xE2\x80\x90- \xE2\x80\x90\xE2\x80\x90\xE2\x80\x90\xE2\x80\x90 test -->\n" "\t<!-- test - \xE2\x80\x90\xE2\x80\x90 \xE2\x80\x90\xE2\x80\x90- \xE2\x80\x90\xE2\x80\x90\xE2\x80\x90\xE2\x80\x90 test -->\n"
"</Test>" "</Test>"
); );
} }
}; };

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games. /* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -254,21 +254,21 @@ QUERYHANDLER(GetObjectMapSettings)
CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
ENSURE(cmpTemplateManager); ENSURE(cmpTemplateManager);
XML_Start(); XMLWriter_File exampleFile;
{ {
XML_Element("Entities"); XMLWriter_Element entitiesTag(exampleFile, "Entities");
{ {
for (entity_id_t id : ids) for (entity_id_t id : ids)
{ {
XML_Element("Entity"); XMLWriter_Element entityTag(exampleFile, "Entity");
{ {
//Template name //Template name
XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(id)); entityTag.Setting("Template", cmpTemplateManager->GetCurrentTemplateName(id));
//Player //Player
CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), id); CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), id);
if (cmpOwnership) if (cmpOwnership)
XML_Setting("Player", (int)cmpOwnership->GetOwner()); entityTag.Setting("Player", static_cast<int>(cmpOwnership->GetOwner()));
//Adding position to make some relative position later //Adding position to make some relative position later
CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id); CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id);
@ -277,29 +277,28 @@ QUERYHANDLER(GetObjectMapSettings)
CFixedVector3D pos = cmpPosition->GetPosition(); CFixedVector3D pos = cmpPosition->GetPosition();
CFixedVector3D rot = cmpPosition->GetRotation(); CFixedVector3D rot = cmpPosition->GetRotation();
{ {
XML_Element("Position"); XMLWriter_Element positionTag(exampleFile, "Position");
XML_Attribute("x", pos.X); positionTag.Attribute("x", pos.X);
XML_Attribute("z", pos.Z); positionTag.Attribute("z", pos.Z);
// TODO: height offset etc // TODO: height offset etc
} }
{ {
XML_Element("Orientation"); XMLWriter_Element orientationTag(exampleFile, "Orientation");
XML_Attribute("y", rot.Y); orientationTag.Attribute("y", rot.Y);
// TODO: X, Z maybe // TODO: X, Z maybe
} }
} }
// Adding actor seed // Adding actor seed
CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id); CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id);
if (cmpVisual) if (cmpVisual)
XML_Setting("ActorSeed", (unsigned int)cmpVisual->GetActorSeed()); entityTag.Setting("ActorSeed", static_cast<unsigned int>(cmpVisual->GetActorSeed()));
} }
} }
} }
} }
const CStr& data = XML_GetOutput(); const CStr& data = exampleFile.GetOutput();
msg->xmldata = std::wstring(data.begin(), data.end()); msg->xmldata = std::wstring(data.begin(), data.end());
} }