Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Adding test support for WINRT
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenyAgafonchikov committed May 26, 2015
1 parent 8fb3760 commit 82f54da
Show file tree
Hide file tree
Showing 26 changed files with 344 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ OCV_OPTION(BUILD_ANDROID_EXAMPLES "Build examples for Android platform"
OCV_OPTION(BUILD_DOCS "Create build rules for OpenCV Documentation" ON IF NOT WINRT)
OCV_OPTION(BUILD_EXAMPLES "Build all examples" OFF )
OCV_OPTION(BUILD_PACKAGE "Enables 'make package_source' command" ON IF NOT WINRT)
OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" ON IF (NOT IOS AND NOT WINRT) )
OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS AND NOT WINRT) )
OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" ON IF (NOT IOS) )
OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS) )
OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON )
OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT for staticaly linked OpenCV" ON IF MSVC )
OCV_OPTION(BUILD_WITH_DYNAMIC_IPP "Enables dynamic linking of IPP (only for standalone IPP)" OFF )
Expand Down
17 changes: 17 additions & 0 deletions cmake/OpenCVCompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ macro(add_extra_compiler_option option)
endif()
endmacro()

# Gets environment variable and puts its value to the corresponding preprocessor definition
# Useful for WINRT that has no access to environment variables
macro(add_env_definitions option)
set(value $ENV{${option}})
if("${value}" STREQUAL "")
message(WARNING "${option} environment variable is empty. Please set it to appropriate location to get correct results")
else()
string(REPLACE "\\" "\\\\" value ${value})
endif()
add_definitions("-D${option}=\"${value}\"")
endmacro()

# OpenCV fails some tests when 'char' is 'unsigned' by default
add_extra_compiler_option(-fsigned-char)

Expand Down Expand Up @@ -286,6 +298,11 @@ if(MSVC12 AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} /FS")
endif()

# Adding additional using directory for WindowsPhone 8.0 to get Windows.winmd properly
if(WINRT_PHONE AND WINRT_8_0)
set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} /AI\$(WindowsSDK_MetadataPath)")
endif()

# Extra link libs if the user selects building static libs:
if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID)
# Android does not need these settings because they are already set by toolchain file
Expand Down
71 changes: 62 additions & 9 deletions cmake/OpenCVModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,28 @@ macro(ocv_create_module)
_ocv_create_module(${ARGN})
set(the_module_target ${the_module})
endif()

if(WINRT)
# removing APPCONTAINER from modules to run from console
# in case of usual starting of WinRT test apps output is missing
# so starting of console version w/o APPCONTAINER is required to get test results
# also this allows to use opencv_extra test data for these tests
if(NOT "${the_module}" STREQUAL "opencv_ts" AND NOT "${the_module}" STREQUAL "opencv_hal")
add_custom_command(TARGET ${the_module}
POST_BUILD
COMMAND link.exe /edit /APPCONTAINER:NO $(TargetPath))
endif()

if("${the_module}" STREQUAL "opencv_ts")
# copy required dll files; WinRT apps need these dlls that are usually substituted by Visual Studio
# however they are not on path and need to be placed with executables to run from console w/o APPCONTAINER
add_custom_command(TARGET ${the_module}
POST_BUILD
COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\msvcp$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\msvcp$(PlatformToolsetVersion)_app.dll\""
COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\msvcr$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\msvcr$(PlatformToolsetVersion)_app.dll\""
COMMAND copy /y "\"$(VCInstallDir)redist\\$(PlatformTarget)\\Microsoft.VC$(PlatformToolsetVersion).CRT\\vccorlib$(PlatformToolsetVersion).dll\"" "\"${CMAKE_BINARY_DIR}\\bin\\$(Configuration)\\vccorlib$(PlatformToolsetVersion)_app.dll\"")
endif()
endif()
endmacro()

macro(_ocv_create_module)
Expand Down Expand Up @@ -936,15 +958,30 @@ function(ocv_add_perf_tests)
add_dependencies(opencv_perf_tests ${the_target})

# Additional target properties
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)

if(NOT WINRT)
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)
else()
# WINRT has issues in case name in appxManifest and real executable name mismatch
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX ""
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)
endif()
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "tests performance")
endif()

