/* * GDevelop Core * Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights * reserved. This project is released under the MIT License. */ /** * @file Tests covering events of GDevelop Core. */ #include "catch.hpp" #include #include #include #include "GDCore/CommonTools.h" #include "GDCore/Project/VariablesContainer.h" TEST_CASE("VariablesContainer", "[common][variables]") { SECTION("Copy and assignment") { gd::VariablesContainer container1; gd::VariablesContainer container2; container1.InsertNew("Variable1", 0).SetString("Hello World"); container1.InsertNew("Variable2", 0).SetValue(42); gd::VariablesContainer container3(container1); container2 = container1; REQUIRE(container2.Has("Variable1") == true); REQUIRE(container2.Has("Variable2") == true); REQUIRE(container3.Has("Variable1") == true); REQUIRE(container3.Has("Variable2") == true); REQUIRE(container1.Get("Variable1").GetString() == "Hello World"); REQUIRE(container1.Get("Variable2").GetValue() == 42); REQUIRE(container2.Get("Variable1").GetString() == "Hello World"); REQUIRE(container2.Get("Variable2").GetValue() == 42); REQUIRE(container3.Get("Variable1").GetString() == "Hello World"); REQUIRE(container3.Get("Variable2").GetValue() == 42); container2.Get("Variable1").SetString("Hello copied World"); container2.Get("Variable2").SetValue(43); container3.Get("Variable1").SetString("Hello second copied World"); container3.Get("Variable2").SetValue(44); REQUIRE(container1.Get("Variable1").GetString() == "Hello World"); REQUIRE(container1.Get("Variable2").GetValue() == 42); REQUIRE(container2.Get("Variable1").GetString() == "Hello copied World"); REQUIRE(container2.Get("Variable2").GetValue() == 43); REQUIRE(container3.Get("Variable1").GetString() == "Hello second copied World"); REQUIRE(container3.Get("Variable2").GetValue() == 44); } SECTION("Insert clears the editor-only mixed values marker") { gd::Variable mixedValuesVariable; mixedValuesVariable.SetValue(123); mixedValuesVariable.MarkAsMixedValues(); gd::Variable mixedTypesVariable; mixedTypesVariable.SetValue(456); mixedTypesVariable.CastTo(gd::Variable::Type::MixedTypes); gd::VariablesContainer container; auto& insertedMixedValuesVariable = container.Insert("MyMixedValuesVariable", mixedValuesVariable, 0); auto& insertedMixedTypesVariable = container.Insert("MyMixedTypesVariable", mixedTypesVariable, 1); // The inserted copies have an actual value: the marker used to display // "Mixed values" in the editor is not kept. REQUIRE(insertedMixedValuesVariable.HasMixedValues() == false); REQUIRE(insertedMixedValuesVariable.GetType() == gd::Variable::Type::Number); REQUIRE(insertedMixedValuesVariable.GetValue() == 123); REQUIRE(insertedMixedTypesVariable.HasMixedValues() == false); REQUIRE(insertedMixedTypesVariable.GetType() == gd::Variable::Type::Number); // The original variables are left untouched. REQUIRE(mixedValuesVariable.HasMixedValues() == true); REQUIRE(mixedTypesVariable.GetType() == gd::Variable::Type::MixedTypes); } }