add config attribute value tests, put them in project files also.

This commit is contained in:
Chris Beck 2014-05-22 22:59:47 -04:00
parent 49f97ee9be
commit 7cd205832f
5 changed files with 364 additions and 42 deletions

View file

@ -3374,25 +3374,27 @@
<File Name="../../src/tests/utils/predicate.hpp"/>
<File Name="../../src/tests/utils/play_scenario.cpp"/>
</VirtualDirectory>
<File Name="../../src/tests/test_version.cpp"/>
<File Name="../../src/tests/test_sdl_utils.hpp"/>
<File Name="../../src/tests/floating_point_emulation.cpp"/>
<File Name="../../src/tests/test_addons.cpp"/>
<File Name="../../src/tests/test_commandline_options.cpp"/>
<File Name="../../src/tests/test_formula_function.cpp"/>
<File Name="../../src/tests/test_formula_ai.cpp"/>
<File Name="../../src/tests/test_image_modifications.cpp"/>
<File Name="../../src/tests/test_addons.cpp"/>
<File Name="../../src/tests/test_sdl_utils.cpp"/>
<File Name="../../src/tests/create_images.cpp"/>
<File Name="../../src/tests/test_whiteboard_side_actions.cpp"/>
<File Name="../../src/tests/test_network_worker.cpp"/>
<File Name="../../src/tests/test_unit_map.cpp"/>
<File Name="../../src/tests/main.cpp"/>
<File Name="../../src/tests/floating_point_emulation.cpp"/>
<File Name="../../src/tests/test_serialization.cpp"/>
<File Name="../../src/tests/test_config.cpp"/>
<File Name="../../src/tests/test_config_cache.cpp"/>
<File Name="../../src/tests/test_team.cpp"/>
<File Name="../../src/tests/test_util.cpp"/>
<File Name="../../src/tests/test_lexical_cast.cpp"/>
<File Name="../../src/tests/map_location.cpp"/>
<File Name="../../src/tests/test_mp_connect.cpp"/>
<File Name="../../src/tests/test_network_worker.cpp"/>
<File Name="../../src/tests/test_sdl_utils.hpp"/>
<File Name="../../src/tests/test_sdl_utils.cpp"/>
<File Name="../../src/tests/test_serialization.cpp"/>
<File Name="../../src/tests/test_team.cpp"/>
<File Name="../../src/tests/test_unit_map.cpp"/>
<File Name="../../src/tests/test_util.cpp"/>
<File Name="../../src/tests/test_version.cpp"/>
<File Name="../../src/tests/test_whiteboard_side_actions.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="ai">
<VirtualDirectory Name="testing">

View file

@ -16219,6 +16219,62 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\tests\test_config.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_with_VLD|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDEBUG|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\tests\test_config_cache.cpp"
>
@ -16499,6 +16555,118 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\tests\test_map_location.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_with_VLD|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDEBUG|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\tests\test_mp_connect.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_with_VLD|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="Test_Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDEBUG|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Tests\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\tests\test_network_worker.cpp"
>

View file

