Переглянути джерело

Regression tested sub-images.

David Piuva 5 роки тому
батько
коміт
54725f762e
2 змінених файлів з 66 додано та 1 видалено
  1. 1 1
      Source/test/tests/DrawTest.cpp
  2. 65 0
      Source/test/tests/ImageTest.cpp

+ 1 - 1
Source/test/tests/DrawTest.cpp

@@ -40,7 +40,7 @@ START_TEST(Draw)
 	draw_rectangle(imageA, IRect(11, 11, 2, 2), white);
 
 	// TODO: Make a reusable macro for comparing images and showing them when a test fails.
-	ASSERT_LESSER_OR_EQUAL(image_maxDifference(imageA, expected1), 1);
+	ASSERT_EQUAL(image_maxDifference(imageA, expected1), 0);
 	//printText("imageA:\n", image_toAscii(imageA, " .x"), "\n");
 END_TEST
 

+ 65 - 0
Source/test/tests/ImageTest.cpp

@@ -82,5 +82,70 @@ START_TEST(Image)
 		image = image_create_RgbaU8(4, 32768);
 		ASSERT_EQUAL(image_isTexture(image), false); // Too high
 	}
+	{ // Sub-images
+		ImageU8 parentImage = image_fromAscii(
+			"< .x>"
+			"< ..  .. >"
+			"<..x..x..>"
+			"<.xx..xx.>"
+			"< ..xx.. >"
+			"< ..xx.. >"
+			"<.xx..xx.>"
+			"<..x..x..>"
+			"< ..  .. >"
+		);
+		ImageU8 upperLeftSubImage = image_getSubImage(parentImage, IRect(0, 0, 4, 4));
+		ImageU8 upperRightSubImage = image_getSubImage(parentImage, IRect(4, 0, 4, 4));
+		ImageU8 lowerLeftSubImage = image_getSubImage(parentImage, IRect(0, 4, 4, 4));
+		ImageU8 lowerRightSubImage = image_getSubImage(parentImage, IRect(4, 4, 4, 4));
+		ImageU8 centerSubImage = image_getSubImage(parentImage, IRect(2, 2, 4, 4));
+		ASSERT_EQUAL(image_maxDifference(upperLeftSubImage, image_fromAscii(
+			"< .x>"
+			"< .. >"
+			"<..x.>"
+			"<.xx.>"
+			"< ..x>"
+		)), 0);
+		ASSERT_EQUAL(image_maxDifference(upperRightSubImage, image_fromAscii(
+			"< .x>"
+			"< .. >"
+			"<.x..>"
+			"<.xx.>"
+			"<x.. >"
+		)), 0);
+		ASSERT_EQUAL(image_maxDifference(lowerLeftSubImage, image_fromAscii(
+			"< .x>"
+			"< ..x>"
+			"<.xx.>"
+			"<..x.>"
+			"< .. >"
+		)), 0);
+		ASSERT_EQUAL(image_maxDifference(lowerRightSubImage, image_fromAscii(
+			"< .x>"
+			"<x.. >"
+			"<.xx.>"
+			"<.x..>"
+			"< .. >"
+		)), 0);
+		ASSERT_EQUAL(image_maxDifference(centerSubImage, image_fromAscii(
+			"< .x>"
+			"<x..x>"
+			"<.xx.>"
+			"<.xx.>"
+			"<x..x>"
+		)), 0);
+		image_fill(centerSubImage, 0);
+		ASSERT_EQUAL(image_maxDifference(parentImage, image_fromAscii(
+			"< .x>"
+			"< ..  .. >"
+			"<..x..x..>"
+			"<.x    x.>"
+			"< .    . >"
+			"< .    . >"
+			"<.x    x.>"
+			"<..x..x..>"
+			"< ..  .. >"
+		)), 0);
+	}
 END_TEST