The Battle for Wesnoth  1.15.0+dev
test_version.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Iris Morelle <shadowm2006@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 #define GETTEXT_DOMAIN "wesnoth-test"
16 
17 #include <boost/test/unit_test.hpp>
18 #include "game_version.hpp"
19 
20 BOOST_AUTO_TEST_SUITE( version )
21 
22 BOOST_AUTO_TEST_CASE( test_version_info )
23 {
24  version_info empty;
25 
26  BOOST_CHECK( empty == version_info(0, 0, 0) );
27  BOOST_CHECK( empty.str() == "0.0.0" );
28 
29  version_info dots1("........");
30  version_info dots2("...hullo");
31 
32  BOOST_CHECK( dots1 == empty);
33  BOOST_CHECK( dots2.str() == "0.0.0hullo" );
34 
35  version_info canonical("1.2.3");
36 
37  BOOST_CHECK( canonical.is_canonical() );
38 
39  version_info canonical_suffixed("1.2.3+dev");
40 
41  BOOST_CHECK( canonical_suffixed > canonical );
42  BOOST_CHECK( canonical < canonical_suffixed );
43 
44  version_info non_canonical("1.2.3.4.5.7.8.9");
45 
46  BOOST_CHECK( !non_canonical.is_canonical() );
47 
48  version_info non_canonical_suffixed("1.2.3.4.5.7.8.9+dev");
49 
50  BOOST_CHECK( non_canonical_suffixed > non_canonical );
51  BOOST_CHECK( non_canonical < non_canonical_suffixed );
52 
53  version_info right_zero("1.2.0");
54  version_info no_right_zero("1.2");
55 
56  BOOST_CHECK( right_zero == no_right_zero );
57 
58  version_info left_zero("0.1.4");
59  version_info no_left_zero("1.4");
60 
61  BOOST_CHECK( left_zero != no_left_zero );
62 
63  const std::string bad_version_info_string_1 = "Viva la revoluciĆ³n!";
64  const std::string bad_version_info_string_2 = "To infinity and beyond!";
65 
66  const version_info bad_version_info1( bad_version_info_string_1 );
67  const version_info bad_version_info2( bad_version_info_string_2 );
68 
69  BOOST_CHECK( bad_version_info1.str() == ("0.0.0"+bad_version_info_string_1) );
70  BOOST_CHECK( bad_version_info2.str() == ("0.0.0"+bad_version_info_string_2) );
71 
72  version_info somewhat_complex("1.5.10-1.6beta2");
73  BOOST_CHECK( somewhat_complex.major_version() == 1 && somewhat_complex.minor_version() == 5 && somewhat_complex.revision_level() == 10 && somewhat_complex.special_version() == "1.6beta2" && somewhat_complex.special_version_separator() == '-' );
74 }
75 
76 BOOST_AUTO_TEST_SUITE_END()
char special_version_separator() const
Retrieves the special version separator (e.g.
BOOST_AUTO_TEST_CASE(test_version_info)
Interfaces for manipulating version numbers of engine, add-ons, etc.
unsigned int revision_level() const
Retrieves the revision level (x3 in "x1.x2.x3").
const std::string & special_version() const
Retrieves the special version suffix (e.g.
unsigned int major_version() const
Retrieves the major version number (x1 in "x1.x2.x3").
unsigned int minor_version() const
Retrieves the minor version number (x2 in "x1.x2.x3").
bool is_canonical() const
Whether the version number is considered canonical for mainline Wesnoth.
Represents version numbers.
std::string str() const
Serializes the version number into string form.