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