Browse Source

Update tests

Michael Ragazzon 4 years ago
parent
commit
6a08691bf0

+ 2 - 5
Samples/assets/test.rcss → Tests/Data/UnitTests/test.rcss

@@ -1,9 +1,6 @@
-div {
-    background: #ccc;
-}
-
 body {
     display:block;
     width: 100px;
     height: 100px;
-}
+	background: #ccc;
+}

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

@@ -161,6 +161,7 @@ void TestsShell::ShutdownShell()
 #ifdef RMLUI_TESTS_USE_SHELL
 		Shell::CloseWindow();
 		Shell::Shutdown();
+		shell_render_interface.SetContext(nullptr);
 #endif
 
 		shell_context = nullptr;

+ 11 - 8
Tests/Source/UnitTests/MediaQueries.cpp → Tests/Source/UnitTests/MediaQuery.cpp

@@ -50,6 +50,7 @@ static const String document_media_query1_rml = R"(
 		div {
 			height: 48px;
 			width: 48px;
+			background: white;
 		}
 
 		@media (min-width: 640px) {
@@ -90,6 +91,7 @@ static const String document_media_query2_rml = R"(
 		div {
 			height: 48px;
 			width: 48px;
+			background: white;
 		}
 
 		@media (orientation: landscape) {
@@ -136,6 +138,7 @@ static const String document_media_query3_rml = R"(
 		div {
 			height: 48px;
 			width: 48px;
+			background: white;
 		}
 
 		@media (orientation: landscape) and (min-width: 640px) {
@@ -161,13 +164,13 @@ static const String document_media_query3_rml = R"(
 )";
 
 
-TEST_CASE("mediaqueries.basic")
+TEST_CASE("mediaquery.basic")
 {
 	Context* context = TestsShell::GetContext();
 	REQUIRE(context);
 
 	// There should be no warnings loading this document. There should be one div of 32px width & height
-	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query1_rml, "assets/");
+	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query1_rml);
 	REQUIRE(document);
 	document->Show();
 
@@ -189,13 +192,13 @@ TEST_CASE("mediaqueries.basic")
 	TestsShell::ShutdownShell();
 }
 
-TEST_CASE("mediaqueries.dynamic")
+TEST_CASE("mediaquery.dynamic")
 {
 	Context* context = TestsShell::GetContext();
 	REQUIRE(context);
 
 	// There should be no warnings loading this document. There should be one div of 32px width & height
-	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query1_rml, "assets/");
+	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query1_rml);
 	REQUIRE(document);
 	document->Show();
 
@@ -223,7 +226,7 @@ TEST_CASE("mediaqueries.dynamic")
 	TestsShell::ShutdownShell();
 }
 
-TEST_CASE("mediaqueries.custom_properties")
+TEST_CASE("mediaquery.custom_properties")
 {
 	Context* context = TestsShell::GetContext();
 	REQUIRE(context);
@@ -231,7 +234,7 @@ TEST_CASE("mediaqueries.custom_properties")
 	context->SetDensityIndependentPixelRatio(2.0f);
 
 	// There should be no warnings loading this document. There should be one div of 32px width & height
-	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query2_rml, "assets/");
+	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query2_rml);
 	REQUIRE(document);
 	document->Show();
 
@@ -253,13 +256,13 @@ TEST_CASE("mediaqueries.custom_properties")
 	TestsShell::ShutdownShell();
 }
 
-TEST_CASE("mediaqueries.composite")
+TEST_CASE("mediaquery.composite")
 {
 	Context* context = TestsShell::GetContext();
 	REQUIRE(context);
 
 	// There should be no warnings loading this document. There should be one div of 32px width & height
-	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query3_rml, "assets/");
+	ElementDocument* document = context->LoadDocumentFromMemory(document_media_query3_rml);
 	REQUIRE(document);
 	document->Show();
 

+ 54 - 15
Tests/Source/UnitTests/StyleSheet.cpp

@@ -34,42 +34,81 @@
 
 using namespace Rml;
 
-static const String simple_doc_rml = R"(
+static const String simple_doc1_rml = R"(
 <rml>
 <head>
 	<title>Test</title>
-	<link type="text/rcss" href="/assets/test.rcss"/>
+	<link type="text/rcss" href="/../Tests/Data/UnitTests/test.rcss"/>
 	<style>
 		body {
 			width: 48px;
 		}
 	</style>
 </head>
-
-<body>
-<div/>
-</body>
+<body/>
+</rml>
+)";
+static const String simple_doc2_rml = R"(
+<rml>
+<head>
+	<title>Test</title>
+	<style>
+		body {
+			width: 48px;
+		}
+	</style>
+	<link type="text/rcss" href="/../Tests/Data/UnitTests/test.rcss"/>
+</head>
+<body/>
+</rml>
+)";
+static const String simple_doc3_rml = R"(
+<rml>
+<head>
+	<title>Test</title>
+	<style>
+		body.narrow {
+			width: 48px;
+		}
+	</style>
+	<link type="text/rcss" href="/../Tests/Data/UnitTests/test.rcss"/>
+</head>
+<body class="narrow"/>
 </rml>
 )";
 
+
 TEST_CASE("stylesheet.override_basic")
 {
 	Context* context = TestsShell::GetContext();
 	REQUIRE(context);
 
-	// There should be no warnings loading this document.
-	ElementDocument* document = context->LoadDocumentFromMemory(simple_doc_rml, "assets/");
-	REQUIRE(document);
-	document->Show();
+	struct Test {
+		const String* document_rml;
+		float expected_width;
+	};
+
+	Test tests[] = {
+		{&simple_doc1_rml, 48.f},
+		{&simple_doc2_rml, 100.f},
+		{&simple_doc3_rml, 48.f},
+	};
+
+	for (const Test& test : tests)
+	{
+		ElementDocument* document = context->LoadDocumentFromMemory(*test.document_rml);
+		REQUIRE(document);
+		document->Show();
 
-	context->Update();
-	context->Render();
+		context->Update();
+		context->Render();
 
-	TestsShell::RenderLoop();
+		TestsShell::RenderLoop();
 
-	CHECK(document->GetBox() == Box(Vector2f(48.0f, 100.0f)));
+		CHECK(document->GetBox().GetSize().x == test.expected_width);
 
-	document->Close();
+		document->Close();
+	}
 
 	TestsShell::ShutdownShell();
 }