Просмотр исходного кода

Tests shell uses system elapsed time unless manually overridden

Michael Ragazzon 1 месяц назад
Родитель
Сommit
e93048926a

+ 1 - 1
Tests/Source/Benchmarks/WidgetTextInput.cpp

@@ -79,7 +79,7 @@ TEST_CASE("WidgetTextInput")
 	auto IncrementTime = [system_interface = TestsShell::GetTestsSystemInterface(), t = 0.0]() mutable {
 		constexpr double dt = 0.5;
 		t += dt;
-		system_interface->SetTime(t);
+		system_interface->SetManualTime(t);
 	};
 	struct TestCase {
 		String name;

+ 14 - 2
Tests/Source/Common/TestsInterface.cpp

@@ -39,7 +39,10 @@ TestsSystemInterface::~TestsSystemInterface()
 
 double TestsSystemInterface::GetElapsedTime()
 {
-	return elapsed_time;
+	if (manual_time)
+		return elapsed_time;
+
+	return Rml::SystemInterface::GetElapsedTime();
 }
 
 bool TestsSystemInterface::LogMessage(Rml::Log::Type type, const Rml::String& message)
@@ -86,11 +89,20 @@ void TestsSystemInterface::SetNumExpectedWarnings(int in_num_expected_warnings)
 	num_expected_warnings = in_num_expected_warnings;
 }
 
-void TestsSystemInterface::SetTime(double t)
+void TestsSystemInterface::SetManualTime(double t)
 {
+	manual_time = true;
 	elapsed_time = t;
 }
 
+void TestsSystemInterface::Reset()
+{
+	SetManualTime(0);
+	manual_time = false;
+
+	SetNumExpectedWarnings(0);
+}
+
 Rml::CompiledGeometryHandle TestsRenderInterface::CompileGeometry(Rml::Span<const Rml::Vertex> vertices, Rml::Span<const int> indices)
 {
 	counters.compile_geometry += 1;

+ 4 - 1
Tests/Source/Common/TestsInterface.h

@@ -46,9 +46,12 @@ public:
 	// warnings and errors until the next call.
 	void SetNumExpectedWarnings(int num_expected_warnings);
 
-	void SetTime(double t);
+	void SetManualTime(double t);
+
+	void Reset();
 
 private:
+	bool manual_time = false;
 	double elapsed_time = 0.0;
 
 	int num_logged_warnings = 0;

+ 1 - 1
Tests/Source/Common/TestsShell.cpp

@@ -177,7 +177,7 @@ void TestsShell::ShutdownShell(bool reset_tests_render_interface)
 
 	Rml::Shutdown();
 
-	tests_system_interface.SetNumExpectedWarnings(0);
+	tests_system_interface.Reset();
 
 	if (use_backend_shell)
 		Backend::Shutdown();

+ 14 - 23
Tests/Source/UnitTests/Animation.cpp

@@ -283,7 +283,7 @@ TEST_CASE("animation.decorator")
 		{
 			const double t_final = 0.1;
 
-			system_interface->SetTime(0.0);
+			system_interface->SetManualTime(0.0);
 			String document_rml = Rml::CreateString(document_decorator_rml.c_str(), test.from_rule.c_str(), test.to_rule.c_str(),
 				property_str.c_str(), test.from.c_str(), property_str.c_str(), test.to.c_str());
 
@@ -293,7 +293,7 @@ TEST_CASE("animation.decorator")
 			document->Show();
 			TestsShell::RenderLoop();
 
-			system_interface->SetTime(0.25 * t_final);
+			system_interface->SetManualTime(0.25 * t_final);
 			TestsShell::RenderLoop();
 
 			CAPTURE(property_str);
@@ -305,8 +305,6 @@ TEST_CASE("animation.decorator")
 		}
 	}
 
-	system_interface->SetTime(0.0);
-
 	TestsShell::ShutdownShell();
 }
 
@@ -413,7 +411,7 @@ TEST_CASE("animation.filter")
 		{
 			const double t_final = 0.1;
 
-			system_interface->SetTime(0.0);
+			system_interface->SetManualTime(0.0);
 			String document_rml = Rml::CreateString(document_filter_rml.c_str(), property_str, test.from.c_str(), property_str, test.to.c_str());
 
 			ElementDocument* document = context->LoadDocumentFromMemory(document_rml, "assets/");
@@ -421,7 +419,7 @@ TEST_CASE("animation.filter")
 
 			document->Show();
 
-			system_interface->SetTime(0.25 * t_final);
+			system_interface->SetManualTime(0.25 * t_final);
 			TestsShell::RenderLoop();
 
 			CHECK_MESSAGE(element->GetProperty<String>(property_str) == test.expected_25p, property_str, " from: ", test.from, ", to: ", test.to);
@@ -430,8 +428,6 @@ TEST_CASE("animation.filter")
 		}
 	}
 
-	system_interface->SetTime(0.0);
-
 	TestsShell::ShutdownShell();
 }
 
@@ -488,7 +484,7 @@ TEST_CASE("animation.case_sensitivity")
 
 	for (const auto& test_case : test_cases)
 	{
-		system_interface->SetTime(0.0);
+		system_interface->SetManualTime(0.0);
 		INFO("@keyframes: ", test_case.keyframe_name);
 		INFO("animation: ", test_case.animation_name);
 
@@ -504,7 +500,7 @@ TEST_CASE("animation.case_sensitivity")
 		while (t < t_end)
 		{
 			t += dt;
-			system_interface->SetTime(t);
+			system_interface->SetManualTime(t);
 			context->Update();
 		}
 
@@ -513,7 +509,6 @@ TEST_CASE("animation.case_sensitivity")
 		document->Close();
 	}
 
