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