Skip to content

Commit

Permalink
Enabling some image drawing tests, moving image drawing to a separate… (
Browse files Browse the repository at this point in the history
#1605)

* Enabling some image drawing tests, moving image drawing to a separate file and updating some image file names
  • Loading branch information
msft-Jeyaram authored Feb 8, 2017
1 parent 0a3efb0 commit 4527ce3
Show file tree
Hide file tree
Showing 33 changed files with 293 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\CGContextDrawing_ShadowTests.cpp" />
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\CGContextDrawing_ImageMaskTests.cpp" />
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\CGContextDrawing_GradientTests.cpp" />
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\CGContextDrawing_ImageDrawingTests.cpp" />
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\CGPathDrawingTests.cpp" />
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\DrawingTest.cpp" />
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.drawing\ImageComparison.cpp" />
Expand Down
260 changes: 1 addition & 259 deletions tests/UnitTests/CoreGraphics.drawing/CGContextDrawingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,272 +239,14 @@ DISABLED_DRAW_TEST_F(CGContext, PatternFillWindowsLogoPath, UIKitMimicTest<>) {
CGPathRelease(thepath);
}

#ifdef WINOBJC
#include "CGContextInternal.h"

DISABLED_DRAW_TEST_F(CGContext, DrawIntoRect, UIKitMimicTest<>) {
// Draw a portion of an image into a different region.
auto drawingConfig = DrawingTestConfig::Get();

woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("png1.9.png")) };
woc::unique_cf<CGImageRef> image{ _CGImageCreateFromPNGFile(testFilename.get()) };
ASSERT_NE(image, nullptr);

CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGAffineTransform flip = CGAffineTransformMakeScale(1, -1);
CGAffineTransform shift = CGAffineTransformTranslate(flip, 0, bounds.size.height * -1);
CGContextConcatCTM(context, shift);

_CGContextDrawImageRect(context,
image.get(),
{ 0, 0, bounds.size.width / 4, bounds.size.height / 4 },
{ 0, 0, bounds.size.width, bounds.size.height });
}
#endif

static void _drawTiledImage(CGContextRef context, CGRect rect, const std::string& name) {
auto drawingConfig = DrawingTestConfig::Get();
woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath(name)) };
woc::unique_cf<CGImageRef> image{ _CGImageCreateFromPNGFile(testFilename.get()) };
ASSERT_NE(image, nullptr);
CGContextDrawTiledImage(context, rect, image.get());
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeart, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 128, 128 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeartScaledUp, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 250, 250 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeartScaledTiny, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 1, 1 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeartScaledAlpha1, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 100, 100 } };
CGContextSetAlpha(GetDrawingContext(), 0.8);
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeartScaledAlpha2, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 256, 256 } };
CGContextSetAlpha(GetDrawingContext(), 0.24);
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeartScaledAlpha3, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 300, 513 } };
CGContextSetAlpha(GetDrawingContext(), 0.66);
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeartScaledDown, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 50, 50 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageHeartScaled, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 250, 128 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageHeart.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDog, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 256, 256 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaledDown, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 50, 50 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaledUp, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 512, 512 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaled, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 350, 500 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaled2, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 128, 240 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaledAspectRatioWrong, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 1024, 25 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaledAspectRatio, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 1024, 1024 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaledAlpha, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 100, 100 } };
CGContextSetAlpha(GetDrawingContext(), 0.8);
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaledAlpha2, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 256, 256 } };
CGContextSetAlpha(GetDrawingContext(), 0.24);
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageDogScaledAlpha3, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 300, 513 } };
CGContextSetAlpha(GetDrawingContext(), 0.66);
_drawTiledImage(GetDrawingContext(), rect, "tiledImageDog.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageCustom, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 562, 469 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageCircleMe.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageCustomScaledUp, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 2050, 2050 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageCircleMe.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageCustomScaledDown, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 20, 20 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageCircleMe.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageCustomScaledDownReallyLow, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 1, 1 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageCircleMe.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageCustomScaled, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 10, 250 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageCircleMe.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageCustomScaledObscure, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 253, 13 } };
_drawTiledImage(GetDrawingContext(), rect, "tiledImageCircleMe.png");
}