-	system_interface->SetTime(0.0);
 	TestsShell::ShutdownShell();
 }
 
@@ -586,7 +581,7 @@ TEST_CASE("animation.case_sensitive_distinct_keyframes")
 	for (const auto& test_case : test_cases)
 	{
 		INFO("Class name: ", test_case.class_name);
-		system_interface->SetTime(0.0);
+		system_interface->SetManualTime(0.0);
 		ElementDocument* document = context->LoadDocumentFromMemory(document_rml, "assets/");
 		Element* element = document->GetChild(0);
 		element->SetClass(test_case.class_name, true);
@@ -599,7 +594,7 @@ TEST_CASE("animation.case_sensitive_distinct_keyframes")
 		while (t < t_end)
 		{
 			t += dt;
-			system_interface->SetTime(t);
+			system_interface->SetManualTime(t);
 			context->Update();
 		}
 
@@ -608,7 +603,6 @@ TEST_CASE("animation.case_sensitive_distinct_keyframes")
 		document->Close();
 	}
 
-	system_interface->SetTime(0.0);
 	TestsShell::ShutdownShell();
 }
 
@@ -682,7 +676,7 @@ TEST_CASE("animation.multiple_values")
 	};
 
 	{
-		system_interface->SetTime(0.0);
+		system_interface->SetManualTime(0.0);
 		ElementDocument* document = context->LoadDocumentFromMemory(document_multiple_values_rml, "assets/");
 		Element* element = document->GetChild(0);
 
@@ -695,7 +689,7 @@ TEST_CASE("animation.multiple_values")
 			while (t < test.time)
 			{
 				t = Math::Min(t + dt, test.time);
-				system_interface->SetTime(t);
+				system_interface->SetManualTime(t);
 				context->Update();
 			}
 
@@ -707,7 +701,6 @@ TEST_CASE("animation.multiple_values")
 		document->Close();
 	}
 
-	system_interface->SetTime(0.0);
 	TestsShell::ShutdownShell();
 }
 
@@ -798,7 +791,7 @@ TEST_CASE("animation.multiple_overlapping")
 	{
 		system_interface->SetNumExpectedWarnings(2);
 
-		system_interface->SetTime(0.0);
+		system_interface->SetManualTime(0.0);
 
 		ElementDocument* document = context->LoadDocumentFromMemory(document_animation_multiple_values_rml, "assets/");
 		Element* element = document->GetChild(0);
@@ -813,7 +806,7 @@ TEST_CASE("animation.multiple_overlapping")
 			while (t < test.time)
 			{
 				t = Math::Min(t + dt, test.time);
-				system_interface->SetTime(t);
+				system_interface->SetManualTime(t);
 				context->Update();
 			}
 
@@ -825,7 +818,6 @@ TEST_CASE("animation.multiple_overlapping")
 		document->Close();
 	}
 
-	system_interface->SetTime(0.0);
 	TestsShell::ShutdownShell();
 }
 
@@ -906,7 +898,7 @@ TEST_CASE("transition.display_and_visibility")
 	};
 
 	{
-		system_interface->SetTime(0.0);
+		system_interface->SetManualTime(0.0);
 
 		ElementDocument* document = context->LoadDocumentFromMemory(document_rml, "assets/");
 		Element* element = document->GetChild(0);
@@ -919,7 +911,7 @@ TEST_CASE("transition.display_and_visibility")
 			while (t < test.time)
 			{
 				t = Math::Min(t + dt, test.time);
-				system_interface->SetTime(t);
+				system_interface->SetManualTime(t);
 				TestsShell::RenderLoop(false);
 			}
 
@@ -938,6 +930,5 @@ TEST_CASE("transition.display_and_visibility")
 		document->Close();
 	}
 
-	system_interface->SetTime(0.0);
 	TestsShell::ShutdownShell();
 }

+ 3 - 3
Tests/Source/UnitTests/Element.cpp

@@ -439,11 +439,11 @@ TEST_CASE("Element.ScrollIntoView")
 		SUBCASE("Smoothscroll")
 		{
 			TestsSystemInterface* system_interface = TestsShell::GetTestsSystemInterface();
-			system_interface->SetTime(0);
+			system_interface->SetManualTime(0);
 			cells[3][3]->ScrollIntoView({ScrollAlignment::Nearest, ScrollAlignment::Nearest, ScrollBehavior::Smooth});
 
 			constexpr double dt = 1.0 / 15.0;
-			system_interface->SetTime(dt);
+			system_interface->SetManualTime(dt);
 			Run(context);
 
 			// We don't define the exact offset at this time step, but it should be somewhere between the start and end offsets.
@@ -456,7 +456,7 @@ TEST_CASE("Element.ScrollIntoView")
 			// After one second it should be at the destination offset.
 			for (double t = 2.0 * dt; t < 1.0; t += dt)
 			{
-				system_interface->SetTime(t);
+				system_interface->SetManualTime(t);
 				Run(context);
 			}
 			CHECK(cells[3][3]->GetAbsoluteOffset(Rml::BoxArea::Border) == Vector2f(50, 50));