mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fixed crash with extensions due to gd::Project::extensionsUsed not being copied properly at runtime. Added tests for LinkedObjects extension
This commit is contained in:
@@ -23,3 +23,4 @@ script:
|
||||
- cd .build-tests
|
||||
- Core/GDCore_tests
|
||||
- GDCpp/GDCpp_tests
|
||||
- Extensions/LinkedObjects/LinkedObjects_Runtime_tests
|
||||
|
@@ -1106,7 +1106,6 @@ void Project::Init(const gd::Project & game)
|
||||
#if defined(GD_IDE_ONLY)
|
||||
author = game.author;
|
||||
latestCompilationDirectory = game.latestCompilationDirectory;
|
||||
extensionsUsed = game.GetUsedExtensions();
|
||||
objectGroups = game.objectGroups;
|
||||
|
||||
GDMajorVersion = game.GDMajorVersion;
|
||||
@@ -1114,6 +1113,7 @@ void Project::Init(const gd::Project & game)
|
||||
|
||||
currentPlatform = game.currentPlatform;
|
||||
#endif
|
||||
extensionsUsed = game.extensionsUsed;
|
||||
platforms = game.platforms;
|
||||
|
||||
//Resources
|
||||
|
@@ -157,3 +157,18 @@ IF(WIN32)
|
||||
ELSE()
|
||||
target_link_libraries(LinkedObjects_Runtime sfml-audio sfml-graphics sfml-window sfml-network sfml-system)
|
||||
ENDIF(WIN32)
|
||||
|
||||
#Tests for the GD C++ Runtime extension
|
||||
###
|
||||
if(BUILD_TESTS)
|
||||
file(
|
||||
GLOB_RECURSE
|
||||
test_source_files
|
||||
tests/*
|
||||
)
|
||||
add_executable(LinkedObjects_Runtime_tests ${test_source_files})
|
||||
target_link_libraries(LinkedObjects_Runtime_tests GDCpp_Runtime)
|
||||
target_link_libraries(LinkedObjects_Runtime_tests LinkedObjects_Runtime)
|
||||
target_link_libraries(LinkedObjects_Runtime_tests sfml-audio sfml-graphics sfml-window sfml-network sfml-system)
|
||||
target_link_libraries(LinkedObjects_Runtime_tests GLU GL)
|
||||
endif()
|
||||
|
88
Extensions/LinkedObjects/tests/LinkedObjects.cpp
Normal file
88
Extensions/LinkedObjects/tests/LinkedObjects.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
|
||||
GDevelop - LinkedObjects Extension
|
||||
Copyright (c) 2011-2014 Florian Rival (Florian.Rival@gmail.com)
|
||||
This project is released under the MIT License.
|
||||
*/
|
||||
/**
|
||||
* @file Tests for the Linked Objects extension.
|
||||
*/
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#include "GDCore/CommonTools.h"
|
||||
#include "GDCore/PlatformDefinition/ClassWithObjects.h"
|
||||
#include "GDCore/PlatformDefinition/Layout.h"
|
||||
#include "GDCore/PlatformDefinition/Object.h"
|
||||
#include "GDCpp/RuntimeScene.h"
|
||||
#include "GDCpp/RuntimeGame.h"
|
||||
#include "GDCpp/RuntimeObject.h"
|
||||
#include "GDCpp/BuiltinExtensions/ObjectTools.h"
|
||||
#include "GDCpp/BuiltinExtensions/ObjectTools.h"
|
||||
#include "../LinkedObjectsTools.h"
|
||||
#include "../ObjectsLinksManager.h"
|
||||
|
||||
TEST_CASE( "LinkedObjects", "[game-engine][linked-objects]" ) {
|
||||
SECTION("LinkedObjectsTools") {
|
||||
//Prepare some objects and the context
|
||||
gd::Object obj1("1");
|
||||
gd::Object obj2("2");
|
||||
|
||||
RuntimeGame game;
|
||||
RuntimeScene scene(NULL, &game);
|
||||
|
||||
RuntimeObject obj1A(scene, obj1);
|
||||
RuntimeObject obj1B(scene, obj1);
|
||||
RuntimeObject obj1C(scene, obj1);
|
||||
|
||||
RuntimeObject obj2A(scene, obj2);
|
||||
RuntimeObject obj2B(scene, obj2);
|
||||
RuntimeObject obj2C(scene, obj2);
|
||||
|
||||
//Link two objects
|
||||
GDpriv::LinkedObjects::ObjectsLinksManager & manager = GDpriv::LinkedObjects::ObjectsLinksManager::managers[&scene];
|
||||
manager.LinkObjects(&obj1A, &obj2A);
|
||||
{
|
||||
std::vector<RuntimeObject*> linkedObjects = manager.GetObjectsLinkedWith(&obj1A);
|
||||
REQUIRE(linkedObjects.size() == 1);
|
||||
REQUIRE(linkedObjects[0] == &obj2A);
|
||||
}
|
||||
{
|
||||
std::vector<RuntimeObject*> linkedObjects = manager.GetObjectsLinkedWith(&obj2A);
|
||||
REQUIRE(linkedObjects.size() == 1);
|
||||
REQUIRE(linkedObjects[0] == &obj1A);
|
||||
}
|
||||
|
||||
//Link more objects
|
||||
manager.LinkObjects(&obj1A, &obj2A); //Including the same objects as before
|
||||
manager.LinkObjects(&obj1A, &obj2B);
|
||||
manager.LinkObjects(&obj1A, &obj2C);
|
||||
{
|
||||
std::vector<RuntimeObject*> linkedObjects = manager.GetObjectsLinkedWith(&obj1A);
|
||||
REQUIRE(linkedObjects.size() == 3);
|
||||
}
|
||||
{
|
||||
std::vector<RuntimeObject*> linkedObjects = manager.GetObjectsLinkedWith(&obj2C);
|
||||
REQUIRE(linkedObjects.size() == 1);
|
||||
REQUIRE(linkedObjects[0] == &obj1A);
|
||||
}
|
||||
|
||||
//Remove all links
|
||||
manager.LinkObjects(&obj2B, &obj2C);
|
||||
manager.RemoveAllLinksOf(&obj1A);
|
||||
manager.RemoveAllLinksOf(&obj1A);
|
||||
{
|
||||
std::vector<RuntimeObject*> linkedObjects = manager.GetObjectsLinkedWith(&obj1A);
|
||||
REQUIRE(linkedObjects.size() == 0);
|
||||
}
|
||||
{
|
||||
std::vector<RuntimeObject*> linkedObjects = manager.GetObjectsLinkedWith(&obj2A);
|
||||
REQUIRE(linkedObjects.size() == 0);
|
||||
}
|
||||
{
|
||||
std::vector<RuntimeObject*> linkedObjects = manager.GetObjectsLinkedWith(&obj2C);
|
||||
REQUIRE(linkedObjects.size() == 1);
|
||||
REQUIRE(linkedObjects[0] == &obj2B);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
8974
Extensions/LinkedObjects/tests/catch.hpp
Normal file
8974
Extensions/LinkedObjects/tests/catch.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -34,3 +34,21 @@ TEST_CASE( "RuntimeScene", "[common]" ) {
|
||||
REQUIRE(scene.GetName() == "My layout");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE( "gd::Project", "[common]" ) {
|
||||
SECTION("Basics") {
|
||||
gd::Project project;
|
||||
project.SetName("MyName");
|
||||
project.GetUsedExtensions().push_back("Ext1");
|
||||
project.GetUsedExtensions().push_back("Ext2");
|
||||
|
||||
REQUIRE( project.GetName() == "MyName" );
|
||||
|
||||
SECTION("Copy a project in memory") {
|
||||
gd::Project copy = project;
|
||||
|
||||
REQUIRE( copy.GetName() == "MyName" );
|
||||
REQUIRE( copy.GetUsedExtensions().size() == project.GetUsedExtensions().size() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user