forked from JACoders/OpenJK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional Boost.Test unit tests (default off).
These already paid off, the previously fixed sscanf issues were found this way. Also includes natvis file for VS Debugger pretty printing
- Loading branch information
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This file tells the Visual Studio Debugger how to display types. --> | ||
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> | ||
<Type Name="gsl::array_view<*>"> | ||
<DisplayString>{{ {begin_,[end_ - begin_]} }}</DisplayString> | ||
<Expand> | ||
<ArrayItems> | ||
<Size>end_ - begin_</Size> | ||
<ValuePointer>begin_</ValuePointer> | ||
</ArrayItems> | ||
</Expand> | ||
</Type> | ||
</AutoVisualizer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#============================================================================ | ||
# Copyright (C) 2013 - 2015, OpenJK contributors | ||
# | ||
# This file is part of the OpenJK source code. | ||
# | ||
# OpenJK is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License version 2 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
#============================================================================ | ||
|
||
# Make sure the user is not executing this script directly | ||
if(NOT InOpenJK) | ||
message(FATAL_ERROR "Use the top-level cmake script!") | ||
endif(NOT InOpenJK) | ||
|
||
set(TestFiles | ||
"main.cpp" | ||
"safe/string.cpp" | ||
"${SharedDir}/qcommon/safe/string.cpp" | ||
) | ||
if(MSVC) | ||
set(TestFiles | ||
${TestFiles} | ||
"${SharedDir}/openjk.natvis" | ||
) | ||
endif() | ||
source_group( "tests" REGULAR_EXPRESSION ".*") | ||
source_group( "tests\\safe" REGULAR_EXPRESSION "safe/.*" ) | ||
source_group( "qcommon\\safe" REGULAR_EXPRESSION "${SharedDir}/qcommon/safe/.*" ) | ||
|
||
set( Boost_USE_STATIC_LIBS ON ) | ||
find_package( Boost COMPONENTS unit_test_framework REQUIRED ) | ||
|
||
set(TestTarget "UnitTests") | ||
set(TestLibraries "${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}") | ||
set(TestIncludeDirectories | ||
"${Boost_INCLUDE_DIRS}" | ||
"${SharedDir}" | ||
"${GSLIncludeDirectory}" | ||
) | ||
set(TestDefines "${SharedDefines}") | ||
|
||
|
||
add_executable(${TestTarget} ${TestFiles}) | ||
set_target_properties(${TestTarget} PROPERTIES COMPILE_DEFINITIONS "${TestDefines}") | ||
set_target_properties(${TestTarget} PROPERTIES INCLUDE_DIRECTORIES "${TestIncludeDirectories}") | ||
set_target_properties(${TestTarget} PROPERTIES PROJECT_LABEL "Unit Tests") | ||
target_link_libraries(${TestTarget} ${TestLibraries}) | ||
install(TARGETS ${TestTarget} DESTINATION ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// create default module initialization | ||
#define BOOST_TEST_MODULE OpenJK | ||
#include <boost/test/unit_test.hpp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "qcommon/safe/string.h" | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
// verifying that the compiler implements the standard correctly | ||
|
||
BOOST_AUTO_TEST_SUITE( safe ) | ||
|
||
BOOST_AUTO_TEST_SUITE( string ) | ||
|
||
BOOST_AUTO_TEST_CASE( literals ) | ||
{ | ||
auto test = CSTRING_VIEW( "test" ); | ||
auto foo = CSTRING_VIEW( "foo" ); | ||
|
||
BOOST_CHECK_EQUAL( test, CSTRING_VIEW( "test" ) ); | ||
BOOST_CHECK_EQUAL( test.size(), 4 ); | ||
|
||
BOOST_CHECK_EQUAL( foo, CSTRING_VIEW( "foo" ) ); | ||
BOOST_CHECK_EQUAL( foo.size(), 3 ); | ||
BOOST_CHECK_NE( test, foo ); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE( stricmp ) | ||
{ | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "hello" ), CSTRING_VIEW( "HELLO" ) ), Q::Ordering::EQ ); | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "aaa" ), CSTRING_VIEW( "aab" ) ), Q::Ordering::LT ); | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "aab" ), CSTRING_VIEW( "aaa" ) ), Q::Ordering::GT ); | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "AAA" ), CSTRING_VIEW( "aab" ) ), Q::Ordering::LT ); | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "AAA" ), CSTRING_VIEW( "aab" ) ), Q::Ordering::LT ); | ||
// prefix is smaller | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "hello" ), CSTRING_VIEW( "hello world" ) ), Q::Ordering::LT ); | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "hello world" ), CSTRING_VIEW( "hello" ) ), Q::Ordering::GT ); | ||
// edge case: empty strings | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "" ), CSTRING_VIEW( "" ) ), Q::Ordering::EQ ); | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "" ), CSTRING_VIEW( "a" ) ), Q::Ordering::LT ); | ||
BOOST_CHECK_EQUAL( Q::stricmp( CSTRING_VIEW( "a" ), CSTRING_VIEW( "" ) ), Q::Ordering::GT ); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE( svtoi ) | ||
{ | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "" ) ), 0 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "asdf" ) ), 0 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "0" ) ), 0 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "1" ) ), 1 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "+1" ) ), 1 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "-1" ) ), -1 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "13foo" ) ), 13 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( " 13" ) ), 13 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "13 27" ) ), 13 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "12345" ) ), 12345 ); | ||
BOOST_CHECK_EQUAL( Q::svtoi( CSTRING_VIEW( "-12345" ) ), -12345 ); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE( sscanf ) | ||
{ | ||
{ | ||
float x = -1, y = -1, z = -1; | ||
BOOST_CHECK_EQUAL( Q::sscanf( CSTRING_VIEW( " 42 13.37" ), x, y, z ), 2 ); | ||
BOOST_CHECK_EQUAL( x, 42.f ); | ||
BOOST_CHECK_CLOSE_FRACTION( y, 13.37f, 0.1f ); // within 0.1% of each other | ||
BOOST_CHECK_EQUAL( z, -1 ); | ||
} | ||
// TODO String tests | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() // string | ||
|
||
BOOST_AUTO_TEST_SUITE_END() // safe |