Rework unit test framework (such as it is) to refer to tests by name & not numeric id. Mark tests as skipped if they don't make any TEST assertions or are skipped explicitly

This commit is contained in:
Brian Cox 2017-09-03 20:28:24 -07:00
parent 0d21e71407
commit 8c73f1cf3b
65 changed files with 650 additions and 273 deletions

View File

@ -186,3 +186,7 @@ void TestArchive()
} }
} }
void RegisterSuite_Archive()
{
RegisterTest("Archive", "Basic", TestArchive);
}

View File

@ -109,3 +109,9 @@ void TestBlockFile()
bf.Close(); bf.Close();
} }
void RegisterSuite_BlockFile()
{
RegisterTest("BlockFile", "Basic", TestBlockFile);
}

View File

@ -125,3 +125,7 @@ void TestBlockRecordArray()
#endif #endif
} }
void RegisterSuite_BlockRecordArray()
{
RegisterTest("BlockRecordArray", "Basic", TestBlockRecordArray);
}

View File

@ -75,11 +75,7 @@ void TestCharUtilBasic()
PrintChars( _T("fo\x23 54") ); PrintChars( _T("fo\x23 54") );
} }
void RegisterSuite_CharUtil()
/* {
TSS_BeginTestSuiteFrom( cCharEncoderTest ) RegisterTest("CharUtil", "Basic", TestCharUtilBasic);
}
TSS_AddTestCase( Basic );
TSS_EndTestSuite( cCharEncoderTest )
*/

View File

@ -161,3 +161,10 @@ void TestCmdLineParser()
// TODO -- test a bunch more!!! // TODO -- test a bunch more!!!
} }
void RegisterSuite_CmdLineParser()
{
RegisterTest("CmdLineParser", "Basic", TestCmdLineParser);
}

View File

@ -185,7 +185,8 @@ char NonZeroChar( char ch )
//TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd" //TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd"
void TestMbToDb() void TestMbToDb()
{ {
TCERR << "\nTODO: TestMbToDb in codeconvert_t.cpp is flaky & needs to be fixed/replaced; currently disabled." << std::endl; skip("This test is flaky & needs to be fixed/replaced; currently disabled.");
#if 0 #if 0
std::string s; std::string s;
s.resize( 0x10000 * 2 ); // two bytes for each combination s.resize( 0x10000 * 2 ); // two bytes for each combination
@ -240,7 +241,8 @@ void TestMbToDb()
// dbchar_t to mbchar_t // dbchar_t to mbchar_t
void TestDbToMb() void TestDbToMb()
{ {
TCERR << "\nTODO: TestDbToMb in codeconvert_t.cpp fails, most likely due to not speaking UTF-16. Should fix this." << std::endl; skip("This test fails, most likely due to not speaking UTF-16. Should fix this.");
#if 0 #if 0
wc16_string ws; wc16_string ws;
wc16_string::size_type n; wc16_string::size_type n;
@ -344,4 +346,8 @@ bool LowASCIILooksLikeUCS2InWchart()
} }
#endif #endif
void RegisterSuite_CodeConvert()
{
RegisterTest("CodeConvert", "MbToDb", TestMbToDb);
RegisterTest("CodeConvert", "DbToMb", TestDbToMb);
}

View File

@ -177,3 +177,9 @@ void TestConfigFile2(void)
d.TraceDetail("Tests Passed!\n"); d.TraceDetail("Tests Passed!\n");
//#endif // NOT_BRIANS_TEST //#endif // NOT_BRIANS_TEST
} }
void RegisterSuite_ConfigFile()
{
RegisterTest("ConfigFile", "Basic 1", TestConfigFile);
RegisterTest("ConfigFile", "Basic 2", TestConfigFile2);
}

View File

@ -299,4 +299,7 @@ void TestCryptoArchive()
#endif #endif
} }
void RegisterSuite_CryptoArchive()
{
RegisterTest("CryptoArchive", "Basic", TestCryptoArchive);
}

View File

@ -416,3 +416,8 @@ void TestCrypto()
} }
} }
void RegisterSuite_Crypto()
{
RegisterTest("Crypto", "Basic", TestCrypto);
}

View File

@ -212,3 +212,8 @@ void TestDbDataSourceBasic()
db.AssertAllBlocksValid(); db.AssertAllBlocksValid();
#endif #endif
} }
void RegisterSuite_DbDataSource()
{
RegisterTest("DbDataSource", "Basic", TestDbDataSourceBasic);
}

View File

@ -90,4 +90,7 @@ void TestDebug()
d.TraceDebug("Exiting...\n"); d.TraceDebug("Exiting...\n");
} }
void RegisterSuite_Debug()
{
RegisterTest("Debug", "Basic", TestDebug);
}

View File

@ -321,17 +321,16 @@ void TestDisplayEncoderBasic()
// make sure there are '\' and '"' in it ) // make sure there are '\' and '"' in it )
} }
/*TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) void RegisterSuite_DisplayEncoder()
{
TSS_AddTestCase( Basic ); RegisterTest("DisplayEncoder", "Basic", TestDisplayEncoderBasic);
TSS_AddTestCase( TestHexToChar ); RegisterTest("DisplayEncoder", "CharToHex", TestCharToHex);
TSS_AddTestCase( TestCharToHex ); RegisterTest("DisplayEncoder", "HexToChar", TestHexToChar);
TSS_AddTestCase( TestStringToHex ); RegisterTest("DisplayEncoder", "StringToHex", TestStringToHex);
TSS_AddTestCase( TestHexToString ); RegisterTest("DisplayEncoder", "HexToString", TestHexToString);
TSS_AddTestCase( TestUnconvertable ); //RegisterTest("DisplayEncoder", "Unconvertable", TestUnconvertable);
TSS_AddTestCase( TestUnprintable ); //RegisterTest("DisplayEncoder", "Unprintable", TestUnprintable);
TSS_AddTestCase( TestQuoteAndBackSlash ); RegisterTest("DisplayEncoder", "QuoteAndBackSlash", TestQuoteAndBackSlash);
}
TSS_EndTestSuite( cDisplayEncoderTest )*/

View File

