Skip to content

Commit

Permalink
Augment the drawing tests with TAEF-specific behaviour.
Browse files Browse the repository at this point in the history
* Fix interoperability with TAEF setup/teardown.
* Add a TAEF entrypoint and clear the win32 stuff out of the OS X one.
  • Loading branch information
DHowett committed Feb 11, 2017
1 parent f790f56 commit 650e749
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
</ItemDefinitionGroup>
<ItemGroup>

<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\EntryPoint.cpp" />
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.Drawing\TAEFEntryPoint.cpp" />
</ItemGroup>
<ItemGroup>
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.drawing\CGTextDrawing.cpp" />
Expand Down
32 changes: 27 additions & 5 deletions tests/UnitTests/CoreGraphics.drawing/DrawingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
#import "CGContextInternal.h"
#endif

#ifdef TARGET_OS_MAC
#define LOG_TEST_FILE(...)
#else
#define LOG_TEST_FILE(...) WEX::Logging::Log::File(__VA_ARGS__)
std::wstring _CFStringToWString(CFStringRef string) {
const UniChar* characters16 = CFStringGetCharactersPtr(string);
if (characters16) {
return {characters16, characters16 + CFStringGetLength(string)};
}

static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.from_bytes(CFStringGetCStringPtr(string, kCFStringEncodingUTF8));
}
#endif

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

template <typename TComparator>
Expand All @@ -34,7 +49,7 @@ CGSize testing::DrawTest<TComparator>::CanvasSize() {
}

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

auto deviceColorSpace = woc::MakeStrongCF<CGColorSpaceRef>(CGColorSpaceCreateDeviceRGB());
Expand Down Expand Up @@ -69,7 +84,7 @@ CFStringRef testing::DrawTest<TComparator>::CreateOutputFilename() {
}

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

#if WINOBJC // Validate that the results are correct even under batched drawing from _CGContextPushBegin/PopEndDraw
Expand Down Expand Up @@ -133,10 +148,12 @@ void testing::DrawTest<TComparator>::TearDown() {

_WriteCFDataToFile(encodedDeltaImageData.get(), deltaFilename.get());

LOG_TEST_PROPERTY("expectedImage", CFStringGetCStringPtr(referenceFilename.get(), kCFStringEncodingUTF8));
LOG_TEST_PROPERTY("actualImage", CFStringGetCStringPtr(outputPath.get(), kCFStringEncodingUTF8));
LOG_TEST_PROPERTY("deltaImage", CFStringGetCStringPtr(deltaFilename.get(), kCFStringEncodingUTF8));
LOG_TEST_FILE(_CFStringToWString(referenceFilename).c_str());
LOG_TEST_FILE(_CFStringToWString(outputPath).c_str());
LOG_TEST_FILE(_CFStringToWString(deltaFilename).c_str());
}
} else if (drawingConfig->GetMode() == DrawingTestMode::Generate) {
LOG_TEST_FILE(_CFStringToWString(outputPath).c_str());
}
}

Expand All @@ -150,6 +167,11 @@ void testing::DrawTest<TComparator>::TestBody() {
// Nothing.
}

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

