@@ -49,22 +49,22 @@ void ClearRenderTargetReference(IRenderDevice* pDevice,
4949namespace
5050{
5151
52- class ComparisonFailureImageGuard
52+ class DifferenceImageGuard
5353{
5454public:
55- ComparisonFailureImageGuard ( ) :
56- m_FileName{GetTestImageComparisonFailureFileName ( )}
55+ explicit DifferenceImageGuard ( bool ComparisonPassed ) :
56+ m_FileName{GetTestImageDifferenceFileName (ComparisonPassed )}
5757 {}
5858
59- ~ComparisonFailureImageGuard ()
59+ ~DifferenceImageGuard ()
6060 {
6161 if (!m_FileName.empty ())
6262 FileSystem::DeleteFile (m_FileName.c_str ());
6363 }
6464
6565 // clang-format off
66- ComparisonFailureImageGuard (const ComparisonFailureImageGuard &) = delete ;
67- ComparisonFailureImageGuard & operator =(const ComparisonFailureImageGuard &) = delete ;
66+ DifferenceImageGuard (const DifferenceImageGuard &) = delete ;
67+ DifferenceImageGuard & operator =(const DifferenceImageGuard &) = delete ;
6868 // clang-format on
6969
7070 const std::string& GetFileName () const
@@ -89,10 +89,10 @@ TEST(TestingSwapChainBaseTest, ExactComparisonAcceptsIdenticalImages)
8989 8 ,
9090 };
9191
92- std::unordered_map<std::string, int > FailureCounters ;
92+ std::unordered_map<std::string, int > DifferenceCounters ;
9393 CompareTestImages (Pixels.data (), 8 , Pixels.data (), 8 , 2 , 1 ,
94- TEX_FORMAT_RGBA8_UNORM , FailureCounters );
95- EXPECT_TRUE (FailureCounters .empty ());
94+ TEX_FORMAT_RGBA8_UNORM , DifferenceCounters );
95+ EXPECT_TRUE (DifferenceCounters .empty ());
9696}
9797
9898TEST (TestingSwapChainBaseTest, ToleratesConfiguredImageDifferences)
@@ -122,12 +122,13 @@ TEST(TestingSwapChainBaseTest, ToleratesConfiguredImageDifferences)
122122 ComparisonAttribs.MaxChannelError = 2 ;
123123 ComparisonAttribs.MaxBadPixelRatio = 0 .5f ;
124124
125- std::unordered_map<std::string, int > FailureCounters ;
126- ComparisonFailureImageGuard FailureImageGuard ;
125+ std::unordered_map<std::string, int > DifferenceCounters ;
126+ DifferenceImageGuard ImageGuard{ true } ;
127127 CompareTestImages (Reference.data (), 8 , Actual.data (), 8 , 2 , 1 ,
128- TEX_FORMAT_RGBA8_UNORM , FailureCounters, ComparisonAttribs);
129- EXPECT_EQ (FailureCounters.size (), 1u );
130- EXPECT_TRUE (FileSystem::FileExists (FailureImageGuard.GetFileName ().c_str ()));
128+ TEX_FORMAT_RGBA8_UNORM , DifferenceCounters, ComparisonAttribs);
129+ EXPECT_EQ (DifferenceCounters.size (), 1u );
130+ EXPECT_TRUE (FileSystem::FileExists (ImageGuard.GetFileName ().c_str ()));
131+ EXPECT_NE (ImageGuard.GetFileName ().find (" _DIFF_OK" ), std::string::npos);
131132}
132133
133134#if !PLATFORM_WEB
@@ -159,31 +160,32 @@ TEST(TestingSwapChainBaseTest, ReportsOnlyNonEmptyDifferenceCategories)
159160 ComparisonAttribs.MaxChannelError = 2 ;
160161
161162 testing::internal::CaptureStdout ();
162- std::unordered_map<std::string, int > FailureCounters ;
163- ComparisonFailureImageGuard FailureImageGuard ;
163+ std::unordered_map<std::string, int > DifferenceCounters ;
164+ DifferenceImageGuard ImageGuard{ true } ;
164165 CompareTestImages (Reference.data (), 8 , Actual.data (), 8 , 2 , 1 ,
165- TEX_FORMAT_RGBA8_UNORM , FailureCounters , ComparisonAttribs);
166+ TEX_FORMAT_RGBA8_UNORM , DifferenceCounters , ComparisonAttribs);
166167 const std::string Output = testing::internal::GetCapturedStdout ();
167168
168169 EXPECT_NE (Output.find (" 1 of 2 pixels differ but remain within the per-channel error threshold 2; "
169170 " maximum channel error is 2" ),
170171 std::string::npos);
171172 EXPECT_EQ (Output.find (" exceed the threshold" ), std::string::npos);
172- EXPECT_TRUE (FileSystem::FileExists (FailureImageGuard .GetFileName ().c_str ()));
173+ EXPECT_TRUE (FileSystem::FileExists (ImageGuard .GetFileName ().c_str ()));
173174}
174175
175- TEST (TestingSwapChainBaseTest, AddsRenderDeviceTypeToFailureImageName )
176+ TEST (TestingSwapChainBaseTest, AddsRenderDeviceTypeToDifferenceImageName )
176177{
177178 constexpr std::array<Uint8, 4 > Reference{255 , 255 , 255 , 255 };
178179 constexpr std::array<Uint8, 4 > Actual{0 , 255 , 255 , 255 };
179180
180- std::unordered_map<std::string, int > FailureCounters ;
181- ComparisonFailureImageGuard FailureImageGuard ;
181+ std::unordered_map<std::string, int > DifferenceCounters ;
182+ DifferenceImageGuard ImageGuard{ false } ;
182183 EXPECT_NONFATAL_FAILURE (
183184 CompareTestImages (Reference.data (), 4 , Actual.data (), 4 , 1 , 1 ,
184- TEX_FORMAT_RGBA8_UNORM , FailureCounters ),
185+ TEX_FORMAT_RGBA8_UNORM , DifferenceCounters ),
185186 " Image rendered by the test differs from the reference image" );
186- EXPECT_TRUE (FileSystem::FileExists (FailureImageGuard.GetFileName ().c_str ()));
187+ EXPECT_TRUE (FileSystem::FileExists (ImageGuard.GetFileName ().c_str ()));
188+ EXPECT_NE (ImageGuard.GetFileName ().find (" _DIFF_FAIL" ), std::string::npos);
187189}
188190
189191TEST (TestingSwapChainBaseTest, ReportsToleratedAndBadPixelStatistics)
@@ -228,11 +230,11 @@ TEST(TestingSwapChainBaseTest, ReportsToleratedAndBadPixelStatistics)
228230 TestImageComparisonAttribs ComparisonAttribs;
229231 ComparisonAttribs.MaxChannelError = 2 ;
230232
231- std::unordered_map<std::string, int > FailureCounters ;
232- ComparisonFailureImageGuard FailureImageGuard ;
233+ std::unordered_map<std::string, int > DifferenceCounters ;
234+ DifferenceImageGuard ImageGuard{ false } ;
233235 EXPECT_NONFATAL_FAILURE (
234236 CompareTestImages (Reference.data (), 16 , Actual.data (), 16 , 4 , 1 ,
235- TEX_FORMAT_RGBA8_UNORM , FailureCounters , ComparisonAttribs),
237+ TEX_FORMAT_RGBA8_UNORM , DifferenceCounters , ComparisonAttribs),
236238 " 1 of 4 pixels differ but remain within the per-channel error threshold 2; maximum channel error is 2\n "
237239 " 1 of 4 pixels (25%) exceed the threshold; maximum channel error is 23; "
238240 " up to 0 bad pixels are allowed" );
@@ -268,7 +270,7 @@ void TestSnapshotComparison(Int32 Channel)
268270
269271 if (Channel >= 0 )
270272 {
271- ComparisonFailureImageGuard FailureImageGuard ;
273+ DifferenceImageGuard ImageGuard{ false } ;
272274 EXPECT_NONFATAL_FAILURE (
273275 pTestingSwapChain->CompareWithSnapshot (nullptr ),
274276 " Image rendered by the test differs from the reference image" );
@@ -314,7 +316,7 @@ void TestImageComparison(Int32 Channel)
314316
315317 if (Channel >= 0 )
316318 {
317- ComparisonFailureImageGuard FailureImageGuard ;
319+ DifferenceImageGuard ImageGuard{ false } ;
318320 EXPECT_NONFATAL_FAILURE (
319321 pTestingSwapChain->CompareWithSnapshot (nullptr ),
320322 " Image rendered by the test differs from the reference image" );
0 commit comments