From d7fee130027c364be81e25c73e0d6e7fc2fa83b3 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 31 Oct 2019 13:33:32 +0100 Subject: [PATCH] Fix memory leak in unit tests --- tests/BattleTests/TurnOrderTests.cpp | 32 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/BattleTests/TurnOrderTests.cpp b/tests/BattleTests/TurnOrderTests.cpp index cba2231..d3fc302 100644 --- a/tests/BattleTests/TurnOrderTests.cpp +++ b/tests/BattleTests/TurnOrderTests.cpp @@ -27,8 +27,10 @@ TEST_CASE( "Turn ordering: Attack before pass", "[Battling]" ) { TEST_CASE( "Turn ordering: High priority goes before no priority", "[Battling]" ) { auto l = GetLibrary()->GetAttackLibrary(); - auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown)); - auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown)); + auto a1 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown); + auto choice1 = new AttackTurnChoice(nullptr, a1); + auto choice2 = new AttackTurnChoice(nullptr, a2); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec,rand); @@ -41,12 +43,16 @@ TEST_CASE( "Turn ordering: High priority goes before no priority", "[Battling]" delete choice1; delete choice2; + delete a1; + delete a2; } TEST_CASE( "Turn ordering: Higher priority goes before high priority", "[Battling]" ) { auto l = GetLibrary()->GetAttackLibrary(); - auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown)); - auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown)); + auto a1 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown); + auto choice1 = new AttackTurnChoice(nullptr, a1); + auto choice2 = new AttackTurnChoice(nullptr, a2); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec,rand); @@ -59,12 +65,16 @@ TEST_CASE( "Turn ordering: Higher priority goes before high priority", "[Battlin delete choice1; delete choice2; + delete a1; + delete a2; } TEST_CASE( "Turn ordering: High priority goes before low priority", "[Battling]" ) { auto l = GetLibrary()->GetAttackLibrary(); - auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown)); - auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown)); + auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown); + auto choice1 = new AttackTurnChoice(nullptr, a1); + auto choice2 = new AttackTurnChoice(nullptr, a2); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec,rand); @@ -77,12 +87,16 @@ TEST_CASE( "Turn ordering: High priority goes before low priority", "[Battling]" delete choice1; delete choice2; + delete a1; + delete a2; } TEST_CASE( "Turn ordering: No priority goes before low priority", "[Battling]" ) { auto l = GetLibrary()->GetAttackLibrary(); - auto choice1 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown)); - auto choice2 = new AttackTurnChoice(nullptr, new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown)); + auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown); + auto a2 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown); + auto choice1 = new AttackTurnChoice(nullptr, a1); + auto choice2 = new AttackTurnChoice(nullptr, a2); auto vec = std::vector{choice1, choice2}; auto rand = Core::Random(); TurnOrdering::OrderChoices(vec,rand); @@ -95,6 +109,8 @@ TEST_CASE( "Turn ordering: No priority goes before low priority", "[Battling]" ) delete choice1; delete choice2; + delete a1; + delete a2; }