2016-12-17 17:22:34 +01:00
///////////////////////////////////////////////////////////////////////////////
// MuldeR's Utilities for Qt
2019-05-02 13:29:07 +02:00
// Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
2016-12-17 17:22:34 +01:00
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// http://www.gnu.org/licenses/lgpl-2.1.txt
//////////////////////////////////////////////////////////////////////////////////
//Google Test
# include <gtest/gtest.h>
//MUtils
# include <MUtils/Global.h>
# include <MUtils/Version.h>
//CRT
# include <cstdio>
# include <cstdlib>
//===========================================================================
// Message Handler
//===========================================================================
static FILE * g_logFile = NULL ;
static void initialize_mutils_log_file ( const int argc , const wchar_t * const * const argv )
{
wchar_t basePath [ _MAX_PATH ] , logFilePath [ _MAX_PATH ] ;
char gtestOutputPath [ _MAX_PATH + 16 ] ;
wcscpy_s ( basePath , _MAX_PATH , L " MUtilsTest " ) ;
if ( ( argc > 0 ) & & argv [ 0 ] & & argv [ 0 ] [ 0 ] )
{
wcsncpy_s ( basePath , _MAX_PATH , argv [ 0 ] , _TRUNCATE ) ;
}
_snwprintf_s ( logFilePath , _MAX_PATH , _TRUNCATE , L " %s.log " , basePath ) ;
if ( _wfopen_s ( & g_logFile , logFilePath , L " w " ) )
{
2016-12-26 18:55:06 +01:00
fprintf ( stderr , " Failed to open log file for writing! \n " ) ;
2016-12-17 17:22:34 +01:00
g_logFile = NULL ;
}
_snprintf_s ( gtestOutputPath , _MAX_PATH + 16 , _TRUNCATE , " xml:%S.xml " , basePath ) ;
2016-12-18 01:05:25 +01:00
if ( gtestOutputPath [ 0 ] & & ( ! strchr ( gtestOutputPath , ' ? ' ) ) )
2016-12-17 17:22:34 +01:00
{
2016-12-18 01:05:25 +01:00
: : testing : : GTEST_FLAG ( output ) = std : : string ( gtestOutputPath ) ;
2016-12-17 17:22:34 +01:00
}
}
2016-12-18 01:05:25 +01:00
static bool get_time_stamp ( char * const buffer , const size_t buff_size )
2016-12-17 17:22:34 +01:00
{
const time_t time_stamp = time ( NULL ) ;
struct tm tm_info ;
2016-12-18 01:05:25 +01:00
if ( localtime_s ( & tm_info , & time_stamp ) )
2016-12-17 17:22:34 +01:00
{
buffer [ 0 ] = L ' \0 ' ;
2016-12-18 01:05:25 +01:00
return false ;
2016-12-17 17:22:34 +01:00
}
2016-12-18 01:05:25 +01:00
const size_t ret = strftime ( buffer , buff_size , " %Y-%m-%d %H:%M:%S " , & tm_info ) ;
return ( ret > 0 ) & & ( ret < buff_size ) ;
2016-12-17 17:22:34 +01:00
}
static void qt_message_handler ( QtMsgType type , const char * const msg )
{
# if defined(MUTILS_DEBUG) && MUTILS_DEBUG
if ( msg & & msg [ 0 ] )
{
fprintf ( stderr , " %s \n " , msg ) ;
}
# endif //MUTILS_DEBUG
if ( g_logFile & & ( ! ferror ( g_logFile ) ) )
{
char time_buffer [ 32 ] ;
2016-12-18 01:05:25 +01:00
if ( get_time_stamp ( time_buffer , 32 ) )
{
fprintf ( g_logFile , " [%s] %s \n " , time_buffer , msg ) ;
}
else
{
fprintf ( g_logFile , " %s \n " , msg ) ;
}
2016-12-17 17:22:34 +01:00
}
}
//===========================================================================
// Main function
//===========================================================================
int wmain ( int argc , wchar_t * * argv )
{
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 " ) ;
2019-05-02 13:29:07 +02:00
printf ( " Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>. Some rights reserved. \n " ) ;
2016-12-17 17:22:34 +01:00
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 ( ) ) ;
printf ( " This library is free software; you can redistribute it and/or \n " ) ;
printf ( " modify it under the terms of the GNU Lesser General Public \n " ) ;
printf ( " License as published by the Free Software Foundation; either \n " ) ;
printf ( " version 2.1 of the License, or (at your option) any later version. \n \n " ) ;
initialize_mutils_log_file ( argc , argv ) ;
qInstallMsgHandler ( qt_message_handler ) ;
: : testing : : InitGoogleTest ( & argc , argv ) ;
return RUN_ALL_TESTS ( ) ;
}