@ -1241,34 +1241,35 @@ if(ENABLE_TESTS)
set(test_SRC
tests/floating_point_emulation.cpp
tests/gui/iterator.cpp
tests/gui/fire_event.cpp
tests/gui/test_drop_target.cpp
tests/gui/test_gui2.cpp
tests/gui/test_save_dialog.cpp
tests/gui/visitor.cpp
tests/main.cpp
tests/utils/fake_display.cpp
tests/utils/fake_event_source.cpp
tests/utils/game_config_manager.cpp
tests/utils/play_scenario.cpp
tests/test_addons.cpp
tests/test_commandline_options.cpp
tests/test_config.cpp
tests/test_config_cache.cpp
tests/test_formula_ai.cpp
tests/test_formula_function.cpp
tests/test_image_modifications.cpp
tests/test_lexical_cast.cpp
tests/test_network_worker.cpp
tests/test_map_location.cpp
tests/test_mp_connect.cpp
tests/test_network_worker.cpp
tests/test_sdl_utils.cpp
tests/test_serialization.cpp
tests/test_team.cpp
tests/test_unit_map.cpp
tests/test_util.cpp
tests/test_sdl_utils.cpp
tests/test_serialization.cpp
tests/test_version.cpp
tests/test_whiteboard_side_actions.cpp
tests/gui/iterator.cpp
tests/gui/fire_event.cpp
tests/gui/test_drop_target.cpp
tests/gui/test_gui2.cpp
tests/gui/visitor.cpp
tests/gui/test_save_dialog.cpp
tests/utils/fake_display.cpp
tests/utils/fake_event_source.cpp
tests/utils/game_config_manager.cpp
tests/utils/play_scenario.cpp
)
if(ENABLE_GAME)
set(test_LIB

View file

@ -648,29 +648,30 @@ libtest_utils = test_env.Library("test_utils", test_utils_sources)
test_sources = Split("""
tests/floating_point_emulation.cpp
tests/main.cpp
tests/test_addons.cpp
tests/test_commandline_options.cpp
tests/test_formula_ai.cpp
tests/test_formula_function.cpp
tests/test_image_modifications.cpp
tests/test_lexical_cast.cpp
tests/test_network_worker.cpp
tests/test_map_location.cpp
tests/test_mp_connect.cpp
tests/test_team.cpp
tests/test_unit_map.cpp
tests/test_util.cpp
tests/test_sdl_utils.cpp
tests/test_serialization.cpp
tests/test_version.cpp
tests/test_whiteboard_side_actions.cpp
tests/gui/fire_event.cpp
tests/gui/iterator.cpp
tests/gui/test_drop_target.cpp
tests/gui/test_gui2.cpp
tests/gui/test_save_dialog.cpp
tests/gui/visitor.cpp
tests/main.cpp
tests/test_addons.cpp
tests/test_commandline_options.cpp
tests/test_config.cpp
tests/test_formula_ai.cpp
tests/test_formula_function.cpp
tests/test_image_modifications.cpp
tests/test_lexical_cast.cpp
tests/test_map_location.cpp
tests/test_mp_connect.cpp
tests/test_network_worker.cpp
tests/test_sdl_utils.cpp
tests/test_serialization.cpp
tests/test_team.cpp
tests/test_unit_map.cpp
tests/test_util.cpp
tests/test_version.cpp
tests/test_whiteboard_side_actions.cpp
tests/utils/play_scenario.cpp
""")
test_sources.extend(test_env.Object("tests/test_config_cache.cpp"))

150
src/tests/test_config.cpp Normal file
View file

@ -0,0 +1,150 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-test"
#include <boost/test/unit_test.hpp>
#include "config.hpp"
BOOST_AUTO_TEST_SUITE ( test_config )
BOOST_AUTO_TEST_CASE ( test_config_attribute_value )
{
config c;
int x_int;
std::string x_str;
long long x_sll;
double x_dbl;
c["x"] = 1;
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "1");
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 1);
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 1ll);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 1.0);
c["x"] = 10000000;
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 10000000);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "10000000");
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 10000000ll);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 1e7);
c["x"] = "";
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 0ll);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "");
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 0);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 0.0);
c["x"] = "0x11";
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 0);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "0x11");
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 0ll);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 0.0);
c["x"] = "0xab";
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 0);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "0xab");
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 0ll);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 0.0);
c["x"] = "00001111";
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 1111);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "00001111");
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 1111ll);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 1.111e3);
c["x"] = "000000";
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 0);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str,"000000");
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 0ll);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 0.0);
c["x"] = "01234567890123456789";
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll,1234567890123456789ll);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str,"01234567890123456789");
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 0);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 1.23456789012345678e18);
c["x"] = "99999999999999999999";
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 0ll);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "99999999999999999999");
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 0);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 0);
c["x"] = 1.499;
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 1ll);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "1.499");
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, 1);
x_dbl = c["x"].to_long_long();
BOOST_CHECK(abs(x_dbl - 1.499) < 1e-6);
c["x"] = 123456789123ll;
x_int = c["x"].to_int();
BOOST_CHECK_EQUAL(x_int, -1097262461);
x_dbl = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_dbl, 1.23456789123e11);
x_sll = c["x"].to_long_long();
BOOST_CHECK_EQUAL(x_sll, 123456789123ll);
x_str = c["x"].str();
BOOST_CHECK_EQUAL(x_str, "123456789123");
}
BOOST_AUTO_TEST_SUITE_END()