Tweak unit tests that didn't invoke TEST() at all; add operator== to cFCOSpecAttr & cFSPropDisplayer for the sake of unit testing.

This commit is contained in:
Brian Cox 2017-09-04 01:35:27 -07:00
parent 8c73f1cf3b
commit e453a81c87
12 changed files with 141 additions and 96 deletions

View File

@ -47,83 +47,101 @@
using namespace std;
static void assertParse(const std::string& configLineIn, bool expectValid)
{
static const std::string sMandatory = \
"\nPOLFILE=foo" \
"\nDBFILE=foo" \
"\nREPORTFILE=foo" \
"\nSITEKEYFILE=foo" \
"\nLOCALKEYFILE=foo";
bool threw = false;
cConfigFile cfg;
std::string configLine = configLineIn + sMandatory;
try
{
cfg.ReadString( configLine );
}
catch( eConfigFileMissReqKey& e)
{
TCERR << "Got a missing key exception, which should not happen" << std::endl;
TEST(false);
}
catch( eConfigFile& e )
{
e.SetFatality(false);
cTWUtil::PrintErrorMsg( e );
threw = true;
}
#ifdef _DEBUG
TCERR << "LINE [" << configLineIn << "]" << std::endl << "Expected = " << expectValid << std::endl << "Threw = " << threw << std::endl;
#endif
TEST(expectValid != threw);
}
void TestConfigFile(void)
{
TSTRING asConfigFileText[] =
{
_T("BRIAN=foo"), // 0 fine
_T("BRIAN=foo\nBILL=bar"), // 1 fine
_T("BRIAN=foo\r\nBILL=bar"), // 2 fine
_T("BRIAN=foo\n\n\rBILL=bar\n"),// 3 fine
_T(" WS=foo \n\n\r BILL=bar\n"), // 4 fine
_T(" WS = foo \n\n\r BILL = bar \n"), // 5 fine
_T("FOO=foo\nBAR=$(FOO)"), // 6 fine
_T("FOO=foo\nBAR=$(FO)"), // 7 undefined var
_T("FOO=foo\nBAR=$(FOO"), // 8 no r paren
_T("FOO=foo\nBAR=$(FOO "), // 9 no r paren
_T("BAR=$(FOO\n"), // 10 no r paren
_T(" VAR =foo \nWS = $(VAR)\n"), // 11 fine
_T(""), // 12 fine
_T("\n"), // 13 fine
_T("\r"), // 14 fine
_T("\r\n"), // 15 fine
_T("B=POO\nA"), // 16 no equals
_T(" B=POO \n A \r"), // 17 no equals
_T("B=POO\nB=CRAP"), // 18 redefined var
_T("DATE=CRAP"), // 19 redefine predefine var
_T("B=POO\nDATE=CRAP"), // 20 redefine predefine var
_T("A=1\nB=$(A)\nC=$(B)"), // 21 fine -- checking var sub
_T("A=$(DATE)"), // 22 fine -- checking predef var sub
_T("A=1\nB=$(A)\nC=$(DATE)"), // 23 fine -- checking predef var sub
_T("A=1\n=$(A)\nC=$(DATE)"), // 24 no key
_T("A=$(DATE)-B"), // 25 fine -- check that the '-' shows up
_T("A=$(DATE)-$(DATE)"), // 26 fine -- check that the '-' shows up
};
// should succeed
assertParse( _T("BRIAN=foo"), true ); // 0 fine
assertParse( _T("BRIAN=foo\nBILL=bar"), true ); // 1 fine
assertParse( _T("BRIAN=foo\r\nBILL=bar"), true ); // 2 fine
assertParse( _T("BRIAN=foo\n\n\rBILL=bar\n"), true ); // 3 fine
assertParse( _T(" WS=foo \n\n\r BILL=bar\n"), true ); // 4 fine
assertParse( _T(" WS = foo \n\n\r BILL = bar \n"), true ); // 5 fine
assertParse( _T("FOO=foo\nBAR=$(FOO)"), true ); // 6 fine
/*
TSTRING sMandatory = \
_T("\nPOLFILE=foo") \
_T("\nDBFILE=foo") \
_T("\nREPORTFILE=foo") \
_T("\nSITEKEYFILE=foo") \
_T("\nLOCALKEYFILE=foo");
*/
// should fail
assertParse( _T("FOO=foo\nBAR=$(FO)"), false ); // 7 undefined var
assertParse( _T("FOO=foo\nBAR=$(FOO"), false ); // 8 no r paren
assertParse( _T("FOO=foo\nBAR=$(FOO "), false ); // 9 no r paren
assertParse( _T("BAR=$(FOO\n"), false ); // 10 no r paren
// should succeed
assertParse( _T(" VAR =foo \nWS = $(VAR)\n"), true ); // 11 fine
assertParse( _T(""), true ); // 12 fine
assertParse( _T("\n"), true ); // 13 fine
assertParse( _T("\r"), true ); // 14 fine
assertParse( _T("\r\n"), true ); // 15 fine
for( TSTRING* at = &asConfigFileText[0];
at != &asConfigFileText[countof(asConfigFileText)];
at++ )
{
cConfigFile cfg;
//*at += sMandatory;
// should fail
assertParse( _T("B=POO\nA"), false ); // 16 no equals
assertParse( _T(" B=POO \n A \r"), false ); // 17 no equals
/* This next test asserts that you can't change a variable once you've defined it.
However there's no actual code in cConfigFile to check for this, and
OST appears to work fine if you redefine a config variable, so I'm not going
to change the current behavior. Leaving this test in w/ a note for reference.
assertParse( _T("B=POO\nB=CRAP"), false ); // 18 redefined var
*/
assertParse( _T("DATE=CRAP"), false ); // 19 redefine predefine var
assertParse( _T("B=POO\nDATE=CRAP"), false ); // 20 redefine predefine var
// should succeed
assertParse( _T("A=1\nB=$(A)\nC=$(B)"), true ); // 21 fine -- checking var sub
assertParse( _T("A=$(DATE)"), true ); // 22 fine -- checking predef var sub
assertParse( _T("A=1\nB=$(A)\nC=$(DATE)"), true ); // 23 fine -- checking predef var sub
// should fail
assertParse( _T("A=1\n=$(A)\nC=$(DATE)"), false ); // 24 no key
// should succeed
assertParse( _T("A=$(DATE)-B"), true ); // 25 fine -- check that the '-' shows up
assertParse( _T("A=$(DATE)-$(DATE)"), true ); // 26 fine -- check that the '-' shows up
TCERR << _T("*** line:") << std::endl;
TCERR << *at << std::endl;
TCERR << _T("*** eol:") << std::endl;
try
{
cfg.ReadString( *at );
}
catch( eConfigFileMissReqKey& )
{
// ignore....
}
catch( eConfigFile& e )
{
int offset = ( at - asConfigFileText );
int itemSize = sizeof( asConfigFileText[0] );
int num = offset / itemSize;
TCERR << num << std::endl;
cTWUtil::PrintErrorMsg( e );
}
}
}
void TestConfigFile2(void)
{
cDebug d("Testconfigfile");
d.TraceDetail("Entering...\n");
iFSServices* pFSServices = iFSServices::GetInstance();
//iFSServices* pFSServices = iFSServices::GetInstance();
//Define some test values for <name, value> pairs to be
//stored in a test config. module. I'm going to use the
@ -175,7 +193,6 @@ void TestConfigFile2(void)
TEST( lookup2 == "test.twd" );
d.TraceDetail("Tests Passed!\n");
//#endif // NOT_BRIANS_TEST
}
void RegisterSuite_ConfigFile()

