Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make text drawing tests more lenient #1692

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/UnitTests/CoreGraphics.drawing/CGContextDrawingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

#include "DrawingTest.h"

DISABLED_DRAW_TEST_F(CGContext, RedBox, UIKitMimicTest) {
DISABLED_DRAW_TEST_F(CGContext, RedBox, UIKitMimicTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextFillRect(context, CGRectInset(bounds, 10, 10));
}

DISABLED_DRAW_TEST_F(CGContext, FillThenStrokeIsSameAsDrawFillStroke, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, FillThenStrokeIsSameAsDrawFillStroke, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand Down Expand Up @@ -62,7 +62,7 @@ static void _drawThreeCirclesInContext(CGContextRef context, CGRect bounds) {
}
}

DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesColorAlpha, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesColorAlpha, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -73,7 +73,7 @@ DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesColorAlpha, WhiteBackgroundTes
_drawThreeCirclesInContext(context, bounds);
}

DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesGlobalAlpha, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesGlobalAlpha, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -86,7 +86,7 @@ DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesGlobalAlpha, WhiteBackgroundTe
_drawThreeCirclesInContext(context, bounds);
}

DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesGlobalAlphaStackedWithColorAlpha, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesGlobalAlphaStackedWithColorAlpha, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -99,7 +99,7 @@ DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesGlobalAlphaStackedWithColorAlp
_drawThreeCirclesInContext(context, bounds);
}

DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesTransparencyLayerAlpha, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesTransparencyLayerAlpha, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -119,7 +119,7 @@ DISABLED_DRAW_TEST_F(CGContext, OverlappingCirclesTransparencyLayerAlpha, WhiteB
// This test proves that the path is stored fully transformed;
// changing the CTM before stroking it does not cause it to scale!
// However, the stroke width _is_ scaled (!)
DISABLED_DRAW_TEST_F(CGContext, ChangeCTMAfterCreatingPath, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, ChangeCTMAfterCreatingPath, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand Down
75 changes: 51 additions & 24 deletions tests/UnitTests/CoreGraphics.drawing/DrawingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@

static const CGSize g_defaultCanvasSize{ 512.f, 256.f };

woc::unique_cf<CGColorSpaceRef> testing::DrawTest::s_deviceColorSpace;
template <typename TComparator>
woc::unique_cf<CGColorSpaceRef> testing::DrawTest<TComparator>::s_deviceColorSpace;

void testing::DrawTest::SetUpTestCase() {
template <typename TComparator>
void testing::DrawTest<TComparator>::SetUpTestCase() {
s_deviceColorSpace.reset(CGColorSpaceCreateDeviceRGB());
}

void testing::DrawTest::TearDownTestCase() {
template <typename TComparator>
void testing::DrawTest<TComparator>::TearDownTestCase() {
s_deviceColorSpace.release();
}

CGSize testing::DrawTest::CanvasSize() {
template <typename TComparator>
CGSize testing::DrawTest<TComparator>::CanvasSize() {
return g_defaultCanvasSize;
}

void testing::DrawTest::SetUp() {
template <typename TComparator>
void testing::DrawTest<TComparator>::SetUp() {
CGSize size = CanvasSize();

_context.reset(CGBitmapContextCreate(
Expand All @@ -50,11 +55,13 @@ void testing::DrawTest::SetUp() {
SetUpContext();
}

CFStringRef testing::DrawTest::CreateAdditionalTestDescription() {
template <typename TComparator>
CFStringRef testing::DrawTest<TComparator>::CreateAdditionalTestDescription() {
return nullptr;
}

CFStringRef testing::DrawTest::CreateOutputFilename() {
template <typename TComparator>
CFStringRef testing::DrawTest<TComparator>::CreateOutputFilename() {
const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
woc::unique_cf<CFStringRef> additionalDesc{ CreateAdditionalTestDescription() };
woc::unique_cf<CFStringRef> filename{ CFStringCreateWithFormat(nullptr,
Expand All @@ -67,7 +74,8 @@ CFStringRef testing::DrawTest::CreateOutputFilename() {
return filename.release();
}

void testing::DrawTest::TearDown() {
template <typename TComparator>
void testing::DrawTest<TComparator>::TearDown() {
CGContextRef context = GetDrawingContext();

// Generate image from context.
Expand Down Expand Up @@ -108,7 +116,7 @@ void testing::DrawTest::TearDown() {
ASSERT_NE(nullptr, referenceImage);

// And fire off a comparator.
PixelByPixelImageComparator comparator;
TComparator comparator;
auto delta = comparator.CompareImages(referenceImage.get(), image.get());

if (delta.result != ImageComparisonResult::Same) {
Expand All @@ -134,29 +142,35 @@ void testing::DrawTest::TearDown() {
}
}

void testing::DrawTest::SetUpContext() {
template <typename TComparator>
void testing::DrawTest<TComparator>::SetUpContext() {
// The default context is fine as-is.
}

void testing::DrawTest::TestBody() {
template <typename TComparator>
void testing::DrawTest<TComparator>::TestBody() {
// Nothing.
}

CGContextRef testing::DrawTest::GetDrawingContext() {
template <typename TComparator>
CGContextRef testing::DrawTest<TComparator>::GetDrawingContext() {
return _context.get();
}

void testing::DrawTest::SetDrawingBounds(CGRect bounds) {
template <typename TComparator>
void testing::DrawTest<TComparator>::SetDrawingBounds(CGRect bounds) {
_bounds = bounds;
}

CGRect testing::DrawTest::GetDrawingBounds() {
template <typename TComparator>
CGRect testing::DrawTest<TComparator>::GetDrawingBounds() {
return _bounds;
}

void WhiteBackgroundTest::SetUpContext() {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
template <typename TComparator>
void WhiteBackgroundTest<TComparator>::SetUpContext() {
CGContextRef context = this->GetDrawingContext();
CGRect bounds = this->GetDrawingBounds();

CGContextSaveGState(context);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
Expand All @@ -166,21 +180,34 @@ void WhiteBackgroundTest::SetUpContext() {
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
}

CGSize UIKitMimicTest::CanvasSize() {
CGSize parent = WhiteBackgroundTest::CanvasSize();
template <typename TComparator>
CGSize UIKitMimicTest<TComparator>::CanvasSize() {
CGSize parent = WhiteBackgroundTest<TComparator>::CanvasSize();
return { parent.width * 2., parent.height * 2. };
}

void UIKitMimicTest::SetUpContext() {
WhiteBackgroundTest::SetUpContext();
template <typename TComparator>
void UIKitMimicTest<TComparator>::SetUpContext() {
WhiteBackgroundTest<TComparator>::SetUpContext();

CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
CGContextRef context = this->GetDrawingContext();
CGRect bounds = this->GetDrawingBounds();

CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0, -bounds.size.height);
CGContextScaleCTM(context, 2.0, 2.0);
bounds = CGRectApplyAffineTransform(bounds, CGAffineTransformMakeScale(.5, .5));

SetDrawingBounds(bounds);
this->SetDrawingBounds(bounds);
}

// Force templates so they compile
template class ::testing::DrawTest<>;
template class WhiteBackgroundTest<>;
template class UIKitMimicTest<>;
template class ::testing::DrawTest<PixelByPixelImageComparator<ComparisonMode::Mask>>;
template class WhiteBackgroundTest<PixelByPixelImageComparator<ComparisonMode::Mask>>;
template class UIKitMimicTest<PixelByPixelImageComparator<ComparisonMode::Mask>>;
template class ::testing::DrawTest<PixelByPixelImageComparator<ComparisonMode::Mask, 1024>>;
template class WhiteBackgroundTest<PixelByPixelImageComparator<ComparisonMode::Mask, 1024>>;
template class UIKitMimicTest<PixelByPixelImageComparator<ComparisonMode::Mask, 1024>>;
29 changes: 25 additions & 4 deletions tests/UnitTests/CoreGraphics.drawing/DrawingTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
#include <CoreGraphics/CoreGraphics.h>

#include <Starboard/SmartTypes.h>
#include "ImageComparison.h"

// Due to how templates are compiled as needed, any new usage of templates needs to be "forced" in DrawingTest.cpp

namespace testing {
template <typename TComparator = PixelByPixelImageComparator<ComparisonMode::Exact>>
class DrawTest : public ::testing::Test {
private:
woc::unique_cf<CGContextRef> _context;
Expand Down Expand Up @@ -63,24 +67,41 @@ inline CGRect _CGRectCenteredOnPoint(CGSize size, CGPoint point) {
};
}

class WhiteBackgroundTest : public ::testing::DrawTest {
template <typename TComparator = PixelByPixelImageComparator<>>
class WhiteBackgroundTest : public ::testing::DrawTest<TComparator> {
protected:
virtual void SetUpContext();
};

class UIKitMimicTest : public WhiteBackgroundTest {
template <typename TComparator = PixelByPixelImageComparator<>>
class UIKitMimicTest : public WhiteBackgroundTest<TComparator> {
protected:
virtual CGSize CanvasSize();
virtual void SetUpContext();
};

#define DRAW_TEST(test_case_name, test_name) \
GTEST_TEST_(test_case_name, test_name, ::testing::DrawTest, ::testing::internal::GetTestTypeId())
GTEST_TEST_(test_case_name, test_name, ::testing::DrawTest<>, ::testing::internal::GetTestTypeId())
#define DRAW_TEST_F(test_case_name, test_name, test_fixture) \
GTEST_TEST_(test_case_name, test_name, test_fixture, ::testing::internal::GetTestTypeId())

#define DISABLED_DRAW_TEST(test_case_name, test_name) DRAW_TEST(test_case_name, DISABLED_##test_name)
#define DISABLED_DRAW_TEST_F(test_case_name, test_name, test_fixture) DRAW_TEST_F(test_case_name, DISABLED_##test_name, test_fixture)

#define DRAW_TEST_P(test_case_name, test_name) TEST_P(test_case_name, test_name)
#define DISABLED_DRAW_TEST_P(test_case_name, test_name) DRAW_TEST_P(test_case_name, DISABLED_##test_name)
#define DISABLED_DRAW_TEST_P(test_case_name, test_name) DRAW_TEST_P(test_case_name, DISABLED_##test_name)

#define TEXT_DRAW_TEST(test_case_name, test_name) \
GTEST_TEST_(test_case_name, \
test_name, \
::testing::DrawTest<PixelByPixelImageComparator<ComparisonMode::Mask>>, \
::testing::internal::GetTestTypeId())
#define TEXT_DRAW_TEST_F(test_case_name, test_name, test_fixture) \
GTEST_TEST_(test_case_name, test_name, test_fixture, ::testing::internal::GetTestTypeId())

#define DISABLED_TEXT_DRAW_TEST(test_case_name, test_name) TEXT_DRAW_TEST(test_case_name, DISABLED_##test_name)
#define DISABLED_TEXT_DRAW_TEST_F(test_case_name, test_name, test_fixture) \
TEXT_DRAW_TEST_F(test_case_name, DISABLED_##test_name, test_fixture)

#define TEXT_DRAW_TEST_P(test_case_name, test_name) TEST_P(test_case_name, test_name)
#define DISABLED_TEXT_DRAW_TEST_P(test_case_name, test_name) TEXT_DRAW_TEST_P(test_case_name, DISABLED_##test_name)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "DrawingTest.h"

DISABLED_DRAW_TEST_F(CGContextFill, ConcentricCirclesWinding, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContextFill, ConcentricCirclesWinding, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -38,7 +38,7 @@ DISABLED_DRAW_TEST_F(CGContextFill, ConcentricCirclesWinding, WhiteBackgroundTes
CGPathRelease(concentricCirclesPath);
}

DISABLED_DRAW_TEST_F(CGContextFill, ConcentricCirclesEvenOdd, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContextFill, ConcentricCirclesEvenOdd, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -60,7 +60,7 @@ DISABLED_DRAW_TEST_F(CGContextFill, ConcentricCirclesEvenOdd, WhiteBackgroundTes
CGPathRelease(concentricCirclesPath);
}

DISABLED_DRAW_TEST_F(CGContextFill, ConcentricRectsWinding, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContextFill, ConcentricRectsWinding, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -82,7 +82,7 @@ DISABLED_DRAW_TEST_F(CGContextFill, ConcentricRectsWinding, WhiteBackgroundTest)
CGPathRelease(path);
}

DISABLED_DRAW_TEST_F(CGContextFill, ConcentricRectsEvenOdd, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContextFill, ConcentricRectsEvenOdd, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "DrawingTest.h"

DISABLED_DRAW_TEST_F(CGContext, Shadow, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, Shadow, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand All @@ -31,7 +31,7 @@ DISABLED_DRAW_TEST_F(CGContext, Shadow, WhiteBackgroundTest) {
CGContextStrokeRect(context, rect);
}

DISABLED_DRAW_TEST_F(CGContext, ShadowWithRotatedCTM, WhiteBackgroundTest) {
DISABLED_DRAW_TEST_F(CGContext, ShadowWithRotatedCTM, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand Down
Loading