Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
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
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" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TAEFEntryPoint [](start = 85, length = 14)

Nice! much cleaner.

</ItemGroup>
<ItemGroup>
<ClangCompile Include="$(StarboardBasePath)\tests\unittests\CoreGraphics.drawing\CGTextDrawing.cpp" />
Expand Down
8 changes: 4 additions & 4 deletions tests/Tests.Shared/test-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ __declspec(noinline) inline std::string _ExchangeAlternateTestName(

// clang-format on

__if_not_exists(GetCurrentTestDirectory) {
IF_NOT_EXISTS_BEGIN(GetCurrentTestDirectory)
static std::string GetCurrentTestDirectory() {
WEX::Common::String testDeploymentPath;
WEX::TestExecution::RuntimeParameters::TryGetValue(L"TestDeploymentDir", testDeploymentPath);
Expand All @@ -575,9 +575,9 @@ __if_not_exists(GetCurrentTestDirectory) {
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.to_bytes(toReturn);
}
}
IF_NOT_EXISTS_END

__if_not_exists(GetTestFullName) {
IF_NOT_EXISTS_BEGIN(GetTestFullName)
static std::string GetTestFullName() {
std::string alternateTestName = _ExchangeAlternateTestName(std::string(), false);
if (!alternateTestName.empty()) {
Expand All @@ -594,7 +594,7 @@ __if_not_exists(GetTestFullName) {
toReturn.replace(toReturn.find("_"), 1, ".");
return toReturn;
}
}
IF_NOT_EXISTS_END

#ifndef LOG_TEST_PROPERTY
#define LOG_TEST_PROPERTY(key, value) \
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(...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no record property?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, not necessary to record the property in an xml file we don't generate for a platform we don't want to diff on :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair. Would be useful to move this macro to TestFramework for the benefit of other tests?


In reply to: 100652177 [](ancestors = 100652177)

#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));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a newline before this guy? I was confused what the log test thing did until I realized this was separate.

#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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEST_P [](start = 9, length = 6)

Just so I understand this, you are modifying the gtest api to have another level of indirection here so we can do the interstitial doodad?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you


// 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
23 changes: 17 additions & 6 deletions tests/frameworks/include/TestFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
#include <Foundation/Foundation.h>
#endif

#ifndef IF_NOT_EXISTS_BEGIN
#ifdef _MSC_VER
#define IF_NOT_EXISTS_BEGIN(name) __if_not_exists(name) {
#define IF_NOT_EXISTS_END }
#else
#define IF_NOT_EXISTS_BEGIN(name)
#define IF_NOT_EXISTS_END
#endif
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solid.


#if TARGET_OS_MAC
#include "gtest-api.h"
#include <mach-o/dyld.h>
#else
#include "test-api.h"
#endif
Expand Down Expand Up @@ -229,23 +240,23 @@ class ObjCTest : public ::testing::Test {
#define boolean Boolean
#endif

__if_not_exists(GetCurrentTestDirectory) {
IF_NOT_EXISTS_BEGIN(GetCurrentTestDirectory)
static std::string GetCurrentTestDirectory() {
std::string tempBuffer;
uint32_t maxPath = _MAX_PATH;
uint32_t maxPath = PATH_MAX;
tempBuffer.resize(maxPath);
_NSGetExecutablePath(&tempBuffer[0], &maxPath);
return tempBuffer.substr(0, tempBuffer.find_last_of('/')).c_str();
}
}
IF_NOT_EXISTS_END

__if_not_exists(GetTestFullName) {
IF_NOT_EXISTS_BEGIN(GetTestFullName)
static std::string GetTestFullName() {
return std::string(::testing::UnitTest::GetInstance()->current_test_info()->test_case_name()) + "." +
::testing::UnitTest::GetInstance()->current_test_info()->name();
}
}
IF_NOT_EXISTS_END

#ifndef LOG_TEST_PROPERTY
#define LOG_TEST_PROPERTY(key, value) RecordProperty(key, value)
#endif
#endif
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
Loading