1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
23 #include <gtest/gtest.h>
26 #include <MUtils/Global.h>
27 #include <MUtils/Version.h>
33 //===========================================================================
35 //===========================================================================
37 static FILE* g_logFile
= NULL
;
39 static void initialize_mutils_log_file(const int argc
, const wchar_t *const *const argv
)
41 wchar_t basePath
[_MAX_PATH
], logFilePath
[_MAX_PATH
];
42 char gtestOutputPath
[_MAX_PATH
+ 16];
44 wcscpy_s(basePath
, _MAX_PATH
, L
"MUtilsTest");
45 if ((argc
> 0) && argv
[0] && argv
[0][0])
47 wcsncpy_s(basePath
, _MAX_PATH
, argv
[0], _TRUNCATE
);
50 _snwprintf_s(logFilePath
, _MAX_PATH
, _TRUNCATE
, L
"%s.log", basePath
);
51 if (_wfopen_s(&g_logFile
, logFilePath
, L
"w"))
53 fprintf(stderr
, "Failed to open log file for writing!\n");
57 _snprintf_s(gtestOutputPath
, _MAX_PATH
+ 16, _TRUNCATE
, "xml:%S.xml", basePath
);
58 if (gtestOutputPath
[0] && (!strchr(gtestOutputPath
, '?')))
60 ::testing::GTEST_FLAG(output
) = std::string(gtestOutputPath
);
64 static bool get_time_stamp(char *const buffer
, const size_t buff_size
)
66 const time_t time_stamp
= time(NULL
);
68 if(localtime_s(&tm_info
, &time_stamp
))
73 const size_t ret
= strftime(buffer
, buff_size
, "%Y-%m-%d %H:%M:%S", &tm_info
);
74 return (ret
> 0) && (ret
< buff_size
);
77 static void qt_message_handler(QtMsgType type
, const char *const msg
)
79 #if defined(MUTILS_DEBUG) && MUTILS_DEBUG
82 fprintf(stderr
, "%s\n", msg
);
85 if (g_logFile
&& (!ferror(g_logFile
)))
88 if (get_time_stamp(time_buffer
, 32))
90 fprintf(g_logFile
, "[%s] %s\n", time_buffer
, msg
);
94 fprintf(g_logFile
, "%s\n", msg
);
99 //===========================================================================
101 //===========================================================================
103 int wmain(int argc
, wchar_t **argv
)
105 printf("MuldeR's Utilities for Qt v%u.%02u - Regression Test Suite [%s]\n", MUtils::Version::lib_version_major(), MUtils::Version::lib_version_minor(), MUTILS_DEBUG
? "DEBUG" : "RELEASE");
106 printf("Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>. Some rights reserved.\n");
107 printf("Built on %s at %s with %s for Win-%s.\n\n", MUTILS_UTF8(MUtils::Version::lib_build_date().toString(Qt::ISODate
)), MUTILS_UTF8(MUtils::Version::lib_build_time().toString(Qt::ISODate
)), MUtils::Version::compiler_version(), MUtils::Version::compiler_arch());
109 printf("This library is free software; you can redistribute it and/or\n");
110 printf("modify it under the terms of the GNU Lesser General Public\n");
111 printf("License as published by the Free Software Foundation; either\n");
112 printf("version 2.1 of the License, or (at your option) any later version.\n\n");
114 initialize_mutils_log_file(argc
, argv
);
115 qInstallMsgHandler(qt_message_handler
);
116 ::testing::InitGoogleTest(&argc
, argv
);
118 return RUN_ALL_TESTS();