Update of /cvsroot/babylonlib/_SrcPool/Cpp/Samples/_LibraryTest/Src In directory sc8-pr-cvs1:/tmp/cvs-serv22342/Cpp/Samples/_LibraryTest/Src Added Files: TsWriteTxt.cpp KTestLog.cpp KTestLog.h stdafx.cpp stdafx.h _TestMain.cpp Log Message: Created --- NEW FILE: TsWriteTxt.cpp --- /*$Workfile: S:\_SrcPool\Cpp\Samples\_LibraryTest\Src\TsWriteTxt.cpp$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:05:28 $ $Author: ddarko $ Outputs text to stdout stream Copyright: CommonSoft Inc. Jan. 2k2 Darko Kolakovic */ // Group=Examples #include "stdafx.h" #ifdef _CONSOLE //TsWriteToView()-------------------------------------------------------------- /*Writes a character string at the console standard output stream. Returns: true always. Note: uses Standard Template Library (STL). */ bool TsWriteToView(LPCTSTR lszText) { if (lszText != NULL) cout << lszText; else cout << _T("<null>"); cout.flush(); return true; } #endif //_CONSOLE /////////////////////////////////////////////////////////////////////////////// /***************************************************************************** * $Log: * 1 Biblioteka1.0 27/01/2003 9:37:26 PMDarko * $ *****************************************************************************/ --- NEW FILE: KTestLog.cpp --- /*$Workfile: S:\_SrcPool\Cpp\Samples\_LibraryTest\Src\KTestLog.cpp$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:05:28 $ $Author: ddarko $ Outputs test data to file Copyright: CommonSoft Inc. Darko Kolakovic 2003-01 */ // Group=Diagnostic /*Note: MS VC/C++ - Disable precompiled headers (/Yu"StdAfx.h" option) */ #include <stdio.h> //fopen() #include "KStrings.h" //BoolToA() #include "KTestLog.h" //TESTENTRY struct #include "KDbgMacr.h" static bool s_bTestLogInitalized = false; //'Test Log initialization passed' flag static FILE* s_fileTestLog; //test log file handler #ifndef UNICODE static LPCTSTR TESTLOGNAME = _T("LibraryTest.log"); //default test //log file name #else static LPCTSTR TESTLOGNAME = _T("LibraryTestUni.log"); //default Unicode test //log file name #endif //InitLogTest()---------------------------------------------------------------- /*Initalizes test log file and writes data about testing environment. */ void InitLogTest() { if (!s_bTestLogInitalized) //Initialize only once { //Open an empty file for reading and writing s_fileTestLog = fopen(TESTLOGNAME,"w+"); if (s_fileTestLog != NULL) { s_bTestLogInitalized = true; LPTSTR szEntry; //Write log header: date and time fwrite(_T(__DATE__), sizeof(TCHAR), _tcslen(__DATE__), s_fileTestLog); fwrite(_T("\t"), sizeof(TCHAR), 1, s_fileTestLog); fwrite(_T(__TIME__), sizeof(TCHAR), _tcslen(__TIME__), s_fileTestLog); fwrite(_T("\n"), sizeof(TCHAR), 1, s_fileTestLog); #ifdef __STDC__ szEntry = _T("ANSI C compliance\n"); fwrite(szEntry, sizeof(TCHAR), _tcslen(szEntry), s_fileTestLog); #endif #ifdef UNICODE szEntry = _T("Unicode\n"); fwrite(szEntry, sizeof(TCHAR), _tcslen(szEntry), s_fileTestLog); #endif #ifdef _CONSOLE szEntry = _T("Console\n"); #else szEntry = _T("GUI\n"); #endif fwrite(szEntry, sizeof(TCHAR), _tcslen(szEntry), s_fileTestLog); TESTENTRY logEntry = {_T("Predefined macros"), _T("KDbgMacr.h"), true}; LogTest(&logEntry); logEntry.m_szObjectName = _T("BoolToA()"); logEntry.m_szFileName = _T("KStrings.h"); logEntry.m_bResult = true; LogTest(&logEntry); logEntry.m_szObjectName = _T("InitLogTest()"); logEntry.m_szFileName = _T("KTestLog.h"); logEntry.m_bResult = true; LogTest(&logEntry); logEntry.m_szObjectName = _T("LogTest()"); logEntry.m_szFileName = _T("KTestLog.h"); logEntry.m_bResult = true; LogTest(&logEntry); logEntry.m_szObjectName = _T("CloseLogTest()"); logEntry.m_szFileName = _T("KTestLog.h"); logEntry.m_bResult = true; LogTest(&logEntry); logEntry.m_szObjectName = _T("CTestLog"); logEntry.m_szFileName = _T("KTestLog.h"); logEntry.m_bResult = true; LogTest(&logEntry); } } } //LogTest()-------------------------------------------------------------------- /*Writes test data to the test log in the following format: SourceCodeFileName \t ObjectName \t Result \n */ void LogTest(const PTESTENTRY pTestLog) { if (!s_bTestLogInitalized) InitLogTest(); if ((pTestLog != NULL) && (s_fileTestLog != NULL)) { //Write source code file name fwrite(pTestLog->m_szFileName, sizeof(TCHAR), _tcslen(pTestLog->m_szFileName), s_fileTestLog); fwrite(_T("\t"), sizeof(TCHAR), 1, s_fileTestLog); //Write name of the tested object fwrite(pTestLog->m_szObjectName, sizeof(TCHAR), _tcslen(pTestLog->m_szObjectName), s_fileTestLog); fwrite(_T("\t"), sizeof(TCHAR), 1, s_fileTestLog); //Write test results LPCTSTR szResult = BoolToA(pTestLog->m_bResult); fwrite(szResult, sizeof(TCHAR), _tcslen(szResult), s_fileTestLog); fwrite(_T("\n"), sizeof(TCHAR), 1, s_fileTestLog); } } //CloseLogTest()--------------------------------------------------------------- /*Closes the test log. */ void CloseLogTest() { if (s_fileTestLog != NULL) { fflush(s_fileTestLog); fclose(s_fileTestLog); } } /////////////////////////////////////////////////////////////////////////////// /***************************************************************************** * $Log: * 1 Biblioteka1.0 30/01/2003 9:44:58 PMDarko * $ *****************************************************************************/ --- NEW FILE: KTestLog.h --- /*$Workfile: S:\_SrcPool\Cpp\Samples\_LibraryTest\Src\KTestLog.h$: header file $Revision: 1.1 $ $Date: 2003/01/31 03:05:28 $ $Author: ddarko $ Collect some information about code testing Copyright: CommonSoft Inc. Darko Kolakovic 2003-01 */ /* Group=Diagnostic */ #ifndef __KTESTLOG_H__ /*KTestLog.h sentry */ #define __KTESTLOG_H__ #include "KTChar.h" /*LPCTSTR */ /*Container holding basic information about tested subject. */ struct tagTestEntry { LPCTSTR m_szObjectName; /*name of the tested function or object */ LPCTSTR m_szFileName; /*function or object file name */ bool m_bResult; /*result of the test */ }; typedef struct tagTestEntry TESTENTRY; /*Basic test data */ typedef struct tagTestEntry* PTESTENTRY; /*Pointer to test data container */ /* ///////////////////////////////////////////////////////////////////////// */ /*Declarations */ #ifdef __cplusplus extern "C" { #endif void InitLogTest(); void LogTest(const PTESTENTRY pTestLog); void CloseLogTest(); #ifdef __cplusplus } #endif /* ///////////////////////////////////////////////////////////////////////// */ /* C++ encapsulation */ #ifdef __cplusplus class CTestLog : public tagTestEntry { public: CTestLog(); ~CTestLog(); void LogTest(TESTENTRY& testLog) const; }; inline CTestLog::CTestLog() { ::InitLogTest(); } inline CTestLog::~CTestLog() { ::CloseLogTest(); } //LogTest()------------------------------------------------------------------ /*Writes an entry to the Test log. */ inline void CTestLog::LogTest(TESTENTRY& testLog //[in] test log entry ) const { ::LogTest(&testLog); } #endif /* ///////////////////////////////////////////////////////////////////////// */ #endif /*__KTESTLOG_H__ */ /****************************************************************************** * $Log: * 1 Biblioteka1.0 30/01/2003 9:45:02 PMDarko * $ *****************************************************************************/ --- NEW FILE: stdafx.cpp --- /*$Workfile: S:\_SrcPool\Cpp\Samples\_LibraryTest\Src\stdafx.cpp$ : source file that includes just the standard includes _LibraryTest.pch will be the pre-compiled header stdafx.obj will contain the pre-compiled type information $Revision: 1.1 $ $Date: 2003/01/31 03:05:28 $ $Author: ddarko $ StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named _LibraryTest.pch and a precompiled types file named StdAfx.obj. Files are generated by Microsoft Visual Studio */ #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file --- NEW FILE: stdafx.h --- /*$Workfile: stdafx.h$ : include file for standard system include files, or project specific include files that are used frequently, but are changed infrequently $Revision: 1.1 $ $Date: 2003/01/31 03:05:28 $ $Author: ddarko $ StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named _LibraryTest.pch and a precompiled types file named StdAfx.obj. Files are generated by Microsoft Visual Studio */ #pragma once #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <stdio.h> #ifdef __cplusplus #include <string> //std::string #include <iostream> //std::cout #include <iomanip.h> //std::endl #include "KTypedef.h" //Type definitions #include "KTChar.h" //Unicode mapping layer #include "KTrace.h" //debugging tools #include "KString.h" //CString #include "KTestLog.h" //CTestLog #endif //__cplusplus // TODO: reference additional headers your program requires here --- NEW FILE: _TestMain.cpp --- /*$Workfile: _TestMain.cpp$: implementation file $Revision: 1.1 $ $Date: 2003/01/31 03:05:28 $ $Author: ddarko $ Defines the entry point for the console application used to test libray functionality. 2003-01 Darko Kolakovic */ // Group=Examples #ifdef _MSC_VER /*Microsoft Visual Studio C/C++ compiler */ #ifndef _CONSOLE #error "define _CONSOLE macro in the project" #endif #endif #ifdef __GNUG__ /*GNU C++ compiler */ #ifndef _CONSOLE #warning "define _CONSOLE macro in the project" #endif #endif #include "stdafx.h" #include "KTrace.h" //TRACE macro #include "KTypedef.h" //BOOL typedef extern bool TestCalculus(); extern bool TestPoint(); extern bool TestQuadraticEquation(); extern bool TestComplex(); extern bool TestPointToComplex(); extern bool TestLeapYear(); //main()----------------------------------------------------------------------- /*Validates different date and time routines. Returns: EXIT_SUCCESS, which represents a value of 0, if successful. Otherwise a non-zero error code is returned. */ int _tmain(int argc, TCHAR* argv[] ) { cout << _T("Libarary validation") << endl << endl; CTestLog logTest; cout << _T("Start Calculus test") << endl << endl; if(TestCalculus()) cout << "Succeeded." << endl << endl; else { cout << "Failed!" << endl; return EXIT_FAILURE + 1; } if(TestPoint()) cout << "Succeeded." << endl << endl; else { cout << "Failed!" << endl; return EXIT_FAILURE + 2; } if(TestQuadraticEquation()) cout << "Succeeded." << endl << endl; else { cout << "Failed!" << endl; return EXIT_FAILURE + 3; } cout << _T("Start Complex number test") << endl << endl; if(TestComplex()) cout << "Succeeded." << endl << endl; else { cout << "Failed!" << endl; //TODO: return EXIT_FAILURE + 4; } if(TestPointToComplex()) cout << "Succeeded." << endl << endl; else { cout << "Failed!" << endl; return EXIT_FAILURE + 5; } cout << _T("Start Date and Time String test") << endl << endl; if(TestLeapYear()) cout << "Succeeded." << endl << endl; else { cout << "Failed!" << endl; return EXIT_FAILURE + 6; } return EXIT_SUCCESS; } /////////////////////////////////////////////////////////////////////////////// |