Adding test support for WINRT

This commit is contained in:
Evgeny Agafonchikov
2015-05-18 11:57:18 +03:00
parent 8869150649
commit 6a6d58d389
19 changed files with 303 additions and 21 deletions

View File

@@ -588,3 +588,102 @@ int main(int argc, char **argv) \
#endif
#include "opencv2/ts/ts_perf.hpp"
#ifdef WINRT
#ifndef __FSTREAM_EMULATED__
#define __FSTREAM_EMULATED__
#include <stdlib.h>
#include <fstream>
#include <sstream>
#undef ifstream
#undef ofstream
#define ifstream ifstream_emulated
#define ofstream ofstream_emulated
namespace std {
class ifstream : public stringstream
{
FILE* f;
public:
ifstream(const char* filename, ios_base::openmode mode = ios_base::in)
: f(NULL)
{
string modeStr("r");
printf("Open file (read): %s\n", filename);
if (mode & ios_base::binary)
modeStr += "b";
f = fopen(filename, modeStr.c_str());
if (f == NULL)
{
printf("Can't open file: %s\n", filename);
return;
}
fseek(f, 0, SEEK_END);
size_t sz = ftell(f);
if (sz > 0)
{
char* buf = (char*) malloc(sz);
fseek(f, 0, SEEK_SET);
if (fread(buf, 1, sz, f) == sz)
{
this->str(std::string(buf, sz));
}
free(buf);
}
}
~ifstream() { close(); }
bool is_open() const { return f != NULL; }
void close()
{
if (f)
fclose(f);
f = NULL;
this->str("");
}
};
class ofstream : public stringstream
{
FILE* f;
public:
ofstream(const char* filename, ios_base::openmode mode = ios_base::out)
: f(NULL)
{
open(filename, mode);
}
~ofstream() { close(); }
void open(const char* filename, ios_base::openmode mode = ios_base::out)
{
string modeStr("w+");
if (mode & ios_base::trunc)
modeStr = "w";
if (mode & ios_base::binary)
modeStr += "b";
f = fopen(filename, modeStr.c_str());
printf("Open file (write): %s\n", filename);
if (f == NULL)
{
printf("Can't open file (write): %s\n", filename);
return;
}
}
bool is_open() const { return f != NULL; }
void close()
{
if (f)
{
fwrite(reinterpret_cast<const char *>(this->str().c_str()), this->str().size(), 1, f);
fclose(f);
}
f = NULL;
this->str("");
}
};
} // namespace std
#endif // __FSTREAM_EMULATED__
#endif // WINRT

View File

@@ -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) {
@@ -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)