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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include "RadiantTest.h"
#include "iselectable.h"
#include "iselection.h"
#include "ishaderclipboard.h"
#include "testutil/CommandFailureHelper.h"
#include "testutil/MapOperationMonitor.h"
#include "algorithm/Primitives.h"
#include "algorithm/View.h"
#include "algorithm/XmlUtils.h"
#include "render/View.h"
namespace test
{
using ClipboardTest = RadiantTest;
// --- Clipboard related tests ---
TEST_F(ClipboardTest, CopyEmptySelection)
{
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Should start with an empty selection";
// Monitor radiant to catch the messages
CommandFailureHelper helper;
MapOperationMonitor operationMonitor;
// This should do nothing, and it should not throw any execution failures neither
GlobalCommandSystem().executeCommand("Copy");
EXPECT_FALSE(helper.messageReceived()) << "Command execution shouldn't have failed";
EXPECT_TRUE(operationMonitor.messageReceived()) << "Command should have sent out an OperationMessage";
}
TEST_F(ClipboardTest, CutEmptySelection)
{
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Should start with an empty selection";
// Monitor radiant to catch the messages
CommandFailureHelper helper;
MapOperationMonitor operationMonitor;
// This should do nothing, and it should not throw any execution failures neither
GlobalCommandSystem().executeCommand("Cut");
EXPECT_FALSE(helper.messageReceived()) << "Command execution shouldn't have failed";
EXPECT_TRUE(operationMonitor.messageReceived()) << "Command should have sent out an OperationMessage";
}
TEST_F(ClipboardTest, CopyNonEmptySelection)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::createCubicBrush(worldspawn);
Node_setSelected(brush, true);
// Monitor radiant to catch the messages
CommandFailureHelper helper;
MapOperationMonitor operationMonitor;
GlobalCommandSystem().executeCommand("Copy");
EXPECT_FALSE(helper.messageReceived()) << "Command execution should not have failed";
EXPECT_TRUE(operationMonitor.messageReceived()) << "Command should have sent out an OperationMessage";
// Check the clipboard contents, it should contain a mapx file
algorithm::assertStringIsMapxFile(GlobalClipboard().getString());
}
TEST_F(ClipboardTest, CutNonEmptySelection)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::createCubicBrush(worldspawn);
Node_setSelected(brush, true);
// Monitor radiant to catch the messages
CommandFailureHelper helper;
MapOperationMonitor operationMonitor;
GlobalCommandSystem().executeCommand("Cut");
EXPECT_FALSE(helper.messageReceived()) << "Command execution should not have failed";
EXPECT_TRUE(operationMonitor.messageReceived()) << "Command should have sent out an OperationMessage";
// Check the clipboard contents, it should contain a mapx file
algorithm::assertStringIsMapxFile(GlobalClipboard().getString());
EXPECT_FALSE(Node_isSelected(brush));
EXPECT_FALSE(brush->getParent()) << "Brush should have been removed from the map";
EXPECT_FALSE(brush->inScene()) << "Brush should be have been removed from the scene";
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Selection should now be empty";
}
TEST_F(ClipboardTest, CutIsUndoable)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::createCubicBrush(worldspawn);
Node_setSelected(brush, true);
// Cut and check the clipboard contents, it should contain a mapx file
GlobalCommandSystem().executeCommand("Cut");
algorithm::assertStringIsMapxFile(GlobalClipboard().getString());
EXPECT_FALSE(brush->getParent()) << "Brush should have been removed from the map";
EXPECT_FALSE(brush->inScene()) << "Brush should be have been removed from the scene";
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Selection should now be empty";
GlobalCommandSystem().executeCommand("Undo");
EXPECT_TRUE(brush->getParent()) << "Brush should be back now";
EXPECT_TRUE(brush->inScene()) << "Brush should be back now";
}
TEST_F(ClipboardTest, CopyFaceSelection)
{
// Create a brush and select a single face
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto brush = algorithm::createCubicBrush(worldspawn, { 0, 0 ,0 }, "textures/common/caulk");
render::View view(true);
algorithm::constructCameraView(view, brush->worldAABB(), Vector3(0, 0, -1), Vector3(-90, 0, 0));
auto rectangle = selection::Rectangle::ConstructFromPoint(Vector2(0, 0), Vector2(8.0 / algorithm::DeviceWidth, 8.0 / algorithm::DeviceHeight));
ConstructSelectionTest(view, rectangle);
SelectionVolume test(view);
GlobalSelectionSystem().selectPoint(test, selection::SelectionSystem::eToggle, true);
EXPECT_EQ(GlobalSelectionSystem().getSelectedFaceCount(), 1) << "One face should be selected now";
// Monitor radiant to catch the messages
CommandFailureHelper helper;
MapOperationMonitor operationMonitor;
GlobalShaderClipboard().clear();
EXPECT_NE(GlobalShaderClipboard().getShaderName(), "textures/common/caulk");
// This should do nothing, and it should not throw any execution failures neither
GlobalCommandSystem().executeCommand("Copy");
EXPECT_FALSE(helper.messageReceived()) << "Command execution should not have failed";
EXPECT_TRUE(operationMonitor.messageReceived()) << "Command should have sent out an OperationMessage";
// Check the shader clipboard, it should contain the material name
EXPECT_EQ(GlobalShaderClipboard().getShaderName(), "textures/common/caulk") << "Shaderclipboard should contain the material name now";
}
}
|