The Battle for Wesnoth  1.15.1+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/unit.hpp"
21 #include "units/ptr.hpp"
22 
23 BOOST_AUTO_TEST_SUITE( recall_list_suite )
24 
27 
28  config orc_config {
29  "id", "Orcish Grunt",
30  "random_traits", false,
31  "animate", false,
32  };
33 
34  unit_type orc_type(orc_config);
35 
37 
38  unit_ptr orc1 = unit::create(orc_type, 1, false);
39  unit_ptr orc2 = unit::create(orc_type, 1, false);
40 
41  orc1->set_name("Larry");
42  orc2->set_name("Moe");
43 
44  orc1->set_id("larry");
45  orc2->set_id("moe");
46 
47  recall_list_manager recall_man;
48  BOOST_CHECK_EQUAL(recall_man.size(), 0);
49  BOOST_CHECK_MESSAGE(recall_man.begin() == recall_man.end(), "failed begin() == end() for an empty container");
50 
51  recall_man.add(orc1);
52  BOOST_CHECK_EQUAL(recall_man.size(), 1);
53  BOOST_CHECK_MESSAGE(recall_man[0] == orc1, "unexpected result at index [0]");
54  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("larry") == orc1, "found something unexpected");
55  BOOST_CHECK_MESSAGE(!recall_man.find_if_matches_id("moe"), "found something unexpected");
56 
57  recall_man.add(orc2);
58  BOOST_CHECK_EQUAL(recall_man.size(), 2);
59  BOOST_CHECK_MESSAGE(recall_man[0] == orc1, "unexpected result at index [0]");
60  BOOST_CHECK_MESSAGE(recall_man[1] == orc2, "unexpected result at index [1]");
61  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("larry") == orc1, "found something unexpected");
62  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("moe") == orc2, "found something unexpected");
63 
64  recall_man.erase_if_matches_id("larry");
65  BOOST_CHECK_EQUAL(recall_man.size(), 1);
66  BOOST_CHECK_MESSAGE(recall_man[0] == orc2, "unexpected result at index [0]");
67  BOOST_CHECK_MESSAGE(!recall_man.find_if_matches_id("larry"), "found something unexpected");
68  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("moe") == orc2, "found something unexpected");
69 
70  recall_man.add(orc1);
71  BOOST_CHECK_EQUAL(recall_man.size(), 2);
72  BOOST_CHECK_MESSAGE(recall_man[0] == orc2, "unexpected result at index [0]");
73  BOOST_CHECK_MESSAGE(recall_man[1] == orc1, "unexpected result at index [1]");
74  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("larry") == orc1, "found something unexpected");
75  BOOST_CHECK_MESSAGE(recall_man.find_if_matches_id("moe") == orc2, "found something unexpected");
76 
77 }
78 
79 BOOST_AUTO_TEST_SUITE_END()
unit_type_data unit_types
Definition: types.cpp:1525
Definitions for the interface to Wesnoth Markup Language (WML).
BOOST_AUTO_TEST_CASE(test_1)
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
Definition: unit.hpp:154
A single unit type that the player may recruit.
Definition: types.hpp:42
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.hpp:373
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:49
std::size_t size() const
Get the number of units on the list.
boost::intrusive_ptr< unit > unit_ptr
Definition: ptr.hpp:29
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:92