From f194201e5e199e9461eec5e3f6a9da0d7a459258 Mon Sep 17 00:00:00 2001 From: AJ Ballway Date: Mon, 23 Jan 2017 18:05:38 -0800 Subject: [PATCH] Fix CT drawing tests on ARM (#1780) --- .../CoreGraphics.drawing/DrawingTest.cpp | 23 ++++++--- .../CoreGraphics.drawing/DrawingTest.h | 2 +- .../CoreGraphics.drawing/CGTextDrawing.cpp | 12 ++--- .../CoreGraphics.drawing/CTDrawingTests.cpp | 28 +++++------ .../CoreGraphics.drawing/ImageComparison.cpp | 47 +++++++------------ .../CoreGraphics.drawing/ImageComparison.h | 20 +++++++- .../TestImage.CTFrame.BasicUnicodeTest.png | 4 +- 7 files changed, 75 insertions(+), 61 deletions(-) diff --git a/tests/UnitTests/CoreGraphics.drawing/DrawingTest.cpp b/tests/UnitTests/CoreGraphics.drawing/DrawingTest.cpp index 0dde5ff633..ecd99d8631 100644 --- a/tests/UnitTests/CoreGraphics.drawing/DrawingTest.cpp +++ b/tests/UnitTests/CoreGraphics.drawing/DrawingTest.cpp @@ -123,7 +123,7 @@ void testing::DrawTest::TearDown() { if (delta.result == ImageComparisonResult::Incomparable) { ADD_FAILURE() << "images are incomparable due to a mismatch in dimensions, presence, or byte length"; } else { - ADD_FAILURE() << "images differ nontrivially"; + ADD_FAILURE() << "images differ nontrivially with " << delta.differences << " registered differences"; } woc::unique_cf deltaFilename{ @@ -205,9 +205,18 @@ void UIKitMimicTest::SetUpContext() { template class ::testing::DrawTest<>; template class WhiteBackgroundTest<>; template class UIKitMimicTest<>; -template class ::testing::DrawTest>; -template class WhiteBackgroundTest>; -template class UIKitMimicTest>; -template class ::testing::DrawTest>; -template class WhiteBackgroundTest>; -template class UIKitMimicTest>; \ No newline at end of file +template class ::testing::DrawTest>>; +template class WhiteBackgroundTest>>; +template class UIKitMimicTest>>; +template class ::testing::DrawTest>>; +template class ::testing::DrawTest>>; +template class ::testing::DrawTest>>; +template class ::testing::DrawTest>>; +template class WhiteBackgroundTest>>; +template class WhiteBackgroundTest>>; +template class WhiteBackgroundTest>>; +template class WhiteBackgroundTest>>; +template class UIKitMimicTest>>; +template class UIKitMimicTest>>; +template class UIKitMimicTest>>; +template class UIKitMimicTest>>; \ No newline at end of file diff --git a/tests/UnitTests/CoreGraphics.drawing/DrawingTest.h b/tests/UnitTests/CoreGraphics.drawing/DrawingTest.h index 513981cfbe..027499a854 100644 --- a/tests/UnitTests/CoreGraphics.drawing/DrawingTest.h +++ b/tests/UnitTests/CoreGraphics.drawing/DrawingTest.h @@ -25,7 +25,7 @@ // Due to how templates are compiled as needed, any new usage of templates needs to be "forced" in DrawingTest.cpp namespace testing { -template > +template > class DrawTest : public ::testing::Test { private: woc::unique_cf _context; diff --git a/tests/unittests/CoreGraphics.drawing/CGTextDrawing.cpp b/tests/unittests/CoreGraphics.drawing/CGTextDrawing.cpp index 8329f1213f..49487c3231 100644 --- a/tests/unittests/CoreGraphics.drawing/CGTextDrawing.cpp +++ b/tests/unittests/CoreGraphics.drawing/CGTextDrawing.cpp @@ -32,7 +32,7 @@ static void __SetFontForContext(CGContextRef context) { CGContextSetFontSize(context, 144); } -TEXT_DRAW_TEST_F(CGContext, ShowGlyphs, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CGContext, ShowGlyphs, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); std::vector glyphs{ __CreateGlyphs() }; __SetFontForContext(context); @@ -40,14 +40,14 @@ TEXT_DRAW_TEST_F(CGContext, ShowGlyphs, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CGContext, ShowGlyphsAtPoint, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); std::vector glyphs{ __CreateGlyphs() }; __SetFontForContext(context); CGContextShowGlyphsAtPoint(context, 25, 50, glyphs.data(), glyphs.size()); } -TEXT_DRAW_TEST_F(CGContext, DrawWithRotatedTextMatrix, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CGContext, DrawWithRotatedTextMatrix, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); std::vector glyphs{ __CreateGlyphs() }; __SetFontForContext(context); @@ -68,7 +68,7 @@ static const CGAffineTransform c_transforms[] = { CGAffineTransformMakeRotation( { 2, 2, 1.75, 2, 0, 0 }, CGAffineTransformIdentity }; -class CGTransform : public WhiteBackgroundTest>, +class CGTransform : public WhiteBackgroundTest>>, public ::testing::WithParamInterface<::testing::tuple> {}; TEXT_DRAW_TEST_P(CGTransform, TestMatrices) { @@ -87,7 +87,7 @@ INSTANTIATE_TEST_CASE_P(TestDrawingTextWithTransformedMatrices, CGTransform, ::testing::Combine(::testing::ValuesIn(c_transforms), ::testing::ValuesIn(c_transforms))); -class CGUIKitTransform : public UIKitMimicTest>, +class CGUIKitTransform : public UIKitMimicTest>>, public ::testing::WithParamInterface<::testing::tuple> {}; TEXT_DRAW_TEST_P(CGUIKitTransform, TestMatrices) { @@ -109,7 +109,7 @@ INSTANTIATE_TEST_CASE_P(TestDrawingTextWithTransformedMatrices, // On reference platform, CGContextShowText* can only be used with CGContextSelectFont // Which we do not currently support. #ifdef WINOBJC -TEXT_DRAW_TEST_F(CGContext, ShowTextAtPoint, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CGContext, ShowTextAtPoint, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); __SetFontForContext(context); CGContextShowTextAtPoint(context, 25, 50, "TEST", 4); diff --git a/tests/unittests/CoreGraphics.drawing/CTDrawingTests.cpp b/tests/unittests/CoreGraphics.drawing/CTDrawingTests.cpp index 119bf60c16..c1a1a5d93d 100644 --- a/tests/unittests/CoreGraphics.drawing/CTDrawingTests.cpp +++ b/tests/unittests/CoreGraphics.drawing/CTDrawingTests.cpp @@ -26,7 +26,7 @@ static NSURL* __GetURLFromPathRelativeToModuleDirectory(NSString* relativePath) } #endif // WINOBJC -TEXT_DRAW_TEST_F(CTFrame, BasicDrawingTest, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CTFrame, BasicDrawingTest, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); @@ -65,7 +65,7 @@ TEXT_DRAW_TEST_F(CTFrame, BasicDrawingTest, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CTFrame, BasicUIKitMimicDrawingTest, UIKitMimicTest>>) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); @@ -104,7 +104,7 @@ TEXT_DRAW_TEST_F(CTFrame, BasicUIKitMimicDrawingTest, UIKitMimicTest>) { +TEXT_DRAW_TEST_F(CTFrame, BasicUnicodeTest, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); @@ -133,7 +133,7 @@ TEXT_DRAW_TEST_F(CTFrame, BasicUnicodeTest, WhiteBackgroundTest attrString{ - CFAttributedStringCreate(nullptr, CFSTR("он прошел այն անցավ ມັນຜ່ານໄປ ਇਸ ਨੂੰ ਪਾਸ ਕੀਤਾ 它通過了 그것이 통과했다 minęło"), dict.get()) + CFAttributedStringCreate(nullptr, CFSTR("он прошел այն անցավ ມັນຜ່ານໄປ minęło"), dict.get()) }; woc::unique_cf framesetter{ CTFramesetterCreateWithAttributedString(attrString.get()) }; @@ -145,7 +145,7 @@ TEXT_DRAW_TEST_F(CTFrame, BasicUnicodeTest, WhiteBackgroundTest>, +class CTFrame : public WhiteBackgroundTest>>, public ::testing::WithParamInterface<::testing::tuple> { CFStringRef CreateOutputFilename() { CTTextAlignment alignment = ::testing::get<0>(GetParam()); @@ -237,7 +237,7 @@ INSTANTIATE_TEST_CASE_P(TestAlignmentLineBreakMode, ::testing::ValuesIn(c_writingDirections), ::testing::ValuesIn(c_fontSizes))); -class Transform : public WhiteBackgroundTest>, +class Transform : public WhiteBackgroundTest>>, public ::testing::WithParamInterface<::testing::tuple> {}; TEXT_DRAW_TEST_P(Transform, TestMatrices) { @@ -292,7 +292,7 @@ INSTANTIATE_TEST_CASE_P(TestDrawingTextWithTransformedMatrices, Transform, ::testing::Combine(::testing::ValuesIn(c_transforms), ::testing::ValuesIn(c_transforms))); -class UIKitTransform : public UIKitMimicTest>, +class UIKitTransform : public UIKitMimicTest>>, public ::testing::WithParamInterface<::testing::tuple> {}; TEXT_DRAW_TEST_P(UIKitTransform, TestMatrices) { @@ -335,7 +335,7 @@ INSTANTIATE_TEST_CASE_P(TestDrawingUITransforms, UIKitTransform, ::testing::Combine(::testing::ValuesIn(c_transforms), ::testing::ValuesIn(c_transforms))); -class ExtraKerning : public WhiteBackgroundTest>, +class ExtraKerning : public WhiteBackgroundTest>>, public ::testing::WithParamInterface { CFStringRef CreateOutputFilename() { CGFloat extraKerning = GetParam(); @@ -373,7 +373,7 @@ TEXT_DRAW_TEST_P(ExtraKerning, TestExtraKerning) { static constexpr CGFloat c_extraKernings[] = { -1.0, 1.0, 5.25, 25.75 }; INSTANTIATE_TEST_CASE_P(TestDrawingTextInExtraKerning, ExtraKerning, ::testing::ValuesIn(c_extraKernings)); -class LineHeightMultiple : public WhiteBackgroundTest>, +class LineHeightMultiple : public WhiteBackgroundTest>>, public ::testing::WithParamInterface { CFStringRef CreateOutputFilename() { CGFloat lineHeightMultiple = GetParam(); @@ -412,7 +412,7 @@ TEXT_DRAW_TEST_P(LineHeightMultiple, TestLineHeightMultiple) { static constexpr CGFloat c_lineHeightMultiples[] = { -1.0, .75, 1.25 }; INSTANTIATE_TEST_CASE_P(TestDrawingTextInLineHeightMultiple, LineHeightMultiple, ::testing::ValuesIn(c_lineHeightMultiples)); -TEXT_DRAW_TEST_F(CTRun, BasicDrawingTest, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CTRun, BasicDrawingTest, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); @@ -440,7 +440,7 @@ TEXT_DRAW_TEST_F(CTRun, BasicDrawingTest, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CTLine, BasicDrawingTest, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); @@ -470,7 +470,7 @@ TEXT_DRAW_TEST_F(CTLine, BasicDrawingTest, WhiteBackgroundTest>, +class Fonts : public WhiteBackgroundTest>>, public ::testing::WithParamInterface { CFStringRef CreateOutputFilename() { CFStringRef fontName = GetParam(); @@ -508,7 +508,7 @@ static CFStringRef c_fontNames[] = { CFSTR("Arial"), CFSTR("Times New Roman"), C INSTANTIATE_TEST_CASE_P(TestDrawingTextInFonts, Fonts, ::testing::ValuesIn(c_fontNames)); #ifdef WINOBJC -TEXT_DRAW_TEST_F(CTFontManager, DrawWithCustomFont, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CTFontManager, DrawWithCustomFont, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); @@ -555,7 +555,7 @@ TEXT_DRAW_TEST_F(CTFontManager, DrawWithCustomFont, WhiteBackgroundTest>) { +TEXT_DRAW_TEST_F(CTFont, DrawGlyphs, WhiteBackgroundTest>>) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); diff --git a/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp b/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp index 974eb8c772..f95e882427 100644 --- a/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp +++ b/tests/unittests/CoreGraphics.drawing/ImageComparison.cpp @@ -23,25 +23,14 @@ struct bgraPixel { uint8_t b, g, r, a; }; -struct rgbaPixel { - uint8_t r, g, b, a; -}; - template bool operator==(const T& t, const U& u) { return t.r == u.r && t.g == u.g && t.b == u.b && t.a == u.a; } -template -struct __comparePixels { - template - rgbaPixel operator()(const LP& background, const LP& bp, const RP& cp, size_t& npxchg); -}; - -template <> -struct __comparePixels { - template - rgbaPixel operator()(const LP& background, const LP& bp, const RP& cp, size_t& npxchg) { +template +template +rgbaPixel PixelComparisonModeExact::ComparePixels(const LP& background, const LP& bp, const RP& cp, size_t& npxchg) { rgbaPixel gp{}; if (!(bp == cp)) { ++npxchg; @@ -61,13 +50,11 @@ struct __comparePixels { } return gp; - } -}; +} -template <> -struct __comparePixels { - template - rgbaPixel operator()(const LP& background, const LP& bp, const RP& cp, size_t& npxchg) { +template +template +rgbaPixel PixelComparisonModeMask::ComparePixels(const LP& background, const LP& bp, const RP& cp, size_t& npxchg) { rgbaPixel gp{}; if (!(bp == cp)) { ++npxchg; @@ -90,11 +77,10 @@ struct __comparePixels { } return gp; - } -}; +} -template -ImageDelta PixelByPixelImageComparator::CompareImages(CGImageRef left, CGImageRef right) { +template +ImageDelta PixelByPixelImageComparator::CompareImages(CGImageRef left, CGImageRef right) { if (!left || !right) { return { ImageComparisonResult::Incomparable }; } @@ -133,12 +119,12 @@ ImageDelta PixelByPixelImageComparator::CompareImages(CG auto background = leftPixels[0]; size_t npxchg = 0; - __comparePixels pixelComparitor{}; + PixelComparisonMode mode; for (off_t i = 0; i < leftLength / sizeof(rgbaPixel); ++i) { auto& bp = leftPixels[i]; auto& cp = rightPixels[i]; auto& gp = deltaPixels[i]; - gp = pixelComparitor(background, bp, cp, npxchg); + gp = mode.ComparePixels(background, bp, cp, npxchg); } woc::unique_cf deltaData{ CFDataCreateWithBytesNoCopy(nullptr, deltaBuffer.release(), leftLength, kCFAllocatorDefault) }; @@ -157,11 +143,14 @@ ImageDelta PixelByPixelImageComparator::CompareImages(CG kCGRenderingIntentDefault) }; return { - (npxchg < FailureThreshold ? ImageComparisonResult::Same : ImageComparisonResult::Different), npxchg, deltaImage.get(), + (npxchg < PixelComparisonMode::Threshold ? ImageComparisonResult::Same : ImageComparisonResult::Different), npxchg, deltaImage.get(), }; } // Force templates so they compile template class PixelByPixelImageComparator<>; -template class PixelByPixelImageComparator; -template class PixelByPixelImageComparator; \ No newline at end of file +template class PixelByPixelImageComparator>; +template class PixelByPixelImageComparator>; +template class PixelByPixelImageComparator>; +template class PixelByPixelImageComparator>; +template class PixelByPixelImageComparator>; \ No newline at end of file diff --git a/tests/unittests/CoreGraphics.drawing/ImageComparison.h b/tests/unittests/CoreGraphics.drawing/ImageComparison.h index e411dd065b..fb0f2a540f 100644 --- a/tests/unittests/CoreGraphics.drawing/ImageComparison.h +++ b/tests/unittests/CoreGraphics.drawing/ImageComparison.h @@ -21,7 +21,23 @@ enum class ImageComparisonResult : unsigned int { Unknown = 0, Incomparable, Different, Same }; -enum struct ComparisonMode { Exact, Mask }; +struct rgbaPixel { + uint8_t r, g, b, a; +}; + +template +struct PixelComparisonModeExact { + static constexpr size_t Threshold = FailureThreshold; + template + rgbaPixel ComparePixels(const LP& background, const LP& bp, const RP& cp, size_t& npxchg); +}; + +template +struct PixelComparisonModeMask { + static constexpr size_t Threshold = FailureThreshold; + template + rgbaPixel ComparePixels(const LP& background, const LP& bp, const RP& cp, size_t& npxchg); +}; struct ImageDelta { ImageComparisonResult result; @@ -41,7 +57,7 @@ class ImageComparator { virtual ImageDelta CompareImages(CGImageRef left, CGImageRef right) = 0; }; -template +template > class PixelByPixelImageComparator : public ImageComparator { public: ImageDelta CompareImages(CGImageRef left, CGImageRef right) override; diff --git a/tests/unittests/CoreGraphics.drawing/data/reference/TestImage.CTFrame.BasicUnicodeTest.png b/tests/unittests/CoreGraphics.drawing/data/reference/TestImage.CTFrame.BasicUnicodeTest.png index 278096b3d8..cb80f47748 100644 --- a/tests/unittests/CoreGraphics.drawing/data/reference/TestImage.CTFrame.BasicUnicodeTest.png +++ b/tests/unittests/CoreGraphics.drawing/data/reference/TestImage.CTFrame.BasicUnicodeTest.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6b63a0fa546794e968c3f593ffd17646dbfe19bc7fe1074ab74ab41858cbd68c -size 7974 +oid sha256:0a5cd002e98d0b48c570debe2cc1adbb610728d21a4de04db99b33fef88c1b6c +size 4543