/
MapExport.cpp
74 lines (53 loc) · 1.84 KB
/
MapExport.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#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"
#include "messages/MapFileOperation.h"
#include "algorithm/XmlUtils.h"
namespace test
{
namespace
{
void createAndSelectSingleBrush()
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brushNode = GlobalBrushCreator().createBrush();
worldspawn->addChildNode(brushNode);
GlobalSelectionSystem().setSelectedAll(false);
Node_setSelected(brushNode, true);
}
}
using MapExportTest = RadiantTest;
TEST_F(MapExportTest, exportSelectedWithFormat)
{
createAndSelectSingleBrush();
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
algorithm::assertStringIsMapxFile(output.str());
}
TEST_F(MapExportTest, exportSelectedDoesNotSendMessages)
{
createAndSelectSingleBrush();
auto format = GlobalMapFormatManager().getMapFormatByName(map::PORTABLE_MAP_FORMAT_NAME);
bool messageReceived = false;
// Subscribe to the messages potentially sent by the MapExporter
auto listener = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::Type::MapFileOperation,
radiant::TypeListener<map::FileOperation>([&](map::FileOperation& msg)
{
messageReceived = true;
}));
std::ostringstream output;
GlobalMapModule().exportSelected(output, format);
output.flush();
GlobalRadiantCore().getMessageBus().removeListener(listener);
EXPECT_FALSE(messageReceived) << "Received a FileOperation message while exporting the selection";
}
}