@ -81,3 +81,8 @@ void TestError()
TEST(threw); TEST(threw);
} }
void RegisterSuite_Error()
{
RegisterTest("Error", "Basic", TestError);
}

View File

@ -143,3 +143,7 @@ void TestErrorBucketImpl()
} }
void RegisterSuite_ErrorBucketImpl()
{
RegisterTest("ErrorBucketImpl", "Basic", TestErrorBucketImpl);
}

View File

@ -158,3 +158,8 @@ void TestFCOCompare()
return; return;
} }
void RegisterSuite_FCOCompare()
{
RegisterTest("FCOCompare", "Basic", TestFCOCompare);
}

View File

@ -32,9 +32,16 @@
// fcodatabasefile.cpp // fcodatabasefile.cpp
#include "tw/stdtw.h" #include "tw/stdtw.h"
#include "tw/fcodatabasefile.h" #include "tw/fcodatabasefile.h"
#include "test.h"
void TestFCODatabaseFile() void TestFCODatabaseFile()
{ {
cDebug d("TestFCODatabaseFile"); cDebug d("TestFCODatabaseFile");
d.TraceError("Implement this!\n"); d.TraceError("Implement this!\n");
skip("TestFCODatabaseFile not implemented");
}
void RegisterSuite_FCODatabaseFile()
{
RegisterTest("FCODatabaseFile", "Basic", TestFCODatabaseFile);
} }

View File

@ -139,4 +139,7 @@ void TestFCOName()
} }
} }
void RegisterSuite_FCOName()
{
RegisterTest("FCOName", "Basic", TestFCOName);
}

View File

@ -61,3 +61,8 @@ void TestFCONameTbl()
pNode4->Release(); pNode4->Release();
pNode5->Release(); pNode5->Release();
} }
void RegisterSuite_FCONameTbl()
{
RegisterTest("FCONameTbl", "Basic", TestFCONameTbl);
}

View File

@ -115,3 +115,7 @@ void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre )
TEST( fcoNameNew == fcoName ); TEST( fcoNameNew == fcoName );
} }
void RegisterSuite_FCONameTranslator()
{
RegisterTest("FCONameTranslator", "Basic", TestFCONameTranslator);
}

View File

@ -94,3 +94,7 @@ void TestFCOPropImpl()
return; return;
} }
void RegisterSuite_FCOPropImpl()
{
RegisterTest("FCOPropImpl", "Basic", TestFCOPropImpl);
}

View File

@ -192,3 +192,8 @@ static void objManip (cFCOPropVector &testV, cDebug& d)
v3.AddItem(3); v3.AddItem(3);
TEST((v1 ^ v2) == v3); TEST((v1 ^ v2) == v3);
} }
void RegisterSuite_FCOPropVector()
{
RegisterTest("FCOPropVector", "Basic", TestFCOPropVector);
}

View File

@ -171,3 +171,7 @@ void TestFCOReport()
d.TraceDebug("Leaving...\n"); d.TraceDebug("Leaving...\n");
} }
void RegisterSuite_FCOReport()
{
RegisterTest("FCOReport", "Basic", TestFCOReport);
}

View File

@ -155,3 +155,7 @@ void TestFCOSetImpl()
} }
void RegisterSuite_FCOSetImpl()
{
RegisterTest("FCOSetImpl", "Basic", TestFCOSetImpl);
}

View File

@ -51,3 +51,8 @@ void TestFCOSpec()
cout << "End\tTestFCOSpec" << endl; cout << "End\tTestFCOSpec" << endl;
return; return;
} }
void RegisterSuite_FCOSpec()
{
RegisterTest("FCOSpec", "Basic", TestFCOSpec);
}

View File

@ -88,3 +88,8 @@ void TestFCOSpecAttr()
pNew->Release(); pNew->Release();
pAttr->Release(); pAttr->Release();
} }
void RegisterSuite_FCOSpecAttr()
{
RegisterTest("FCOSpecAttr", "Basic", TestFCOSpecAttr);
}

View File

@ -129,3 +129,8 @@ void TestFCOSpecHelper()
delete pHelp1; delete pHelp1;
delete pHelp2; delete pHelp2;
} }
void RegisterSuite_FCOSpecHelper()
{
RegisterTest("FCOSpecHelper", "Basic", TestFCOSpecHelper);
}

View File

@ -164,3 +164,7 @@ void TestFCOSpecList()
return; return;
} }
void RegisterSuite_FCOSpecList()
{
RegisterTest("FCOSpecList", "Basic", TestFCOSpecList);
}

View File

@ -80,3 +80,8 @@ void TestFcoSpecUtil()
d.TraceDebug("Leaving..\n"); d.TraceDebug("Leaving..\n");
} }
void RegisterSuite_FcoSpecUtil()
{
RegisterTest("FcoSpecUtil", "Basic", TestFcoSpecUtil);
}

View File

@ -58,3 +58,7 @@ void TestFile()
TEST(testStream); TEST(testStream);
} }
void RegisterSuite_File()
{
RegisterTest("File", "Basic", TestFile);
}

View File

@ -126,3 +126,8 @@ void TestFileHeader()
TEST(memcmp(buf, "abc123", 6) == 0); TEST(memcmp(buf, "abc123", 6) == 0);
} }
} }
void RegisterSuite_FileHeader()
{
RegisterTest("FileHeader", "Basic", TestFileHeader);
}

View File

@ -71,3 +71,7 @@ void TestFileUtil()
unlink(source.c_str()); unlink(source.c_str());
} }
void RegisterSuite_FileUtil()
{
RegisterTest("FileUtil", "Basic", TestFileUtil);
}

View File

@ -108,4 +108,9 @@ void TestFSDataSourceIter()
PrintIter( iter, d ); PrintIter( iter, d );
} }
void RegisterSuite_FSDataSourceIter()
{
RegisterTest("FSDataSourceIter", "Basic", TestFSDataSourceIter);
}

View File

@ -32,9 +32,16 @@
// fsobject_t -- the file system object test driver // fsobject_t -- the file system object test driver
#include "fs/stdfs.h" #include "fs/stdfs.h"
#include "fs/fsobject.h" #include "fs/fsobject.h"
#include "test.h"
void TestFSObject() void TestFSObject()
{ {
cDebug d("TestFSObject"); cDebug d("TestFSObject");
d.TraceError("Implement this!\n"); d.TraceError("Implement this!\n");
skip("TestFSObject not implemented");
}
void RegisterSuite_FSObject()
{
RegisterTest("FSObject", "Basic", TestFSObject);
} }

View File

@ -155,4 +155,8 @@ void TestGetSymLinkStr()
TEST(arch.Length() == (int64)file.size()); TEST(arch.Length() == (int64)file.size());
} }
void RegisterSuite_FSPropCalc()
{
RegisterTest("FSPropCalc", "Basic", TestFSPropCalc);
RegisterTest("FSPropCalc", "GetSymLinkStr", TestGetSymLinkStr);
}

View File

@ -133,3 +133,7 @@ void cTestFSPropDisplayer::Test()
return; return;
} }
void RegisterSuite_FSPropDisplayer()
{
RegisterTest("FSPropDisplayer", "Basic", TestFSPropDisplayer);
}

View File

@ -92,3 +92,8 @@ void TestFSPropSet()
return; return;
} }
void RegisterSuite_FSPropSet()
{
RegisterTest("FSPropSet", "Basic", TestFSPropSet);
}

View File

@ -102,3 +102,7 @@ void TestFCOSpecImpl()
pSpec->Release(); pSpec->Release();
} }
void RegisterSuite_FCOSpecImpl()
{
RegisterTest("FCOSpecImpl", "Basic", TestFCOSpecImpl);
}

View File

@ -33,31 +33,30 @@
// genre_t.cpp // genre_t.cpp
// //
#include <typeinfo>
#include "fco/stdfco.h" #include "fco/stdfco.h"
#include "fco/genreswitcher.h" #include "fco/genreswitcher.h"
#include "twtest/test.h" #include "twtest/test.h"
#include "fs/fs.h" #include "fs/fs.h"
#include "fs/fsfactory.h" void TestGenre()
void TestGenreSwitcher()
{ {
cDebug d("TestGenreSwitcher"); cDebug d("TestGenre");
d.TraceDebug("Entering...\n"); d.TraceDebug("Entering...\n");
cGenreSwitcher* genreSwitcher = cGenreSwitcher::GetInstance(); TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cFS::GenreID())) == cFS::GenreID());
TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); //TODO: GenreToString() dies w/ GENRE_INVALID. Figure out if this should be changed.
//
// can't switch to invalid genre //TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cGenre::GENRE_INVALID)) == cGenre::GENRE_INVALID);
//genreSwitcher->SelectGenre(cGenre::GENRE_INVALID);
//TEST(genreSwitcher->CurrentGenre() == cGenre::GENRE_INVALID);
genreSwitcher->SelectGenre(cFS::GenreID());
TEST(genreSwitcher->CurrentGenre() == cFS::GenreID()); TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("fs")) == cFS::GenreID());
TEST(typeid(*iTWFactory::GetInstance()) == typeid(cFSFactory)); TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("none of the above")) == cGenre::GENRE_INVALID);
d.TraceDebug("All tests passed.\n"); d.TraceDebug("All tests passed.\n");
} }
void RegisterSuite_Genre()
{
RegisterTest("Genre", "Basic", TestGenre);
}

View File

@ -91,3 +91,12 @@ void TestGenreSpecList()
d.TraceDebug("All tests passed.\n"); d.TraceDebug("All tests passed.\n");
} }
void RegisterSuite_GenreSpecList()
{
RegisterTest("GenreSpecList", "Basic", TestGenreSpecList);
}

View File

@ -33,25 +33,36 @@
// genreswitcher_t.h // genreswitcher_t.h
// //
#include <typeinfo>
#include "fco/stdfco.h" #include "fco/stdfco.h"
#include "fco/genreswitcher.h" #include "fco/genreswitcher.h"
#include "twtest/test.h" #include "twtest/test.h"
#include "fs/fs.h" #include "fs/fs.h"
void TestGenre() #include "fs/fsfactory.h"
void TestGenreSwitcher()
{ {
cDebug d("TestGenre"); cDebug d("TestGenreSwitcher");
d.TraceDebug("Entering...\n"); d.TraceDebug("Entering...\n");
TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cFS::GenreID())) == cFS::GenreID()); cGenreSwitcher* genreSwitcher = cGenreSwitcher::GetInstance();
//TODO: GenreToString() dies w/ GENRE_INVALID. Figure out if this should be changed.
//
//TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cGenre::GENRE_INVALID)) == cGenre::GENRE_INVALID);
TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("fs")) == cFS::GenreID()); TEST(genreSwitcher->CurrentGenre() == cFS::GenreID());
TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("none of the above")) == cGenre::GENRE_INVALID);
// can't switch to invalid genre
//genreSwitcher->SelectGenre(cGenre::GENRE_INVALID);
//TEST(genreSwitcher->CurrentGenre() == cGenre::GENRE_INVALID);
genreSwitcher->SelectGenre(cFS::GenreID());
TEST(genreSwitcher->CurrentGenre() == cFS::GenreID());
TEST(typeid(*iTWFactory::GetInstance()) == typeid(cFSFactory));
d.TraceDebug("All tests passed.\n"); d.TraceDebug("All tests passed.\n");
} }
void RegisterSuite_GenreSwitcher()
{
RegisterTest("GenreSwitcher", "Basic", TestGenreSwitcher);
}

View File

@ -97,3 +97,7 @@ void TestGrowHeap()
TEST( gh.TotalMemUsage() == 0 ); TEST( gh.TotalMemUsage() == 0 );
} }
void RegisterSuite_GrowHeap()
{
RegisterTest("GrowHeap", "Basic", TestGrowHeap);
}

View File

@ -43,15 +43,6 @@
using namespace std; using namespace std;
void HashTest1();
void HashTest2();
void TestHashTable(void)
{
HashTest1();
HashTest2();
}
void HashTest1() void HashTest1()
{ {
//Test the Hash table with Key = TSTRING //Test the Hash table with Key = TSTRING
@ -218,3 +209,9 @@ void HashTest2()
d.TraceDebug("PASSED!\n"); d.TraceDebug("PASSED!\n");
} }
void RegisterSuite_HashTable()
{
RegisterTest("HashTable", "Basic 1", HashTest1);
RegisterTest("HashTable", "Basic 2", HashTest2);
}

View File

@ -206,3 +206,8 @@ void TestHierDatabaseBasic()
#endif #endif
} }
void RegisterSuite_HierDatabase()
{
RegisterTest("HierDatabase", "Basic", TestHierDatabaseBasic);
}

View File

@ -134,3 +134,7 @@ void TestKeyFile()
return; return;
} }
void RegisterSuite_KeyFile()
{
RegisterTest("KeyFile", "Basic", TestKeyFile);
}

View File

@ -204,6 +204,7 @@ void TestSizes()
{ {
cDebug d("TestSizes"); cDebug d("TestSizes");
d.TraceError("Fix this!\n"); d.TraceError("Fix this!\n");
skip("TODO: TestSizes needs work");
/* /*
TEST( CanBeRepresentedAs( char(), char() ) ); TEST( CanBeRepresentedAs( char(), char() ) );
TEST( CanBeRepresentedAs( char(), unsigned char() ) ); TEST( CanBeRepresentedAs( char(), unsigned char() ) );
@ -234,3 +235,9 @@ bool CanBeRepresentedAs( E e, T t )
return fReturn; return fReturn;
} }
void RegisterSuite_Platform()
{
RegisterTest("Platform", "Alignment", TestAlignment);
RegisterTest("Platform", "Sizes", TestSizes);
}

View File

@ -101,6 +101,9 @@ void TestPolicyParser()
cDebug d("TestPolicyParser()"); cDebug d("TestPolicyParser()");
test_policy_file("pol.txt"); test_policy_file("pol.txt");
TCERR << "TestPolicyParser: Parser needs work to be able to test more than one policy" << std::endl;
// test_policy_file("directives.txt"); //fails unless you substitute your hostname for 'your_host' in this file // test_policy_file("directives.txt"); //fails unless you substitute your hostname for 'your_host' in this file
// TODO: test currently segfaults if you create more than one policy parser in a process. (Not a real world scenario). // TODO: test currently segfaults if you create more than one policy parser in a process. (Not a real world scenario).
@ -110,4 +113,7 @@ void TestPolicyParser()
test_policy_file("polruleattr.txt"); */ test_policy_file("polruleattr.txt"); */
} }
void RegisterSuite_PolicyParser()
{
RegisterTest("PolicyParser", "Basic", TestPolicyParser);
}

View File

@ -33,6 +33,7 @@
#include "core/stdcore.h" #include "core/stdcore.h"
#include "core/refcountobj.h" #include "core/refcountobj.h"
#include "core/debug.h" #include "core/debug.h"
#include "test.h"
class cRefCountTestObj : public cRefCountObj class cRefCountTestObj : public cRefCountObj
{ {
@ -166,3 +167,7 @@ void TestRefCountObj()
return; return;
} }
void RegisterSuite_RefCountObj()
{
RegisterTest("RefCountObj", "Basic", TestRefCountObj);
}

View File

@ -95,6 +95,9 @@ void TestResources()
} }
void RegisterSuite_Resources()
{
RegisterTest("Resources", "Basic", TestResources);
}

View File

@ -38,6 +38,7 @@
#include "core/stdcore.h" #include "core/stdcore.h"
#include "core/serializer.h" #include "core/serializer.h"
#include "core/serializable.h" #include "core/serializable.h"
#include "test.h"
// The reading and writing functionality of the serializer is tested in // The reading and writing functionality of the serializer is tested in
// serializerimpl_t.cpp, so there's very little to be done here. // serializerimpl_t.cpp, so there's very little to be done here.
@ -71,3 +72,8 @@ void TestSerializer()
{ {
cSerTestObject test_obj; cSerTestObject test_obj;
} }
void RegisterSuite_Serializer()
{
RegisterTest("Serializer", "Basic", TestSerializer);
}

View File

@ -178,3 +178,7 @@ void TestSerializerImpl()
return; return;
} }
void RegisterSuite_SerializerImpl()
{
RegisterTest("SerializerImpl", "Basic", TestSerializerImpl);
}

View File

@ -361,3 +361,7 @@ void TestSignature()
return; return;
} }
void RegisterSuite_Signature()
{
RegisterTest("Signature", "Basic", TestSignature);
}

View File

@ -144,3 +144,7 @@ void TestSerRefCountObj()
return; return;
} }
void RegisterSuite_SerRefCountObj()
{
RegisterTest("SerRefCountObj", "Basic", TestSerRefCountObj);
}

View File

@ -93,3 +93,7 @@ void OutputString( TSTRING& str )
TEST( str == qe.Unencode(qe.Encode(str)) ); TEST( str == qe.Unencode(qe.Encode(str)) );
} }
void RegisterSuite_StringEncoder()
{
RegisterTest("StringEncoder", "Basic", TestStringEncoder);
}

View File

@ -172,3 +172,8 @@ void TestStringUtil()
#endif//__STRINGUTIL_T_H #endif//__STRINGUTIL_T_H
void RegisterSuite_StringUtil()
{
RegisterTest("StringUtil", "Basic", TestStringUtil);
}

View File

@ -31,11 +31,17 @@
// //
// tasktimer_t -- test driver for cTaskTimer // tasktimer_t -- test driver for cTaskTimer
#include "core/stdcore.h" #include "core/stdcore.h"
#include "test.h"
void TestTaskTimer() void TestTaskTimer()
{ {
cDebug d("TestTaskTimer"); cDebug d("TestTaskTimer");
d.TraceError("Implement this!\n"); d.TraceError("Implement this!\n");
skip("TestTaskTimer unimplemented");
} }
void RegisterSuite_TaskTimer()
{
RegisterTest("TaskTimer", "Basic", TestTaskTimer);
}

View File

@ -133,3 +133,8 @@ void test_wist(const TSTRING& input, cDebug& d)
d.TraceDetail("%s \n", parse.c_str() ); d.TraceDetail("%s \n", parse.c_str() );
} }
void RegisterSuite_TCHAR()
{
RegisterTest("TCHAR", "Basic", TestTCHAR);
}

View File

@ -64,197 +64,142 @@
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
// the test routines // Known test suites
void TestFCOName(); void RegisterSuite_Archive();
void TestFCOTest(); void RegisterSuite_BlockFile();
void TestFCOSetImpl(); void RegisterSuite_BlockRecordArray();
void TestFCOSpec(); void RegisterSuite_CharUtil();
void TestFCOPropVector(); void RegisterSuite_CmdLineParser();
void TestFileHeader(); void RegisterSuite_CodeConvert();
void TestFile(); void RegisterSuite_ConfigFile();
void TestFSPropSet(); void RegisterSuite_CryptoArchive();
void TestFCOSpecImpl(); void RegisterSuite_Crypto();
void TestFSObject(); void RegisterSuite_DbDataSource();
void TestFSPropCalc(); void RegisterSuite_Debug();
void TestFCOPropImpl(); void RegisterSuite_DisplayEncoder();
void TestFCOCompare(); void RegisterSuite_Error();
//void TestTripwire(); void RegisterSuite_ErrorBucketImpl();
void TestWin32FSServices(); void RegisterSuite_FCOCompare();
void TestFCOSpecList(); void RegisterSuite_FCODatabaseFile();
void TestFCOReport(); void RegisterSuite_FCOName();
void TestArchive(); void RegisterSuite_FCONameTbl();
void TestSerializer(); void RegisterSuite_FCONameTranslator();
void TestSerializerImpl(); void RegisterSuite_FCOPropImpl();
void TestRefCountObj(); void RegisterSuite_FCOPropVector();
void TestSignature(); void RegisterSuite_FCOReport();
void TestSerRefCountObj(); void RegisterSuite_FCOSetImpl();
void TestUnixFSServices(); void RegisterSuite_FCOSpec();
void TestError(); void RegisterSuite_FCOSpecAttr();
void TestDebug(); void RegisterSuite_FCOSpecHelper();
void TestFcoSpecUtil(); void RegisterSuite_FCOSpecList();
void TestTypes(); void RegisterSuite_FcoSpecUtil();
void TestTCHAR(); void RegisterSuite_File();
void TestErrorBucketImpl(); void RegisterSuite_FileHeader();
void TestHashTable(); void RegisterSuite_FileUtil();
void TestTextReportViewer(); void RegisterSuite_FSDataSourceIter();
void TestFCONameTbl(); void RegisterSuite_FSObject();
void TestConfigFile(); void RegisterSuite_FSPropCalc();
void TestResources(); void RegisterSuite_FSPropDisplayer();
void TestGetSymLinkStr(); void RegisterSuite_FSPropSet();
void TestPolicyParser(); void RegisterSuite_FCOSpecImpl();
void RegisterSuite_GenreSwitcher();
void TestFCOSpecHelper(); void RegisterSuite_GenreSpecList();
void TestCrypto(); void RegisterSuite_Error();
void TestCryptoArchive(); void RegisterSuite_GrowHeap();
void TestFCOSpecAttr(); void RegisterSuite_HashTable();
void TestCmdLineParser(); void RegisterSuite_HierDatabase();
void TestTaskTimer(); void RegisterSuite_KeyFile();
void TestKeyFile(); void RegisterSuite_Platform();
void TestTWUtil(); void RegisterSuite_PolicyParser();
void TestFSPropDisplayer(); void RegisterSuite_RefCountObj();
void TestFSPropDisplayer(); void RegisterSuite_Resources();
void TestGenre(); void RegisterSuite_Serializer();
void TestFSDataSourceIter(); void RegisterSuite_SerializerImpl();
void TestGenerateDb(); void RegisterSuite_Signature();
void TestHierDatabaseBasic(); void RegisterSuite_SerRefCountObj();
void TestGenreSwitcher(); void RegisterSuite_StringEncoder();
void TestDbDataSourceBasic(); void RegisterSuite_StringUtil();
void TestGenreSpecList(); void RegisterSuite_TaskTimer();
void TestIntegrityCheck(); void RegisterSuite_TCHAR();
void TestFCODatabaseFile(); void RegisterSuite_TextReportViewer();
void TestWchar16(); void RegisterSuite_TWLocale();
void TestStringEncoder(); void RegisterSuite_TWUtil();
void RegisterSuite_Types();
void TestGrowHeap(); void RegisterSuite_UnixFSServices();
void TestPlatform(); void RegisterSuite_UserNotifyStdout();
void TestBlockFile(); void RegisterSuite_Wchar16();
void TestBlockRecordArray();
void TestTWLocale();
void TestFileUtil();
void TestFCONameTranslator();
void TestCodeConverter();
void TestCharToHex();
void TestHexToChar();
void TestStringToHex();
void TestHexToString();
//void TestUnconvertable();
//void TestUnprintable();
void TestQuoteAndBackSlash();
void TestDisplayEncoderBasic();
void TestCharUtilBasic();
void TestConfigFile2();
void TestUserNotifyStdout();
/// This is easier than all the (cpp) files and declarations /// This is easier than all the (cpp) files and declarations
#include "stringutil_t.h" #include "stringutil_t.h"
void Usage() void Usage()
{ {
TCERR << _T("Usage: test {all | testid [testid ...]}\n") TCERR << _T("Usage: test {all | list | testid [testid ...]}\n")
_T("\n") _T("\n")
_T("Ex: test 1 2 3 12\n") _T("Ex: test foo bar/baz\n")
_T("(runs test id's 1, 2, 3, and 12)\n\n"); _T("(runs suite foo and test bar/baz)\n\n");
} }
const int MAX_TEST_ID = 88;
static int ran_count = 0; static int ran_count = 0;
static int failed_count = 0; static int failed_count = 0;
static int skipped_count = 0;
static int macro_count = 0;
static std::vector<std::string> error_strings; static std::vector<std::string> error_strings;
static std::vector<std::string> skipped_strings;
static void Test(int testID) class skip_exception : public std::runtime_error
{ {
TCERR << std::endl << "=== Running test ID #" << testID << " ===" << std::endl; public:
skip_exception(const std::string& reason) : std::runtime_error(reason) {}
bool ran = true; };
try { void skip(const std::string& reason)
{
switch (testID) throw skip_exception(reason);
}
void CountMacro()
{
macro_count++;
TCERR << "*** Incrementing macro count, value is now" << macro_count << std::endl;;
}
/////////////////////////
static TestMap tests;
void RegisterTest(const std::string& suite, const std::string testName, TestPtr testPtr )
{
tests[suite][testName] = testPtr;
}
static void RunTest(const std::string& suiteName, const std::string& testName, TestPtr testPtr)
{
try
{
if (testPtr)
{ {
case 1: TestArchive(); break; ran_count++;
case 2: TestCmdLineParser(); break; int pre_count = macro_count;
case 3: TestCrypto(); break; testPtr();
case 4: TestCryptoArchive(); break; if (macro_count > pre_count)
case 5: TestDebug(); break; TCERR << "PASSED" << std::endl;
case 6: TestError(); break; else
case 7: TestErrorBucketImpl(); break; skip("Test did not make any TEST assertions");
case 8: TestFCOCompare(); break;
case 9: TestUserNotifyStdout(); break;
case 12: TestFCOName(); break;
case 13: TestFCONameTbl(); break;
case 14: TestFCOPropVector(); break;
case 15: TestFCOPropImpl(); break;
case 16: TestFCOReport(); break;
case 17: TestGetSymLinkStr(); break;
case 18: TestFCOSetImpl(); break;
case 19: TestFCOSpec(); break;
case 20: TestFCOSpecAttr(); break;
case 21: TestFCOSpecHelper(); break;
case 22: TestFCOSpecList(); break;
case 23: TestFcoSpecUtil(); break;
case 24: TestFileHeader(); break;
case 25: TestFile(); break;
case 26: TestFSPropSet(); break;
case 27: TestFSPropCalc(); break;
case 28: TestFCOSpecImpl(); break;
case 29: TestFSObject(); break;
case 30: TestSerializer(); break;
case 31: TestRefCountObj(); break;
case 32: TestSerializerImpl(); break;
case 33: TestResources(); break;
case 34: TestSignature(); break;
case 35: TestTaskTimer(); break;
//case 36: TestTripwire(); break;
case 37: TestTextReportViewer(); break;
case 39: TestSerRefCountObj(); break;
case 40: TestError(); break;
case 41: TestFCODatabaseFile(); break;
case 42: TestHashTable(); break;
case 43: TestTCHAR(); break;
case 44: TestTypes(); break;
case 45: TestUnixFSServices(); break;
case 46: TestConfigFile(); break;
case 47: TestPolicyParser(); break;
case 48: TestKeyFile(); break;
case 49: TestTWUtil(); break;
case 50: TestFSPropDisplayer(); break;
case 52: TestGenre(); break;
case 53: TestFSDataSourceIter(); break;
//case 54: TestGenerateDb(); break;
case 55: TestHierDatabaseBasic(); break;
case 56: TestGenreSwitcher(); break;
case 57: TestDbDataSourceBasic(); break;
case 58: TestGenreSpecList(); break;
//case 59: TestIntegrityCheck(); break;
case 65: TestWchar16(); break;
case 66: TestStringEncoder(); break;
case 69: TestGrowHeap(); break;
case 70: TestPlatform(); break;
case 71: TestBlockFile(); break;
case 72: TestBlockRecordArray(); break;
case 74: TestFileUtil(); break;
case 75: TestTWLocale(); break;
case 76: TestFCONameTranslator(); break;
case 77: TestStringUtil(); break;
case 78: TestCodeConverter(); break;
case 79: TestCharToHex(); break;
case 80: TestHexToChar(); break;
case 81: TestStringToHex(); break;
case 82: TestHexToString(); break;
// case 83: TestUnconvertable(); break;
// case 84: TestUnprintable(); break;
case 85: TestQuoteAndBackSlash(); break;
case 86: TestDisplayEncoderBasic(); break;
case 87: TestCharUtilBasic(); break;
case 88: TestConfigFile2(); break;
default: ran = false; break;
} }
return;
}
catch (skip_exception& e)
{
TCERR << "SKIPPED: " << e.what() << std::endl;
std::stringstream sstr;
sstr << "Test " << suiteName << "/" << testName << ": " << e.what();
skipped_strings.push_back(sstr.str());
skipped_count++;
} }
catch (eError& error) catch (eError& error)
{ {
@ -262,7 +207,7 @@ static void Test(int testID)
cTWUtil::PrintErrorMsg(error); cTWUtil::PrintErrorMsg(error);
std::stringstream sstr; std::stringstream sstr;
sstr << "Test " << testID << ": " << error.GetMsg(); sstr << "Test " << suiteName << "/" << testName << ": " << error.GetMsg();
error_strings.push_back(sstr.str()); error_strings.push_back(sstr.str());
failed_count++; failed_count++;
@ -271,7 +216,7 @@ static void Test(int testID)
TCERR << "FAILED: " << e.what() << std::endl; TCERR << "FAILED: " << e.what() << std::endl;
std::stringstream sstr; std::stringstream sstr;
sstr << "Test " << testID << ": " << e.what(); sstr << "Test " << suiteName << "/" << testName << ": " << e.what();
error_strings.push_back(sstr.str()); error_strings.push_back(sstr.str());
failed_count++; failed_count++;
@ -280,21 +225,134 @@ static void Test(int testID)
TCERR << "FAILED: <unknown>" << std::endl; TCERR << "FAILED: <unknown>" << std::endl;
std::stringstream sstr; std::stringstream sstr;
sstr << "Test " << testID << ": <unknown>"; sstr << "Test " << suiteName << "/" << testName << ": <unknown>";
error_strings.push_back(sstr.str()); error_strings.push_back(sstr.str());
failed_count++;
} }
}
if(ran)
static void RunTestSuite(const std::string& suiteName, SuiteMap suite)
{
SuiteMap::const_iterator itr;
for( itr = suite.begin(); itr != suite.end(); ++itr)
{ {
ran_count++; TCERR << "----- Running test: " << suiteName << "/" << itr->first << " -----" << std::endl << std::endl;
TCERR << std::endl << "=== test ID #" << testID << " completed ===" << std::endl; RunTest(suiteName, itr->first, itr->second);
TCERR << std::endl << "----- Finished test: " << suiteName << "/" << itr->first << " -----" << std::endl;
}
}
static void RunAllTests()
{
TestMap::const_iterator itr;
for( itr = tests.begin(); itr != tests.end(); ++itr)
{
TCERR << std::endl << "===== Starting test suite: " << itr->first << " =====" << std::endl;
RunTestSuite(itr->first, itr->second);
TCERR << "===== Finished test suite: " << itr->first << " =====" << std::endl;
}
}
static void ListTests()
{
TestMap::const_iterator itr;
for( itr = tests.begin(); itr != tests.end(); ++itr)
{
std::string suiteName = itr->first;
SuiteMap suite = itr->second;
TCERR << suiteName << std::endl;
SuiteMap::const_iterator itr;
for( itr = suite.begin(); itr != suite.end(); ++itr)
{
TCERR << " " << suiteName << "/" << itr->first << std::endl;
}
}
}
static void RunTest(const std::string& to_run)
{
std::string::size_type pos = to_run.find_first_of("/");
if(pos == std::string::npos)
{
RunTestSuite(to_run, tests[to_run]);
} }
else else
TCERR << std::endl << "=== test ID #" << testID << " currently unused ===" << std::endl; {
std::string suite = to_run.substr(0, pos);
std::string testName = to_run.substr(pos+1);
RunTest(suite, testName, tests[suite][testName]);
}
} }
static void RegisterSuites()
{
RegisterSuite_Archive();
RegisterSuite_BlockFile();
RegisterSuite_BlockRecordArray();
RegisterSuite_CharUtil();
RegisterSuite_CmdLineParser();
RegisterSuite_CodeConvert();
RegisterSuite_ConfigFile();
RegisterSuite_CryptoArchive();
RegisterSuite_Crypto();
RegisterSuite_DbDataSource();
RegisterSuite_Debug();
RegisterSuite_DisplayEncoder();
RegisterSuite_Error();
RegisterSuite_ErrorBucketImpl();
RegisterSuite_FCOCompare();
RegisterSuite_FCODatabaseFile();
RegisterSuite_FCOName();
RegisterSuite_FCONameTbl();
RegisterSuite_FCONameTranslator();
RegisterSuite_FCOPropImpl();
RegisterSuite_FCOPropVector();
RegisterSuite_FCOReport();
RegisterSuite_FCOSetImpl();
RegisterSuite_FCOSpec();
RegisterSuite_FCOSpecAttr();
RegisterSuite_FCOSpecHelper();
RegisterSuite_FCOSpecList();
RegisterSuite_FcoSpecUtil();
RegisterSuite_File();
RegisterSuite_FileHeader();
RegisterSuite_FileUtil();
RegisterSuite_FSDataSourceIter();
RegisterSuite_FSObject();
RegisterSuite_FSPropCalc();
RegisterSuite_FSPropDisplayer();
RegisterSuite_FSPropSet();
RegisterSuite_FCOSpecImpl();
RegisterSuite_GenreSwitcher();
RegisterSuite_GenreSpecList();
RegisterSuite_Error();
RegisterSuite_GrowHeap();
RegisterSuite_HashTable();
RegisterSuite_HierDatabase();
RegisterSuite_KeyFile();
RegisterSuite_Platform();
RegisterSuite_PolicyParser();
RegisterSuite_RefCountObj();
RegisterSuite_Resources();
RegisterSuite_Serializer();
RegisterSuite_SerializerImpl();
RegisterSuite_Signature();
RegisterSuite_SerRefCountObj();
RegisterSuite_StringEncoder();
RegisterSuite_StringUtil();
RegisterSuite_TaskTimer();
RegisterSuite_TCHAR();
RegisterSuite_TextReportViewer();
RegisterSuite_TWLocale();
RegisterSuite_TWUtil();
RegisterSuite_Types();
RegisterSuite_UnixFSServices();
RegisterSuite_UserNotifyStdout();
RegisterSuite_Wchar16();
}
std::string TwTestDir() std::string TwTestDir()
{ {
static std::string dir; static std::string dir;
@ -358,17 +416,21 @@ void tw_unexpected_handler()
int _tmain(int argc, TCHAR** argv) int _tmain(int argc, TCHAR** argv)
{ {
#ifdef _DEBUG
std::cout << "Test: Init" << std::endl; std::cout << "Test: Init" << std::endl;
std::cout << "Test: Setup" << std::endl;
std::cout << "Test: argc - " << argc << std::endl;
std::cout << "Test: *argv - " << argv[0] << std::endl;
#endif
try try
{ {
std::cout << "Test: Setup" << std::endl;
std::cout << "Test: argc - " << argc << std::endl;
std::cout << "Test: *argv - " << argv[0] << std::endl;
EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler); EXCEPTION_NAMESPACE set_terminate(tw_terminate_handler);
EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler); EXCEPTION_NAMESPACE set_unexpected(tw_unexpected_handler);
if (argc < 2)
Usage();
cTWInit twInit; cTWInit twInit;
twInit.Init( argv[0] ); twInit.Init( argv[0] );
@ -377,20 +439,24 @@ int _tmain(int argc, TCHAR** argv)
//cDebug::SetDebugLevel(cDebug::D_NEVER); //cDebug::SetDebugLevel(cDebug::D_NEVER);
cDebug::SetDebugLevel(cDebug::D_DETAIL); cDebug::SetDebugLevel(cDebug::D_DETAIL);
//cDebug::SetDebugLevel(cDebug::D_DEBUG); //cDebug::SetDebugLevel(cDebug::D_DEBUG);
int i;
if (argc < 2) RegisterSuites();
Usage();
else if (_tcsicmp(argv[1], _T("all")) == 0) if (_tcsicmp(argv[1], _T("all")) == 0)
// run all the tests {
for (i = 1; i <= MAX_TEST_ID; ++i) RunAllTests();
Test(i); }
else if(_tcsicmp(argv[1], _T("list")) == 0)
{
ListTests();
}
else else
for (i = 1; i < argc; ++i) {
Test(_ttoi(argv[i])); // Note: if atoi returns 0, Test() will handle it fine. for (int i = 1; i < argc; ++i)
RunTest(argv[i]);
} }
}
catch (eError& error) catch (eError& error)
{ {
cTWUtil::PrintErrorMsg(error); cTWUtil::PrintErrorMsg(error);
@ -404,16 +470,30 @@ int _tmain(int argc, TCHAR** argv)
return 1; return 1;
} }
// make sure all the refrence counted objects have been destroyed // make sure all the reference counted objects have been destroyed
// this test always fails because of the static cFCONameTbl // this test always fails because of the static cFCONameTbl
//TEST(cRefCountObj::AllRefCountObjDestoryed() == true); //TEST(cRefCountObj::AllRefCountObjDestoryed() == true);
std::cout << std::endl << "Ran " << ran_count << " unit tests with " << failed_count << " failures." << std::endl; std::cout << std::endl << "Ran " << ran_count << " unit tests with " << failed_count << " failures, " << skipped_count << " skipped." << std::endl;
std::vector<std::string>::iterator itr; if (failed_count)
for (itr = error_strings.begin(); itr != error_strings.end(); ++itr)
{ {
std::cout << "\t" << *itr << std::endl; std::cout << std::endl << "Failures: " << std::endl;
std::vector<std::string>::iterator itr;
for (itr = error_strings.begin(); itr != error_strings.end(); ++itr)
{
std::cout << "\t" << *itr << std::endl;
}
}
if (skipped_count)
{
std::cout << std::endl << "Skipped: " << std::endl;
std::vector<std::string>::iterator itr;
for (itr = skipped_strings.begin(); itr != skipped_strings.end(); ++itr)
{
std::cout << "\t" << *itr << std::endl;
}
} }
std::cout << std::endl; std::cout << std::endl;

View File

@ -66,9 +66,13 @@ public:
TSS_EndPackage( cTest ) TSS_EndPackage( cTest )
void CountMacro();
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// TEST() -- Works like ASSERT() but it also breaks during release mode // TEST() -- throw a std::runtime error if test condition is false.
#define TEST(exp) if (!(exp)) \ //
#define TEST(exp) CountMacro(); \
if (!(exp)) \
{ \ { \
std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \ std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \
throw std::runtime_error(#exp); \ throw std::runtime_error(#exp); \
@ -79,5 +83,14 @@ TSS_EndPackage( cTest )
std::string TwTestDir(); std::string TwTestDir();
std::string TwTestPath(const std::string& child); std::string TwTestPath(const std::string& child);
typedef void (*TestPtr)();
typedef std::map< std::string, TestPtr > SuiteMap;
typedef std::map< std::string, SuiteMap > TestMap;
void RegisterTest(const std::string& suite, const std::string testName, TestPtr testPtr );
void skip(const std::string& reason);
#endif // __TEST_H #endif // __TEST_H

View File

@ -127,7 +127,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d)
void TestTextReportViewer() void TestTextReportViewer()
{ {
TCERR << std::endl << "TestTextReportViewer needs to be cleaned up & fixed, currently disabled" << std::endl; skip("TestTextReportViewer needs to be cleaned up & fixed, currently disabled");
#if 0 #if 0
cFCOReport report; cFCOReport report;
@ -476,3 +476,7 @@ void MakeDir( const TCHAR* const lpszDirName )
//#endif //FIXED_TRV_TEST_SUITE //#endif //FIXED_TRV_TEST_SUITE
void RegisterSuite_TextReportViewer()
{
RegisterTest("TextReportViewer", "Basic", TestTextReportViewer);
}

View File

@ -40,6 +40,7 @@
#include "core/stdcore.h" #include "core/stdcore.h"
#include "core/debug.h" #include "core/debug.h"
#include "core/twlocale.h" #include "core/twlocale.h"
#include "test.h"
void TestAtoi(); void TestAtoi();
void TestItoa(); void TestItoa();
@ -56,6 +57,8 @@ void TestHex();
void TestTWLocale() void TestTWLocale()
{ {
skip("TWLocale tests are ifdef'd out, need to revisit them");
#ifdef DOESNTWORK #ifdef DOESNTWORK
TestHex(); TestHex();
TestAtoi(); TestAtoi();
@ -225,3 +228,8 @@ void TestHex()
} }
#endif//DOESNTWORK #endif//DOESNTWORK
void RegisterSuite_TWLocale()
{
RegisterTest("TWLocale", "Basic", TestTWLocale);
}

View File

@ -108,3 +108,8 @@ std::string WideToNarrow( const TSTRING& strWide )
return strWide; return strWide;
} }
void RegisterSuite_TWUtil()
{
RegisterTest("TWUtil", "Basic", TestTWUtil);
}

View File

@ -50,3 +50,8 @@ void TestTypes()
TEST(sizeof(float32) == 4); TEST(sizeof(float32) == 4);
TEST(sizeof(float64) == 8); TEST(sizeof(float64) == 8);
} }
void RegisterSuite_Types()
{
RegisterTest("Types", "Basic", TestTypes);
}

View File

@ -158,7 +158,10 @@ void TestUnixFSServices()
TEST( pFSServices->FileDelete( newtestfile ) ); TEST( pFSServices->FileDelete( newtestfile ) );
} }
void RegisterSuite_UnixFSServices()
{
RegisterTest("UnixFSServices", "Basic", TestUnixFSServices);
}

View File

@ -41,4 +41,10 @@ void TestUserNotifyStdout()
{ {
cDebug d("TestUserNotifyStdout"); cDebug d("TestUserNotifyStdout");
d.TraceError("Implement this!\n"); d.TraceError("Implement this!\n");
skip("TestUserNotifyStdout unimplemented");
}
void RegisterSuite_UserNotifyStdout()
{
RegisterTest("UserNotifyStdout", "Basic", TestUserNotifyStdout);
} }

View File

@ -124,3 +124,8 @@ void TestWchar16()
db.TraceAlways("Done...\n"); db.TraceAlways("Done...\n");
} }
void RegisterSuite_Wchar16()
{
RegisterTest("Wchar16", "Basic", TestWchar16);
}