Removed obsolete tests

This commit is contained in:
mathusummut 2018-11-02 18:17:26 +01:00
parent 8f942f4a74
commit 1ce342a70d
9 changed files with 0 additions and 1788 deletions

View File

@ -33,7 +33,6 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
ENDIF()
OPTION(BUILD_ZETAGLEST "Build ZetaGlest" ON)
OPTION(BUILD_ZETAGLEST_TESTS "Build ZetaGlest Unit Tests" OFF)
OPTION(WANT_STATIC_LIBS "Builds as many static libs as possible." OFF)
OPTION(WANT_USE_OpenSSL "Use libOpenSSL during CURL linking." ON)
OPTION(WANT_USE_FriBiDi "Enable libFriBIDi support." ON)
@ -274,8 +273,6 @@ IF(EXISTS "${PROJECT_SOURCE_DIR}/source/")
# MESSAGE(STATUS "WARNING... the following game tools will NOT be built since we cannot find wxWidgets on this machine")
# MESSAGE(STATUS "map editor, g3d viewer")
#endif()
ADD_SUBDIRECTORY( ${PROJECT_SOURCE_DIR}/source/tests )
ENDIF()
#

View File

@ -1,206 +0,0 @@
#########################################################################################
# zetaglest_tests
SET(EXTERNAL_LIBS "")
SET(TARGET_NAME "zetaglest_tests")
IF(BUILD_ZETAGLEST_TESTS)
MESSAGE(STATUS "Build ${TARGET_NAME} = YES")
# On Travis, the build fails on osx and Ubuntu trusty using
# clang 5.0 unless the -std=c++11 if used
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
INCLUDE (CheckIncludeFiles)
FIND_PACKAGE(CppUnit REQUIRED)
INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR})
IF(UNIX)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${CPPUNIT_LIBRARY})
ENDIF()
FIND_PACKAGE(${SDL_VERSION_NAME} REQUIRED)
INCLUDE_DIRECTORIES(${${SDL_VERSION_NAME}_INCLUDE_DIR})
IF(UNIX)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${${SDL_VERSION_NAME}_LIBRARY})
ENDIF()
if(WANT_USE_FriBiDi)
find_package( FriBiDi )
if(FRIBIDI_FOUND)
add_definitions(-DHAVE_FRIBIDI)
include_directories( ${FRIBIDI_INCLUDE_DIR} )
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${FRIBIDI_LIBRARIES})
else()
message("Could not find FriBiDi. Disabling FriBiDi support.")
endif()
endif()
find_package(PkgConfig REQUIRED)
IF(FORCE_STREFLOP_SOFTWRAPPER)
pkg_search_module(STREFLOP streflop-soft)
ELSE()
IF(HAS_SSE_EXTENSIONS AND NOT ${FORCE_MAX_SSE_LEVEL} MATCHES "0")
pkg_search_module(STREFLOP streflop-sse)
ELSE()
IF(HAS_X87_SUPPORT)
pkg_search_module(STREFLOP streflop-x87)
ELSE()
pkg_search_module(STREFLOP streflop-soft)
ENDIF()
ENDIF()
ENDIF()
IF(NOT STREFLOP_FOUND)
pkg_search_module(STREFLOP streflop)
ENDIF()
MESSAGE(STATUS "Search for Library STREFLOP result = ${STREFLOP_FOUND} libs: ${STREFLOP_LIBRARIES} include dirs: ${STREFLOP_INCLUDE_DIRS}")
IF(FORCE_EMBEDDED_LIBS)
SET(STREFLOP_FOUND OFF)
MESSAGE(STATUS "FORCING USE of EMBEDDED Libraries...")
ENDIF()
IF(WANT_USE_STREFLOP)
IF(STREFLOP_FOUND)
INCLUDE_DIRECTORIES(${STREFLOP_INCLUDE_DIRS} ${STREFLOP_INCLUDE_DIRS}/streflop)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${STREFLOP_LIBRARIES})
ADD_DEFINITIONS("-DUSE_STREFLOP_PKG")
ENDIF()
ENDIF()
#########################################################################################
# zetaglest test code
SET(DIRS_WITH_SRC
./
shared_lib/graphics
shared_lib/util
shared_lib/xml)
IF(NOT STREFLOP_FOUND)
SET(DIRS_WITH_SRC
${DIRS_WITH_SRC}
shared_lib/streflop)
ENDIF()
SET(MG_INCLUDES_ROOT "./")
SET(MG_SOURCES_ROOT "./")
SET(ZG_INCLUDE_FILES "")
SET(ZG_SOURCE_FILES "")
SET(GLEST_LIB_INCLUDE_ROOT "../shared_lib/include/")
SET(GLEST_LIB_INCLUDE_DIRS
${GLEST_LIB_INCLUDE_ROOT}platform/common
${GLEST_LIB_INCLUDE_ROOT}platform/posix
${GLEST_LIB_INCLUDE_ROOT}util
${GLEST_LIB_INCLUDE_ROOT}graphics
${GLEST_LIB_INCLUDE_ROOT}graphics/gl
${GLEST_LIB_INCLUDE_ROOT}graphics/iqm
${GLEST_LIB_INCLUDE_ROOT}sound
${GLEST_LIB_INCLUDE_ROOT}sound/openal
${GLEST_LIB_INCLUDE_ROOT}xml
${GLEST_LIB_INCLUDE_ROOT}xml/rapidxml
${GLEST_LIB_INCLUDE_ROOT}glew
${GLEST_LIB_INCLUDE_ROOT}lua
${GLEST_LIB_INCLUDE_ROOT}map
${PROJECT_SOURCE_DIR}/source/glest_game/graphics
${PROJECT_SOURCE_DIR}/source/glest_game/world
${PROJECT_SOURCE_DIR}/source/glest_game/sound
${PROJECT_SOURCE_DIR}/source/glest_game/type_instances
${PROJECT_SOURCE_DIR}/source/glest_game/types
)
IF(WANT_USE_STREFLOP)
IF(NOT STREFLOP_FOUND)
SET(GLEST_LIB_INCLUDE_DIRS
${GLEST_LIB_INCLUDE_DIRS}
${GLEST_LIB_INCLUDE_ROOT}streflop
${GLEST_LIB_INCLUDE_ROOT}streflop/libm_flt32_source)
ENDIF()
ENDIF()
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_DIRS} )
IF(WIN32)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/posix)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32)
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/${SDL_VERSION_SNAME} )
ELSE()
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/${SDL_VERSION_SNAME} )
SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_DIRS} ${GLEST_LIB_INCLUDE_ROOT}platform/${SDL_VERSION_SNAME})
SET(GLEST_LIB_INCLUDE_DIRS ${GLEST_LIB_INCLUDE_DIRS} ${GLEST_LIB_INCLUDE_ROOT}platform/unix)
ENDIF()
FOREACH(DIR IN LISTS DIRS_WITH_SRC)
set(INCLUDE_DIR_TO_GLOB ${MG_INCLUDES_ROOT}${DIR})
INCLUDE_DIRECTORIES( ${INCLUDE_DIR_TO_GLOB} )
IF(APPLE)
#MESSAGE(STATUS "INCLUDE_DIR_TO_GLOB: ${INCLUDE_DIR_TO_GLOB}")
FILE(GLOB INC_FILES_FROM_THIS_DIR ${INCLUDE_DIR_TO_GLOB}/*.h)
#MESSAGE(STATUS "INCLUDE FILES GLOBBED: ${INC_FILES_FROM_THIS_DIR}")
SET(ZG_INCLUDE_FILES ${ZG_INCLUDE_FILES} ${INC_FILES_FROM_THIS_DIR})
ENDIF(APPLE)
set(SRC_DIR_TO_GLOB ${MG_SOURCES_ROOT}${DIR})
#MESSAGE(STATUS "SRC_DIR_TO_GLOB: ${SRC_DIR_TO_GLOB}")
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.cpp)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(ZG_SOURCE_FILES ${ZG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
set(SRC_DIR_TO_GLOB ${MG_SOURCES_ROOT}${DIR})
#MESSAGE(STATUS "SRC_DIR_TO_GLOB: ${SRC_DIR_TO_GLOB}")
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.c)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(ZG_SOURCE_FILES ${ZG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
IF(APPLE)
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.mm)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(ZG_SOURCE_FILES ${ZG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.m)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(ZG_SOURCE_FILES ${ZG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
ENDIF(APPLE)
ENDFOREACH(DIR)
#MESSAGE(STATUS "Source files: ${ZG_INCLUDE_FILES}")
#MESSAGE(STATUS "Source files: ${ZG_SOURCE_FILES}")
#MESSAGE(STATUS "Include dirs: ${INCLUDE_DIRECTORIES}")
IF(APPLE)
SET(PLATFORM_SPECIFIC_DEFINES "-DHAVE_SYS_IOCTL_H")
ELSEIF(WIN32)
SET(PLATFORM_SPECIFIC_DEFINES "-DX11_AVAILABLE")
ELSE()
SET(PLATFORM_SPECIFIC_DEFINES "-DX11_AVAILABLE -DHAVE_SYS_IOCTL_H")
ENDIF()
SET_SOURCE_FILES_PROPERTIES(${ZG_SOURCE_FILES} PROPERTIES COMPILE_FLAGS
"${PLATFORM_SPECIFIC_DEFINES} ${STREFLOP_PROPERTIES} ${CXXFLAGS}")
SET_SOURCE_FILES_PROPERTIES(${ZG_INCLUDE_FILES} PROPERTIES HEADER_FILE_ONLY 1)
MESSAGE(STATUS "EXTERNAL_LIBS = [${EXTERNAL_LIBS}]")
SET_SOURCE_FILES_PROPERTIES(${ZG_INCLUDE_FILES} PROPERTIES HEADER_FILE_ONLY 1)
ADD_EXECUTABLE(${TARGET_NAME} ${ZG_SOURCE_FILES} ${ZG_INCLUDE_FILES})
IF(NOT WIN32)
IF(WANT_USE_STREFLOP AND NOT STREFLOP_FOUND)
TARGET_LINK_LIBRARIES(${TARGET_NAME} ${MG_STREFLOP})
ENDIF()
TARGET_LINK_LIBRARIES(${TARGET_NAME} libzetaglest)
ENDIF()
TARGET_LINK_LIBRARIES(${TARGET_NAME} ${EXTERNAL_LIBS})
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}"
COMMENT "***-- Found ZetaGlest test runner: ${TARGET_NAME} about to run unit tests...")
ENDIF()

View File

@ -1,178 +0,0 @@
// ==============================================================
// This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
// Copyright (C) 2013 Mark Vejvoda
//
// You can redistribute this code 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
// ==============================================================
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include "font.h"
#include <vector>
#include <algorithm>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
using namespace Shared::Graphics;
//
// Tests for font class
//
class FontTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( FontTest );
CPPUNIT_TEST( test_LTR_RTL_Mixed );
CPPUNIT_TEST( test_bidi_newline_handling );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
public:
void test_bidi_newline_handling() {
string text = "\n\nHP: 9000/9000\nArmor: 0 (Stone)\nSight: 15\nProduce Slave";
string expected = text;
#ifdef HAVE_FRIBIDI
Font::bidi_cvt(text);
//printf("Expected: [%s] result[%s]\n",expected.c_str(),text.c_str());
CPPUNIT_ASSERT_EQUAL( expected,text );
#endif
}
void test_LTR_RTL_Mixed() {
Font::fontSupportMixedRightToLeft = true;
string IntroText1 = "מבוסס על \"award-winning classic Glest\"";
string expected = IntroText1;
CPPUNIT_ASSERT_EQUAL( 45,(int)IntroText1.size() );
#ifdef HAVE_FRIBIDI
IntroText1 = expected;
Font::bidi_cvt(IntroText1);
//CPPUNIT_ASSERT_EQUAL( 45,(int)IntroText1.size() );
CPPUNIT_ASSERT_EQUAL( string("לע ססובמ"),IntroText1.substr(0, 15) );
CPPUNIT_ASSERT_EQUAL( string("\"award-winning classic Glest\""),IntroText1.substr(16) );
#endif
string LuaDisableSecuritySandbox = "בטל אבטחת ארגז חול של Lua";
LuaDisableSecuritySandbox.insert(18,"\"");
LuaDisableSecuritySandbox.insert(34,"\"");
//printf("Result1: [%s]\n",LuaDisableSecuritySandbox.c_str());
string expected2 = LuaDisableSecuritySandbox;
CPPUNIT_ASSERT_EQUAL( 44,(int)LuaDisableSecuritySandbox.size() );
//printf("Result: [%s]\n",LuaDisableSecuritySandbox.c_str());
#ifdef HAVE_FRIBIDI
LuaDisableSecuritySandbox = expected2;
Font::bidi_cvt(LuaDisableSecuritySandbox);
CPPUNIT_ASSERT_EQUAL( 44,(int)LuaDisableSecuritySandbox.size() );
string expected_result = "לש לוח זגרא תחטבא לטב";
expected_result.insert(5,"\"");
expected_result.insert(21,"\"");
//printf("Test: expected [%s] actual [%s]\n",expected_result.c_str(),LuaDisableSecuritySandbox.substr(0,40).c_str());
CPPUNIT_ASSERT_EQUAL( expected_result,LuaDisableSecuritySandbox.substr(0,40) );
CPPUNIT_ASSERT_EQUAL( string("Lua"),LuaDisableSecuritySandbox.substr(41) );
#endif
string PrivacyPlease = "הפעל מצב פרטי\\n(הסתר מדינה, וכו)";
PrivacyPlease.insert(52,"\"");
string expected3 = PrivacyPlease;
//printf("Result: [%s]\n",PrivacyPlease.c_str());
CPPUNIT_ASSERT_EQUAL( 56,(int)PrivacyPlease.size() );
#ifdef HAVE_FRIBIDI
Font::bidi_cvt(PrivacyPlease);
CPPUNIT_ASSERT_EQUAL( 56,(int)PrivacyPlease.size() );
string expected_result3 = "יטרפ בצמ לעפה\\n(וכו ,הנידמ רתסה)";
expected_result3.insert(29,"\"");
//printf("Test: expected [%s] actual [%s]\n",expected_result3.c_str(),PrivacyPlease.c_str());
CPPUNIT_ASSERT_EQUAL( expected_result3,PrivacyPlease );
#endif
string FactionName_indian = "Indian (אינדיאנים)";
string expected4 = FactionName_indian;
//printf("Result: [%s]\n",PrivacyPlease.c_str());
CPPUNIT_ASSERT_EQUAL( 27,(int)FactionName_indian.size() );
#ifdef HAVE_FRIBIDI
Font::bidi_cvt(FactionName_indian);
CPPUNIT_ASSERT_EQUAL( 27,(int)FactionName_indian.size() );
string expected_result4 = "Indian (םינאידניא)";
//printf("Test: expected [%s] actual [%s]\n",expected_result3.c_str(),PrivacyPlease.c_str());
CPPUNIT_ASSERT_EQUAL( expected_result4,FactionName_indian );
#endif
string LanIP = "כתובות IP מקומי:192.168.0.150 ( 61357 / 61357 )";
string expected5 = LanIP;
//printf("LanIP [%s]\n",LanIP.c_str());
CPPUNIT_ASSERT_EQUAL( 58,(int)LanIP.size() );
#ifdef HAVE_FRIBIDI
Font::bidi_cvt(LanIP);
CPPUNIT_ASSERT_EQUAL( 58,(int)LanIP.size() );
string expected_result5 = "192.168.0.150:ימוקמ תובותכ IP ( 61357 / 61357 )";
CPPUNIT_ASSERT_EQUAL( expected_result5,LanIP );
#endif
string IntroText1_ar = "مبني على الحاصلة على جائزة Glest الكلاسيكية";
//printf("START IntroText1_ar [%s]\n",IntroText1_ar.c_str());
string expected6 = IntroText1_ar;
//printf("LanIP [%s]\n",LanIP.c_str());
CPPUNIT_ASSERT_EQUAL( 75,(int)IntroText1_ar.size() );
#ifdef HAVE_FRIBIDI
//printf("Before IntroText1_ar [%s]\n",IntroText1_ar.c_str());
Font::bidi_cvt(IntroText1_ar);
//printf("After IntroText1_ar [%s]\n",IntroText1_ar.c_str());
CPPUNIT_ASSERT_EQUAL( 104,(int)IntroText1_ar.size() );
string expected_result6 = "ﺓﺰﺋﺎﺟ ﻰﻠﻋ ﺔﻠﺻﺎﺤﻟﺍ ﻰﻠﻋ ﻲﻨﺒﻣ Glest ﺔﻴﻜﻴﺳﻼﻜﻟﺍ";
CPPUNIT_ASSERT_EQUAL( expected_result6,IntroText1_ar );
#endif
string IntroText2 = "فريق MegaGlest يقدم";
string expected7 = IntroText2;
CPPUNIT_ASSERT_EQUAL( 27,(int)IntroText2.size() );
#ifdef HAVE_FRIBIDI
Font::bidi_cvt(IntroText2);
CPPUNIT_ASSERT_EQUAL( 35,(int)IntroText2.size() );
string expected_result7 = "ﻖﻳﺮﻓ MegaGlest ﻡﺪﻘﻳ";
CPPUNIT_ASSERT_EQUAL( expected_result7,IntroText2 );
#endif
}
};
// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( FontTest );
//

View File

@ -1,68 +0,0 @@
// ==============================================================
// This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
// Copyright (C) 2013 Mark Vejvoda
//
// You can redistribute this code 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
// ==============================================================
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include "math_util.h"
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
using namespace Shared::Graphics;
//
// Tests for math_util
//
class MathUtilTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( MathUtilTest );
CPPUNIT_TEST( test_RoundFloat );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
public:
void test_RoundFloat() {
float value1 = truncateDecimal<float>(1.123456f, 6);
CPPUNIT_ASSERT_EQUAL( 1.123456f, value1 );
value1 = truncateDecimal<float>(1.123456f, 5);
CPPUNIT_ASSERT_EQUAL( 1.12345f, value1 );
value1 = truncateDecimal<float>(1.123456f, 4);
CPPUNIT_ASSERT_EQUAL( 1.1234f, value1 );
value1 = truncateDecimal<float>(1.123456f, 3);
CPPUNIT_ASSERT_EQUAL( 1.123f, value1 );
value1 = truncateDecimal<float>(1.123456f, 2);
CPPUNIT_ASSERT_EQUAL( 1.12f, value1 );
value1 = truncateDecimal<float>(1.123456f, 1);
CPPUNIT_ASSERT_EQUAL( 1.1f, value1 );
// int32 value2 = xs_CRoundToInt(1.123456f);
// CPPUNIT_ASSERT_EQUAL( (int32)1, value2 );
//
// value2 = xs_CRoundToInt(1.523456f);
// CPPUNIT_ASSERT_EQUAL( (int32)2, value2 );
}
};
// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( MathUtilTest );
//

View File

@ -1,108 +0,0 @@
// ==============================================================
// This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
// Copyright (C) 2013 Mark Vejvoda
//
// You can redistribute this code 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
// ==============================================================
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include "model.h"
#include <vector>
#include <algorithm>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
using namespace Shared::Graphics;
class TestBaseColorPickEntity : public BaseColorPickEntity {
public:
virtual string getUniquePickName() const {
return getColorDescription();
}
};
//
// Tests for font class
//
class ModelTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( ModelTest );
CPPUNIT_TEST( test_ColorPicking_loop );
CPPUNIT_TEST( test_ColorPicking_prime );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
public:
void test_ColorPicking_loop() {
BaseColorPickEntity::setTrackColorUse(true);
BaseColorPickEntity::setUsingLoopMethod(true);
BaseColorPickEntity::resetUniqueColors();
TestBaseColorPickEntity colorPicker;
// This is the max color count this algorithm supports
const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD = 32767;
for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD; ++i) {
bool duplicate = colorPicker.get_next_assign_color(colorPicker.getUniqueColorID());
CPPUNIT_ASSERT_EQUAL( false,duplicate );
}
BaseColorPickEntity::resetUniqueColors();
TestBaseColorPickEntity colorPicker2;
// This is a test to prove when the algorithm fails
const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL = 32768;
for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL; ++i) {
bool duplicate = colorPicker2.get_next_assign_color(colorPicker2.getUniqueColorID());
CPPUNIT_ASSERT_EQUAL( (i+1 >= MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL),duplicate );
}
BaseColorPickEntity::resetUniqueColors();
BaseColorPickEntity::setTrackColorUse(false);
}
void test_ColorPicking_prime() {
BaseColorPickEntity::setTrackColorUse(true);
BaseColorPickEntity::setUsingLoopMethod(false);
BaseColorPickEntity::resetUniqueColors();
TestBaseColorPickEntity colorPicker;
// This is the max color count this algorithm supports
const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD = 64005;
for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD; ++i) {
bool duplicate = colorPicker.get_next_assign_color(colorPicker.getUniqueColorID());
CPPUNIT_ASSERT_EQUAL( false,duplicate );
}
BaseColorPickEntity::resetUniqueColors();
TestBaseColorPickEntity colorPicker2;
// This is a test to prove when the algorithm fails
const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL = 64006;
for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL; ++i) {
bool duplicate = colorPicker2.get_next_assign_color(colorPicker2.getUniqueColorID());
CPPUNIT_ASSERT_EQUAL( (i+1 >= MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL),duplicate );
}
BaseColorPickEntity::resetUniqueColors();
BaseColorPickEntity::setTrackColorUse(false);
}
};
// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( ModelTest );
//

View File

@ -1,356 +0,0 @@
// ==============================================================
// This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
// Copyright (C) 2013 Mark Vejvoda
//
// You can redistribute this code 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
// ==============================================================
#include <cppunit/extensions/HelperMacros.h>
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
#include "vec.h"
#include "skill_type.h"
#include <memory>
#include <vector>
#include <algorithm>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
using namespace Shared::Util;
using namespace Shared::Graphics;
using namespace Glest::Game;
//
// Tests for streflop floating point consistency
//
const int64 PROGRESS_SPEED_MULTIPLIER = 100000;
const float standardAirHeight = 5.0f;
const float FLOAT_TOLERANCE = 1e-10f;
class StreflopTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( StreflopTest );
CPPUNIT_TEST( test_warmup_cases );
CPPUNIT_TEST( test_known_out_of_synch_cases );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
private:
float cellHeight;
Field currField;
float tileSetAirHeight;
int cellLandUnitHeight;
int cellObjectHeight;
SkillClass currSkill;
int curUnitTypeSize;
int64 progress;
Vec2i lastPos;
Vec2i pos;
void reset() {
cellHeight = 0.f;
currField = fLand;
tileSetAirHeight = standardAirHeight;
cellLandUnitHeight = 0;
cellObjectHeight = 0;
currSkill = scStop;
curUnitTypeSize = 0;
progress = 0;
lastPos = Vec2i(0,0);
pos = Vec2i(0,0);
}
public:
StreflopTest() {
#ifdef USE_STREFLOP
//#define STREFLOP_NO_DENORMALS
//
//#if defined(STREFLOP_SSE)
// const char *instruction_set = "[SSE]";
//#elif defined(STREFLOP_X87)
// const char *instruction_set = "[X87]";
//#elif defined(STREFLOP_SOFT)
// const char *instruction_set = "[SOFTFLOAT]";
//#else
// const char *instruction_set = "[none]";
//#endif
//
//#if defined(STREFLOP_NO_DENORMALS)
// const char *denormals = "[no-denormals]";
//#else
// const char *denormals = "[denormals]";
//#endif
//
// printf("Tests - using STREFLOP %s - %s\n",instruction_set,denormals);
streflop_init<streflop::Simple>();
#endif
reset();
}
void test_warmup_cases() {
int unitTypeHeight = 0;
cellHeight = 1.1f;
currField = fLand;
tileSetAirHeight = standardAirHeight;
cellLandUnitHeight = 1;
cellObjectHeight = 0;
currSkill = scMove;
curUnitTypeSize = 1;
progress = 10;
lastPos = Vec2i(1,1);
pos = Vec2i(1,2);
unitTypeHeight = 1;
Vec3f result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() );
unitTypeHeight = 0;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.1] z [1.0001]"), result.getString() );
unitTypeHeight = 2;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [2.1] z [1.0001]"), result.getString() );
unitTypeHeight = 1;
currField = fAir;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [1.0001]"), result.getString() );
unitTypeHeight = 1;
currField = fAir;
currSkill = scAttack;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [2]"), result.getString() );
unitTypeHeight = 1;
currField = fLand;
currSkill = scAttack;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [2]"), result.getString() );
unitTypeHeight = 1;
currField = fLand;
currSkill = scAttack;
cellLandUnitHeight = -1;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [2]"), result.getString() );
unitTypeHeight = 1;
currField = fAir;
currSkill = scAttack;
cellLandUnitHeight = -1;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [2]"), result.getString() );
unitTypeHeight = 1;
currField = fLand;
currSkill = scMove;
cellLandUnitHeight = 2;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() );
unitTypeHeight = 1;
currField = fAir;
currSkill = scMove;
cellLandUnitHeight = 2;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [1.0001]"), result.getString() );
unitTypeHeight = 1;
currField = fLand;
currSkill = scMove;
cellLandUnitHeight = -1;
cellObjectHeight = 0;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() );
unitTypeHeight = 1;
currField = fLand;
currSkill = scMove;
cellLandUnitHeight = -1;
cellObjectHeight = 1;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [1.0001]"), result.getString() );
unitTypeHeight = 1;
currField = fAir;
currSkill = scMove;
cellLandUnitHeight = -1;
cellObjectHeight = 1;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [6.6] z [1.0001]"), result.getString() );
unitTypeHeight = 1;
currField = fLand;
currSkill = scMove;
progress = 1324312;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [1] y [1.6] z [14.2431]"), result.getString() );
cellHeight = 2.870369f;
currField = fLand;
tileSetAirHeight = standardAirHeight;
cellLandUnitHeight = 0;
cellObjectHeight = 0;
currSkill = scAttack;
curUnitTypeSize = 1;
progress = 21250;
lastPos = Vec2i(96,34);
pos = Vec2i(95,35);
unitTypeHeight = 3;
result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [95] y [4.37037] z [35]"), result.getString() );
double x = 1.0;
x /= 10.0;
double y = x;
// THIS IS NOT ALWAYS TRUE without streflop!
CPPUNIT_ASSERT_DOUBLES_EQUAL( x, y, FLOAT_TOLERANCE );
float xf = 1.0;
xf /= 10.0;
float yf = xf;
// THIS IS NOT ALWAYS TRUE without streflop!
CPPUNIT_ASSERT_DOUBLES_EQUAL( xf, yf, FLOAT_TOLERANCE );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.2f, 0.1f + 0.1f, FLOAT_TOLERANCE );
CPPUNIT_ASSERT_EQUAL( string("0.200000"), floatToStr(0.1f + 0.1f,6) );
CPPUNIT_ASSERT_EQUAL( string("0.2000000"), floatToStr(0.1f + 0.1f,7) );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.01f, 0.1f * 0.1f, 1e-9 );
CPPUNIT_ASSERT_EQUAL( string("0.010000"), floatToStr(0.1f * 0.1f,6) );
CPPUNIT_ASSERT_EQUAL( string("0.0100000"), floatToStr(0.1f * 0.1f,7) );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.002877f, 2877.0f / 1000000.0f, FLOAT_TOLERANCE );
CPPUNIT_ASSERT_EQUAL( string("0.002877"), floatToStr(2877.0f / 1000000.0f,6) );
CPPUNIT_ASSERT_EQUAL( string("0.0028770"), floatToStr(2877.0f / 1000000.0f,7) );
}
void test_known_out_of_synch_cases() {
// Documented cases of out of synch go here to test cross platform for
// consistency
int unitTypeHeight = 0;
cellHeight = 2.814814f;
currField = fLand;
tileSetAirHeight = 5.000000f;
cellLandUnitHeight = -1;
cellObjectHeight = -1;
currSkill = scMove;
curUnitTypeSize = 1;
progress = 35145;
lastPos = Vec2i(40,41);
pos = Vec2i(39,40);
unitTypeHeight = 2;
Vec3f result = getCurrVector(unitTypeHeight);
CPPUNIT_ASSERT_EQUAL( string("x [39.6485] y [3.81481] z [40.6485]"), result.getString() );
}
// =========================== Helper Methods =================================
float computeHeight(const Vec2i &pos) const {
float height = cellHeight;
if(currField == fAir) {
float airHeight = tileSetAirHeight;
airHeight = truncateDecimal<float>(airHeight,6);
height += airHeight;
height = truncateDecimal<float>(height,6);
if(cellLandUnitHeight >= 0 && cellLandUnitHeight > airHeight) {
height += (min((float)cellLandUnitHeight,standardAirHeight * 3) - airHeight);
height = truncateDecimal<float>(height,6);
}
else {
if(cellObjectHeight >= 0) {
if(cellObjectHeight > airHeight) {
height += (min((float)cellObjectHeight,standardAirHeight * 3) - airHeight);
height = truncateDecimal<float>(height,6);
}
}
}
}
return height;
}
float getProgressAsFloat() const {
float result = (static_cast<float>(progress) / static_cast<float>(PROGRESS_SPEED_MULTIPLIER));
result = truncateDecimal<float>(result,6);
return result;
}
Vec3f getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) const {
Vec3f v;
float y1= computeHeight(lastPosValue);
float y2= computeHeight(curPosValue);
if(currSkill == scMove) {
float progressAsFloat = getProgressAsFloat();
v.x = lastPosValue.x + progressAsFloat * (curPosValue.x - lastPosValue.x);
v.z = lastPosValue.y + progressAsFloat * (curPosValue.y - lastPosValue.y);
v.y = y1 + progressAsFloat * (y2-y1);
v.x = truncateDecimal<float>(v.x,6);
v.y = truncateDecimal<float>(v.y,6);
v.z = truncateDecimal<float>(v.z,6);
}
else {
v.x = static_cast<float>(curPosValue.x);
v.z = static_cast<float>(curPosValue.y);
v.y = y2;
v.x = truncateDecimal<float>(v.x,6);
v.y = truncateDecimal<float>(v.y,6);
v.z = truncateDecimal<float>(v.z,6);
}
v.x += curUnitTypeSize / 2.f - 0.5f;
v.z += curUnitTypeSize / 2.f - 0.5f;
v.x = truncateDecimal<float>(v.x,6);
v.z = truncateDecimal<float>(v.z,6);
return v;
}
Vec3f getCurrVectorFlat() const {
return getVectorFlat(lastPos, pos);
}
Vec3f getCurrVector(int unitTypeHeight) const {
Vec3f result = getCurrVectorFlat() + Vec3f(0.f, unitTypeHeight / 2.f, 0.f);
result.x = truncateDecimal<float>(result.x,6);
result.y = truncateDecimal<float>(result.y,6);
result.z = truncateDecimal<float>(result.z,6);
return result;
}
};
// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( StreflopTest );
//

View File

@ -1,199 +0,0 @@
// ==============================================================
// This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
// Copyright (C) 2013 Mark Vejvoda
//
// You can redistribute this code 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
// ==============================================================
#include <cppunit/extensions/HelperMacros.h>
#include "util.h"
#include <memory>
#include <vector>
#include <algorithm>
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
using namespace Shared::Util;
//
// Tests for util classes
//
// **NOTE: IMPORTANT!
// AFTER 3.7.0 we moved to 2 digit compatibility checks
class UtilTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( UtilTest );
CPPUNIT_TEST( test_checkVersionComptability_2_digit_versions );
CPPUNIT_TEST( test_checkVersionComptability_3_digit_versions );
CPPUNIT_TEST( test_checkVersionComptability_mixed_digit_versions );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
public:
void test_checkVersionComptability_2_digit_versions() {
bool debug_verbose_tests = false;
SystemFlags::VERBOSE_MODE_ENABLED = debug_verbose_tests;
// -------- START
// 2 digit version checks
bool result = checkVersionComptability("v4.0", "v3.9");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.9-dev", "v4.0");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v4.0-dev", "v4.0");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.9-dev", "v3.9");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8", "v3.9");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8-dev", "v3.9");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8-dev", "v3.8");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8-beta2", "v3.8");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8-beta1", "v3.8");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8-beta1", "v3.8");
CPPUNIT_ASSERT_EQUAL( false,result );
// -------- END
SystemFlags::VERBOSE_MODE_ENABLED = false;
}
void test_checkVersionComptability_3_digit_versions() {
bool debug_verbose_tests = false;
SystemFlags::VERBOSE_MODE_ENABLED = debug_verbose_tests;
// -------- START
// 3 digit version checks
bool result = checkVersionComptability("v3.9.0", "v3.9.1");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.9.0-dev", "v3.9.0");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-beta2", "v3.9.0");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8.0-beta1", "v3.9.0");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8.0-dev", "v3.9.0");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8.1", "v3.8.2");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-beta2", "v3.8.0");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-dev", "v3.8.0");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-beta2", "v3.8.0-dev");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-beta1", "v3.8.0-dev");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-beta1", "v3.8.0-beta2");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.7.1", "v3.7.2-dev");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.7.1", "v3.7.2");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.7.1-dev", "v3.7.1");
CPPUNIT_ASSERT_EQUAL( true,result );
// **NOTE: IMPORTANT!
// AFTER 3.7.0 we moved to 2 digit compatibility checks
result = checkVersionComptability("v3.7.0", "v3.7.1-dev");
CPPUNIT_ASSERT_EQUAL( false,result );
// -------- END
SystemFlags::VERBOSE_MODE_ENABLED = false;
}
void test_checkVersionComptability_mixed_digit_versions() {
bool debug_verbose_tests = false;
SystemFlags::VERBOSE_MODE_ENABLED = debug_verbose_tests;
// -------- START
bool result = checkVersionComptability("v3.8.0-dev", "v3.9");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8.0-beta2", "v3.9");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.8.0-beta1", "v3.9");
CPPUNIT_ASSERT_EQUAL( false,result );
// Mixed digit version checks
result = checkVersionComptability("v3.8", "v3.8.2");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8", "v3.8.1");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-dev", "v3.8");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-beta2", "v3.8");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.8.0-beta1", "v3.8");
CPPUNIT_ASSERT_EQUAL( true,result );
result = checkVersionComptability("v3.7.2-dev", "v3.8-dev");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.7.1", "v3.8");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.7.1", "v3.8-dev");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.7.1", "v3.8-beta2");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.7.1", "v3.8-beta1");
CPPUNIT_ASSERT_EQUAL( false,result );
result = checkVersionComptability("v3.7.0", "v3.8");
CPPUNIT_ASSERT_EQUAL( false,result );
// -------- END
SystemFlags::VERBOSE_MODE_ENABLED = false;
}
};
// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( UtilTest );
//

View File

@ -1,636 +0,0 @@
// ==============================================================
// This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
// Copyright (C) 2013 Mark Vejvoda
//
// You can redistribute this code 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
// ==============================================================
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <fstream>
#include "xml_parser.h"
#include "platform_util.h"
#if defined(WANT_XERCES)
#include <xercesc/dom/DOM.hpp>
//#include <xercesc/util/PlatformUtils.hpp>
//#include <xercesc/framework/LocalFileFormatTarget.hpp>
#endif
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
using namespace Shared::Xml;
using namespace Shared::Platform;
//
// Utility methods for tests
//
bool removeTestFile(string file) {
#ifdef WIN32
int result = _unlink(file.c_str());
#else
int result = unlink(file.c_str());
#endif
return (result == 0);
}
void createValidXMLTestFile(const string& test_filename) {
std::ofstream xmlFile(test_filename.c_str());
xmlFile << "<?xml version=\"1.0\"?>" << std::endl
<< "<menu mytest-attribute=\"true\">" << std::endl
<< "<menu-background-model value=\"data/core/menu/main_model/menu_main1.g3d\"/>" << std::endl
<< "</menu>" << std::endl;
xmlFile.close();
}
void createMalformedXMLTestFile(const string& test_filename) {
std::ofstream xmlFile(test_filename.c_str());
xmlFile << "<?xml version=\"1.0\"?> #@$ !#@$@#$" << std::endl
<< "<menu>" << std::endl
<< "<menu-background-model value=\"data/core/menu/main_model/menu_main1.g3d\"/>"
<< std::endl;
xmlFile.close();
}
class SafeRemoveTestFile {
private:
string filename;
public:
SafeRemoveTestFile(const string &filename) {
this->filename = filename;
}
~SafeRemoveTestFile() {
removeTestFile(this->filename);
}
};
//
#if defined(WANT_XERCES)
//
// Tests for XmlIo
//
class XmlIoTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( XmlIoTest );
CPPUNIT_TEST( test_getInstance );
CPPUNIT_TEST( test_cleanup );
CPPUNIT_TEST_EXCEPTION( test_load_file_missing, megaglest_runtime_error );
CPPUNIT_TEST( test_load_file_valid );
CPPUNIT_TEST_EXCEPTION( test_load_file_malformed_content, megaglest_runtime_error );
CPPUNIT_TEST_EXCEPTION( test_save_file_null_node, megaglest_runtime_error );
CPPUNIT_TEST(test_save_file_valid_node );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
public:
void test_getInstance() {
XmlIo &newInstance = XmlIo::getInstance();
CPPUNIT_ASSERT_EQUAL( true, newInstance.isInitialized() );
}
void test_cleanup() {
XmlIo &newInstance = XmlIo::getInstance();
CPPUNIT_ASSERT_EQUAL( true, newInstance.isInitialized() );
newInstance.cleanup();
CPPUNIT_ASSERT_EQUAL( false, newInstance.isInitialized() );
}
void test_load_file_missing() {
XmlNode *rootNode = XmlIo::getInstance().load("/some/path/that/does/not exist", std::map<string,string>());
delete rootNode;
}
void test_load_file_valid() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlNode *rootNode = XmlIo::getInstance().load(test_filename, std::map<string,string>());
CPPUNIT_ASSERT( rootNode != NULL );
CPPUNIT_ASSERT_EQUAL( string("menu"), (rootNode != NULL ? rootNode->getName() : string("")) );
delete rootNode;
}
void test_load_file_malformed_content() {
const string test_filename = "xml_test_malformed.xml";
createMalformedXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlNode *rootNode = XmlIo::getInstance().load(test_filename, std::map<string,string>());
delete rootNode;
}
void test_save_file_null_node() {
XmlNode *rootNode = NULL;
XmlIo::getInstance().save("",rootNode);
}
void test_save_file_valid_node() {
const string test_filename_load = "xml_test_save_load_valid.xml";
const string test_filename_save = "xml_test_save_valid.xml";
createValidXMLTestFile(test_filename_load);
SafeRemoveTestFile deleteFile(test_filename_load);
XmlNode *rootNode = XmlIo::getInstance().load(test_filename_load, std::map<string,string>());
XmlIo::getInstance().save(test_filename_save,rootNode);
SafeRemoveTestFile deleteFile2(test_filename_save);
delete rootNode;
}
};
#endif
//
// Tests for XmlIoRapid
//
class XmlIoRapidTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( XmlIoRapidTest );
CPPUNIT_TEST( test_getInstance );
CPPUNIT_TEST( test_cleanup );
CPPUNIT_TEST_EXCEPTION( test_load_file_missing, megaglest_runtime_error );
CPPUNIT_TEST( test_load_file_valid );
CPPUNIT_TEST_EXCEPTION( test_load_file_malformed_content, megaglest_runtime_error );
CPPUNIT_TEST_EXCEPTION( test_save_file_null_node, megaglest_runtime_error );
CPPUNIT_TEST(test_save_file_valid_node );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
public:
void test_getInstance() {
XmlIoRapid &newInstance = XmlIoRapid::getInstance();
CPPUNIT_ASSERT_EQUAL( true, newInstance.isInitialized() );
}
void test_cleanup() {
XmlIoRapid &newInstance = XmlIoRapid::getInstance();
CPPUNIT_ASSERT_EQUAL( true, newInstance.isInitialized() );
newInstance.cleanup();
CPPUNIT_ASSERT_EQUAL( false, newInstance.isInitialized() );
}
void test_load_file_missing() {
XmlNode *rootNode = XmlIoRapid::getInstance().load("/some/path/that/does/not exist", std::map<string,string>());
delete rootNode;
}
void test_load_file_valid() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlNode *rootNode = XmlIoRapid::getInstance().load(test_filename, std::map<string,string>());
CPPUNIT_ASSERT( rootNode != NULL );
CPPUNIT_ASSERT_EQUAL( string("menu"), (rootNode != NULL ? rootNode->getName() : string("")) );
delete rootNode;
}
void test_load_file_malformed_content() {
const string test_filename = "xml_test_malformed.xml";
createMalformedXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlNode *rootNode = XmlIoRapid::getInstance().load(test_filename, std::map<string,string>());
delete rootNode;
}
void test_save_file_null_node() {
XmlNode *rootNode = NULL;
XmlIoRapid::getInstance().save("",rootNode);
}
void test_save_file_valid_node() {
const string test_filename_load = "xml_test_save_load_valid.xml";
const string test_filename_save = "xml_test_save_valid.xml";
createValidXMLTestFile(test_filename_load);
SafeRemoveTestFile deleteFile(test_filename_load);
XmlNode *rootNode = XmlIoRapid::getInstance().load(test_filename_load, std::map<string,string>());
XmlIoRapid::getInstance().save(test_filename_save,rootNode);
SafeRemoveTestFile deleteFile2(test_filename_save);
delete rootNode;
}
};
//
// Tests for XmlTree
//
class XmlTreeTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( XmlTreeTest );
CPPUNIT_TEST_EXCEPTION( test_invalid_xml_engine_lowerbound, megaglest_runtime_error );
CPPUNIT_TEST_EXCEPTION( test_invalid_xml_engine_upperbound, megaglest_runtime_error );
CPPUNIT_TEST( test_valid_xml_engine );
CPPUNIT_TEST( test_init );
CPPUNIT_TEST_EXCEPTION( test_load_simultaneously_same_file, megaglest_runtime_error );
CPPUNIT_TEST( test_load_simultaneously_different_file );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
public:
#if defined(WANT_XERCES)
void test_invalid_xml_engine_lowerbound() {
xml_engine_parser_type testType = static_cast<xml_engine_parser_type>(XML_XERCES_ENGINE - 1);
if((int)testType == (int)(XML_XERCES_ENGINE - 1)) {
XmlTree xml(testType);
}
}
#else
void test_invalid_xml_engine_lowerbound() {
xml_engine_parser_type testType = static_cast<xml_engine_parser_type>(XML_RAPIDXML_ENGINE - 1);
if((int)testType == (int)(XML_RAPIDXML_ENGINE - 1)) {
XmlTree xml(testType);
}
}
#endif
void test_invalid_xml_engine_upperbound() {
xml_engine_parser_type testType = static_cast<xml_engine_parser_type>(XML_RAPIDXML_ENGINE + 1);
if((int)testType == (int)(XML_RAPIDXML_ENGINE + 1)) {
XmlTree xml(testType);
}
}
void test_valid_xml_engine() {
XmlTree xmlInstance;
CPPUNIT_ASSERT_EQUAL( (XmlNode *)NULL, xmlInstance.getRootNode() );
}
void test_init() {
XmlTree xmlInstance;
xmlInstance.init("");
CPPUNIT_ASSERT( xmlInstance.getRootNode() != NULL );
CPPUNIT_ASSERT_EQUAL( string(""), xmlInstance.getRootNode()->getName() );
xmlInstance.init("testRoot");
CPPUNIT_ASSERT( xmlInstance.getRootNode() != NULL );
CPPUNIT_ASSERT_EQUAL( string("testRoot"), xmlInstance.getRootNode()->getName() );
}
void test_load_simultaneously_same_file() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlTree xmlInstance1;
xmlInstance1.load(test_filename, std::map<string,string>());
XmlTree xmlInstance2;
xmlInstance2.load(test_filename, std::map<string,string>());
}
void test_load_simultaneously_different_file() {
const string test_filename1 = "xml_test_valid1.xml";
createValidXMLTestFile(test_filename1);
SafeRemoveTestFile deleteFile(test_filename1);
const string test_filename2 = "xml_test_valid2.xml";
createValidXMLTestFile(test_filename2);
SafeRemoveTestFile deleteFile2(test_filename2);
XmlTree xmlInstance1;
xmlInstance1.load(test_filename1, std::map<string,string>());
XmlTree xmlInstance2;
xmlInstance2.load(test_filename2, std::map<string,string>());
}
};
//
// Tests for XmlNode
//
class XmlNodeTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( XmlNodeTest );
#if defined(WANT_XERCES)
CPPUNIT_TEST_EXCEPTION( test_null_xerces_node, megaglest_runtime_error );
CPPUNIT_TEST( test_valid_xerces_node );
#endif
CPPUNIT_TEST_EXCEPTION( test_null_rapidxml_node, megaglest_runtime_error );
CPPUNIT_TEST( test_valid_named_node );
CPPUNIT_TEST( test_child_nodes );
CPPUNIT_TEST( test_node_attributes );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
private:
#if defined(WANT_XERCES)
class XmlIoMock : public XmlIo {
protected:
virtual void releaseDOMParser() { }
public:
XmlIoMock() : XmlIo() { }
DOMNode *loadDOMNode(const string &path, bool noValidation=false) {
return XmlIo::loadDOMNode(path, noValidation);
}
void manualParserRelease() {
XmlIo::releaseDOMParser();
}
};
#endif
public:
#if defined(WANT_XERCES)
void test_null_xerces_node() {
XERCES_CPP_NAMESPACE::DOMNode *node = NULL;
const std::map<string,string> mapTagReplacementValues;
XmlNode(node, mapTagReplacementValues);
}
void test_valid_xerces_node() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlIoMock xml;
XERCES_CPP_NAMESPACE::DOMNode *domNode = xml.loadDOMNode(test_filename);
CPPUNIT_ASSERT( domNode != NULL );
const std::map<string,string> mapTagReplacementValues;
XmlNode node(domNode, mapTagReplacementValues);
xml.manualParserRelease();
CPPUNIT_ASSERT_EQUAL( string("menu"), node.getName() );
CPPUNIT_ASSERT( node.hasAttribute("mytest-attribute") == true );
CPPUNIT_ASSERT( node.hasChild("menu-background-model") == true );
}
#endif
void test_null_rapidxml_node() {
xml_node<> *node = NULL;
const std::map<string,string> mapTagReplacementValues;
XmlNode(node, mapTagReplacementValues);
}
void test_valid_named_node() {
XmlNode node("testNode");
CPPUNIT_ASSERT_EQUAL( string("testNode"), node.getName() );
}
void test_child_nodes() {
XmlNode node("testNode");
CPPUNIT_ASSERT_EQUAL( string("testNode"), node.getName() );
CPPUNIT_ASSERT_EQUAL( (size_t)0,node.getChildCount() );
XmlNode *childNode1 = node.addChild("child1");
CPPUNIT_ASSERT_EQUAL( (size_t)1,node.getChildCount() );
CPPUNIT_ASSERT_EQUAL( string(""), childNode1->getText() );
XmlNode *childChildNode1 = childNode1->addChild("childchild1", "testValue");
CPPUNIT_ASSERT_EQUAL( (size_t)1,childNode1->getChildCount() );
CPPUNIT_ASSERT_EQUAL( string("testValue"), childChildNode1->getText() );
XmlNode *childChildNode2 = childNode1->addChild("childchild2", "testValue2");
CPPUNIT_ASSERT_EQUAL( (size_t)2, childNode1->getChildCount() );
CPPUNIT_ASSERT_EQUAL( string("testValue2"), childChildNode2->getText() );
XmlNode *childChildNode3 = childNode1->addChild("childchild2", "testValue3");
CPPUNIT_ASSERT_EQUAL( (size_t)3, childNode1->getChildCount() );
CPPUNIT_ASSERT_EQUAL( string("testValue3"), childChildNode3->getText() );
CPPUNIT_ASSERT_EQUAL( true, childNode1->hasChildAtIndex("childchild2",1));
XmlNode *childNode2 = node.addChild("child2","child2Value");
CPPUNIT_ASSERT_EQUAL( (size_t)2,node.getChildCount() );
CPPUNIT_ASSERT_EQUAL( string("child2Value"), childNode2->getText() );
CPPUNIT_ASSERT_EQUAL( string("child2"), node.getChild(1)->getName() );
CPPUNIT_ASSERT_EQUAL( string("child2"), node.getChild("child2")->getName() );
CPPUNIT_ASSERT_EQUAL( string("child1"), node.getChild("child1")->getName() );
XmlNode *childNode2x = node.addChild("child2","child2xValue");
CPPUNIT_ASSERT_EQUAL( (size_t)3, node.getChildCount() );
CPPUNIT_ASSERT_EQUAL( string("child2xValue"), childNode2x->getText() );
CPPUNIT_ASSERT_EQUAL( string("child2xValue"), node.getChild("child2",1)->getText() );
XmlNode *childNode3 = node.addChild("child3","child3Value");
CPPUNIT_ASSERT_EQUAL( (size_t)4, node.getChildCount() );
vector<XmlNode *> child2List = node.getChildList("child2");
CPPUNIT_ASSERT_EQUAL( (size_t)2, child2List.size() );
CPPUNIT_ASSERT_EQUAL( string("child2Value"), child2List[0]->getText() );
CPPUNIT_ASSERT_EQUAL( string("child2xValue"), child2List[1]->getText() );
//printf("%d\n",__LINE__);
CPPUNIT_ASSERT_EQUAL( false, childNode3->hasChild("child2"));
CPPUNIT_ASSERT_EQUAL( 2, node.clearChild("child2"));
CPPUNIT_ASSERT_EQUAL( (size_t)2,node.getChildCount() );
}
void test_node_attributes() {
XmlNode node("testNode");
CPPUNIT_ASSERT_EQUAL( string("testNode"), node.getName() );
CPPUNIT_ASSERT_EQUAL( (size_t)0,node.getAttributeCount() );
CPPUNIT_ASSERT_EQUAL( (XmlAttribute *)NULL, node.getAttribute("some-attribute",false) );
CPPUNIT_ASSERT_EQUAL( false, node.hasAttribute("some-attribute") );
std::map<string,string> mapTagReplacementValues;
XmlAttribute *attribute1 = node.addAttribute("some-attribute", "some-value", mapTagReplacementValues);
CPPUNIT_ASSERT_EQUAL( (size_t)1,node.getAttributeCount() );
CPPUNIT_ASSERT_EQUAL( attribute1, node.getAttribute("some-attribute") );
CPPUNIT_ASSERT_EQUAL( string("some-attribute"), node.getAttribute(0)->getName() );
CPPUNIT_ASSERT_EQUAL( true, node.hasAttribute("some-attribute") );
}
};
#if defined(WANT_XERCES)
//
// Tests for XmlAttribute
//
class XmlAttributeTest : public CppUnit::TestFixture {
// Register the suite of tests for this fixture
CPPUNIT_TEST_SUITE( XmlAttributeTest );
CPPUNIT_TEST_EXCEPTION( test_null_xerces_attribute, megaglest_runtime_error );
CPPUNIT_TEST( test_node_attributes );
CPPUNIT_TEST_EXCEPTION( test_node_attributes_restricted, megaglest_runtime_error );
CPPUNIT_TEST_EXCEPTION( test_node_attributes_int_outofrange, megaglest_runtime_error );
CPPUNIT_TEST_EXCEPTION( test_node_attributes_float_outofrange, megaglest_runtime_error );
CPPUNIT_TEST_SUITE_END();
// End of Fixture registration
private:
class XmlIoMock : public XmlIo {
protected:
virtual void releaseDOMParser() { }
public:
XmlIoMock() : XmlIo() { }
DOMNode *loadDOMNode(const string &path, bool noValidation=false) {
return XmlIo::loadDOMNode(path, noValidation);
}
void manualParserRelease() {
XmlIo::releaseDOMParser();
}
};
public:
void test_null_xerces_attribute() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XERCES_CPP_NAMESPACE::DOMNode *node = NULL;
const std::map<string,string> mapTagReplacementValues;
XmlAttribute attr(node, mapTagReplacementValues);
}
void test_node_attributes() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlIoMock xmlIo;
XERCES_CPP_NAMESPACE::DOMNode *node = xmlIo.loadDOMNode(test_filename);
const std::map<string,string> mapTagReplacementValues;
XmlAttribute attr(node, mapTagReplacementValues);
CPPUNIT_ASSERT_EQUAL( string("menu"),attr.getName() );
CPPUNIT_ASSERT_EQUAL( string(""),attr.getValue() );
attr.setValue("abcdefg");
CPPUNIT_ASSERT_EQUAL( string("abcdefg"),attr.getValue() );
CPPUNIT_ASSERT_EQUAL( string("abcdefg"),attr.getRestrictedValue() );
attr.setValue("!@#$%^&*()_+");
CPPUNIT_ASSERT_EQUAL( string("!@#$%^&*()_+"),attr.getValue() );
attr.setValue("true");
CPPUNIT_ASSERT_EQUAL( true,attr.getBoolValue() );
attr.setValue("false");
CPPUNIT_ASSERT_EQUAL( false,attr.getBoolValue() );
attr.setValue("-123456");
CPPUNIT_ASSERT_EQUAL( -123456,attr.getIntValue() );
attr.setValue("1");
CPPUNIT_ASSERT_EQUAL( 1,attr.getIntValue(1, 10) );
attr.setValue("10");
CPPUNIT_ASSERT_EQUAL( 10,attr.getIntValue(1, 10) );
attr.setValue("5");
CPPUNIT_ASSERT_EQUAL( 5,attr.getIntValue(1, 10) );
attr.setValue("-123456.123456");
CPPUNIT_ASSERT_DOUBLES_EQUAL( -123456.123456f,attr.getFloatValue(), 1e-6 );
// Nasty floating point issues shown by this test sometimes may need to comment out
attr.setValue("123456.123456");
CPPUNIT_ASSERT_DOUBLES_EQUAL( 123456.123456f,attr.getFloatValue(123456.01f, 123456.999f), 1e-6 );
}
void test_node_attributes_restricted() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlIoMock xmlIo;
XERCES_CPP_NAMESPACE::DOMNode *node = xmlIo.loadDOMNode(test_filename);
const std::map<string,string> mapTagReplacementValues;
XmlAttribute attr(node, mapTagReplacementValues);
CPPUNIT_ASSERT_EQUAL( string("menu"),attr.getName() );
CPPUNIT_ASSERT_EQUAL( string(""),attr.getValue() );
attr.setValue("!@#$%^&*()_+");
CPPUNIT_ASSERT_EQUAL( string("!@#$%^&*()_+"),attr.getRestrictedValue() );
}
void test_node_attributes_int_outofrange() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlIoMock xmlIo;
XERCES_CPP_NAMESPACE::DOMNode *node = xmlIo.loadDOMNode(test_filename);
const std::map<string,string> mapTagReplacementValues;
XmlAttribute attr(node, mapTagReplacementValues);
CPPUNIT_ASSERT_EQUAL( string("menu"),attr.getName() );
CPPUNIT_ASSERT_EQUAL( string(""),attr.getValue() );
attr.setValue("-123456");
attr.getIntValue(1, 10);
}
void test_node_attributes_float_outofrange() {
const string test_filename = "xml_test_valid.xml";
createValidXMLTestFile(test_filename);
SafeRemoveTestFile deleteFile(test_filename);
XmlIoMock xmlIo;
XERCES_CPP_NAMESPACE::DOMNode *node = xmlIo.loadDOMNode(test_filename);
const std::map<string,string> mapTagReplacementValues;
XmlAttribute attr(node, mapTagReplacementValues);
attr.setValue("-123456.01");
attr.getFloatValue(-123456.999f, -123456.123456f);
}
};
#endif
// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( XmlIoRapidTest );
CPPUNIT_TEST_SUITE_REGISTRATION( XmlTreeTest );
CPPUNIT_TEST_SUITE_REGISTRATION( XmlNodeTest );
#if defined(WANT_XERCES)
CPPUNIT_TEST_SUITE_REGISTRATION( XmlIoTest );
CPPUNIT_TEST_SUITE_REGISTRATION( XmlAttributeTest );
#endif
//

View File

@ -1,34 +0,0 @@
// ==============================================================
// This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
// Copyright (C) 2013 Mark Vejvoda
//
// You can redistribute this code 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
// ==============================================================
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main(int argc, char* argv[])
{
// Get the top level suite from the registry
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
// Adds the test to the list of test to run
CppUnit::TextUi::TestRunner runner;
runner.addTest( suite );
// Change the default outputter to a compiler error format outputter
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
std::cerr ) );
// Run the tests.
bool wasSucessful = runner.run();
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
}