Skip to content

Commit

Permalink
#5374: Add a unit test checking that Map::exportSelected is not faili…
Browse files Browse the repository at this point in the history
…ng and produces a string result that looks like an XML file.
  • Loading branch information
codereader committed Nov 1, 2020
1 parent e5b3ae0 commit 079ade4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Makefile.am
Expand Up @@ -33,6 +33,7 @@ drtest_SOURCES = math/Matrix4.cpp \
HeadlessOpenGLContext.cpp \
FacePlane.cpp \
Materials.cpp \
MapExport.cpp \
ModelScale.cpp \
SelectionAlgorithm.cpp \
VFS.cpp
39 changes: 39 additions & 0 deletions test/MapExport.cpp
@@ -0,0 +1,39 @@
#include "RadiantTest.h"

#include "imap.h"
#include "imapformat.h"
#include "ibrush.h"
#include "iselection.h"
#include "scenelib.h"
#include "string/predicate.h"
#include "xmlutil/Document.h"

namespace test
{

using MapExportTest = RadiantTest;

TEST_F(MapExportTest, exportSelectedWithFormat)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();

auto brushNode = GlobalBrushCreator().createBrush();
worldspawn->addChildNode(brushNode);

GlobalSelectionSystem().setSelectedAll(false);
Node_setSelected(brushNode, true);

auto format = GlobalMapFormatManager().getMapFormatByName(map::PORTABLE_MAP_FORMAT_NAME);

std::ostringstream output;
GlobalMapModule().exportSelected(output, format);

output.flush();

// Minimal assertion: we got a string that appears to start like an XML document
auto result = output.str();
ASSERT_TRUE(string::starts_with(result, "<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
ASSERT_TRUE(result.find("<map") != std::string::npos);
}

}
5 changes: 5 additions & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -34,21 +34,25 @@
<Import Project="..\properties\DarkRadiant Base Debug x64.props" />
<Import Project="..\properties\Tests.props" />
<Import Project="..\properties\GLEW.props" />
<Import Project="..\properties\libxml2.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="..\properties\DarkRadiant Base Debug Win32.props" />
<Import Project="..\properties\Tests.props" />
<Import Project="..\properties\GLEW.props" />
<Import Project="..\properties\libxml2.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="..\properties\DarkRadiant Base Release Win32.props" />
<Import Project="..\properties\Tests.props" />
<Import Project="..\properties\GLEW.props" />
<Import Project="..\properties\libxml2.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="..\properties\DarkRadiant Base Release x64.props" />
<Import Project="..\properties\Tests.props" />
<Import Project="..\properties\GLEW.props" />
<Import Project="..\properties\libxml2.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemGroup>
Expand All @@ -65,6 +69,7 @@
<ClCompile Include="..\..\..\test\CSG.cpp" />
<ClCompile Include="..\..\..\test\FacePlane.cpp" />
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" />
<ClCompile Include="..\..\..\test\MapExport.cpp" />
<ClCompile Include="..\..\..\test\Materials.cpp" />
<ClCompile Include="..\..\..\test\math\Matrix4.cpp" />
<ClCompile Include="..\..\..\test\math\Plane3.cpp" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -21,6 +21,7 @@
<ClCompile Include="..\..\..\test\math\Plane3.cpp">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="..\..\..\test\MapExport.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down

0 comments on commit 079ade4

Please sign in to comment.