View File

@ -85,6 +85,8 @@ void TestFCOSpecAttr()
// trace contents...
TraceSpecAttr(pNew, d);
TEST( *pAttr == *pNew );
pNew->Release();
pAttr->Release();
}

View File

@ -62,13 +62,12 @@ static void PrintDb( cHierDatabase::iterator iter, cDebug d, bool bFirst = true
static void PrintIter( cFSDataSourceIter iter, cDebug& d )
{
//
//debug stuff
//
int count = 0;
if( ! iter.CanDescend() )
{
d.TraceError( "Iterator cannot descend; returning!\n");
TEST(!"Unexpected !CanDescend at beginning of test");
return;
}
iter.Descend();
@ -76,6 +75,7 @@ static void PrintIter( cFSDataSourceIter iter, cDebug& d )
for( iter.SeekBegin(); ! iter.Done(); iter.Next() )
{
count++;
iFCO* pFCO = iter.CreateFCO();
if( pFCO )
{
@ -85,6 +85,7 @@ static void PrintIter( cFSDataSourceIter iter, cDebug& d )
else
{
d.TraceError( "*** Create of FCO failed!\n");
fail("CreateFCO() failure");
}
if( iter.CanDescend() )
{
@ -92,16 +93,23 @@ static void PrintIter( cFSDataSourceIter iter, cDebug& d )
PrintIter(iter, d);
}
}
TEST(count > 0);
}
void TestFSDataSourceIter()
{
skip("Fix this test");
cFSDataSourceIter iter;
cDebug d("TestFSDataSourceIter");
cFCOName base(TwTestDir());
// go to my temp directory and iterate over everything!
iter.SeekToFCO( cFCOName(_T("/tmp")) );
iter.SeekToFCO( cFCOName(TwTestDir()) );
//
// print out everything below the iterator
//

View File

@ -83,11 +83,11 @@ void cTestFSPropDisplayer::Test()
pPDNew->Merge( pPD );
/*
////////////////////////
// write pd
cFileArchive outFile;
outFile.OpenReadWrite(_T("c:\\tmp\\tmp.pd"));
outFile.OpenReadWrite( TwTestPath("tmp.pd").c_str() );
cSerializerImpl outSer(outFile, cSerializerImpl::S_WRITE);
outSer.Init();
@ -101,16 +101,17 @@ void cTestFSPropDisplayer::Test()
////////////////////////
// read pd
cFileArchive inFile;
inFile.OpenRead(_T("c:\\tmp\\tmp.pd"));
inFile.OpenRead( TwTestPath("tmp.pd").c_str() );
cSerializerImpl inSer(inFile, cSerializerImpl::S_READ);
cFSPropDisplayer* pPDNew = new cFSPropDisplayer();
cFSPropDisplayer* pPDRead = new cFSPropDisplayer();
inSer.Init();
pPDNew->Read( &inSer );
pPDRead->Read( &inSer );
inSer.Finit();
*/
TEST( *pPD == *pPDRead );
TSTRING strRet;
for( i = 0; i < 26; i++ )
{
@ -129,6 +130,7 @@ void cTestFSPropDisplayer::Test()
delete pPD;
delete pPDNew;
delete pPDRead;
return;
}

View File

@ -119,10 +119,14 @@ AlignMe<ALIGN_SIZE>::AlignMe()
TCOUT << _T("Writing...") << std::endl;
*pb = I; // access memory for write
TCOUT << _T("Write succeeded.") << std::endl;
#endif
TCOUT << _T("Alignment of ") << ALIGN_SIZE << _T(" ") << ( ALIGN_SIZE == 1 ? _T("byte") : _T("bytes") ) << _T(" is OK") << std::endl
<< _T("=========================================\n");
TEST("Aligned"); // The actual test is not bus erroring up above; this just tells the framework we tested something.
#endif
}
@ -173,6 +177,7 @@ void TestAlignment()
*pi = *pi; // misaligned access (read and write)
TCOUT << _T("Misaligned access OK.") << std::endl;
TEST("Misaligned ok"); //again, the test is not exploding up above
// - - - - - - - - - - - - - - - - - - - - - -
// make sure our BYTE_ALIGN value is correct --
@ -198,6 +203,7 @@ void TestAlignment()
TCOUT << _T("Aligned access OK. BYTE_ALIGN value of ") << BYTE_ALIGN << _T(" is good.") << std::endl;
TCOUT << _T("=========================================\n");
TEST("BYTE_ALIGN ok"); // yet again, the test is not falling over a couple of lines up.
}
void TestSizes()

View File

@ -89,6 +89,7 @@ void test_policy_file(const std::string& polfile)
errorQ.SetChild( &errorT );
parser.Execute( policy, &errorQ );
TEST("No exceptions thrown in cPolicyParser::Execute");
TCERR << "Parsed policy test file " << polfile << std::endl;
return;

View File

@ -84,15 +84,13 @@ TSS_ImplementPackage( cTestResources )
void TestResources()
{
TSS_Package( cTestResources ).Count( 20 );
TCOUT << _T("Package::Count(") << TSS_Package( cTestResources ).Count() << _T(")\n" ) << std::endl;
TCOUT << TSS_GetString( cTestResources, test::IDS_TEST1 ) << std::endl;
TCOUT << TSS_GetString( cTestResources, test::IDS_TEST2 ) << std::endl;
TCOUT << TSS_GetString( cTestResources, test::IDS_TEST3 ) << std::endl;
TCOUT << TSS_GetString( cTestResources, test::IDS_INVALID ) << std::endl;
TEST( TSS_Package( cTestResources ).Count() == 20) ;
TEST( TSS_GetString( cTestResources, test::IDS_TEST1 ) == _T("Test String 1") );
TEST( TSS_GetString( cTestResources, test::IDS_TEST2 ) == _T("Test String 2") );
TEST( TSS_GetString( cTestResources, test::IDS_TEST3 ) == _T("Test String 3") );
TEST( TSS_GetString( cTestResources, test::IDS_INVALID ) == _T("") );
TEST( TSS_GetString( cTestResources, 42 ) == _T("") );
}
void RegisterSuite_Resources()

View File

@ -71,6 +71,9 @@ cSerTestObject::cSerTestObject()
void TestSerializer()
{
cSerTestObject test_obj;
TEST( std::string(test_obj.GetType().AsString()) == std::string("cSerTestObject") );
TEST( test_obj.Version() == 1);
}
void RegisterSuite_Serializer()

View File

@ -167,6 +167,8 @@ void TestStringUtil()
TEST(tStr.length() == 9);
db.TraceAlways("Done...\n");
#else
skip("Implement this for non-DBS, i.e. most everywhere.");
#endif // USING_NTDBS_STUFF
}

