mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-24 07:14:31 +01:00
Create simple test framework
* Run all tests by passing "test" as a command line argument to 'openrct2' * Using CuTest 1.5 as a test framework
This commit is contained in:
@@ -123,6 +123,13 @@ static int cmdline_for_edit(const char **argv, int argc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmdline_for_test(const char **argv, int argc)
|
||||
{
|
||||
gOpenRCT2StartupAction = STARTUP_ACTION_TEST;
|
||||
gOpenRCT2Headless = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmdline_for_none(const char **argv, int argc)
|
||||
{
|
||||
assert(argc >= 1);
|
||||
@@ -141,7 +148,8 @@ struct { const char *firstArg; cmdline_action action; } cmdline_table[] = {
|
||||
{ "intro", cmdline_for_intro },
|
||||
{ "edit", cmdline_for_edit },
|
||||
{ "sprite", cmdline_for_sprite },
|
||||
{ "screenshot", cmdline_for_screenshot }
|
||||
{ "screenshot", cmdline_for_screenshot },
|
||||
{ "test", cmdline_for_test }
|
||||
};
|
||||
|
||||
static int cmdline_call_action(const char **argv, int argc)
|
||||
|
||||
@@ -258,6 +258,26 @@ void finance_set_loan(money32 loan)
|
||||
game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, loan, GAME_COMMAND_SET_CURRENT_LOAN, 0, 0);
|
||||
}
|
||||
|
||||
money32 finance_get_initial_cash()
|
||||
{
|
||||
return RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32);
|
||||
}
|
||||
|
||||
money32 finance_get_current_loan()
|
||||
{
|
||||
return RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32);
|
||||
}
|
||||
|
||||
money32 finance_get_maximum_loan()
|
||||
{
|
||||
return RCT2_GLOBAL(RCT2_ADDRESS_MAXIMUM_LOAN, money32);
|
||||
}
|
||||
|
||||
money32 finance_get_current_cash()
|
||||
{
|
||||
return DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0069DFB3
|
||||
|
||||
@@ -60,6 +60,10 @@ void finance_shift_expenditure_table();
|
||||
void sub_69E869();
|
||||
|
||||
void finance_set_loan(money32 loan);
|
||||
money32 finance_get_initial_cash();
|
||||
money32 finance_get_current_loan();
|
||||
money32 finance_get_maximum_loan();
|
||||
money32 finance_get_current_cash();
|
||||
void game_command_set_current_loan(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp);
|
||||
|
||||
#endif
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "platform/platform.h"
|
||||
#include "util/sawyercoding.h"
|
||||
#include "world/mapgen.h"
|
||||
#include "test/tests.h"
|
||||
|
||||
int gOpenRCT2StartupAction = STARTUP_ACTION_TITLE;
|
||||
char gOpenRCT2StartupActionPath[512] = { 0 };
|
||||
@@ -186,6 +187,11 @@ void openrct2_launch()
|
||||
editor_load_landscape(gOpenRCT2StartupActionPath);
|
||||
}
|
||||
break;
|
||||
case STARTUP_ACTION_TEST:
|
||||
gExitCode = run_all_tests();
|
||||
openrct2_dispose();
|
||||
exit(gExitCode);
|
||||
return;
|
||||
}
|
||||
openrct2_loop();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ enum {
|
||||
STARTUP_ACTION_INTRO,
|
||||
STARTUP_ACTION_TITLE,
|
||||
STARTUP_ACTION_OPEN,
|
||||
STARTUP_ACTION_EDIT
|
||||
STARTUP_ACTION_EDIT,
|
||||
STARTUP_ACTION_TEST
|
||||
};
|
||||
|
||||
extern int gOpenRCT2StartupAction;
|
||||
|
||||
@@ -402,6 +402,7 @@ extern rct_scenario_basic *gScenarioList;
|
||||
|
||||
int scenario_scores_save();
|
||||
void scenario_load_list();
|
||||
rct_scenario_basic *get_scenario_by_filename(const char *filename);
|
||||
int scenario_load_basic(const char *path, rct_s6_header *header, rct_s6_info *info);
|
||||
int scenario_load(const char *path);
|
||||
int scenario_load_and_play(const rct_scenario_basic *scenario);
|
||||
|
||||
@@ -32,7 +32,7 @@ static void scenario_list_sort();
|
||||
static int scenario_list_sort_compare(const void *a, const void *b);
|
||||
static int scenario_scores_load();
|
||||
|
||||
static rct_scenario_basic *get_scenario_by_filename(const char *filename)
|
||||
rct_scenario_basic *get_scenario_by_filename(const char *filename)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < gScenarioListCount; i++)
|
||||
|
||||
60
src/test/management/finance_test.c
Normal file
60
src/test/management/finance_test.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2015 Marco Costa
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* This file is part of OpenRCT2.
|
||||
*
|
||||
* OpenRCT2 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 3 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; 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/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../../addresses.h"
|
||||
#include "../../openrct2.h"
|
||||
#include "../../scenario.h"
|
||||
|
||||
#include "../../management/finance.h"
|
||||
#include "finance_test.h"
|
||||
|
||||
void test_finance_setup(CuTest* tc) {
|
||||
test_load_scenario(tc, "Build your own Six Flags Park.SC6");
|
||||
}
|
||||
|
||||
void test_finance_loan_increase(CuTest* tc) {
|
||||
money32 initialCash = finance_get_current_cash();
|
||||
money32 initialLoan = finance_get_current_loan();
|
||||
|
||||
money32 newLoan = finance_get_maximum_loan();
|
||||
finance_set_loan(newLoan);
|
||||
|
||||
money32 actual = finance_get_current_loan();
|
||||
CuAssertIntEquals(tc, newLoan, actual);
|
||||
|
||||
money32 actualCash = finance_get_current_cash();
|
||||
CuAssertIntEquals(tc, initialCash + newLoan - initialLoan, actualCash);
|
||||
}
|
||||
|
||||
void test_finance_loan_pay_back(CuTest* tc) {
|
||||
money32 initialCash = finance_get_current_cash();
|
||||
money32 initialLoan = finance_get_current_loan();
|
||||
|
||||
money32 newLoan = MONEY(0, 00);
|
||||
finance_set_loan(newLoan);
|
||||
|
||||
money32 actual = finance_get_current_loan();
|
||||
CuAssertIntEquals(tc, newLoan, actual);
|
||||
|
||||
money32 actualCash = finance_get_current_cash();
|
||||
CuAssertIntEquals(tc, MONEY(0, 00), actualCash);
|
||||
}
|
||||
|
||||
|
||||
30
src/test/management/finance_test.h
Normal file
30
src/test/management/finance_test.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2015 Marco Costa
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* This file is part of OpenRCT2.
|
||||
*
|
||||
* OpenRCT2 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 3 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; 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/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _FINANCE_TEST_H_
|
||||
#define _FINANCE_TEST_H_
|
||||
|
||||
#include "../tests.h"
|
||||
|
||||
void test_finance_setup(CuTest* tc);
|
||||
void test_finance_loan_increase(CuTest* tc);
|
||||
void test_finance_loan_pay_back(CuTest* tc);
|
||||
|
||||
#endif
|
||||
54
src/test/tests.c
Normal file
54
src/test/tests.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2015 Marco Costa
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* This file is part of OpenRCT2.
|
||||
*
|
||||
* OpenRCT2 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 3 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; 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/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "management/finance_test.h"
|
||||
|
||||
CuSuite* new_suite(void)
|
||||
{
|
||||
CuSuite* suite = CuSuiteNew();
|
||||
|
||||
// Test Finance
|
||||
SUITE_ADD_TEST(suite, test_finance_setup);
|
||||
SUITE_ADD_TEST(suite, test_finance_loan_increase);
|
||||
SUITE_ADD_TEST(suite, test_finance_loan_pay_back);
|
||||
|
||||
// Future Tests:
|
||||
// Test X
|
||||
// SUITE_ADD_TEST(suite, test_X_setup);
|
||||
// SUITE_ADD_TEST(suite, test_X_Y);
|
||||
// SUITE_ADD_TEST(suite, test_X_Z);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
int run_all_tests(void)
|
||||
{
|
||||
CuString *output = CuStringNew();
|
||||
CuSuite* suite = CuSuiteNew();
|
||||
|
||||
CuSuiteAddSuite(suite, new_suite());
|
||||
|
||||
CuSuiteRun(suite);
|
||||
CuSuiteSummary(suite, output);
|
||||
CuSuiteDetails(suite, output);
|
||||
printf("Test results:\n%s\n", output->buffer);
|
||||
|
||||
return suite->failCount > 0;
|
||||
}
|
||||
43
src/test/tests.h
Normal file
43
src/test/tests.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2015 Marco Costa
|
||||
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||
*
|
||||
* This file is part of OpenRCT2.
|
||||
*
|
||||
* OpenRCT2 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 3 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; 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/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _TESTS_H_
|
||||
#define _TESTS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
|
||||
#include "../scenario.h"
|
||||
|
||||
int run_all_tests();
|
||||
|
||||
/*
|
||||
* Test utilities
|
||||
*/
|
||||
static void test_load_scenario(CuTest* tc, const char* file_name) {
|
||||
const rct_scenario_basic* scenario = get_scenario_by_filename(file_name);
|
||||
if (scenario == NULL) {
|
||||
CuFail(tc, "Could not load scenario");
|
||||
}
|
||||
scenario_load_and_play(scenario);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user