template <typename TComparator>
CGContextRef testing::DrawTest<TComparator>::GetDrawingContext() {
return _context.get();
Expand Down
47 changes: 35 additions & 12 deletions tests/UnitTests/CoreGraphics.drawing/DrawingTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace testing {
template <typename TComparator = PixelByPixelImageComparator<>>
class DrawTest : public ::testing::Test {
class DrawTest: public ::testing::Test {
private:
woc::unique_cf<CGContextRef> _context;
CGRect _bounds;
Expand All @@ -36,8 +36,11 @@ class DrawTest : public ::testing::Test {
virtual CFStringRef CreateOutputFilename();
virtual CGSize CanvasSize();
virtual void SetUpContext();
virtual void SetUp();
virtual void TearDown();

virtual void PreDraw();
virtual void Draw();
virtual void PostDraw();

virtual void TestBody();

CGContextRef GetDrawingContext();
Expand Down Expand Up @@ -74,28 +77,48 @@ class UIKitMimicTest : public WhiteBackgroundTest<TComparator> {
virtual void SetUpContext();
};

#define DRAW_TEST(test_case_name, test_name) \
GTEST_TEST_(test_case_name, test_name, ::testing::DrawTest<>, ::testing::internal::GetTestTypeId())
#define _DRAW_TEST_INTERSTITIAL_CLASS_NAME(test_case_name, test_name) \
test_case_name##_##test_name##_Drawing
#define _DRAW_TEST_INTERSTITIAL_CLASS(test_case_name, test_name, test_fixture) \
class _DRAW_TEST_INTERSTITIAL_CLASS_NAME(test_case_name, test_name): public test_fixture { \
public: \
virtual void Draw(); \
};
#define _DRAW_TEST_INTERSTITIAL_BODY { \
PreDraw(); \
Draw(); \
PostDraw(); \
}

#define DRAW_TEST_F(test_case_name, test_name, test_fixture) \
GTEST_TEST_(test_case_name, test_name, test_fixture, ::testing::internal::GetTestTypeId())
_DRAW_TEST_INTERSTITIAL_CLASS(test_case_name, test_name, test_fixture) \
GTEST_TEST_(test_case_name, test_name, _DRAW_TEST_INTERSTITIAL_CLASS_NAME(test_case_name, test_name), ::testing::internal::GetTestTypeId()) \
_DRAW_TEST_INTERSTITIAL_BODY \
void _DRAW_TEST_INTERSTITIAL_CLASS_NAME(test_case_name, test_name)::Draw()

#define DRAW_TEST(test_case_name, test_name) \
DRAW_TEST_F(test_case_name, test_name, ::testing::DrawTest<>)

#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 DRAW_TEST_P(test_case_name, test_name) \
_DRAW_TEST_INTERSTITIAL_CLASS(test_case_name, test_name, test_case_name) \
GTEST_TEST_P_(test_case_name, test_name, _DRAW_TEST_INTERSTITIAL_CLASS_NAME(test_case_name, test_name)) \
_DRAW_TEST_INTERSTITIAL_BODY \
void _DRAW_TEST_INTERSTITIAL_CLASS_NAME(test_case_name, test_name)::Draw()
#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, \
DRAW_TEST_F(test_case_name, \
test_name, \
::testing::DrawTest<PixelByPixelImageComparator<ComparisonMode::Mask>>, \
::testing::internal::GetTestTypeId())
::testing::DrawTest<PixelByPixelImageComparator<ComparisonMode::Mask>>)
#define TEXT_DRAW_TEST_F(test_case_name, test_name, test_fixture) \
GTEST_TEST_(test_case_name, test_name, test_fixture, ::testing::internal::GetTestTypeId())
DRAW_TEST_F(test_case_name, test_name, test_fixture)

#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 TEXT_DRAW_TEST_P(test_case_name, test_name) DRAW_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)
93 changes: 0 additions & 93 deletions tests/UnitTests/CoreGraphics.drawing/EntryPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ class CommandLineDrawingTestConfigImpl : public DrawingTestConfigImpl {
public:
CommandLineDrawingTestConfigImpl(int argc, char** argv)
: _mode(DrawingTestMode::Compare), _outputPath(__OutputDirectory()), _comparisonPath(__ModuleDirectory() + "/data/reference") {
#ifdef WIN32
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;

WEX::Common::String outputPath;
WEX::TestExecution::RuntimeParameters::TryGetValue(L"out", outputPath);
if (!outputPath.IsEmpty()) {
_outputPath = converter.to_bytes(std::wstring(outputPath));
}

WEX::Common::String comparisonPath;
WEX::TestExecution::RuntimeParameters::TryGetValue(L"compare", comparisonPath);
if (!comparisonPath.IsEmpty()) {
_comparisonPath = converter.to_bytes(std::wstring(comparisonPath));
}
#else
for (int i = 1; i < argc; ++i) {
char* arg = argv[i];
if (!arg) {
Expand All @@ -78,7 +63,6 @@ class CommandLineDrawingTestConfigImpl : public DrawingTestConfigImpl {
_comparisonPath = std::move(std::string(arg + 10));
}
}
#endif
}

virtual DrawingTestMode GetMode() override {
Expand All @@ -104,88 +88,11 @@ std::shared_ptr<DrawingTestConfigImpl> _configImpl;
return _configImpl.get();
}

#ifdef WIN32
#include <roapi.h>
#include <WexTestClass.h>
#include <wrl\client.h>
#include <wrl\wrappers\corewrappers.h>
#include <windows.storage.h>

using namespace ABI::Windows::Storage;
using namespace Microsoft::WRL;
using namespace Windows::Foundation;

Wrappers::HString GetAppDataPath() {
Wrappers::HString toReturn;
ComPtr<IStorageFolder> folder;
ComPtr<IApplicationDataStatics> applicationDataStatics;
ComPtr<IApplicationData> applicationData;
ComPtr<IStorageItem> storageItem;

if (FAILED(Windows::Foundation::GetActivationFactory(Wrappers::HStringReference(RuntimeClass_Windows_Storage_ApplicationData).Get(),
&applicationDataStatics))) {
return toReturn;
}

if (FAILED(applicationDataStatics->get_Current(&applicationData))) {
return toReturn;
}

if (FAILED(applicationData->get_LocalFolder(&folder))) {
return toReturn;
}

if (FAILED(folder.As<IStorageItem>(&storageItem))) {
return toReturn;
}

if (FAILED(storageItem->get_Path(toReturn.GetAddressOf()))) {
return toReturn;
}

return toReturn;
}
#endif

#ifdef WIN32
BEGIN_MODULE()
MODULE_PROPERTY(L"RunAs", L"UAP")
END_MODULE()

MODULE_SETUP(ModuleSetup) {
#else
int main(int argc, char** argv) {
#endif

#ifdef WIN32
if (FAILED(RoInitialize(RO_INIT_MULTITHREADED))) {
return FALSE;
}

Wrappers::HString path = GetAppDataPath();
if (path.IsValid()) {
unsigned int rawLength;
_wchdir(WindowsGetStringRawBuffer(path.Get(), &rawLength));
}

int argc = 1;
char* argv[] = { "UnitTests" };
#endif
testing::InitGoogleTest(&argc, argv);

_configImpl = std::move(std::make_shared<CommandLineDrawingTestConfigImpl>(argc, argv));

#ifdef WIN32
return TRUE;
#else
auto result = RUN_ALL_TESTS();
return result;
#endif
}

#ifdef WIN32
MODULE_CLEANUP(ModuleCleanup) {
RoUninitialize();
return true;
}
#endif
2 changes: 1 addition & 1 deletion tests/UnitTests/CoreGraphics.drawing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# CoreGraphics.Drawing.UnitTests.exe
UT_NAME = CoreGraphics.Drawing
UT_FILES := $(wildcard *.cpp)
UT_FILES := $(filter-out TAEF%,$(wildcard *.cpp))
UT_RESOURCES := data
UT_FRAMEWORKS = CoreGraphics ImageIO CoreText

Expand Down
6 changes: 4 additions & 2 deletions tests/frameworks/gtest/include/gtest/gtest-param-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -1377,9 +1377,9 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,



# define TEST_P(test_case_name, test_name) \
# define GTEST_TEST_P_(test_case_name, test_name, test_fixture_name) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
: public test_case_name { \
: public test_fixture_name { \
public: \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
virtual void TestBody(); \
Expand All @@ -1406,6 +1406,8 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()

# define TEST_P(test_case_name, test_name) GTEST_TEST_P_(test_case_name, test_name, test_case_name)

// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
// to specify a function or functor that generates custom test name suffixes
// based on the test parameters. The function should accept one argument of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CGContextBlendMode : public WhiteBackgroundTest<>, public ::testing::WithP
}
};

TEST_P(CGContextBlendMode, OverlappedEllipses) {
DRAW_TEST_P(CGContextBlendMode, OverlappedEllipses) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
CGBlendMode blendMode = ::testing::get<1>(GetParam()).blendMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ std::vector<std::tuple<ClippingShape, CGSize, std::function<void(CGContextRef, C
{ ClippingShapeRectangle, CGSize{ 256, 128 }, __GradientMaskGenerator },
};

TEST_P(CGContextClipping, StraightMask) {
DRAW_TEST_P(CGContextClipping, StraightMask) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
ClippingShape shape = ::testing::get<0>(GetParam());
Expand All @@ -193,7 +193,7 @@ TEST_P(CGContextClipping, StraightMask) {
_FillContext();
}

TEST_P(CGContextClipping, TransformedMask) {
DRAW_TEST_P(CGContextClipping, TransformedMask) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
ClippingShape shape = ::testing::get<0>(GetParam());
Expand All @@ -207,7 +207,7 @@ TEST_P(CGContextClipping, TransformedMask) {
_FillContext();
}

TEST_P(CGContextClipping, StackedMaskSameType) {
DRAW_TEST_P(CGContextClipping, StackedMaskSameType) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
ClippingShape shape = ::testing::get<0>(GetParam());
Expand All @@ -222,7 +222,7 @@ TEST_P(CGContextClipping, StackedMaskSameType) {
_FillContext();
}

TEST_P(CGContextClipping, StackedMaskOtherType) {
DRAW_TEST_P(CGContextClipping, StackedMaskOtherType) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
ClippingShape shape = ::testing::get<0>(GetParam());
Expand All @@ -238,7 +238,7 @@ TEST_P(CGContextClipping, StackedMaskOtherType) {
_FillContext();
}

TEST_P(CGContextClipping, MaskedAndClipped) {
DRAW_TEST_P(CGContextClipping, MaskedAndClipped) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
ClippingShape shape = ::testing::get<0>(GetParam());
Expand Down
Loading

0 comments on commit 650e749

Please sign in to comment.