Files
compute-runtime/unit_tests/helpers/windows/gl_helper_tests.cpp
Katarzyna Cencelewska f18532c8c4 Refactor of glcl sharing
new pattern to load gl and wgl functions from dll

Change-Id: I71d7510a210462c09d50e03ce8a444770c017b8d
2018-12-17 23:04:28 +01:00

50 lines
1.8 KiB
C++

/*
* Copyright (C) 2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include <memory>
#include "runtime/os_interface/os_library.h"
#include "runtime/os_interface/windows/windows_wrapper.h"
#include "runtime/helpers/windows/gl_helper.h"
#include "unit_tests/helpers/windows/mock_function.h"
#include "test.h"
#include "gtest/gtest.h"
typedef const char *(__cdecl *funcType)();
namespace OCLRT {
class glFunctionHelperMock : public glFunctionHelper {
public:
glFunctionHelperMock(OsLibrary *glLibrary, const std::string &functionName) : glFunctionHelper(glLibrary, functionName) {}
using glFunctionHelper::glFunctionPtr;
};
TEST(glFunctionHelper, whenCreateGlFunctionHelperThenSetGlFunctionPtrToLoadAnotherFunctions) {
std::unique_ptr<OsLibrary> glLibrary(OsLibrary::load("mock_opengl32.dll"));
EXPECT_TRUE(glLibrary->isLoaded());
glFunctionHelperMock loader(glLibrary.get(), "mockLoader");
funcType function1 = ConvertibleProcAddr{loader.glFunctionPtr("realFunction")};
funcType function2 = loader["realFunction"];
EXPECT_STREQ(function1(), function2());
}
TEST(glFunctionHelper, givenNonExistingFunctionNameWhenCreateGlFunctionHelperThenNullptr) {
std::unique_ptr<OsLibrary> glLibrary(OsLibrary::load("mock_opengl32.dll"));
EXPECT_TRUE(glLibrary->isLoaded());
glFunctionHelper loader(glLibrary.get(), "mockLoader");
funcType function = loader["nonExistingFunction"];
EXPECT_EQ(nullptr, function);
}
TEST(glFunctionHelper, givenRealFunctionNameWhenCreateGlFunctionHelperThenGetPointerToAppropriateFunction) {
std::unique_ptr<OsLibrary> glLibrary(OsLibrary::load("mock_opengl32.dll"));
EXPECT_TRUE(glLibrary->isLoaded());
glFunctionHelper loader(glLibrary.get(), "mockLoader");
funcType function = loader["realFunction"];
EXPECT_STREQ(realFunction(), function());
}
}; // namespace OCLRT