Skip to content

Commit

Permalink
#5108: Add unit test checking the user being able to cancel the map l…
Browse files Browse the repository at this point in the history
…oading process
  • Loading branch information
codereader committed Nov 28, 2020
1 parent db49aa7 commit c12db2b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/MapSavingLoading.cpp
Expand Up @@ -9,6 +9,7 @@
#include "ilightnode.h"
#include "icommandsystem.h"
#include "messages/FileSelectionRequest.h"
#include "messages/MapFileOperation.h"
#include "algorithm/Scene.h"
#include "algorithm/XmlUtils.h"
#include "algorithm/Primitives.h"
Expand Down Expand Up @@ -333,6 +334,47 @@ TEST_F(MapLoadingTest, openMapWithoutInfoFile)
EXPECT_EQ(GlobalMapModule().getMapName(), tempPath.string());
}

TEST_F(MapLoadingTest, loadingCanBeCancelled)
{
std::string mapName = "altar.map";
std::string otherMap = "altar_loadingCanBeCancelled.map";
auto tempPath = createMapCopyInTempDataPath(mapName, otherMap);

// Load a valid map first
GlobalCommandSystem().executeCommand("OpenMap", mapName);
checkAltarScene();

bool cancelIssued = false;

// Subscribe to the map file operation progress event to cancel loading
// Subscribe to the event we expect to be fired
auto msgSubscription = GlobalRadiantCore().getMessageBus().addListener(
radiant::IMessage::Type::MapFileOperation,
radiant::TypeListener<map::FileOperation>(
[&](map::FileOperation& msg)
{
if (msg.getOperationType() == map::FileOperation::Type::Import &&
msg.getMessageType() == map::FileOperation::Started)
{
// set the flag before, since cancelOperation will be throwing an exception
cancelIssued = true;
msg.cancelOperation();
}
}));

// Now load the other map and cancel the operation
GlobalCommandSystem().executeCommand("OpenMap", tempPath.string());

// Operation should have been actively cancelled
EXPECT_TRUE(cancelIssued);

// Map should be empty
EXPECT_FALSE(algorithm::getEntityByName(GlobalMapModule().getRoot(), "world"));
EXPECT_EQ(GlobalMapModule().getMapName(), "unnamed.map");

GlobalRadiantCore().getMessageBus().removeListener(msgSubscription);
}

TEST_F(MapSavingTest, saveMapWithoutModification)
{
auto tempPath = createMapCopyInTempDataPath("altar.map", "altar_saveMapWithoutModification.map");
Expand Down

0 comments on commit c12db2b

Please sign in to comment.