if(WINRT)
# removing APPCONTAINER from tests to run from console
# look for detailed description inside of ocv_create_module macro above
add_custom_command(TARGET "opencv_perf_${name}"
POST_BUILD
COMMAND link.exe /edit /APPCONTAINER:NO $(TargetPath))
endif()

if(NOT BUILD_opencv_world)
_ocv_add_precompiled_headers(${the_target})
endif()
Expand Down Expand Up @@ -991,10 +1028,18 @@ function(ocv_add_accuracy_tests)
add_dependencies(opencv_tests ${the_target})

# Additional target properties
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)
if(NOT WINRT)
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)
else()
# WINRT has issues in case name in appxManifest and real executable name mismatch
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX ""
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)
endif()

if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy")
Expand All @@ -1004,6 +1049,14 @@ function(ocv_add_accuracy_tests)
get_target_property(LOC ${the_target} LOCATION)
add_test(${the_target} "${LOC}")

if(WINRT)
# removing APPCONTAINER from tests to run from console
# look for detailed description inside of ocv_create_module macro above
add_custom_command(TARGET "opencv_test_${name}"
POST_BUILD
COMMAND link.exe /edit /APPCONTAINER:NO $(TargetPath))
endif()

if(NOT BUILD_opencv_world)
_ocv_add_precompiled_headers(${the_target})
endif()
Expand Down
1 change: 1 addition & 0 deletions modules/calib3d/test/test_fisheye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "test_precomp.hpp"
#include <opencv2/ts/cuda_test.hpp>
#include "../src/fisheye.hpp"
#include "opencv2/videoio.hpp"

class fisheyeTest : public ::testing::Test {

Expand Down
1 change: 0 additions & 1 deletion modules/features2d/test/test_detectors_regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;
Expand Down
1 change: 0 additions & 1 deletion modules/features2d/test/test_keypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core/core_c.h"

using namespace std;
Expand Down
1 change: 0 additions & 1 deletion modules/features2d/test/test_matchers_algorithmic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;
Expand Down
4 changes: 3 additions & 1 deletion modules/features2d/test/test_mser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/highgui.hpp"
#ifdef RENDER_MSERS
#include "opencv2/highgui.hpp"
#endif

#include <vector>
#include <string>
Expand Down
1 change: 0 additions & 1 deletion modules/features2d/test/test_orb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;
Expand Down
7 changes: 7 additions & 0 deletions modules/imgcodecs/test/test_grfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,16 @@ TEST(Imgcodecs_Tiff, decode_infinite_rowsperstrip)
};

const string filename = cv::tempfile(".tiff");
#ifndef WINRT
std::ofstream outfile(filename.c_str(), std::ofstream::binary);
outfile.write(reinterpret_cast<const char *>(sample_data), sizeof sample_data);
outfile.close();
#else
FILE* outfile = fopen(filename.c_str(), "w+");
ASSERT_TRUE(outfile != NULL);
fwrite(reinterpret_cast<const char *>(sample_data), sizeof sample_data, 1, outfile);
fclose(outfile);
#endif

EXPECT_NO_THROW(cv::imread(filename, IMREAD_UNCHANGED));

Expand Down
1 change: 0 additions & 1 deletion modules/imgproc/test/test_contours.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//M*/

#include "test_precomp.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace std;
Expand Down
4 changes: 3 additions & 1 deletion modules/objdetect/perf/perf_precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

#include "opencv2/ts.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#ifndef WINRT
#include "opencv2/highgui.hpp"
#endif

