From 2ea634ba83bbd102f0219b03a9e7b897a1fe5806 Mon Sep 17 00:00:00 2001 From: Eric Pierce Date: Fri, 31 Dec 2021 16:37:39 -0700 Subject: [PATCH] tests: Use scoped_weather_override for widget test --- tests/widget_test.cpp | 67 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/tests/widget_test.cpp b/tests/widget_test.cpp index 1dd9af1661041..fc88b1ee55fff 100644 --- a/tests/widget_test.cpp +++ b/tests/widget_test.cpp @@ -2,6 +2,7 @@ #include "player_helpers.h" #include "morale.h" +#include "options_helpers.h" #include "weather.h" #include "weather_type.h" #include "widget.h" @@ -17,12 +18,12 @@ static const move_mode_id move_mode_prone( "prone" ); static const move_mode_id move_mode_run( "run" ); static const move_mode_id move_mode_walk( "walk" ); -static const weather_type_id weather_acid_rain( "acid_rain" ); -static const weather_type_id weather_cloudy( "cloudy" ); -static const weather_type_id weather_drizzle( "drizzle" ); -static const weather_type_id weather_portal_storm( "portal_storm" ); -static const weather_type_id weather_snowing( "snowing" ); -static const weather_type_id weather_sunny( "sunny" ); +static const weather_type_id weather_type_acid_rain( "acid_rain" ); +static const weather_type_id weather_type_cloudy( "cloudy" ); +static const weather_type_id weather_type_drizzle( "drizzle" ); +static const weather_type_id weather_type_portal_storm( "portal_storm" ); +static const weather_type_id weather_type_snowing( "snowing" ); +static const weather_type_id weather_type_sunny( "sunny" ); static const widget_id widget_test_bp_wetness_head_num( "test_bp_wetness_head_num" ); static const widget_id widget_test_bp_wetness_torso_num( "test_bp_wetness_torso_num" ); @@ -533,7 +534,7 @@ TEST_CASE( "widgets showing avatar attributes", "[widget][avatar]" ) } } -TEST_CASE( "widgets showing environment features", "[widget][environment]" ) +TEST_CASE( "widgets showing weather conditions", "[widget][weather]" ) { widget weather_w = widget_test_weather_text.obj(); @@ -541,35 +542,41 @@ TEST_CASE( "widgets showing environment features", "[widget][environment]" ) clear_avatar(); SECTION( "weather conditions" ) { - weather_manager &weather = get_weather(); - - weather.weather_override = weather_sunny; - weather.set_nextweather( calendar::turn ); - CHECK( weather_w.layout( ava ) == "Weather: Sunny" ); + SECTION( "sunny" ) { + scoped_weather_override weather_sunny( weather_type_sunny ); + REQUIRE( get_weather().weather_id->name.translated() == "Sunny" ); + CHECK( weather_w.layout( ava ) == "Weather: Sunny" ); + } - weather.weather_override = weather_cloudy; - weather.set_nextweather( calendar::turn ); - CHECK( weather_w.layout( ava ) == "Weather: Cloudy" ); + SECTION( "cloudy" ) { + scoped_weather_override weather_cloudy( weather_type_cloudy ); + CHECK( weather_w.layout( ava ) == "Weather: Cloudy" ); + } - weather.weather_override = weather_drizzle; - weather.set_nextweather( calendar::turn ); - CHECK( weather_w.layout( ava ) == "Weather: Drizzle" ); + SECTION( "drizzle" ) { + scoped_weather_override weather_drizzle( weather_type_drizzle ); + CHECK( weather_w.layout( ava ) == "Weather: Drizzle" ); + } - weather.weather_override = weather_snowing; - weather.set_nextweather( calendar::turn ); - CHECK( weather_w.layout( ava ) == "Weather: Snowing" ); + SECTION( "snowing" ) { + scoped_weather_override weather_snowing( weather_type_snowing ); + CHECK( weather_w.layout( ava ) == "Weather: Snowing" ); + } - weather.weather_override = weather_acid_rain; - weather.set_nextweather( calendar::turn ); - CHECK( weather_w.layout( ava ) == "Weather: Acid Rain" ); + SECTION( "acid rain" ) { + scoped_weather_override weather_acid_rain( weather_type_acid_rain ); + CHECK( weather_w.layout( ava ) == "Weather: Acid Rain" ); + } - weather.weather_override = weather_portal_storm; - weather.set_nextweather( calendar::turn ); - CHECK( weather_w.layout( ava ) == "Weather: Portal Storm" ); + SECTION( "portal storm" ) { + scoped_weather_override weather_portal_storm( weather_type_portal_storm ); + CHECK( weather_w.layout( ava ) == "Weather: Portal Storm" ); + } - // Cannot see weather when underground - ava.setpos( { 0, 0, -1 } ); - CHECK( weather_w.layout( ava ) == "Weather: Underground" ); + SECTION( "cannot see weather when underground" ) { + ava.setpos( tripoint_below ); + CHECK( weather_w.layout( ava ) == "Weather: Underground" ); + } } }