OpenRCT2/test/tests/RideRatings.cpp

91 lines
2.5 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 <openrct2/ride/RideData.h>
2018-06-22 22:29:03 +02:00
#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 (const auto& ride : GetRideManager())
{
ride_ratings_update_ride(ride);
}
}
void DumpRatings()
{
for (const auto& ride : GetRideManager())
{
std::string line = FormatRatings(ride);
printf("%s\n", line.c_str());
}
}
std::string FormatRatings(const Ride& ride)
{
RatingTuple ratings = ride.ratings;
2018-06-22 22:29:03 +02:00
std::string line = String::StdFormat(
"%s: (%d, %d, %d)", ride.GetRideTypeDescriptor().EnumName, static_cast<int>(ratings.Excitement),
static_cast<int>(ratings.Intensity), static_cast<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
ASSERT_EQ(ride_get_count(), 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 (const auto& ride : GetRideManager())
2017-01-10 13:57:55 +01:00
{
auto actual = FormatRatings(ride);
auto expected = expectedRatings[expI];
ASSERT_STREQ(actual.c_str(), expected.c_str());
2017-01-10 13:57:55 +01:00
expI++;
2017-01-10 13:57:55 +01:00
}
}