#ifdef GTEST_CREATE_SHARED_LIBRARY
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
Expand Down
35 changes: 31 additions & 4 deletions modules/photo/test/test_hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,38 @@ void checkEqual(Mat img0, Mat img1, double threshold, const string& name)
static vector<float> DEFAULT_VECTOR;
void loadExposureSeq(String path, vector<Mat>& images, vector<float>& times = DEFAULT_VECTOR)
{
ifstream list_file((path + "list.txt").c_str());
ASSERT_TRUE(list_file.is_open());
string name;
float val;
while(list_file >> name >> val) {
String listPath = path + "list.txt";
#ifndef WINRT
string name;
ifstream list_file(listPath.c_str());
ASSERT_TRUE(list_file.is_open());
while (list_file >> name >> val) {
#else
char* name = (char *) malloc(_MAX_PATH - strlen(path.c_str()));
FILE* list_file = fopen(listPath.c_str(), "r");
ASSERT_TRUE(list_file != NULL);

while (fscanf(list_file, "%s %f", name, &val) == 2)
{
#endif
Mat img = imread(path + name);
ASSERT_FALSE(img.empty()) << "Could not load input image " << path + name;
images.push_back(img);
times.push_back(1 / val);
}
#ifndef WINRT
list_file.close();
#else
free(name);
fclose(list_file);
#endif
}

void loadResponseCSV(String path, Mat& response)
{
response = Mat(256, 1, CV_32FC3);
#ifndef WINRT
ifstream resp_file(path.c_str());
for(int i = 0; i < 256; i++) {
for(int c = 0; c < 3; c++) {
Expand All @@ -84,6 +100,17 @@ void loadResponseCSV(String path, Mat& response)
}
}
resp_file.close();
#else
FILE* resp_file = fopen(path.c_str(), "r");
ASSERT_TRUE(resp_file != NULL);

int i = 0;
while (fscanf(resp_file, "%f%*s%f%*s%f%*[; ]", &response.at<Vec3f>(i)[0], &response.at<Vec3f>(i)[1], &response.at<Vec3f>(i)[2]) == 3)
{
i++;
}
fclose(resp_file);
#endif
}

TEST(Photo_Tonemap, regression)
Expand Down
15 changes: 13 additions & 2 deletions modules/ts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
set(the_description "The ts module")

if(IOS OR WINRT)
if(IOS)
ocv_module_disable(ts)
endif()

set(OPENCV_MODULE_TYPE STATIC)
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)

if(WINRT)
# WINRT doesn't have access to environment variables
# so adding corresponding macros during CMake run
add_env_definitions(OPENCV_TEST_DATA_PATH)
add_env_definitions(OPENCV_PERF_VALIDATION_DIR)
endif()

ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)

ocv_add_module(ts INTERNAL opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui)
if(NOT WINRT)
ocv_add_module(ts INTERNAL opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui)
else()
ocv_add_module(ts INTERNAL opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio)
endif()

ocv_glob_module_sources()
ocv_module_include_directories()
Expand Down
4 changes: 3 additions & 1 deletion modules/ts/include/opencv2/ts/cuda_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
#include "opencv2/core.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#ifndef WINRT
#include "opencv2/highgui.hpp"
#endif
#include "opencv2/imgproc.hpp"
#include "opencv2/ts.hpp"

Expand Down
4 changes: 3 additions & 1 deletion modules/ts/include/opencv2/ts/ocl_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@

#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#ifndef WINRT
#include "opencv2/highgui.hpp"
#endif
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/types_c.h"
#include "opencv2/core/ocl.hpp"
Expand Down
4 changes: 2 additions & 2 deletions modules/ts/include/opencv2/ts/ts_gtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,7 @@ inline const char* StrNCpy(char* dest, const char* src, size_t n) {
// StrError() aren't needed on Windows CE at this time and thus not
// defined there.

#if !GTEST_OS_WINDOWS_MOBILE
#if !GTEST_OS_WINDOWS_MOBILE && !defined WINRT
inline int ChDir(const char* dir) { return chdir(dir); }
#endif
inline FILE* FOpen(const char* path, const char* mode) {
Expand All @@ -2948,7 +2948,7 @@ inline int Close(int fd) { return close(fd); }
inline const char* StrError(int errnum) { return strerror(errnum); }
#endif
inline const char* GetEnv(const char* name) {
#if GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS_MOBILE || defined WINRT
// We are on Windows CE, which has no environment variables.
return NULL;
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
Expand Down
4 changes: 4 additions & 0 deletions modules/ts/src/cuda_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ namespace cvtest

void showDiff(InputArray gold_, InputArray actual_, double eps)
{
#ifndef WINRT
Mat gold = getMat(gold_);
Mat actual = getMat(actual_);

Expand All @@ -430,6 +431,9 @@ namespace cvtest
imshow("diff", diff);

waitKey();
#else
printf("These features are not supported on WINRT");
#endif
}

namespace
Expand Down
Loading

0 comments on commit 82f54da

Please sign in to comment.