OpenRCT2/test/tests/RideRatings.cpp

102 lines
2.8 KiB
C++
Raw Normal View History

/*****************************************************************************
* Copyright (c) 2014-2018 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2018-06-22 22:29:03 +02:00
#include "TestData.h"
2017-01-10 13:57:55 +01:00
#include <gtest/gtest.h>
#include <openrct2/Context.h>
2018-06-22 22:29:03 +02:00
#include <openrct2/Game.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/AudioContext.h>
2017-05-17 20:12:02 +02:00
#include <openrct2/core/File.h>
2017-01-10 13:57:55 +01:00
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/platform/platform.h>
2018-06-22 22:29:03 +02:00
#include <openrct2/ride/Ride.h>
#include <string>
2017-01-10 13:57:55 +01:00
using namespace OpenRCT2;
2017-01-10 13:57:55 +01:00
class RideRatings : public testing::Test
{
protected:
void CalculateRatingsForAllRides()
{
for (int rideId = 0; rideId < MAX_RIDES; rideId++)
{
2018-06-22 22:29:03 +02:00
Ride* ride = get_ride(rideId);
if (ride->type != RIDE_TYPE_NULL)
{
ride_ratings_update_ride(rideId);
}
}
}
void DumpRatings()
{
for (int rideId = 0; rideId < MAX_RIDES; rideId++)
{
2018-06-22 22:29:03 +02:00
Ride* ride = get_ride(rideId);
if (ride->type != RIDE_TYPE_NULL)
{
std::string line = FormatRatings(ride);
printf("%s\n", line.c_str());
}
}
}
2018-06-22 22:29:03 +02:00
std::string FormatRatings(Ride* ride)
{
rating_tuple ratings = ride->ratings;
2018-06-22 22:29:03 +02:00
std::string line = String::StdFormat(
2018-07-21 17:27:15 +02:00
"%s: (%d, %d, %d)", ride_type_get_enum_name(ride->type), (int)ratings.excitement, (int)ratings.intensity,
(int)ratings.nausea);
return line;
}
2017-01-10 13:57:55 +01:00
};
TEST_F(RideRatings, all)
{
2017-05-17 20:12:02 +02:00
std::string path = TestData::GetParkPath("bpb.sv6");
2017-01-10 13:57:55 +01:00
gOpenRCT2Headless = true;
2018-04-10 13:33:37 +02:00
gOpenRCT2NoGraphics = true;
2017-01-10 13:57:55 +01:00
core_init();
auto context = CreateContext();
bool initialised = context->Initialise();
ASSERT_TRUE(initialised);
load_from_sv6(path.c_str());
2017-01-10 13:57:55 +01:00
// Check ride count to check load was successful
2017-05-17 20:12:02 +02:00
ASSERT_EQ(gRideCount, 134);
2017-01-10 13:57:55 +01:00
CalculateRatingsForAllRides();
2017-05-17 20:12:02 +02:00
// Load expected ratings
auto expectedDataPath = Path::Combine(TestData::GetBasePath(), "ratings", "bpb.sv6.txt");
auto expectedRatings = File::ReadAllLines(expectedDataPath);
2017-01-10 13:57:55 +01:00
// Check ride ratings
int expI = 0;
for (int rideId = 0; rideId < MAX_RIDES; rideId++)
{
2018-06-22 22:29:03 +02:00
Ride* ride = get_ride(rideId);
2017-01-10 13:57:55 +01:00
if (ride->type != RIDE_TYPE_NULL)
{
std::string actual = FormatRatings(ride);
2017-05-17 20:12:02 +02:00
std::string expected = expectedRatings[expI];
ASSERT_STREQ(actual.c_str(), expected.c_str());
2017-01-10 13:57:55 +01:00
expI++;
}
}
}