Skip to content

Commit

Permalink
tests: remove TESTS_NODATA configuration option
Browse files Browse the repository at this point in the history
Add --nodata argument to the tests executable.
This will at runtime disable the tests that require game data.

How to use:
./rwtests
./rwtests -- --help
./rwtests -- --nodata
  • Loading branch information
madebr committed Aug 29, 2018
1 parent e52f933 commit a0b97a4
Show file tree
Hide file tree
Showing 30 changed files with 290 additions and 206 deletions.
7 changes: 6 additions & 1 deletion cmake/ctest/build.ctest
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ set(_CONFIGURE_OPTIONS
"-DBUILD_TOOLS=${BUILD_TOOLS}"
"-DBUILD_VIEWER=${BUILD_VIEWER}"
"-DBUILD_TESTS=TRUE"
"-DTESTS_NODATA=${TESTS_NODATA}"
"-DTEST_COVERAGE=${RUN_COVERAGE}"
"-DSEPARATE_TEST_SUITES=${SEPARATE_TEST_SUITES}"
"-DCHECK_IWYU=${CHECK_IWYU}"
Expand Down Expand Up @@ -190,7 +189,13 @@ ctest_build(

if(RUN_TESTS)
message(STATUS "Running tests...")
if(TESTS_NODATA)
set(TEST_INCLUDE_REGEX "no_data")
else()
set(TEST_INCLUDE_REGEX "")
endif()
ctest_test(
INCLUDE "${TEST_INCLUDE_REGEX}"
RETURN_VALUE _TEST_RESULT
)
else()
Expand Down
12 changes: 2 additions & 10 deletions cmake/ctest/script_ci.ctest
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,14 @@ set(RUN_COVERAGE FALSE)
set(RUN_MEMCHECK FALSE)
openrw_should_submit_ci(SUBMIT)

# Build with no data and test
set(BUILDER_NAME "${BUILDER_NAME_BASE}-nodata")
# Configure, build and test with no data
set(BUILDER_NAME "${BUILDER_NAME_BASE}")
set(APPEND_RESULTS FALSE)
set(TESTS_NODATA TRUE)
set(RUN_TESTS TRUE)

include("${CTEST_SCRIPT_DIRECTORY}/build.ctest")

# Build with data and do not test
set(BUILDER_NAME "${BUILDER_NAME_BASE}-data")
set(APPEND_RESULTS FALSE)
set(TESTS_NODATA FALSE)
set(RUN_TESTS FALSE)

include("${CTEST_SCRIPT_DIRECTORY}/build.ctest")

if(WARNING_MESSAGES)
foreach(WARNING_MESSAGE ${WARNING_MESSAGES})
message(WARNING "${WARNING_MESSAGE}")
Expand Down
2 changes: 0 additions & 2 deletions cmake_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ option(BUILD_VIEWER "Build GUI data viewer")
option(ENABLE_SCRIPT_DEBUG "Enable verbose script execution")
option(ENABLE_PROFILING "Enable detailed profiling metrics")

option(TESTS_NODATA "Build tests for no-data testing")

set(FAILED_CHECK_ACTION "IGNORE" CACHE STRING "What action to perform on a failed RW_CHECK (in debug mode)")
set_property(CACHE FAILED_CHECK_ACTION PROPERTY STRINGS "IGNORE" "ABORT" "BREAKPOINT")

Expand Down
3 changes: 0 additions & 3 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ class OpenrwConan(ConanFile):
description = "OpenRW 'Open ReWrite' is an un-official open source recreation of the classic Grand Theft Auto III game executable"
settings = 'os', 'compiler', 'build_type', 'arch'
options = {
'test_data': [True, False],
'viewer': [True, False],
'tools': [True, False],
}

default_options = (
'test_data=False',
'viewer=True',
'tools=True',
'bullet:shared=False',
Expand Down Expand Up @@ -66,7 +64,6 @@ def _configure_cmake(self):
'BUILD_TESTS': True,
'BUILD_VIEWER': self.options.viewer,
'BUILD_TOOLS': self.options.tools,
'TESTS_NODATA': not self.options.test_data,
'USE_CONAN': True,
'BOOST_STATIC': not self.options['boost'].shared,
}
Expand Down
20 changes: 13 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(TESTS
)

set(TEST_SOURCES
boost_fixes.hpp

main.cpp
test_Globals.cpp
test_Globals.hpp
Expand All @@ -56,11 +58,6 @@ add_executable(rwtests
${TEST_SOURCES}
)

target_compile_definitions(rwtests
PRIVATE
"RW_TEST_WITH_DATA=$<NOT:$<BOOL:${TESTS_NODATA}>>"
)

target_include_directories(rwtests
PRIVATE
"${PROJECT_SOURCE_DIR}/tests"
Expand All @@ -70,6 +67,7 @@ target_include_directories(rwtests
target_link_libraries(rwtests
PRIVATE
Boost::unit_test_framework
Boost::program_options
rwengine
SDL2::SDL2
Boost::filesystem
Expand All @@ -89,10 +87,18 @@ if(SEPARATE_TEST_SUITES)
)
endforeach()
else()
add_test(NAME UnitTests
add_test(NAME all_tests
COMMAND "$<TARGET_FILE:rwtests>"
)
set_tests_properties(UnitTests
set_tests_properties(all_tests
PROPERTIES
TIMEOUT 300
)

add_test(NAME all_tests_no_data
COMMAND "$<TARGET_FILE:rwtests>" "--" "--nodata"
)
set_tests_properties(all_tests
PROPERTIES
TIMEOUT 300
)
Expand Down
64 changes: 64 additions & 0 deletions tests/boost_fixes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef _RWTESTS_BOOST_FIXES_HPP_
#define _RWTESTS_BOOST_FIXES_HPP_

#include <fonts/GameTexts.hpp>

#include <boost/test/unit_test.hpp>
#include <glm/gtx/string_cast.hpp>

// Boost moved the print_log_value struct in version 1.59
// TODO: use another testing library
#if BOOST_VERSION >= 105900
#define BOOST_NS_MAGIC namespace tt_detail {
#define BOOST_NS_MAGIC_CLOSING }
#else
#define BOOST_NS_MAGIC
#define BOOST_NS_MAGIC_CLOSING
#endif

namespace boost {
namespace test_tools {
BOOST_NS_MAGIC
template <>
struct print_log_value<glm::vec3> {
void operator()(std::ostream& s, glm::vec3 const& v) {
s << glm::to_string(v);
}
};
BOOST_NS_MAGIC_CLOSING
}
}

#if BOOST_VERSION < 106400
namespace boost {
namespace test_tools {
BOOST_NS_MAGIC
template <>
struct print_log_value<std::nullptr_t> {
void operator()(std::ostream& s, std::nullptr_t) {
s << "nullptr";
}
};
BOOST_NS_MAGIC_CLOSING
}
}
#endif

namespace boost {
namespace test_tools {
BOOST_NS_MAGIC
template <>
struct print_log_value<GameString> {
void operator()(std::ostream& s, GameString const& v) {
for (GameString::size_type i = 0u; i < v.size(); ++i) {
s << static_cast<char>(v[i]);
}
}
};
BOOST_NS_MAGIC_CLOSING
}
}

#undef BOOST_NS_MAGIC
#undef BOOST_NS_MAGIC_CLOSING
#endif
50 changes: 50 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
#define BOOST_TEST_MODULE openrw
#include <boost/test/unit_test.hpp>
#include <boost/program_options.hpp>

#include "test_Globals.hpp"

#include <iostream>

static bool global_texture_ran = false;

class RWTestGlobalFixture {
public:
RWTestGlobalFixture() {
int argc = utf::framework::master_test_suite().argc;
char** argv= utf::framework::master_test_suite().argv;
parse_args(argc, argv);

global_texture_ran = true;
}
private:
void parse_args(int argc, char** argv) {
namespace po = boost::program_options;
po::options_description test_options("Test options");
test_options.add_options()(
"nodata", "Disable tests that need game data")(
"help", "Show this help message");

po::variables_map vm;
try {
po::store(po::parse_command_line(argc, argv, test_options), vm);
po::notify(vm);
} catch (po::error& ex) {
std::cout << "Error parsing arguments: " << ex.what() << std::endl;
std::cerr << test_options;
_exit(EXIT_FAILURE);
}
if (vm.count("help")) {
std::cout << test_options;
_exit(EXIT_SUCCESS);
}

if (vm.count("nodata")) {
global_args.with_data = false;
}
}
};

BOOST_TEST_GLOBAL_FIXTURE(RWTestGlobalFixture);

BOOST_AUTO_TEST_CASE(test_global_fixture) {
BOOST_TEST_REQUIRE(global_texture_ran);
}
5 changes: 2 additions & 3 deletions tests/test_Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

BOOST_AUTO_TEST_SUITE(AnimationTests)

#if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(test_matrix) {
BOOST_AUTO_TEST_CASE(test_matrix,
* utf::precondition(with_data{})) {
{
auto animation = std::make_shared<Animation>();

Expand Down Expand Up @@ -46,6 +46,5 @@ BOOST_AUTO_TEST_CASE(test_matrix) {
glm::vec3(0.f, 1.f, 0.f));
}
}
#endif

BOOST_AUTO_TEST_SUITE_END()
5 changes: 2 additions & 3 deletions tests/test_Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

BOOST_AUTO_TEST_SUITE(ArchiveTests)

#if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(test_open_archive) {
BOOST_AUTO_TEST_CASE(test_open_archive,
* utf::precondition(with_data{})) {
LoaderIMG archive;

BOOST_REQUIRE(archive.load(Global::getGamePath() + "/models/gta3"));
Expand All @@ -28,6 +28,5 @@ BOOST_AUTO_TEST_CASE(test_open_archive) {
BOOST_CHECK_EQUAL(f2.offset, f.offset);
BOOST_CHECK_EQUAL(f2.size, f.size);
}
#endif

BOOST_AUTO_TEST_SUITE_END()
5 changes: 2 additions & 3 deletions tests/test_Buoyancy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

BOOST_AUTO_TEST_SUITE(BuoyancyTests)

#if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(test_vehicle_buoyancy) {
BOOST_AUTO_TEST_CASE(test_vehicle_buoyancy,
* utf::precondition(with_data{})) {
glm::vec2 tpos(-WATER_WORLD_SIZE / 2.f + 10.f);
{
VehicleObject* vehicle = Global::get().e->createVehicle(
Expand Down Expand Up @@ -57,6 +57,5 @@ BOOST_AUTO_TEST_CASE(test_vehicle_buoyancy) {
Global::get().e->destroyObject(vehicle);
}
}
#endif

BOOST_AUTO_TEST_SUITE_END()
20 changes: 12 additions & 8 deletions tests/test_Character.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "test_Globals.hpp"

#include <ai/DefaultAIController.hpp>
#include <boost/test/unit_test.hpp>
#include <engine/Animator.hpp>
#include <objects/CharacterObject.hpp>
#include <objects/VehicleObject.hpp>
#include "test_Globals.hpp"

#include <btBulletDynamicsCommon.h>

BOOST_AUTO_TEST_SUITE(CharacterTests)

#if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(test_create) {
BOOST_AUTO_TEST_CASE(test_create,
* utf::precondition(with_data{})) {
{
auto character =
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
Expand All @@ -31,7 +33,8 @@ BOOST_AUTO_TEST_CASE(test_create) {
}
}

BOOST_AUTO_TEST_CASE(test_activities) {
BOOST_AUTO_TEST_CASE(test_activities,
* utf::precondition(with_data{})) {
{
auto character =
Global::get().e->createPedestrian(1, {0.f, 0.f, 225.6f});
Expand Down Expand Up @@ -120,7 +123,8 @@ BOOST_AUTO_TEST_CASE(test_activities) {
}
}

BOOST_AUTO_TEST_CASE(test_death) {
BOOST_AUTO_TEST_CASE(test_death,
* utf::precondition(with_data{})) {
{
auto character =
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
Expand Down Expand Up @@ -148,7 +152,8 @@ BOOST_AUTO_TEST_CASE(test_death) {
}
}

BOOST_AUTO_TEST_CASE(test_cycle_animating) {
BOOST_AUTO_TEST_CASE(test_cycle_animating,
* utf::precondition(with_data{})) {
{
auto character =
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
Expand All @@ -162,6 +167,5 @@ BOOST_AUTO_TEST_CASE(test_cycle_animating) {
static_cast<uint32_t>(AnimCycle::ArrestGun));
}
}
#endif

BOOST_AUTO_TEST_SUITE_END()
5 changes: 2 additions & 3 deletions tests/test_Chase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

BOOST_AUTO_TEST_SUITE(ChaseTests)

#if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(test_load_keyframes) {
BOOST_AUTO_TEST_CASE(test_load_keyframes,
* utf::precondition(with_data{})) {
std::vector<ChaseKeyframe> keyframes;
BOOST_REQUIRE(ChaseKeyframe::load(
Global::getGamePath() + "/data/paths/CHASE0.DAT", keyframes));
BOOST_REQUIRE(keyframes.size() == 5400);
BOOST_CHECK_CLOSE(keyframes[0].position.x, 273.5422, 0.1);
}
#endif

BOOST_AUTO_TEST_SUITE_END()
5 changes: 2 additions & 3 deletions tests/test_Cutscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

BOOST_AUTO_TEST_SUITE(CutsceneTests)

#if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(test_load) {
BOOST_AUTO_TEST_CASE(test_load,
* utf::precondition(with_data{})) {
{
auto d = Global::get().e->data->index.openFile("intro.dat");

Expand All @@ -29,6 +29,5 @@ BOOST_AUTO_TEST_CASE(test_load) {
BOOST_CHECK(tracks.duration == 64.8f);
}
}
#endif

BOOST_AUTO_TEST_SUITE_END()
Loading

0 comments on commit a0b97a4

Please sign in to comment.