diff --git a/test/CSG.cpp b/test/CSG.cpp index 7984d0c7b0..6476b48684 100644 --- a/test/CSG.cpp +++ b/test/CSG.cpp @@ -5,6 +5,9 @@ #include "entitylib.h" #include "algorithm/Scene.h" +namespace test +{ + TEST_F(RadiantTest, CSGMergeTwoRegularWorldspawnBrushes) { loadMap("csg_merge.map"); @@ -13,8 +16,8 @@ TEST_F(RadiantTest, CSGMergeTwoRegularWorldspawnBrushes) auto worldspawn = GlobalMapModule().getWorldspawn(); // Try to merge the two brushes with the "1" and "2" materials - auto firstBrush = test::algorithm::findFirstBrushWithMaterial(worldspawn, "1"); - auto secondBrush = test::algorithm::findFirstBrushWithMaterial(worldspawn, "2"); + auto firstBrush = algorithm::findFirstBrushWithMaterial(worldspawn, "1"); + auto secondBrush = algorithm::findFirstBrushWithMaterial(worldspawn, "2"); ASSERT_TRUE(Node_getIBrush(firstBrush)->getNumFaces() == 5); ASSERT_TRUE(Node_getIBrush(secondBrush)->getNumFaces() == 5); @@ -32,8 +35,8 @@ TEST_F(RadiantTest, CSGMergeTwoRegularWorldspawnBrushes) ASSERT_TRUE(secondBrush->getParent() == nullptr); // The merged brush will carry both materials - auto brushWithMaterial1 = test::algorithm::findFirstBrushWithMaterial(worldspawn, "1"); - auto brushWithMaterial2 = test::algorithm::findFirstBrushWithMaterial(worldspawn, "2"); + auto brushWithMaterial1 = algorithm::findFirstBrushWithMaterial(worldspawn, "1"); + auto brushWithMaterial2 = algorithm::findFirstBrushWithMaterial(worldspawn, "2"); ASSERT_TRUE(brushWithMaterial1 == brushWithMaterial2); ASSERT_TRUE(Node_getIBrush(brushWithMaterial1)->getNumFaces() == 6); @@ -48,10 +51,10 @@ TEST_F(RadiantTest, CSGMergeFourRegularWorldspawnBrushes) // Try to merge the two brushes with the "1" and "2" materials std::vector brushes = { - test::algorithm::findFirstBrushWithMaterial(worldspawn, "1"), - test::algorithm::findFirstBrushWithMaterial(worldspawn, "2"), - test::algorithm::findFirstBrushWithMaterial(worldspawn, "3"), - test::algorithm::findFirstBrushWithMaterial(worldspawn, "4") + algorithm::findFirstBrushWithMaterial(worldspawn, "1"), + algorithm::findFirstBrushWithMaterial(worldspawn, "2"), + algorithm::findFirstBrushWithMaterial(worldspawn, "3"), + algorithm::findFirstBrushWithMaterial(worldspawn, "4") }; // Check the correct setup @@ -77,7 +80,7 @@ TEST_F(RadiantTest, CSGMergeFourRegularWorldspawnBrushes) } // The combined brush should be a 6-sided cuboid - auto brushWithMaterial1 = test::algorithm::findFirstBrushWithMaterial(worldspawn, "1"); + auto brushWithMaterial1 = algorithm::findFirstBrushWithMaterial(worldspawn, "1"); ASSERT_TRUE(Node_getIBrush(brushWithMaterial1)->getNumFaces() == 6); } @@ -92,8 +95,8 @@ TEST_F(RadiantTest, CSGMergeTwoFuncStaticBrushes) auto entity = walker.getEntityNode(); // Try to merge the two brushes with the "1" and "2" materials - auto firstBrush = test::algorithm::findFirstBrushWithMaterial(entity, "1"); - auto secondBrush = test::algorithm::findFirstBrushWithMaterial(entity, "2"); + auto firstBrush = algorithm::findFirstBrushWithMaterial(entity, "1"); + auto secondBrush = algorithm::findFirstBrushWithMaterial(entity, "2"); ASSERT_TRUE(Node_getIBrush(firstBrush)->getNumFaces() == 5); ASSERT_TRUE(Node_getIBrush(secondBrush)->getNumFaces() == 5); @@ -109,10 +112,10 @@ TEST_F(RadiantTest, CSGMergeTwoFuncStaticBrushes) // The two brushes should be gone, replaced by a new one ASSERT_TRUE(firstBrush->getParent() == nullptr); ASSERT_TRUE(secondBrush->getParent() == nullptr); - + // The merged brush will carry both materials - auto brushWithMaterial1 = test::algorithm::findFirstBrushWithMaterial(entity, "1"); - auto brushWithMaterial2 = test::algorithm::findFirstBrushWithMaterial(entity, "2"); + auto brushWithMaterial1 = algorithm::findFirstBrushWithMaterial(entity, "1"); + auto brushWithMaterial2 = algorithm::findFirstBrushWithMaterial(entity, "2"); ASSERT_TRUE(brushWithMaterial1 == brushWithMaterial2); ASSERT_TRUE(Node_getIBrush(brushWithMaterial1)->getNumFaces() == 6); @@ -137,10 +140,10 @@ TEST_F(RadiantTest, CSGMergeBrushesOfMixedEntitySelection) // Select the mergeable brushes of both entities carrying the "1" and "2" materials std::vector brushes = { - test::algorithm::findFirstBrushWithMaterial(entity, "1"), - test::algorithm::findFirstBrushWithMaterial(entity, "2"), - test::algorithm::findFirstBrushWithMaterial(worldspawn, "1"), - test::algorithm::findFirstBrushWithMaterial(worldspawn, "2") + algorithm::findFirstBrushWithMaterial(entity, "1"), + algorithm::findFirstBrushWithMaterial(entity, "2"), + algorithm::findFirstBrushWithMaterial(worldspawn, "1"), + algorithm::findFirstBrushWithMaterial(worldspawn, "2") }; // Check the correct setup @@ -167,16 +170,16 @@ TEST_F(RadiantTest, CSGMergeBrushesOfMixedEntitySelection) } // The merged brush will carry both materials - auto funcBrush1 = test::algorithm::findFirstBrushWithMaterial(entity, "1"); - auto funcBrush2 = test::algorithm::findFirstBrushWithMaterial(entity, "2"); + auto funcBrush1 = algorithm::findFirstBrushWithMaterial(entity, "1"); + auto funcBrush2 = algorithm::findFirstBrushWithMaterial(entity, "2"); ASSERT_TRUE(funcBrush1); ASSERT_TRUE(funcBrush1 == funcBrush2); ASSERT_TRUE(Node_getIBrush(funcBrush1)->getNumFaces() == 6); // Same for the worldspawn entity - auto worldBrush1 = test::algorithm::findFirstBrushWithMaterial(worldspawn, "1"); - auto worldBrush2 = test::algorithm::findFirstBrushWithMaterial(worldspawn, "2"); + auto worldBrush1 = algorithm::findFirstBrushWithMaterial(worldspawn, "1"); + auto worldBrush2 = algorithm::findFirstBrushWithMaterial(worldspawn, "2"); ASSERT_TRUE(worldBrush1); ASSERT_TRUE(worldBrush1 == worldBrush2); @@ -189,7 +192,7 @@ TEST_F(RadiantTest, CSGMergeWithFuncStatic) loadMap("csg_merge_with_func_static.map"); // Locate the first worldspawn brush - auto firstBrush = test::algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0); + auto firstBrush = algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0); ASSERT_TRUE(firstBrush); // Locate the func_static in the map @@ -210,7 +213,7 @@ TEST_F(RadiantTest, CSGMergeWithFuncStatic) // No merge should have happened since the brushes // are not part of the same entity // So assume the scene didn't change - ASSERT_TRUE(test::algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0) == firstBrush); + ASSERT_TRUE(algorithm::getNthChild(GlobalMapModule().getWorldspawn(), 0) == firstBrush); EntityNodeFindByClassnameWalker walker2("func_static"); GlobalSceneGraph().root()->traverse(walker2); @@ -218,3 +221,5 @@ TEST_F(RadiantTest, CSGMergeWithFuncStatic) ASSERT_TRUE(walker.getEntityNode()); ASSERT_TRUE(walker.getEntityNode()->hasChildNodes()); } + +} diff --git a/test/Camera.cpp b/test/Camera.cpp new file mode 100644 index 0000000000..2bf6e2c690 --- /dev/null +++ b/test/Camera.cpp @@ -0,0 +1,59 @@ +#include "RadiantTest.h" + +#include "icameraview.h" +#include "icommandsystem.h" +#include "render/View.h" + +namespace test +{ + +TEST_F(RadiantTest, SetCameraPositionAndAngles) +{ + // Assume that we don't have any camera at first + bool exceptionThrown = false; + + try + { + GlobalCameraManager().getActiveView(); + } + catch (const std::runtime_error&) + { + exceptionThrown = true; + } + + ASSERT_TRUE(exceptionThrown); + + render::View view; + auto allocatedCam = GlobalCameraManager().createCamera(view, [](bool) {}); + + // We should be able to get an active camera now + exceptionThrown = false; + try + { + auto& camera = GlobalCameraManager().getActiveView(); + auto oldPosition = camera.getCameraOrigin(); + auto oldAngles = camera.getCameraAngles(); + + // Run the command, and compare the camera's angles + GlobalCommandSystem().executeCommand("SetActiveCameraPosition", cmd::Argument(oldPosition + Vector3(50,50,50))); + + auto newPosition = camera.getCameraOrigin(); + ASSERT_TRUE(oldPosition != newPosition); // position changed + ASSERT_TRUE(camera.getCameraAngles() == oldAngles); // angles unchanged + + GlobalCommandSystem().executeCommand("SetActiveCameraAngles", cmd::Argument(oldAngles + Vector3(10,10,10))); + + ASSERT_TRUE(camera.getCameraOrigin() == newPosition); // position unchanged + ASSERT_TRUE(camera.getCameraAngles() != oldAngles); // angles changed + } + catch (const std::runtime_error&) + { + exceptionThrown = true; + } + + ASSERT_TRUE(exceptionThrown == false); + + GlobalCameraManager().destroyCamera(allocatedCam); +} + +} diff --git a/test/RadiantTest.h b/test/RadiantTest.h index 62fc3866e6..726cdc4d57 100644 --- a/test/RadiantTest.h +++ b/test/RadiantTest.h @@ -14,6 +14,9 @@ #include "module/CoreModule.h" #include "messages/GameConfigNeededMessage.h" +namespace test +{ + /** * Test fixture setting up the application context and * the radiant core module. @@ -66,8 +69,8 @@ class RadiantTest : // Wire up the game-config-needed handler, we need to respond _gameSetupListener = _coreModule->get()->getMessageBus().addListener( radiant::IMessage::Type::GameConfigNeeded, - radiant::TypeListener( - sigc::mem_fun(this, &RadiantTest::handleGameConfigMessage))); + radiant::TypeListener( + sigc::mem_fun(this, &RadiantTest::handleGameConfigMessage))); try { @@ -123,4 +126,6 @@ class RadiantTest : message.setConfig(config); message.setHandled(true); } -}; \ No newline at end of file +}; + +} diff --git a/tools/msvc/Tests/Tests.vcxproj b/tools/msvc/Tests/Tests.vcxproj index 6c48918abb..fe1466dfca 100644 --- a/tools/msvc/Tests/Tests.vcxproj +++ b/tools/msvc/Tests/Tests.vcxproj @@ -61,6 +61,7 @@ + diff --git a/tools/msvc/Tests/Tests.vcxproj.filters b/tools/msvc/Tests/Tests.vcxproj.filters index f7065a3977..b8576799d7 100644 --- a/tools/msvc/Tests/Tests.vcxproj.filters +++ b/tools/msvc/Tests/Tests.vcxproj.filters @@ -3,6 +3,7 @@ +