Happy new year 2017!
[MUtilities.git] / test / src / Main.cpp
blobaf9e893a47f806c4c85c6342e67683558f79740c
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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 //////////////////////////////////////////////////////////////////////////////////
22 //Google Test
23 #include <gtest/gtest.h>
25 //MUtils
26 #include <MUtils/Global.h>
27 #include <MUtils/Version.h>
29 //CRT
30 #include <cstdio>
31 #include <cstdlib>
33 //===========================================================================
34 // Message Handler
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");
54 g_logFile = NULL;
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);
67 struct tm tm_info;
68 if(localtime_s(&tm_info, &time_stamp))
70 buffer[0] = L'\0';
71 return false;
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
80 if (msg && msg[0])
82 fprintf(stderr, "%s\n", msg);
84 #endif //MUTILS_DEBUG
85 if (g_logFile && (!ferror(g_logFile)))
87 char time_buffer[32];
88 if (get_time_stamp(time_buffer, 32))
90 fprintf(g_logFile, "[%s] %s\n", time_buffer, msg);
92 else
94 fprintf(g_logFile, "%s\n", msg);
99 //===========================================================================
100 // Main function
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-2017 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();