The Battle for Wesnoth  1.19.6+dev
test_mp_connect.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2024
3  by Andrius Silinskas <silinskas.andrius@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 #define GETTEXT_DOMAIN "wesnoth-test"
17 
18 #include <boost/test/unit_test.hpp>
19 
20 #include "game_config_manager.hpp"
21 #include "game_display.hpp"
24 #include "mt_rng.hpp"
25 #include "saved_game.hpp"
27 
28 /* Definitions */
29 
31 public:
33  ng::connect_engine(gamestate, true, nullptr)
34  {}
35 };
36 
37 /* Variables */
38 
39 namespace {
40 
41 std::unique_ptr<saved_game> state;
42 std::unique_ptr<randomness::mt_rng> rng;
43 
44 }
45 
46 /* Global fixture */
47 
50  dummy_args({"wesnoth", "--noaddons"}),
54  {
58 
59  state.reset(new saved_game());
60  state->classification().type = campaign_type::type::multiplayer;
61  state->classification().era_id = "era_default";
62  config_manager->load_game_config_for_game(state->classification(), state->get_scenario_id());
63 
64  state->mp_settings().name = "multiplayer_The_Freelands";
65  state->mp_settings().use_map_settings = true;
66  state->mp_settings().saved_game = saved_game_mode::type::no;
67 
68  state->set_scenario(config_manager->game_config().find_mandatory_child("multiplayer", "id", state->mp_settings().name));
69 
70  state->mp_settings().num_turns = state->get_starting_point()["turns"].to_int();
71 
72  rng.reset(new randomness::mt_rng());
73  }
75  {
76  }
77  std::vector<std::string> dummy_args;
80  std::unique_ptr<game_config_manager> config_manager;
81 };
82 
83 
84 /* Test classes creation utilities */
85 
87 {
88  test_connect_engine* connect_engine =
89  new test_connect_engine(*state);
90 
91  return connect_engine;
92 }
93 
94 static ng::side_engine* create_side_engine(const config& defaults,
95  test_connect_engine* connect_engine)
96 {
97  config side_cfg = connect_engine->current_config()->mandatory_child("side");
98  side_cfg.remove_attributes("faction");
99  side_cfg.clear_children("default_faction");
100  side_cfg.append(defaults);
101 
102  return new ng::side_engine(side_cfg, *connect_engine, 0);
103 }
104 
105 
106 /* Tests */
107 
109 
110 
111 BOOST_AUTO_TEST_CASE( flg_map_settings2 )
112 {
113  // Set up side_engine and its dependencies.
114  state->mp_settings().use_map_settings = true;
115  state->mp_settings().saved_game = saved_game_mode::type::no;
116  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
117  ng::side_engine_ptr side_engine;
118  config side;
119 
120  // Recruit list with no faction.
121  side.clear();
122  side["recruit"] = "Elvish Archer";
123  side_engine.reset(create_side_engine(side, connect_engine.get()));
124  BOOST_CHECK_EQUAL( side_engine->new_config()["recruit"], "Elvish Archer" );
125 }
126 
127 BOOST_AUTO_TEST_CASE( flg_map_settings3 )
128 {
129  // Set up side_engine and its dependencies.
130  state->mp_settings().use_map_settings = true;
131  state->mp_settings().saved_game = saved_game_mode::type::no;
132  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
133  ng::side_engine_ptr side_engine;
134  config side;
135 
136  // Custom faction, no recruits.
137  side.clear();
138  side["faction"] = "Custom";
139  side_engine.reset(create_side_engine(side, connect_engine.get()));
140  BOOST_CHECK_EQUAL( side_engine->flg().current_faction()["id"], "Custom" );
141  BOOST_CHECK_EQUAL( side_engine->new_config()["recruit"].empty(), true );
142 }
143 
144 BOOST_AUTO_TEST_CASE( flg_map_settings4 )
145 {
146  // Set up side_engine and its dependencies.
147  state->mp_settings().use_map_settings = true;
148  state->mp_settings().saved_game = saved_game_mode::type::no;
149  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
150  ng::side_engine_ptr side_engine;
151  config side;
152 
153  // Random faction.
154  side.clear();
155  side["faction"] = "Random";
156  side_engine.reset(create_side_engine(side, connect_engine.get()));
157  BOOST_CHECK_EQUAL( side_engine->flg().current_faction()["id"], "Random" );
158 }
159 
160 BOOST_AUTO_TEST_CASE( flg_map_settings5 )
161 {
162  // Set up side_engine and its dependencies.
163  state->mp_settings().use_map_settings = true;
164  state->mp_settings().saved_game = saved_game_mode::type::no;
165  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
166  ng::side_engine_ptr side_engine;
167  config side;
168 
169  // Valid faction.
170  side.clear();
171  side["faction"] = "Rebels";
172  side_engine.reset(create_side_engine(side, connect_engine.get()));
173  BOOST_CHECK_EQUAL( side_engine->flg().current_faction()["id"], "Rebels" );
174 }
175 
176 BOOST_AUTO_TEST_CASE( flg_map_settings6 )
177 {
178  // Set up side_engine and its dependencies.
179  state->mp_settings().use_map_settings = true;
180  state->mp_settings().saved_game = saved_game_mode::type::no;
181  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
182  ng::side_engine_ptr side_engine;
183  config side;
184 
185  // Invalid faction.
186  side.clear();
187  side["faction"] = "ThisFactionDoesNotExist";
188  side_engine.reset(create_side_engine(side, connect_engine.get()));
189  BOOST_CHECK( side_engine->flg().choosable_factions().size() > 1 );
190  BOOST_CHECK_EQUAL( side_engine->flg().current_faction()["id"], "Random" );
191 }
192 
193 BOOST_AUTO_TEST_CASE( flg_map_settings7 )
194 {
195  // Set up side_engine and its dependencies.
196  state->mp_settings().use_map_settings = true;
197  state->mp_settings().saved_game = saved_game_mode::type::no;
198  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
199  ng::side_engine_ptr side_engine;
200  config side;
201 
202  // Faction and recruit list.
203  side.clear();
204  side["recruit"] = "Elvish Archer";
205  side["faction"] = "Undead";
206  side_engine.reset(create_side_engine(side, connect_engine.get()));
207 }
208 
209 BOOST_AUTO_TEST_CASE( flg_map_settings8 )
210 {
211  // Set up side_engine and its dependencies.
212  state->mp_settings().use_map_settings = true;
213  state->mp_settings().saved_game = saved_game_mode::type::no;
214  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
215  ng::side_engine_ptr side_engine;
216  config side;
217 
218  // Carried over recruits.
219  side.clear();
220  side["previous_recruits"] = "Elvish Archer";
221  side_engine.reset(create_side_engine(side, connect_engine.get()));
222  BOOST_CHECK_EQUAL( side_engine->new_config()["previous_recruits"], "Elvish Archer" );
223 }
224 
225 BOOST_AUTO_TEST_CASE( flg_map_settings9 )
226 {
227  // Set up side_engine and its dependencies.
228  state->mp_settings().use_map_settings = true;
229  state->mp_settings().saved_game = saved_game_mode::type::no;
230  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
231  ng::side_engine_ptr side_engine;
232  config side;
233 
234  // Valid leader unit.
235  side.clear();
236  side["type"] = "Shadow";
237  side_engine.reset(create_side_engine(side, connect_engine.get()));
238  BOOST_CHECK_EQUAL( side_engine->flg().choosable_leaders().size(), 1 );
239  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "Shadow" );
240  BOOST_CHECK_EQUAL( side_engine->new_config()["type"], "Shadow" );
241 }
242 
243 BOOST_AUTO_TEST_CASE( flg_map_settings10 )
244 {
245  // Set up side_engine and its dependencies.
246  state->mp_settings().use_map_settings = true;
247  state->mp_settings().saved_game = saved_game_mode::type::no;
248  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
249  ng::side_engine_ptr side_engine;
250  config side;
251 
252  // Invalid leader unit.
253  side.clear();
254  side["type"] = "ThisUnitDoesNotExist";
255  side_engine.reset(create_side_engine(side, connect_engine.get()));
256  BOOST_CHECK_EQUAL( side_engine->flg().choosable_leaders().size(), 1 );
257  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "null" );
258 }
259 
260 BOOST_AUTO_TEST_CASE( flg_map_settings11 )
261 {
262  // Set up side_engine and its dependencies.
263  state->mp_settings().use_map_settings = true;
264  state->mp_settings().saved_game = saved_game_mode::type::no;
265  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
266  ng::side_engine_ptr side_engine;
267  config side;
268 
269  // No leader, Custom faction.
270  side.clear();
271  side["faction"] = "Custom";
272  side_engine.reset(create_side_engine(side, connect_engine.get()));
273  BOOST_CHECK( side_engine->flg().choosable_leaders().size() > 1 );
274  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "random" );
275 }
276 
277 BOOST_AUTO_TEST_CASE( flg_map_settings12 )
278 {
279  // Set up side_engine and its dependencies.
280  state->mp_settings().use_map_settings = true;
281  state->mp_settings().saved_game = saved_game_mode::type::no;
282  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
283  ng::side_engine_ptr side_engine;
284  config side;
285 
286  // No leader, Random faction.
287  side.clear();
288  side["faction"] = "Random";
289  side_engine.reset(create_side_engine(side, connect_engine.get()));
290  BOOST_CHECK_EQUAL( side_engine->flg().choosable_leaders().size(), 1 );
291  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "null" );
292 }
293 
294 BOOST_AUTO_TEST_CASE( flg_map_settings13 )
295 {
296  // Set up side_engine and its dependencies.
297  state->mp_settings().use_map_settings = true;
298  state->mp_settings().saved_game = saved_game_mode::type::no;
299  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
300  ng::side_engine_ptr side_engine;
301  config side;
302 
303 
304 }
305 
306 BOOST_AUTO_TEST_CASE( flg_map_settings14 )
307 {
308  // Set up side_engine and its dependencies.
309  state->mp_settings().use_map_settings = true;
310  state->mp_settings().saved_game = saved_game_mode::type::no;
311  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
312  ng::side_engine_ptr side_engine;
313  config side;
314 
315  // No leader, regular faction.
316  side.clear();
317  side["faction"] = "Undead";
318  side_engine.reset(create_side_engine(side, connect_engine.get()));
319  BOOST_CHECK( side_engine->flg().choosable_leaders().size() > 1 );
320  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "random" );
321 }
322 
323 BOOST_AUTO_TEST_CASE( flg_map_settings15 )
324 {
325  // Set up side_engine and its dependencies.
326  state->mp_settings().use_map_settings = true;
327  state->mp_settings().saved_game = saved_game_mode::type::no;
328  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
329  ng::side_engine_ptr side_engine;
330  config side;
331 
332  // Carried over leader.
333  side.clear();
334  side["id"] = "LeaderID";
335  side["type"] = "Elvish Archer";
336  config& unit = side.add_child("unit");
337  unit["id"] = "LeaderID";
338  unit["type"] = "Elvish Ranger";
339  side_engine.reset(create_side_engine(side, connect_engine.get()));
340  BOOST_CHECK_EQUAL( side_engine->flg().choosable_leaders().size(), 1 );
341  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "Elvish Ranger" );
342 }
343 
344 BOOST_AUTO_TEST_CASE( flg_map_settings16 )
345 {
346  // Set up side_engine and its dependencies.
347  state->mp_settings().use_map_settings = true;
348  state->mp_settings().saved_game = saved_game_mode::type::no;
349  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
350  ng::side_engine_ptr side_engine;
351  config side;
352 
353 
354 }
355 
356 BOOST_AUTO_TEST_CASE( flg_map_settings17 )
357 {
358  // Set up side_engine and its dependencies.
359  state->mp_settings().use_map_settings = true;
360  state->mp_settings().saved_game = saved_game_mode::type::no;
361  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
362  ng::side_engine_ptr side_engine;
363  config side;
364 
365  // Random leader.
366  side.clear();
367  side["type"] = "random";
368  side_engine.reset(create_side_engine(side, connect_engine.get()));
369  BOOST_CHECK_EQUAL( side_engine->flg().choosable_leaders().size(), 1 );
370 }
371 
372 BOOST_AUTO_TEST_CASE( flg_map_settings18 )
373 {
374  // Set up side_engine and its dependencies.
375  state->mp_settings().use_map_settings = true;
376  state->mp_settings().saved_game = saved_game_mode::type::no;
377  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
378  ng::side_engine_ptr side_engine;
379  config side;
380 
381  // Leader with both genders.
382  side.clear();
383  side["type"] = "Elvish Archer";
384  side_engine.reset(create_side_engine(side, connect_engine.get()));
385  BOOST_CHECK_EQUAL( side_engine->flg().choosable_genders().size(), 3 );
386  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "random" );
387 }
388 
389 BOOST_AUTO_TEST_CASE( flg_map_settings19 )
390 {
391  // Set up side_engine and its dependencies.
392  state->mp_settings().use_map_settings = true;
393  state->mp_settings().saved_game = saved_game_mode::type::no;
394  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
395  ng::side_engine_ptr side_engine;
396  config side;
397 
398  // Leader with only male gender.
399  side.clear();
400  side["type"] = "Swordsman";
401  side_engine.reset(create_side_engine(side, connect_engine.get()));
402  BOOST_CHECK_EQUAL( side_engine->flg().choosable_genders().size(), 1 );
403  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "male" );
404 }
405 
406 BOOST_AUTO_TEST_CASE( flg_map_settings20 )
407 {
408  // Set up side_engine and its dependencies.
409  state->mp_settings().use_map_settings = true;
410  state->mp_settings().saved_game = saved_game_mode::type::no;
411  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
412  ng::side_engine_ptr side_engine;
413  config side;
414 
415  // Leader with only female gender.
416  side.clear();
417  side["type"] = "Elvish Druid";
418  side_engine.reset(create_side_engine(side, connect_engine.get()));
419  BOOST_CHECK_EQUAL( side_engine->flg().choosable_genders().size(), 1 );
420  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "female" );
421 }
422 
423 BOOST_AUTO_TEST_CASE( flg_map_settings21 )
424 {
425  // Set up side_engine and its dependencies.
426  state->mp_settings().use_map_settings = true;
427  state->mp_settings().saved_game = saved_game_mode::type::no;
428  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
429  ng::side_engine_ptr side_engine;
430  config side;
431 
432  // Valid leader with valid gender.
433  side.clear();
434  side["type"] = "White Mage";
435  side["gender"] = "female";
436  side_engine.reset(create_side_engine(side, connect_engine.get()));
437  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "female" );
438 }
439 
440 BOOST_AUTO_TEST_CASE( flg_map_settings22 )
441 {
442  // Set up side_engine and its dependencies.
443  state->mp_settings().use_map_settings = true;
444  state->mp_settings().saved_game = saved_game_mode::type::no;
445  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
446  ng::side_engine_ptr side_engine;
447  config side;
448 
449  // Valid leader with invalid gender.
450  side.clear();
451  side["type"] = "Troll";
452  side["gender"] = "female";
453  side_engine.reset(create_side_engine(side, connect_engine.get()));
454  BOOST_CHECK_EQUAL( side_engine->flg().choosable_genders().size(), 1 );
455  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "male" );
456 }
457 
458 BOOST_AUTO_TEST_CASE( flg_map_settings23 )
459 {
460  // Set up side_engine and its dependencies.
461  state->mp_settings().use_map_settings = true;
462  state->mp_settings().saved_game = saved_game_mode::type::no;
463  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
464  ng::side_engine_ptr side_engine;
465  config side;
466 
467  // Leader with random gender.
468  side.clear();
469  side["type"] = "White Mage";
470  side["gender"] = "random";
471  side_engine.reset(create_side_engine(side, connect_engine.get()));
472  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "random" );
473 }
474 
475 BOOST_AUTO_TEST_CASE( flg_map_settings24 )
476 {
477  // Set up side_engine and its dependencies.
478  state->mp_settings().use_map_settings = true;
479  state->mp_settings().saved_game = saved_game_mode::type::no;
480  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
481  ng::side_engine_ptr side_engine;
482  config side;
483 
484 
485 }
486 
487 BOOST_AUTO_TEST_CASE( flg_map_settings25 )
488 {
489  // Set up side_engine and its dependencies.
490  state->mp_settings().use_map_settings = true;
491  state->mp_settings().saved_game = saved_game_mode::type::no;
492  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
493  ng::side_engine_ptr side_engine;
494  config side;
495 
496  // No leader.
497  side.clear();
498  side["leader_lock"] = true;
499  side_engine.reset(create_side_engine(side, connect_engine.get()));
500  BOOST_CHECK_EQUAL( side_engine->flg().choosable_leaders().size(), 1 );
501  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "null" );
502 }
503 
504 BOOST_AUTO_TEST_CASE( flg_map_settings26 )
505 {
506  // Set up side_engine and its dependencies.
507  state->mp_settings().use_map_settings = true;
508  state->mp_settings().saved_game = saved_game_mode::type::no;
509  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
510  ng::side_engine_ptr side_engine;
511  config side;
512 
513  // Resolve random faction.
514  side.clear();
515  side["faction"] = "Random";
516  side_engine.reset(create_side_engine(side, connect_engine.get()));
517  side_engine->resolve_random(*rng);
518  BOOST_CHECK( side_engine->flg().current_faction()["id"] != "Random" );
519  BOOST_CHECK( side_engine->flg().current_leader() != "random" && side_engine->flg().current_leader() != "null");
520  BOOST_CHECK( side_engine->flg().current_gender() != "random" && side_engine->flg().current_gender() != "null");
521 }
522 
523 BOOST_AUTO_TEST_CASE( flg_map_settings27 )
524 {
525  // Set up side_engine and its dependencies.
526  state->mp_settings().use_map_settings = true;
527  state->mp_settings().saved_game = saved_game_mode::type::no;
528  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
529  ng::side_engine_ptr side_engine;
530  config side;
531 
532  // Resolve random faction with default leader.
533  side.clear();
534  side["faction"] = "Random";
535  side["type"] = "Troll";
536  side_engine.reset(create_side_engine(side, connect_engine.get()));
537  side_engine->resolve_random(*rng);
538  BOOST_CHECK( side_engine->flg().current_faction()["id"] != "Random" );
539  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "Troll" );
540  BOOST_CHECK( side_engine->flg().current_gender() != "random" && side_engine->flg().current_gender() != "null" );
541 }
542 
543 BOOST_AUTO_TEST_CASE( flg_map_settings28 )
544 {
545  // Set up side_engine and its dependencies.
546  state->mp_settings().use_map_settings = true;
547  state->mp_settings().saved_game = saved_game_mode::type::no;
548  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
549  ng::side_engine_ptr side_engine;
550  config side;
551 
552  // Resolve random faction with default leader and gender.
553  side.clear();
554  side["faction"] = "Random";
555  side["type"] = "White Mage";
556  side["gender"] = "male";
557  side_engine.reset(create_side_engine(side, connect_engine.get()));
558  side_engine->resolve_random(*rng);
559  BOOST_CHECK( side_engine->flg().current_faction()["id"] != "Random" );
560  BOOST_CHECK_EQUAL( side_engine->flg().current_leader(), "White Mage" );
561  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "male" );
562 }
563 
564 BOOST_AUTO_TEST_CASE( flg_map_settings29 )
565 {
566  // Set up side_engine and its dependencies.
567  state->mp_settings().use_map_settings = true;
568  state->mp_settings().saved_game = saved_game_mode::type::no;
569  std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
570  ng::side_engine_ptr side_engine;
571  config side;
572 
573  // Resolve random leader.
574  side.clear();
575  side["type"] = "random";
576  side_engine.reset(create_side_engine(side, connect_engine.get()));
577  side_engine->resolve_random(*rng);
578  BOOST_CHECK( side_engine->flg().current_leader() != "random" );
579 }
580 
581 
582 
583 
584 
585 BOOST_AUTO_TEST_CASE( flg_no_map_settings1 )
586 {
587  // Set up side_engine and its dependencies.
588  state->mp_settings().use_map_settings = false;
589  state->mp_settings().saved_game = saved_game_mode::type::no;
590  const std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
591  ng::side_engine_ptr side_engine;
592  config side;
593 
594  // Recruit list with no faction.
595  side.clear();
596  side["recruit"] = "Elvish Archer";
597  side_engine.reset(create_side_engine(side, connect_engine.get()));
598  BOOST_CHECK( side_engine->flg().choosable_factions().size() > 1 );
599 }
600 
601 BOOST_AUTO_TEST_CASE( flg_no_map_settings2 )
602 {
603  // Set up side_engine and its dependencies.
604  state->mp_settings().use_map_settings = false;
605  state->mp_settings().saved_game = saved_game_mode::type::no;
606  const std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
607  ng::side_engine_ptr side_engine;
608  config side;
609 
610  // Custom faction, no recruits.
611  side.clear();
612  side["faction"] = "Custom";
613  side_engine.reset(create_side_engine(side, connect_engine.get()));
614  BOOST_CHECK( side_engine->flg().choosable_factions().size() > 1 );
615  BOOST_CHECK_EQUAL( side_engine->flg().current_faction()["id"], "Custom" );
616  BOOST_CHECK_EQUAL( side_engine->new_config()["recruit"].empty(), true );
617 }
618 
619 BOOST_AUTO_TEST_CASE( flg_no_map_settings3 )
620 {
621  // Set up side_engine and its dependencies.
622  state->mp_settings().use_map_settings = false;
623  state->mp_settings().saved_game = saved_game_mode::type::no;
624  const std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
625  ng::side_engine_ptr side_engine;
626  config side;
627 
628  // Carried over recruits.
629  side.clear();
630  side["previous_recruits"] = "Elvish Archer";
631  side_engine.reset(create_side_engine(side, connect_engine.get()));
632  BOOST_CHECK( side_engine->flg().choosable_factions().size() > 1 );
633  BOOST_CHECK_EQUAL( side_engine->new_config()["previous_recruits"], "Elvish Archer" );
634 }
635 
636 BOOST_AUTO_TEST_CASE( flg_no_map_settings4 )
637 {
638  // Set up side_engine and its dependencies.
639  state->mp_settings().use_map_settings = false;
640  state->mp_settings().saved_game = saved_game_mode::type::no;
641  const std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
642  ng::side_engine_ptr side_engine;
643  config side;
644 
645  // Explicit leader for faction with multiple leaders.
646  side.clear();
647  side["type"] = "Goblin Impaler";
648  side_engine.reset(create_side_engine(side, connect_engine.get()));
649  side_engine->flg().set_current_faction("Rebels");
650  BOOST_CHECK( side_engine->flg().choosable_leaders().size() > 1 );
651 }
652 
653 BOOST_AUTO_TEST_CASE( flg_no_map_settings5 )
654 {
655  // Set up side_engine and its dependencies.
656  state->mp_settings().use_map_settings = false;
657  state->mp_settings().saved_game = saved_game_mode::type::no;
658  const std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
659  ng::side_engine_ptr side_engine;
660  config side;
661 
662  // Duplicate leaders.
663  side.clear();
664  side["faction"] = "Custom";
665  side["type"] = "Swordsman";
666  side_engine.reset(create_side_engine(side, connect_engine.get()));
667  BOOST_CHECK( side_engine->flg().choosable_leaders().size() > 1 );
668  const std::vector<std::string>& leaders = side_engine->flg().choosable_leaders();
669  BOOST_CHECK_EQUAL( std::count(leaders.begin(), leaders.end(), "Swordsman"), 1 );
670 }
671 
672 BOOST_AUTO_TEST_CASE( flg_no_map_settings6 )
673 {
674  // Set up side_engine and its dependencies.
675  state->mp_settings().use_map_settings = false;
676  state->mp_settings().saved_game = saved_game_mode::type::no;
677  const std::unique_ptr<test_connect_engine> connect_engine(create_test_connect_engine());
678  ng::side_engine_ptr side_engine;
679  config side;
680 
681  // Explicit gender for unit with both genders available.
682  side.clear();
683  side["gender"] = "female";
684  side_engine.reset(create_side_engine(side, connect_engine.get()));
685  side_engine->flg().set_current_faction("Rebels");
686  side_engine->flg().set_current_leader("Elvish Ranger");
687  BOOST_CHECK_EQUAL( side_engine->flg().current_gender(), "random" );
688 }
689 
690 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
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:203
void remove_attributes(T... keys)
Definition: config.hpp:551
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
Definition: config.cpp:366
void clear_children(T... keys)
Definition: config.hpp:616
void clear()
Definition: config.cpp:828
const attribute_value * get(config_key_type key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
Definition: config.cpp:685
config & add_child(config_key_type key)
Definition: config.cpp:440
@ NO_FORCE_RELOAD
Don't reload if the previous defines equal the new defines.
this class is initialized once at game start put all initialization and wipe code in the methods here...
connect_engine(saved_game &state, const bool first_scenario, mp_game_metadata *metadata)
test_connect_engine(saved_game &gamestate)
This class represents a single unit of a specific type.
Definition: unit.hpp:133
std::shared_ptr< side_engine > side_engine_ptr
game_display & get_fake_display(const int width, const int height)
Gets a fake test display.
std::vector< std::string > dummy_args
hotkey::manager hotkey_manager
commandline_options cmdline_opts
std::unique_ptr< game_config_manager > config_manager
BOOST_FIXTURE_TEST_SUITE(test_map_location, MLFixture)
static ng::side_engine * create_side_engine(const config &defaults, test_connect_engine *connect_engine)
static test_connect_engine * create_test_connect_engine()
BOOST_AUTO_TEST_CASE(flg_map_settings2)