The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_recall_list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 "config_assign.hpp"
19 #include "recall_list_manager.hpp"
21 #include "units/unit.hpp"
22 #include "units/ptr.hpp"
23 
24 BOOST_AUTO_TEST_SUITE( recall_list_suite )
25 
27  return;
29 
30  config orc_config = config_of
31  ("id", "Orcish Grunt")
32  ("random_traits", false)
33  ("animate", false);
34 
35  unit_type orc_type(orc_config);
36 
38 
39  unit_ptr orc1(new unit(orc_type, 1, false));
40  unit_ptr orc2(new unit(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()
81 
Definition: unit.hpp:95
size_t size() const
Get the number of units on the list.
unit_type_data unit_types
Definition: types.cpp:1314
BOOST_AUTO_TEST_SUITE(test_map_location)
Definitions for the interface to Wesnoth Markup Language (WML).
BOOST_AUTO_TEST_CASE(test_1)
unit_ptr find_if_matches_id(const std::string &unit_id)
Find a unit by id. Null pointer if not found.
iterator begin()
begin iterator
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:326
iterator end()
end iterator
void erase_if_matches_id(const std::string &unit_id)
Erase any unit with this id.
config get_test_config()
Game configuration data as global variables.
Definition: build_info.cpp:38
void add(const unit_ptr &ptr)
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:83