View File

@ -46,13 +46,15 @@ void test_wist(const TSTRING&, cDebug& d);
void TestTCHAR()
{
TCERR << "TODO: Right now this test mostly verifies that STL string & file classes work, which is not overly useful." << std::endl;
cDebug d("TestTCHAR()");
d.TraceDetail("Entering...\n");
//Testing TCOUT:
TCOUT<< _T("Simple test of TSTRING (and TCOUT) :\n\n");
TCERR<< _T("This should show up on cerr");
TCERR<< _T("This should show up on cerr") << std::endl;
TSTRING pString;
pString = _T("Hi Mom!");
@ -82,7 +84,7 @@ void TestTCHAR()
//A true statement!
d.TraceDetail("Testing TISTRINGSTREAM with TSTRING:\n");
TSTRING send = _T("These should appear on seperate lines");
TSTRING send = _T("These should appear on separate lines");
test_wist(send, d);
//Did they?
@ -100,19 +102,18 @@ void TestTCHAR()
TIFSTREAM from;
from.open(inputfile.c_str(), std::ios_base::in);
if(!from)
d.TraceDetail("error opening input file\n");
TEST(from);
TOFSTREAM to(outputfile.c_str(), std::ios_base::trunc);
if(!to)
d.TraceDetail("error opening output file\n");
TEST(to);
//Copy contents of input file to output file.
TCHAR ch;
while(from.get(ch))
to.put(ch);
if(!from.eof() || !to)
d.TraceDetail("something has gone terribly wrong...\n");
TEST(from.eof() && to);
return;
}

View File

@ -159,10 +159,14 @@ void skip(const std::string& reason)
throw skip_exception(reason);
}
void fail(const std::string& reason)
{
throw std::runtime_error(reason);
}
void CountMacro()
{
macro_count++;
TCERR << "*** Incrementing macro count, value is now" << macro_count << std::endl;;
}
/////////////////////////

View File

@ -90,6 +90,7 @@ 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);
void fail(const std::string& reason);
#endif // __TEST_H