DISABLED_DRAW_TEST_F(CGContext, TiledImageCustomScaledAlpha, UIKitMimicTest<>) {
CGRect rect = { { 0, 0 }, { 128, 128 } };
CGContextSetAlpha(GetDrawingContext(), 0.88);
_drawTiledImage(GetDrawingContext(), rect, "tiledImageCircleMe.png");
}

DISABLED_DRAW_TEST_F(CGContext, DrawAnImage, UIKitMimicTest<>) {
// Load an Image and draw it into the canvas context
auto drawingConfig = DrawingTestConfig::Get();

woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("jpg1.jpg")) };
woc::unique_cf<CGImageRef> image{ _CGImageCreateFromJPEGFile(testFilename.get()) };
ASSERT_NE(image, nullptr);

CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGAffineTransform flip = CGAffineTransformMakeScale(1, -1);
CGAffineTransform shift = CGAffineTransformTranslate(flip, 0, bounds.size.height * -1);
CGContextConcatCTM(context, shift);

CGContextDrawImage(context, bounds, image.get());
}

DRAW_TEST_F(CGContext, DrawAnImageWithOpacity, UIKitMimicTest<>) {
// Load an Image and draw it into the canvas context
auto drawingConfig = DrawingTestConfig::Get();

woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("png1.9.png")) };
woc::unique_cf<CGImageRef> image{ _CGImageCreateFromPNGFile(testFilename.get()) };
ASSERT_NE(image, nullptr);

CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGAffineTransform flip = CGAffineTransformMakeScale(1, -1);
CGAffineTransform shift = CGAffineTransformTranslate(flip, 0, bounds.size.height * -1);
CGContextConcatCTM(context, shift);

CGContextSetAlpha(context, 0.7);
CGContextDrawImage(context, bounds, image.get());
}

DRAW_TEST_F(CGContext, DrawAnImageWithInterpolationQuality, UIKitMimicTest<>) {
auto drawingConfig = DrawingTestConfig::Get();

woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("png1.9.png")) };
woc::unique_cf<CGImageRef> image{ _CGImageCreateFromPNGFile(testFilename.get()) };
ASSERT_NE(image, nullptr);

CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGContextSetInterpolationQuality(context, kCGInterpolationLow);
CGContextDrawImage(context, bounds, image.get());
}

DRAW_TEST_F(CGContext, DrawAnImageWithInterpolationQualityAndAlpha, UIKitMimicTest<>) {
auto drawingConfig = DrawingTestConfig::Get();
woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("png1.9.png")) };
woc::unique_cf<CGImageRef> image{ _CGImageCreateFromPNGFile(testFilename.get()) };
ASSERT_NE(image, nullptr);

CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGContextSetAlpha(context, 0.25);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextDrawImage(context, bounds, image.get());
}

DISABLED_DRAW_TEST_F(CGContext, RedBox, UIKitMimicTest<>) {
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, DrawAContextIntoAnImage, UIKitMimicTest<>) {
// This test will create a bitmap context, draw some entity into the context, then create a image out of the bitmap context.
// Thereafter it will draw the image into the Canvas context

static woc::unique_cf<CGColorSpaceRef> rgbColorSpace(CGColorSpaceCreateDeviceRGB());
// Create a bitmap context to draw the Image into
woc::unique_cf<CGContextRef> contextImage(CGBitmapContextCreate(
nullptr, 10, 10, 8, 4 * 10 /* bytesPerRow = bytesPerPixel*width*/, rgbColorSpace.get(), kCGImageAlphaPremultipliedFirst));
ASSERT_NE(contextImage, nullptr);

CGContextSetRGBFillColor(contextImage.get(), 1.0, 0.0, 0.0, 1.0);
CGContextFillRect(contextImage.get(), { 0, 0, 10, 10 });

// Create the image out of the bitmap context
woc::unique_cf<CGImageRef> image(CGBitmapContextCreateImage(contextImage.get()));
ASSERT_NE(image, nullptr);

CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGAffineTransform flip = CGAffineTransformMakeScale(1, -1);
CGAffineTransform shift = CGAffineTransformTranslate(flip, 0, bounds.size.height * -1);
CGContextConcatCTM(context, shift);

// draw the image
CGContextDrawImage(context, bounds, image.get());
}

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

0 comments on commit 4527ce3

Please sign in to comment.