The Battle for Wesnoth  1.19.5+dev
test_recall_list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include <boost/test/unit_test.hpp>
17 
18 #include "config.hpp"
19 #include "recall_list_manager.hpp"
21 #include "units/ptr.hpp"
22 #include "units/types.hpp"
23 #include "units/unit.hpp"
24 
25 BOOST_AUTO_TEST_SUITE( recall_list_suite )
26 
29 
30  config orc_config {
31  "id", "Orcish Grunt",
32  "random_traits", false,
33  "animate", false,
34  };
35 
36  unit_type orc_type(orc_config);
37 
39 
40  unit_ptr orc1 = unit::create(orc_type, 1, false);
41  unit_ptr orc2 = unit::create(orc_type, 1, false);
42 
43  orc1->set_name("Larry");
44  orc2->set_name("Moe");
45 
46  orc1->set_id("larry");
47  orc2->set_id("moe");
48 
49  recall_list_manager recall_man;
50  BOOST_CHECK_EQUAL(recall_man.size(), 0);
51  BOOST_CHECK_MESSAGE(recall_man.begin() == recall_man.end(), "failed begin() == end() for an empty container");
52 
53  recall_man.add(orc1);
54  BOOST_CHECK_EQUAL(recall_man.size(), 1);
55  BOOST_CHECK_MESSAGE(recall_man[0] == orc1, "unexpected result at index [0]");
56  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("larry") == orc1, "found something unexpected");
57  BOOST_CHECK_MESSAGE(!recall_man.find_if_matches_id("moe"), "found something unexpected");
58 
59  recall_man.add(orc2);
60  BOOST_CHECK_EQUAL(recall_man.size(), 2);
61  BOOST_CHECK_MESSAGE(recall_man[0] == orc1, "unexpected result at index [0]");
62  BOOST_CHECK_MESSAGE(recall_man[1] == orc2, "unexpected result at index [1]");
63  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("larry") == orc1, "found something unexpected");
64  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("moe") == orc2, "found something unexpected");
65 
66  recall_man.erase_if_matches_id("larry");
67  BOOST_CHECK_EQUAL(recall_man.size(), 1);
68  BOOST_CHECK_MESSAGE(recall_man[0] == orc2, "unexpected result at index [0]");
69  BOOST_CHECK_MESSAGE(!recall_man.find_if_matches_id("larry"), "found something unexpected");
70  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("moe") == orc2, "found something unexpected");
71 
72  recall_man.add(orc1);
73  BOOST_CHECK_EQUAL(recall_man.size(), 2);
74  BOOST_CHECK_MESSAGE(recall_man[0] == orc2, "unexpected result at index [0]");
75  BOOST_CHECK_MESSAGE(recall_man[1] == orc1, "unexpected result at index [1]");
76  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("larry") == orc1, "found something unexpected");
77  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("moe") == orc2, "found something unexpected");
78 
79 }
80 
81 BOOST_AUTO_TEST_SUITE_END()
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
This class encapsulates the recall list of a team.
std::size_t size() const
Get the number of units on the list.
void add(const unit_ptr &ptr, int pos=-1)
Add a unit to the list.
unit_ptr find_if_matches_id(const std::string &unit_id)
Find a unit by id.
iterator end()
end iterator
iterator begin()
begin iterator
void erase_if_matches_id(const std::string &unit_id)
Erase any unit with this id.
void build_unit_type(const unit_type &ut, unit_type::BUILD_STATUS status) const
Makes sure the provided unit_type is built to the specified level.
Definition: types.cpp:1257
A single unit type that the player may recruit.
Definition: types.hpp:43
@ FULL
Definition: types.hpp:74
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
Definition: unit.hpp:201
Definitions for the interface to Wesnoth Markup Language (WML).
Game configuration data as global variables.
Definition: build_info.cpp:61
std::shared_ptr< unit > unit_ptr
Definition: ptr.hpp:26
BOOST_AUTO_TEST_SUITE(filesystem)
BOOST_AUTO_TEST_CASE(test_1)
unit_type_data unit_types
Definition: types.cpp:1500