Skip to content
Open
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
50 changes: 28 additions & 22 deletions common/visual-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <dali/integration-api/events/point.h>
#include <dali/integration-api/events/touch-event-integ.h>
#include <string>
#include <functional>

extern char *gTempFilename;
extern char *gTempDir;
Expand All @@ -46,30 +47,35 @@ bool ParseEnvironment(int argc, char **argv, int width, int height);
* @note This sets the DPI to be 96 for all tests so that text tests all produce
* the same output image
*/
#define DALI_VISUAL_TEST_WITH_WINDOW_SIZE(VisualTestName, InitFunction, \
WindowWidth, WindowHeight) \
int DALI_EXPORT_API main(int argc, char **argv) { \
int n = asprintf(&gTempDir, "/tmp/dali-tests"); \
if (n > 0) { \
bool cont = ParseEnvironment(argc, argv, WindowWidth, WindowHeight); \
if (!cont) \
return 0; \
n = asprintf(&gTempFilename, "%s/%s", gTempDir, #VisualTestName); \
setenv("DALI_DPI_HORIZONTAL", "96", true); \
setenv("DALI_DPI_VERTICAL", "96", true); \
Rect<int> windowSize{0, 0, WindowWidth, WindowHeight}; \
WindowData windowData; \
windowData.SetTransparency(false); \
windowData.SetPositionSize(windowSize); \
Application application = \
Application::New(&argc, &argv, "", false, windowData); \
VisualTestName test(application); \
application.InitSignal().Connect(&test, &VisualTestName::InitFunction); \
application.MainLoop(); \
return gExitValue; \
} \
#define DALI_VISUAL_TEST_WITH_WINDOW_SIZE_AND_PREPROESS(VisualTestName, InitFunction, \
WindowWidth, WindowHeight, \
Preprocess) \
int DALI_EXPORT_API main(int argc, char** argv) \
{ \
int n=asprintf(&gTempDir, "/tmp/dali-tests"); \
if(n>0) \
{ \
bool cont = ParseEnvironment(argc, argv, WindowWidth, WindowHeight); \
if(!cont) return 0; \
n=asprintf(&gTempFilename, "%s/%s", gTempDir, #VisualTestName); \
setenv("DALI_DPI_HORIZONTAL", "96", true); \
setenv("DALI_DPI_VERTICAL", "96", true); \
Preprocess(); \
Rect<int> windowSize{0, 0, WindowWidth, WindowHeight}; \
WindowData windowData; \
windowData.SetTransparency(false); \
windowData.SetPositionSize(windowSize); \
Application application = \
Application::New(&argc, &argv, "", false, windowData); \
VisualTestName test(application); \
application.InitSignal().Connect(&test, &VisualTestName::InitFunction); \
application.MainLoop(); \
return gExitValue; \
} \
}

#define DALI_VISUAL_TEST_WITH_WINDOW_SIZE(VisualTestName, InitFunction, WindowWidth, WindowHeight) DALI_VISUAL_TEST_WITH_WINDOW_SIZE_AND_PREPROESS(VisualTestName, InitFunction, WindowWidth, WindowHeight, std::function<void()>([](){}))

/**
* DALI_VISUAL_TEST is a wrapper for the boilerplate code to create the main
* function of the visual test application with the default main window size
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

// EXTERNAL INCLUDES
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>

#include <dali/devel-api/adaptor-framework/application-devel.h>
#include <dali/devel-api/adaptor-framework/graphics-backend.h>

#include <dali-toolkit/devel-api/toolkit-pre-initialize.h>

// INTERNAL INCLUDES
#include "visual-test.h"

using namespace Dali;
using namespace Dali::Toolkit;

namespace
{
const std::string EXPECTED_IMAGE_FILE = TEST_IMAGE_DIR "preinitialize-gles-to-vk/expected-result.png";
} // namespace

/**
* @brief This test is to make sure we can create PreInitialize application with GLES backend, and actual applicatoin is Vulkan backend.
*/
class PreInitialieTestGlesToVulkan: public VisualTest
{
public:

PreInitialieTestGlesToVulkan( Application& application )
: mApplication( application )
{
}

void OnInit( Application application )
{
Dali::Window window = mApplication.GetWindow();
window.SetBackgroundColor( Color::WHITE );

Control simpleControl = Control::New();
simpleControl[Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
simpleControl[Actor::Property::SIZE] = Vector2(100.0f, 100.0f);
simpleControl[Control::Property::BACKGROUND] = Color::RED;

window.Add(simpleControl);

// Start the test
PerformNextTest();
}

void PostRender(std::string outputFile, bool success) override
{
CompareImageFile(EXPECTED_IMAGE_FILE, outputFile, 0.98f);
mApplication.Quit();
}

void PerformNextTest()
{
Window window = mApplication.GetWindow();
CaptureWindowAfterFrameRendered(window);
}

private:
Application& mApplication;
};

void PreInitialize()
{
// Set preferred backend as GLES.
setenv("DALI_GRAPHICS_BACKEND", "GLES", 1);

printf("DaliToolkitPreInitialize\n");
DaliToolkitPreInitialize(nullptr, nullptr, nullptr);
printf("DaliToolkitPreInitialize done\n");

// Forcibly set backend as Vulkan.
Dali::Graphics::SetGraphicsBackend(Dali::Graphics::Backend::VULKAN);
}

DALI_VISUAL_TEST_WITH_WINDOW_SIZE_AND_PREPROESS( PreInitialieTestGlesToVulkan, OnInit, 200, 200, PreInitialize )
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions visual-tests/preinitialize-gles/preinitialize-gles-test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

// EXTERNAL INCLUDES
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>

#include <dali/devel-api/adaptor-framework/application-devel.h>
#include <dali/devel-api/adaptor-framework/graphics-backend.h>

#include <dali-toolkit/devel-api/toolkit-pre-initialize.h>

// INTERNAL INCLUDES
#include "visual-test.h"

using namespace Dali;
using namespace Dali::Toolkit;

namespace
{
const std::string EXPECTED_IMAGE_FILE = TEST_IMAGE_DIR "preinitialize-gles/expected-result.png";
} // namespace

/**
* @brief This test is to make sure we can create PreInitialize application with GLES backend.
*/
class PreInitialieTestGles: public VisualTest
{
public:

PreInitialieTestGles( Application& application )
: mApplication( application )
{
}

void OnInit( Application application )
{
Dali::Window window = mApplication.GetWindow();
window.SetBackgroundColor( Color::WHITE );

Control simpleControl = Control::New();
simpleControl[Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
simpleControl[Actor::Property::SIZE] = Vector2(100.0f, 100.0f);
simpleControl[Control::Property::BACKGROUND] = Color::RED;

window.Add(simpleControl);

// Start the test
PerformNextTest();
}

void PostRender(std::string outputFile, bool success) override
{
CompareImageFile(EXPECTED_IMAGE_FILE, outputFile, 0.98f);
mApplication.Quit();
}

void PerformNextTest()
{
Window window = mApplication.GetWindow();
CaptureWindowAfterFrameRendered(window);
}

private:
Application& mApplication;
};

void PreInitialize()
{
// Set preferred backend as GLES.
setenv("DALI_GRAPHICS_BACKEND", "GLES", 1);

printf("DaliToolkitPreInitialize\n");
DaliToolkitPreInitialize(nullptr, nullptr, nullptr);
printf("DaliToolkitPreInitialize done\n");

// Forcibly set backend as GLES.
Dali::Graphics::SetGraphicsBackend(Dali::Graphics::Backend::GLES);
}

DALI_VISUAL_TEST_WITH_WINDOW_SIZE_AND_PREPROESS( PreInitialieTestGles, OnInit, 200, 200, PreInitialize )
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

// EXTERNAL INCLUDES
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>

#include <dali/devel-api/adaptor-framework/application-devel.h>
#include <dali/devel-api/adaptor-framework/graphics-backend.h>

#include <dali-toolkit/devel-api/toolkit-pre-initialize.h>

// INTERNAL INCLUDES
#include "visual-test.h"

using namespace Dali;
using namespace Dali::Toolkit;

namespace
{
const std::string EXPECTED_IMAGE_FILE = TEST_IMAGE_DIR "preinitialize-vk-to-gles/expected-result.png";
} // namespace

/**
* @brief This test is to make sure we can create PreInitialize application with Vulkan backend, and actual applicatoin is GLES backend.
*/
class PreInitialieTestVulkanToGles: public VisualTest
{
public:

PreInitialieTestVulkanToGles( Application& application )
: mApplication( application )
{
}

void OnInit( Application application )
{
Dali::Window window = mApplication.GetWindow();
window.SetBackgroundColor( Color::WHITE );

Control simpleControl = Control::New();
simpleControl[Actor::Property::PARENT_ORIGIN] = ParentOrigin::CENTER;
simpleControl[Actor::Property::SIZE] = Vector2(100.0f, 100.0f);
simpleControl[Control::Property::BACKGROUND] = Color::RED;

window.Add(simpleControl);

// Start the test
PerformNextTest();
}

void PostRender(std::string outputFile, bool success) override
{
CompareImageFile(EXPECTED_IMAGE_FILE, outputFile, 0.98f);
mApplication.Quit();
}

void PerformNextTest()
{
Window window = mApplication.GetWindow();
CaptureWindowAfterFrameRendered(window);
}

private:
Application& mApplication;
};

void PreInitialize()
{
// Set preferred backend as Vulkan.
setenv("DALI_GRAPHICS_BACKEND", "VK", 1);

printf("DaliToolkitPreInitialize\n");
DaliToolkitPreInitialize(nullptr, nullptr, nullptr);
printf("DaliToolkitPreInitialize done\n");

// Forcibly set backend as GLES.
Dali::Graphics::SetGraphicsBackend(Dali::Graphics::Backend::GLES);
}

DALI_VISUAL_TEST_WITH_WINDOW_SIZE_AND_PREPROESS( PreInitialieTestVulkanToGles, OnInit, 200, 200, PreInitialize )
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading