Enable/repair more unit tests, and undo an earlier change to hex_to_char() that was causing test failures

This commit is contained in:
Brian Cox 2017-03-27 00:50:33 -07:00
parent cdb7310dae
commit 2c03fdf878
22 changed files with 249 additions and 191 deletions

View File

@ -568,7 +568,7 @@ TCHAR cCharEncoderUtil::hex_to_char( TSTRING::const_iterator first,
if( ss.bad() || ss.fail() )
ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) );
if( ch > (unsigned long)max_char || ch < (unsigned long)min_char )
if( (TCHAR)ch > max_char || (TCHAR)ch < min_char )
ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) );
return (TCHAR)ch;

View File

@ -293,6 +293,11 @@ bool cConfigFile::Lookup( const TSTRING& sKey, TSTRING& sVal ) const
return( fFound );
}
void cConfigFile::Insert( const TSTRING& sKey, const TSTRING& sVal )
{
mStringHashTable.Insert(sKey, sVal);
}
///////////////////////////////////////////////////////////////////////////////
// GetFileHeaderID()
///////////////////////////////////////////////////////////////////////////////

View File

@ -107,6 +107,10 @@ public:
bool Lookup( const TSTRING& tstrKey, TSTRING& tstrVal ) const;
// returns true if key is found in internal container and returns its value in tstrVal.
void Insert( const TSTRING& tstrKey, const TSTRING& tstrVal );
// add key+value to config data. visible for unit testing.
void WriteString( TSTRING& configText );
// writes all key/value pairs from internal container to filename as "name=value\n"
void ReadString( const TSTRING configText ); // throw( eConfigFile );

View File

@ -40,6 +40,7 @@
#include "core/charutil.h"
#include "core/debug.h"
#include "core/errorbucketimpl.h"
#include "twtest/test.h"
void PrintChars( const TSTRING& str )
@ -78,7 +79,7 @@ void TestCharUtilBasic()
catch( eError& e )
{
cErrorReporter::PrintErrorMsg( e );
ASSERT(false);
TEST(false);
}
}

View File

@ -41,7 +41,7 @@
const int argc1 = 9;
const TCHAR* argv1[] =
{
_T("tripwire.exe"),
_T("tripwire"),
_T("-m"),
_T("Init"),
_T("-tp"),
@ -55,7 +55,7 @@ const TCHAR* argv1[] =
const int argc2 = 3;
const TCHAR* argv2[] =
{
_T("tripwire.exe"),
_T("tripwire"),
_T("-m"),
_T("-v")
};
@ -63,7 +63,7 @@ const TCHAR* argv2[] =
const int argc3 = 3;
const TCHAR* argv3[] =
{
_T("tripwire.exe"),
_T("tripwire"),
_T("dog"),
_T("-v"),
};
@ -72,7 +72,7 @@ const TCHAR* argv3[] =
const int argc4 = 5;
const TCHAR* argv4[] =
{
_T("tripwire.exe"),
_T("tripwire"),
_T("-tp"),
_T("-v"),
_T("frog"),
@ -82,7 +82,7 @@ const TCHAR* argv4[] =
const int argc5 = 4;
const TCHAR* argv5[] =
{
_T("tripwire.exe"),
_T("tripwire"),
_T("-tp"),
_T("-v"),
_T("frog")
@ -100,6 +100,33 @@ static void PrintCmdLine(int argc, const TCHAR** argv, cDebug d)
d.TraceDebug(_T(">>>%s\n"), str.c_str());
}
static void test_parse(cCmdLineParser& parser, const int argc, const TCHAR** argv, bool should_throw)
{
#ifdef _DEBUG
cDebug d("test_parse");
PrintCmdLine(argc, argv, d);
#endif
bool threw = false;
try {
parser.Parse(argc, argv);
} catch (eError& e) {
if (!should_throw)
TCERR << e.GetMsg() << std::endl;
threw = true;
}
TEST(threw == should_throw);
#ifdef _DEBUG
parser.TraceContents();
#endif
}
void TestCmdLineParser()
{
enum ArgId { ID_M, ID_TP, ID_V, ID_UNNAMED };
@ -113,58 +140,22 @@ void TestCmdLineParser()
cDebug d("TestCmdLineParser");
PrintCmdLine(argc1, argv1, d);
p.Parse(argc1, argv1);
#ifdef _DEBUG
p.TraceContents();
#endif
test_parse(p, argc1, argv1, false);
test_parse(p, argc2, argv2, true);
test_parse(p, argc3, argv3, true);
test_parse(p, argc4, argv4, false);
PrintCmdLine(argc2, argv2, d);
p.Parse(argc2, argv2); // should fail.
#ifdef _DEBUG
p.TraceContents();
#endif
PrintCmdLine(argc3, argv3, d);
p.Parse(argc3, argv3); // should fail
#ifdef _DEBUG
p.TraceContents();
#endif
PrintCmdLine(argc4, argv4, d);
p.Parse(argc4, argv4);
#ifdef _DEBUG
p.TraceContents();
#endif
/*
// TODO - test mutual exclusion...
cCmdLineParser::ErrorType et;
TSTRING errStr;
// command line arg mutual exclusion
d.TraceDebug("** Making -m and -v mutually exclusive, then running on first cmd line...\n");
p.AddMutEx(ID_M, ID_V);
p.Parse(argc1, argv1); // should fail
p.GetErrorInfo(et, errStr);
TEST(et == cCmdLineParser::ERR_MUTUAL_EXCLUSION);
d.TraceDebug(_T("Mutual exclusion test worked; here is the error string: %s\n"), errStr.c_str());
*/
test_parse(p, argc1, argv1, true); // should fail
// make the command line want one parameter
d.TraceDebug("** Changing cmd line to only want one last param...\n");
p.AddArg(ID_UNNAMED, TSTRING(_T("")), TSTRING(_T("")), cCmdLineParser::PARAM_ONE);
PrintCmdLine(argc4, argv4, d);
p.Parse(argc4, argv4); // should fail
#ifdef _DEBUG
p.TraceContents();
#endif
PrintCmdLine(argc5, argv5, d);
p.Parse(argc5, argv5);
#ifdef _DEBUG
p.TraceContents();
#endif
test_parse(p, argc4, argv4, true);
test_parse(p, argc5, argv5, false);
// TODO -- test a bunch more!!!
}
@ -172,7 +163,8 @@ void TestCmdLineParser()
{
TCERR << _T("Command line error: ");
TCERR << e.GetMsg() << std::endl;
//TODO... TEST(false);
//TODO...
TEST(false);
}
}

View File

@ -117,8 +117,10 @@ void TestConfigFile(void)
cTWUtil::PrintErrorMsg( e );
}
}
}
#ifdef NOT_BRIANS_TEST
void TestConfigFile2(void)
{
cDebug d("Testconfigfile");
d.TraceDetail("Entering...\n");
iFSServices* pFSServices = iFSServices::GetInstance();
@ -129,32 +131,21 @@ void TestConfigFile(void)
TSTRING currpath;
pFSServices->GetCurrentDir(currpath);
const TSTRING testTWROOT = currpath;
const TSTRING testTWBIN = (testTWROOT + _T("/bin/"));
const TSTRING testTWCFG = (testTWROOT + _T("/etc/"));
const TSTRING testTWMAN = (testTWROOT + _T("/man/"));
const TSTRING testTWHTML = (testTWROOT + _T("/html/"));
const TSTRING testTWDB = (testTWROOT + _T("/db/"));
const TSTRING testTWKEY = (testTWROOT + _T("/key/"));
const TSTRING testTWREPORT = (testTWROOT + _T("/report/"));
const TSTRING testTWPASSWORD = (testTWROOT + _T("/null_password"));
//TODO maybe also test read failure when mandatory config values aren't set
//Begin tests of config. module parser:
cConfigFile write_cfgmod;
//Filename for writing/reading some value pairs:
const TSTRING testfile = testTWCFG + _T("tripwire.cfg");
//Add all the mandatory config options.
write_cfgmod.Insert( _T("POLFILE"), "test.pol");
write_cfgmod.Insert( _T("DBFILE"), "test.twd");
write_cfgmod.Insert( _T("REPORTFILE"), "test.twr");
write_cfgmod.Insert( _T("SITEKEYFILE"), "site.key");
write_cfgmod.Insert( _T("LOCALKEYFILE"), "local.key");
//Insert the test values into cConfigFile's hashtable:
/*
write_cfgmod.Insert( _T("TWROOT"), testTWROOT);
write_cfgmod.Insert( _T("TWBIN"), testTWBIN);
write_cfgmod.Insert( _T("TWCFG"), testTWCFG);
write_cfgmod.Insert( _T("TWMAN"), testTWMAN);
write_cfgmod.Insert( _T("TWHTML"), testTWHTML);
write_cfgmod.Insert( _T("TWDB"), testTWDB);
write_cfgmod.Insert( _T("TWKEY"), testTWKEY);
write_cfgmod.Insert( _T("TWREPORT"), testTWREPORT);
write_cfgmod.Insert( _T("TWPASSWORD"), testTWPASSWORD);
*/
//Filename for writing/reading some value pairs:
const TSTRING testfile = testTWROOT + _T("/tripwire.cfg");
//Store these values on disk.
TSTRING configText;
@ -173,19 +164,19 @@ void TestConfigFile(void)
catch (eError& error)
{
TCERR << (int)error.GetID() << std::endl << error.GetMsg() << std::endl;
ASSERT(false);
TEST(false);
}
//These TSTRINGS will hold info. from .Lookup:
TSTRING lookup1, lookup2;
read_cfgmod.Lookup( _T("TWROOT"), lookup1);
read_cfgmod.Lookup( _T("TWDB"), lookup2);
read_cfgmod.Lookup( _T("POLFILE"), lookup1);
read_cfgmod.Lookup( _T("DBFILE"), lookup2);
d.TraceDetail("First lookup's value: %s \n", lookup1.c_str());
d.TraceDetail("Second lookup's value: %s \n", lookup2.c_str());
TEST( lookup1 == testTWROOT );
TEST( lookup2 == testTWDB );
TEST( lookup1 == "test.pol" );
TEST( lookup2 == "test.twd" );
d.TraceDetail("Tests Passed!\n");
#endif // NOT_BRIANS_TEST
//#endif // NOT_BRIANS_TEST
}

View File

@ -40,6 +40,7 @@
#include "fco/fcopropset.h"
#include "fco/fcoprop.h"
#include "fco/fco.h"
#include "twtest/test.h"
static void GetNoun( TSTRING& noun )
{
@ -84,11 +85,16 @@ static void PrintFCO( const iFCO* pFCO )
void TestDbDataSource()
{
TCERR << std::endl << "TestDbDataSource needs to be redesigned so it doesn't require user interaction" << std::endl;
#if 0
cDebug d("TestDbDataSource");
cHierDatabase db;
const TSTRING dbName = _T("c:/tmp/tw.db");
const TSTRING dbName = _T("tw.db");
try
{
// TODO -- get the case sensitiveness and delimiting char out of the factory instead of iFSServices
@ -296,5 +302,7 @@ void TestDbDataSource()
catch( eError& e )
{
d.TraceError("*** Caught error: %d %s\n", e.GetID(), e.GetMsg().c_str() );
TEST(false);
}
#endif
}

View File

@ -104,17 +104,25 @@ void TestCharToHex()
///////////////////////////////////////////////////////////////////////////
// TestHexToChar
///////////////////////////////////////////////////////////////////////////
void test_hex_to_char(const TSTRING& str, char expected)
void test_hex_to_char(const TSTRING& str, char expected, bool should_throw=false)
{
char observed = cCharEncoderUtil::hex_to_char( str.begin(), str.end() );
TEST(expected == observed);
bool threw = false;
try
{
char observed = cCharEncoderUtil::hex_to_char( str.begin(), str.end() );
TEST(expected == observed);
}
catch(eError& e)
{
threw = true;
}
TEST(should_throw == threw);
}
void TestHexToChar()
{
TCERR << "\nTODO: TestHexToChar in displayencoder_t.cpp needs to be fixed; currently disabled." << std::endl;
#if 0
test_hex_to_char( "fe", 0xfe );
test_hex_to_char( "ff", 0xff );
test_hex_to_char( "00", 0x00 );
@ -122,9 +130,8 @@ void TestHexToChar()
test_hex_to_char( "7f", 0x7f );
test_hex_to_char( "80", 0x80 );
test_hex_to_char( "100", 0); // should throw
test_hex_to_char( "-01", 0); // should throw
#endif
test_hex_to_char( "100", 0, true); // should throw
test_hex_to_char( "-01", 0, true); // should throw
}
@ -157,13 +164,10 @@ void test_hex_to_string(const std::string& str, const std::string& expected)
void TestHexToString()
{
TCERR << "\nTODO: TestHexToString in displayencoder_t.cpp needs to be fixed; currently disabled." << std::endl;
#if 0
test_hex_to_string( "0a", "\n");
test_hex_to_string( "0d", "\r");
test_hex_to_string( "0d0a", "\r\n");
test_hex_to_string( "610d0a62", "a\r\nb");
#endif
}
#if 0

View File

@ -34,40 +34,50 @@
#include "core/stdcore.h"
#include "core/error.h"
#include "core/errorgeneral.h"
#include "core/errorutil.h"
#include "twtest/test.h"
#include <iostream>
void TestError()
{
//#pragma message( __FILE__ "(1) : TODO - implement this test file")
/*
bool threw = false;
try
{
std::cout << "Before Exception" << std::endl;
std::cout << "Line number before throw: " << __LINE__ << std::endl;
THROW_ERROR(53, _T("This is an error!"));
throw eErrorGeneral(_T("This is an error!"));
std::cout << "After Exception" << std::endl;
}
catch(eError& e)
{
TEST(e.GetErrorNum() == 53);
threw = true;
TEST(_tcscmp(e.GetMsg().c_str(), _T("This is an error!")) == 0);
TCOUT << _T("Exception caught!\n\tErrorNum=") << e.GetErrorNum() << _T("\n\t") << e.GetMsg() << std::endl;
}
try
{
THROW_INTERNAL("error_t.cpp");
}
catch(eInternal& e)
{
TEST(e.GetErrorNum() == eInternal::ERR_INTERNAL);
TCOUT << _T("Internal error caught!\n\tErrorNum=") << e.GetErrorNum() << _T("\n\t") << e.GetMsg() << std::endl;
TCOUT << _T("Exception caught!\n\nID=") << e.GetID() << _T("\n\t") << e.GetMsg() << std::endl;
}
catch(...)
{
TEST(false);
}
*/
TEST(threw);
try
{
threw = false;
throw eInternal("error_t.cpp");
}
catch(eInternal& e)
{
threw = true;
TEST(_tcscmp(e.GetMsg().c_str(), _T("error_t.cpp")) == 0);
TCOUT << _T("Internal error caught!\n\nID=") << e.GetID() << _T("\n\t") << e.GetMsg() << std::endl;
}
catch(...)
{
TEST(false);
}
TEST(threw);
}

View File

@ -37,11 +37,13 @@
#include "core/debug.h"
#include "core/archive.h"
#include "core/errorgeneral.h"
#include "core/errortable.h"
// test option 7
void TestErrorBucketImpl()
{
/*
cDebug d("TestErrorBucketImpl");
//This whole function is in sorry shape... TODO: Fix this DRA
d.TraceDebug("Entering...\n");
@ -54,13 +56,13 @@ void TestErrorBucketImpl()
//These calls to PrintErrorMsg are broken. The code is probably old. -DRA
// Test error reporting
cErrorReporter::PrintErrorMsg(eError(_T("This should have a single line.")));
cErrorReporter::PrintErrorMsg(eError(_T("This should have a mulitiple lines since I have")
cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("This should have a single line.")));
cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("This should have a mulitiple lines since I have")
_T(" put so much text here. But it does have a lot")
_T(" of spaces so cErrorReporter should have no")
_T(" problem breaking it up.")
));
cErrorReporter::PrintErrorMsg(eError(_T("This has many long words: ")
cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("This has many long words: ")
_T("40chars_________________________________")
_T(" short words ")
_T("50chars___________________________________________")
@ -69,7 +71,7 @@ void TestErrorBucketImpl()
_T(" short words short words short words short words ")
_T("90chars___________________________________________________________________________________")
));
cErrorReporter::PrintErrorMsg(eError(_T("The error reporter should handle newlines.\n")
cErrorReporter::PrintErrorMsg(eErrorGeneral(_T("The error reporter should handle newlines.\n")
_T("Newlines should break up the text appropriately. Who knows when they will occur. Can't have them getting in the way.\n")
_T("And one last line with a big char strings: 90chars___________________________________________________________________________________ 40chars_________________________________ 50chars___________________________________________")
));
@ -109,13 +111,14 @@ void TestErrorBucketImpl()
}
}
TODO - test this stuff that's commented out
//TODO - test this stuff that's commented out
TCOUT << _T("Following string should be a cArchive::ERR_OPEN_FAILED error:\n");
TCOUT << cErrorTable::GetErrorString(cArchive::ERR_OPEN_FAILED) << std::endl;
// TCOUT << _T("Following string should be a cArchive::ERR_OPEN_FAILED error:\n");
// TCOUT << cErrorTable::GetErrorString(cArchive::ERR_OPEN_FAILED) << std::endl;
/* This isn't going to work anymore, given that we don't have numeric errror constants
// print out all error strings
#if 1
// Look up all errors.
// Note: our current error printing format limits us to 4 digit errors, so this should work for a while.
int errornum;
@ -134,9 +137,9 @@ void TestErrorBucketImpl()
TCOUT << _T(": ") << errorString << std::endl;
}
}
#endif
*/
d.TraceDebug("Leaving...\n");
*/
}

View File

@ -35,6 +35,7 @@
#include "core/debug.h"
#include "fs/fsobject.h"
#include "fs/fspropcalc.h"
#include "fs/fsdatasourceiter.h"
#include "twtest/test.h"
#include <fstream>
@ -42,7 +43,7 @@
///////////////////////////////////////////////////////////////////////////////
// PrintProps -- prints out all the valid property names and values as pairs...
///////////////////////////////////////////////////////////////////////////////
/*
static void PrintProps(const iFCO* pFCO)
{
cDebug d("PrintProps");
@ -57,13 +58,10 @@ static void PrintProps(const iFCO* pFCO)
}
}
}
*/
void TestFCOCompare()
{
#pragma message( __FILE__ "(1) : TODO - implement this test file")
#if 0
const TCHAR* FILE_NAME = TEMP_DIR _T("/dog.txt");
const char* FILE_NAME_N = TEMP_DIR_N "/dog.txt";
@ -84,8 +82,9 @@ void TestFCOCompare()
fstr.close();
// create the test FCO
cFSDataSource ds;
iFCO* pFCO = ds.CreateFCO(cFCOName(FILE_NAME), 0);
cFSDataSourceIter ds;
ds.SeekToFCO(cFCOName(FILE_NAME), false);
iFCO* pFCO = ds.CreateFCO();
TEST(pFCO);
// measure a couple of properties, some of which will change...
@ -104,15 +103,14 @@ void TestFCOCompare()
// first, try comparing it to itself...
cFCOCompare comp;
cFCOCompare::CompareResult result;
comp.SetPropsToCmp(v);
comp.Compare(pFCO, pFCO, result);
d.TraceDebug("Compare to itself is (expect true) %s\n", result.mResult == cFCOCompare::EQUAL? "true" : "false");
TEST(result.mResult == cFCOCompare::EQUAL);
unsigned int result = comp.Compare(pFCO, pFCO);
d.TraceDebug("Compare to itself is (expect true) %s\n", result == cFCOCompare::EQUAL? "true" : "false");
TEST(result == cFCOCompare::EQUAL);
// change the file...
d.TraceDebug("Changing the file...\n");
fstr.open(FILE_NAME_N);
fstr.open(FILE_NAME);
if(fstr.bad())
{
d.TraceError("Unable to reopen %s!\n", FILE_NAME_N);
@ -122,36 +120,42 @@ void TestFCOCompare()
fstr << "Meow! Meow! Meow! Meow!" << std::endl;
fstr.close();
iFCO* pFCO2 = ds.CreateFCO(cFCOName(FILE_NAME), 0);
//need a new data source iter, otherwise the existing FCO gets updated & you get a ref to it,
// and the resulting FCOs always match.
cFSDataSourceIter ds2;
ds2.SeekToFCO(cFCOName(FILE_NAME), false);
iFCO* pFCO2 = ds2.CreateFCO();
ASSERT(pFCO2);
pFCO2->AcceptVisitor(&propCalc);
d.TraceDebug("Second FCO's properties:\n");
PrintProps(pFCO2);
comp.Compare(pFCO, pFCO2, result);
d.TraceDebug("Compare to new object is (expect false) %s\n", result.mResult == cFCOCompare::EQUAL? "true" : "false");
TEST(result.mResult == cFCOCompare::UNEQUAL);
result = comp.Compare(pFCO, pFCO2);
d.TraceDebug("Compare to new object is (expect false) %s\n", result == cFCOCompare::EQUAL? "true" : "false");
TEST(result == cFCOCompare::PROPS_UNEQUAL);
d.TraceDebug("Properties that differ are:\n");
result.mPropVector.TraceContents();
//result.mPropVector.TraceContents();
cFSDataSourceIter ds3;
ds3.SeekToFCO(cFCOName(FILE_NAME), false);
// try testing properties that weren't calculated...
d.TraceDebug("Comparing FCOs with different properties calculated\n");
iFCO* pFCO3 = ds.CreateFCO(cFCOName(FILE_NAME), 0);
iFCO* pFCO3 = ds3.CreateFCO();
v = propCalc.GetPropVector();
v.AddItem(cFSPropSet::PROP_MD5);
propCalc.SetPropVector(v);
pFCO3->AcceptVisitor(&propCalc);
// do the compare
comp.SetPropsToCmp(v);
comp.Compare(pFCO2, pFCO3, result);
TEST(result.mResult == cFCOCompare::PROPS_NOT_ALL_VALID);
result = comp.Compare(pFCO2, pFCO3);
TEST(result == cFCOCompare::PROPS_NOT_ALL_VALID);
d.TraceDebug("Properties not valid are (should be %d):\n", cFSPropSet::PROP_MD5);
result.mPropVector.TraceContents();
//result.mPropVector.TraceContents();
// release the fcos
pFCO3->Release();
pFCO2->Release();
pFCO->Release();
#endif
return;
}

View File

@ -39,7 +39,7 @@
#include "fco/fconametranslator.h"
#include "fco/genreswitcher.h"
#include "fco/fconame.h"
#include "twtest/test.h"
void TestName( const TCHAR* pchName, const TCHAR* pchGenre );
void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre );
@ -61,9 +61,9 @@ void TestName( const TCHAR* pchName, const TCHAR* pchGenre )
// set up name translator
//
iFCONameTranslator* mpCurNT = NULL;
cGenre::Genre gNTFS = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre );
ASSERT( gNTFS != cGenre::GENRE_INVALID );
mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( gNTFS )->GetNameTranslator();
cGenre::Genre genre = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre );
TEST( genre != cGenre::GENRE_INVALID );
mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( genre )->GetNameTranslator();
//
// encode name
@ -76,13 +76,13 @@ void TestName( const TCHAR* pchName, const TCHAR* pchGenre )
// unencode name
//
cFCOName fcoNameNew;
ASSERT( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) );
TEST( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) );
TCOUT << _T("> back to: <") << fcoNameNew.AsString() << _T(">") << std::endl;
//
// check result
//
ASSERT( fcoNameNew == fcoName );
TEST( fcoNameNew == fcoName );
}
@ -92,9 +92,9 @@ void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre )
// set up name translator
//
iFCONameTranslator* mpCurNT = NULL;
cGenre::Genre gNTFS = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre );
ASSERT( gNTFS != cGenre::GENRE_INVALID );
mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( gNTFS )->GetNameTranslator();
cGenre::Genre genre = cGenreSwitcher::GetInstance()->StringToGenre( pchGenre );
TEST( genre != cGenre::GENRE_INVALID );
mpCurNT = cGenreSwitcher::GetInstance()->GetFactoryForGenre( genre )->GetNameTranslator();
//
// encode name
@ -107,11 +107,11 @@ void TestUnprintable( const TCHAR* pchName, const TCHAR* pchGenre )
// unencode name
//
cFCOName fcoNameNew;
ASSERT( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) );
TEST( mpCurNT->DisplayStringToFCOName( strName, fcoNameNew ) );
//
// check result
//
ASSERT( fcoNameNew == fcoName );
TEST( fcoNameNew == fcoName );
}

View File

@ -33,6 +33,7 @@
#include "fco/stdfco.h"
#include "fco/fcopropimpl.h"
#include "core/debug.h"
#include "twtest/test.h"
void TestFCOPropImpl()
{
@ -51,22 +52,43 @@ void TestFCOPropImpl()
pui64.SetValue(456);
pui64b.SetValue(333);
d.TraceDebug(_T("property int64 = (should be -456) %s\n"), pi64.AsString().c_str());
TEST(pi64.AsString() == "-456");
// test a few operators
d.TraceDebug("-456 < 456 (uint cmp to int should fail)= %d\n", pi64.Compare(&pui64, iFCOProp::OP_LT));
TEST( iFCOProp::CMP_WRONG_PROP_TYPE == pi64.Compare(&pui64, iFCOProp::OP_LT) );
cFCOPropInt64 p2i64;
p2i64.SetValue(4);
d.TraceDebug("-456 < 4 = %d\n", pi64.Compare(&p2i64, iFCOProp::OP_LT));
TEST( iFCOProp::CMP_TRUE == pi64.Compare(&p2i64, iFCOProp::OP_LT));
d.TraceDebug("4 == 456 = %d\n", p2i64.Compare(&pi64, iFCOProp::OP_EQ));
TEST( iFCOProp::CMP_FALSE == p2i64.Compare(&pi64, iFCOProp::OP_EQ));
d.TraceDebug("333ui64 == 456ui64 = %d\n", pui64.Compare(&pui64b, iFCOProp::OP_EQ));
TEST( iFCOProp::CMP_FALSE == p2i64.Compare(&pi64, iFCOProp::OP_EQ));
cFCOPropTSTRING pt1;
cFCOPropTSTRING pt2;
pt1.SetValue(TSTRING(_T("bar")));
pt2.SetValue(TSTRING(_T("foo")));
d.TraceDebug(_T("property TSTRING = (should be \"bar\") %s\n"), pt1.AsString().c_str());
TEST(pt1.AsString() == "bar");
d.TraceDebug(_T("property TSTRING = (should be \"foo\") %s\n"), pt2.AsString().c_str());
TEST(pt2.AsString() == "foo");
d.TraceDebug("bar == foo = %d\n", pt1.Compare(&pt2, iFCOProp::OP_EQ));
TEST( iFCOProp::CMP_FALSE == pt1.Compare(&pt2, iFCOProp::OP_EQ));
d.TraceDebug("bar == bar = %d\n", pt1.Compare(&pt1, iFCOProp::OP_EQ));
TEST( iFCOProp::CMP_TRUE == pt1.Compare(&pt1, iFCOProp::OP_EQ));
d.TraceDebug("bar == 456 = %d\n", pt1.Compare(&pi64, iFCOProp::OP_EQ));
TEST( iFCOProp::CMP_WRONG_PROP_TYPE == pt1.Compare(&pi64, iFCOProp::OP_EQ));
d.TraceDebug("Leaving...\n");
return;

View File

@ -88,6 +88,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d)
}
}
//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws
void TestFCOReport()
{
cDebug d("TestFCOReport");

View File

@ -50,6 +50,7 @@ static void TraceSpecAttr(const cFCOSpecAttr* pAttr, cDebug d)
}
}
//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws
void TestFCOSpecAttr()
{
cDebug d("TestFCOSpecAttr");

View File

@ -37,6 +37,7 @@
#include "twtest/test.h"
#include <stdio.h>
//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws
void TestFile()
{

View File

@ -33,15 +33,21 @@
#include "fs/stdfs.h"
#include "fs/fspropcalc.h"
#include "core/debug.h"
#include "core/archive.h"
#include "core/fsservices.h"
#include "fco/fcopropset.h"
#include "fs/fspropset.h"
#include "fs/fsdatasourceiter.h"
#include "twtest/test.h"
#include "fco/fco.h"
#include <iostream>
#include <fstream>
///////////////////////////////////////////////////////////////////////////////
// PrintProps -- prints out all the valid property names and values as pairs...
///////////////////////////////////////////////////////////////////////////////
/*
static void PrintProps(const iFCO* pFCO)
{
cDebug d("PrintProps");
@ -52,35 +58,39 @@ static void PrintProps(const iFCO* pFCO)
{
if(v.ContainsItem(i))
{
d.TraceDebug("[%d] %s\t%s\n", i, pSet->GetPropName(i), pSet->GetPropAt(i)->AsString().c_str());
d.TraceDebug("[%d] %s\t%s\n", i, pSet->GetPropName(i).c_str(), pSet->GetPropAt(i)->AsString().c_str());
}
}
}
*/
void TestFSPropCalc()
{
#pragma message( __FILE__ "(1) : TODO - implement this test file")
#if 0
cDebug d("TestFSPropCalc");
cFSDataSource ds;
iFSServices* pFSServices = iFSServices::GetInstance();
bool bCaseSensitive = pFSServices->IsCaseSensitive();
cFSDataSourceIter ds;
TSTRING foo_bin = TEMP_DIR;
foo_bin.append("/foo.bin");
//iFSServices* pFSServices = iFSServices::GetInstance();
// oh boy! I finally get to test property calculation!
d.TraceDebug("Creating FCO c:\\temp\\foo.bin\n");
std::ofstream fstr(foo_bin);
if(fstr.bad())
{
d.TraceError("Unable to create test file %s!\n", foo_bin.c_str());
TEST(false);
}
fstr.close();
cFileArchive arch;
int ret;
ret = arch.OpenReadWrite(TEMP_DIR _T("/foo.bin"), true);
TEST(ret);
arch.OpenReadWrite(foo_bin.c_str(), true);
arch.WriteBlob("\x1\x2\x3\x4\x5\x6\x7\x8\x9\x0", 10);
arch.Close();
// get the fco but none of its children...
iFCO* pFCO = ds.CreateFCO(cFCOName(TEMP_DIR _T("/foo.bin")), 0);
ds.SeekToFCO(cFCOName(foo_bin), false);
iFCO* pFCO = ds.CreateFCO();
ASSERT(pFCO);
// create the calculator and set some properties to calculate...
@ -111,8 +121,7 @@ void TestFSPropCalc()
// test only calculating unevaluated props...
d.TraceDebug("invalidating PROP_MD5 in fco, and changing the file. \n\tAll should remain the same except md5.\n");
ret = arch.OpenReadWrite(TEMP_DIR _T("/foo.bin"), true);
TEST(ret);
arch.OpenReadWrite(foo_bin.c_str(), true);
arch.WriteString(_T("Bark Bark Bark\n"));
arch.Close();
@ -126,6 +135,6 @@ void TestFSPropCalc()
// release the fco
pFCO->Release();
#endif
return;
}

View File

@ -37,12 +37,10 @@
#include "fco/genrespeclist.h"
#include "twtest/test.h"
#include "fco/fcospecimpl.h"
#include "fs/fs.h"
void TestGenreSpecList()
{
#pragma message( __FILE__ "(1) : TODO - implement this test file")
#if 0
cDebug d("TestGenreSpecList");
d.TraceDebug("Entering...\n");
@ -51,8 +49,8 @@ void TestGenreSpecList()
TEST(gslPair.GetGenre() == cGenre::GENRE_INVALID);
gslPair.SetGenre(cGenre::FS);
TEST(gslPair.GetGenre() == cGenre::FS);
gslPair.SetGenre(cFS::GenreID());
TEST(gslPair.GetGenre() == cFS::GenreID());
cFCOSpecList speclist;
cFCOSpecImpl* fsSpec = new cFCOSpecImpl(_T("test fsspce name"), NULL);
@ -91,6 +89,5 @@ void TestGenreSpecList()
TEST(gslVector.at(2).GetSpecList().Lookup(fsSpec)->GetName() == gslPair3.GetSpecList().Lookup(fsSpec)->GetName());
d.TraceDebug("All tests passed.\n");
#endif
}

View File

@ -36,23 +36,22 @@
#include "fco/stdfco.h"
#include "fco/genreswitcher.h"
#include "twtest/test.h"
#include "fs/fs.h"
void TestGenre()
{
TCERR << "TODO: genreswitcher_t.cpp test ifdef'd due to unhandled exception" << std::endl;
#if 0
cDebug d("TestGenre");
d.TraceDebug("Entering...\n");
TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(0x00020001)) == 0x00020001);
TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(0x00010001)) == 0x00010001);
TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(0x00010002)) == 0x00010002);
TEST(cGenreSwitcher::GetInstance()->StringToGenre(cGenreSwitcher::GetInstance()->GenreToString(cFS::GenreID())) == cFS::GenreID());
//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")) == 0x00020001);
TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("NT file system")) == 0x00010001);
TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("fs")) == cFS::GenreID());
TEST(cGenreSwitcher::GetInstance()->StringToGenre(_T("none of the above")) == cGenre::GENRE_INVALID);
d.TraceDebug("All tests passed.\n");
#endif
}

View File

@ -40,6 +40,7 @@
#include "core/debug.h"
#include "core/archive.h"
#include "core/srefcountobj.h"
#include "twtest/test.h"
class cSerRefCountObjTest : public iSerRefCountObj
{
@ -133,9 +134,9 @@ void TestSerRefCountObj()
serializer.Finit();
}
ASSERT(pObj1 == pObj3);
ASSERT(pObj1 == pObj4);
ASSERT(pObj1 != pObj2);
TEST(pObj1 == pObj3);
TEST(pObj1 == pObj4);
TEST(pObj1 != pObj2);
pObj1->Release();
pObj2->Release();

View File

@ -39,6 +39,7 @@
#include "util/stdutil.h"
#include "util/stringencoder.h"
#include "twtest/test.h"
//=========================================================================
// STANDARD LIBRARY INCLUDES
@ -88,5 +89,7 @@ void OutputString( TSTRING& str )
TCOUT << _T("Plain string: <") << str << _T(">") << endl;
TCOUT << _T("Encoded string: <") << qe.Encode( str ) << _T(">") << endl;
TCOUT << _T("Decoded string: <") << qe.Unencode( str ) << _T(">") << endl << endl ;
TEST( str == qe.Unencode(qe.Encode(str)) );
}

View File

@ -145,6 +145,7 @@ void TestHexToString();
void TestQuoteAndBackSlash();
void TestDisplayEncoderBasic();
void TestCharUtilBasic();
void TestConfigFile2();
/// This is easier than all the (cpp) files and declarations
#include "stringutil_t.h"
@ -170,7 +171,7 @@ static void Test(int testID)
case 5: TestDebug(); break;
case 6: TestError(); break;
case 7: TestErrorBucketImpl(); break;
//case 8: TestFCOCompare(); break;
case 8: TestFCOCompare(); break;
//case 9: TestFCODatabase(); break;
//case 11: TestFCOErrorQueue(); break;
case 12: TestFCOName(); break;
@ -188,7 +189,7 @@ static void Test(int testID)
case 24: TestFileHeader(); break;
//case 25: TestFSDataSource(); break;
case 26: TestFSPropSet(); break;
//case 27: TestFSPropCalc(); break;
case 27: TestFSPropCalc(); break;
case 28: TestFCOSpecImpl(); break;
case 29: TestHashTable(); break;
// case 30: TestObjectPool(); break;
@ -241,6 +242,7 @@ static void Test(int testID)
case 85: TestQuoteAndBackSlash(); break;
case 86: TestDisplayEncoderBasic(); break;
case 87: TestCharUtilBasic(); break;
case 88: TestConfigFile2(); break;
}
}