From 2a278ad29be6ee62f76ff71ba1bb65fda657d401 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 9 Sep 2017 23:26:45 -0700 Subject: [PATCH] Make 'syslog not supported' a warning vs a fatal error if someone tries to use it on syslog-less platforms; clean up unit & harness tests & handle some per-platform quirks --- src/test-harness/tests/complex.pm | 42 ++++++++++++++---------- src/test-harness/tests/dbupdate.pm | 6 ++-- src/test-harness/tests/inoderef.pm | 42 ++++++++++++++---------- src/test-harness/tests/integritycheck.pm | 35 +++++++++++++++----- src/test-harness/tests/readonly.pm | 41 +++++++++++++---------- src/test-harness/tests/siggen.pm | 11 ++++--- src/test-harness/twtools.pm | 4 +-- src/tripwire/twcmdline.cpp | 13 +++++--- src/twtest/configfile_t.cpp | 4 +-- src/twtest/displayencoder_t.cpp | 21 +++++++++--- src/twtest/error_t.cpp | 10 +++--- src/twtest/fconame_t.cpp | 8 +++-- src/twtest/fcospec_t.cpp | 6 +--- src/twtest/fsspec_t.cpp | 2 ++ src/twtest/growheap_t.cpp | 18 +++++----- src/twtest/platform_t.cpp | 40 +++++++++++----------- src/twtest/signature_t.cpp | 4 --- src/twtest/stringencoder_t.cpp | 4 +-- src/twtest/test.cpp | 1 + 19 files changed, 184 insertions(+), 128 deletions(-) diff --git a/src/test-harness/tests/complex.pm b/src/test-harness/tests/complex.pm index 5a08c50..936dffe 100644 --- a/src/test-harness/tests/complex.pm +++ b/src/test-harness/tests/complex.pm @@ -119,8 +119,8 @@ EOT # sub initialize() { - my $twstr = getPolicyFileString(); - twtools::GeneratePolicyFile($twstr); + my $twstr = getPolicyFileString(); + twtools::GeneratePolicyFile($twstr); } @@ -131,30 +131,36 @@ sub initialize() { # sub run() { - my $twpassed = 1; + twtools::logStatus("*** Beginning $description\n"); + printf("%-30s", "-- $description"); - twtools::logStatus("*** Beginning $description\n"); - printf("%-30s", "-- $description"); + if ($^O eq "skyos") { + ++$twtools::twskippedtests; + print "SKIPPED; TODO: SkyOS has fewer expected changes here; refactor so we can test for correct values\n"; + return; + } - ######################################################### - # - # Run the tests describe above in the %TESTS structure. - # - $twpassed = twtools::RunIntegrityTests(%TESTS); + my $twpassed = 1; + + ######################################################### + # + # Run the tests describe above in the %TESTS structure. + # + $twpassed = twtools::RunIntegrityTests(%TESTS); - ######################################################### - # - # See if the tests all succeeded... - # - if ($twpassed) { + ######################################################### + # + # See if the tests all succeeded... + # + if ($twpassed) { print "PASSED\n"; ++$twtools::twpassedtests; - } - else { + } + else { ++$twtools::twfailedtests; print "*FAILED*\n"; - } + } } diff --git a/src/test-harness/tests/dbupdate.pm b/src/test-harness/tests/dbupdate.pm index 4f361f4..9bab52b 100644 --- a/src/test-harness/tests/dbupdate.pm +++ b/src/test-harness/tests/dbupdate.pm @@ -159,9 +159,11 @@ sub RunBasicTest # Make sure we got 4 violations: 2 mod, 1 add, 1 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = ($^O ne "skyos") ? 4 : 3; + my $c_expected = ($^O ne "skyos") ? 2 : 1; + + if( ($n != $n_expected) || ($a != 1) || ($r != 1) || ($c != $c_expected) ) { - if( ($n != 4) || ($a != 1) || ($r != 1) || ($c != 2) ) - { twtools::logStatus("FAILED -- initial integrity check had unexpected results\n"); return 0; } diff --git a/src/test-harness/tests/inoderef.pm b/src/test-harness/tests/inoderef.pm index b779180..69e322b 100644 --- a/src/test-harness/tests/inoderef.pm +++ b/src/test-harness/tests/inoderef.pm @@ -77,8 +77,8 @@ EOT # sub initialize() { - my $twstr = getPolicyFileString(); - twtools::GeneratePolicyFile($twstr); + my $twstr = getPolicyFileString(); + twtools::GeneratePolicyFile($twstr); } @@ -89,30 +89,36 @@ sub initialize() { # sub run() { - my $twpassed = 1; + twtools::logStatus("*** Beginning $description\n"); + printf("%-30s", "-- $description"); - twtools::logStatus("*** Beginning $description\n"); - printf("%-30s", "-- $description"); + if ($^O eq "skyos" || $^O eq "haiku") { + ++$twtools::twskippedtests; + print "SKIPPED; OS doesn't support hardlinks.\n"; + return; + } - ######################################################### - # - # Run the tests describe above in the %TESTS structure. - # - $twpassed = twtools::RunIntegrityTests(%TESTS); + my $twpassed = 1; + + ######################################################### + # + # Run the tests describe above in the %TESTS structure. + # + $twpassed = twtools::RunIntegrityTests(%TESTS); - ######################################################### - # - # See if the tests all succeeded... - # - if ($twpassed) { + ######################################################### + # + # See if the tests all succeeded... + # + if ($twpassed) { ++$twtools::twpassedtests; print "PASSED\n"; - } - else { + } + else { ++$twtools::twfailedtests; print "*FAILED*\n"; - } + } } diff --git a/src/test-harness/tests/integritycheck.pm b/src/test-harness/tests/integritycheck.pm index a7b8159..e37dcc3 100644 --- a/src/test-harness/tests/integritycheck.pm +++ b/src/test-harness/tests/integritycheck.pm @@ -161,6 +161,7 @@ sub PrepareForTest sub run { my $twpassed = 1; + my $dir_mods = ($^O eq "skyos") ? 0 : 1; twtools::logStatus("*** Beginning integrity check test\n"); printf("%-30s", "-- $description"); @@ -181,8 +182,10 @@ sub run # Make sure we got 6 violations: 3 mod, 1 add, 2 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 6 : 4; + my $c_expected = $dir_mods ? 3 : 1; - if( ($n != 6) || ($a != 1) || ($r != 2) || ($c != 3) ) + if( ($n != $n_expected) || ($a != 1) || ($r != 2) || ($c != $c_expected) ) { twtools::logStatus("Full IC failed: $n $a $r $c\n"); $twpassed = 0; @@ -213,8 +216,10 @@ sub run # Make sure we got 6 violations: 3 mod, 1 add, 2 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 6 : 4; + my $c_expected = $dir_mods ? 3 : 1; - if( ($n != 6) || ($a != 1) || ($r != 2) || ($c != 3) ) + if( ($n != $n_expected) || ($a != 1) || ($r != 2) || ($c != $c_expected) ) { twtools::logStatus("IC with FS section failed: $n $a $r $c\n"); $twpassed = 0; @@ -229,8 +234,10 @@ sub run # Make sure we got 6 violations: 3 mod, 1 add, 2 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 6 : 4; + my $c_expected = $dir_mods ? 3 : 1; - if( ($n != 6) || ($a != 1) || ($r != 2) || ($c != 3) ) + if( ($n != $n_expected) || ($a != 1) || ($r != 2) || ($c != $c_expected) ) { twtools::logStatus("IC with FS section failed: $n $a $r $c\n"); $twpassed = 0; @@ -245,8 +252,10 @@ sub run # Make sure we got 4 violations this time: 2 mod, 1 add, 1 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 4 : 3; + my $c_expected = $dir_mods ? 2 : 1; - if( ($n != 4) || ($a != 1) || ($r != 1) || ($c != 2) ) + if( ($n != $n_expected) || ($a != 1) || ($r != 1) || ($c != $c_expected) ) { twtools::logStatus("IC of Rule A failed: $n $a $r $c\n"); $twpassed = 0; @@ -261,8 +270,10 @@ sub run # Make sure we got 2 violations this time: 1 mod, 0 add, 1 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 2 : 1; + my $c_expected = $dir_mods ? 1 : 0; - if( ($n != 2) || ($a != 0) || ($r != 1) || ($c != 1) ) + if( ($n != $n_expected) || ($a != 0) || ($r != 1) || ($c != $c_expected) ) { twtools::logStatus("IC of severity 200+ failed: $n $a $r $c\n"); $twpassed = 0; @@ -277,8 +288,10 @@ sub run # Make sure we got 2 violations this time: 1 mod, 0 add, 1 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 2 : 1; + my $c_expected = $dir_mods ? 1 : 0; - if( ($n != 2) || ($a != 0) || ($r != 1) || ($c != 1) ) + if( ($n != $n_expected) || ($a != 0) || ($r != 1) || ($c != $c_expected) ) { twtools::logStatus("IC of severity 'high' failed: $n $a $r $c\n"); $twpassed = 0; @@ -314,8 +327,10 @@ sub run # Make sure we got 6 violations: 3 mod, 1 add, 2 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 6 : 4; + my $c_expected = $dir_mods ? 3 : 1; - if( ($n != 6) || ($a != 1) || ($r != 2) || ($c != 3) ) + if( ($n != $n_expected) || ($a != 1) || ($r != 2) || ($c != $c_expected) ) { twtools::logStatus("Full IC failed: $n $a $r $c\n"); $twpassed = 0; @@ -328,11 +343,13 @@ sub run RemoveFile("$reportloc"); twtools::RunIntegrityCheck({trailing-opts => "-I -V cat -P $twtools::twlocalpass"}); - # Make sure we got 1 violation this time: 1 mod, 0 add, 0 rm. + # Make sure we got 6 violations: 3 mod, 1 add, 2 rm. # my ($n, $a, $r, $c) = twtools::AnalyzeReport( twtools::RunReport() ); + my $n_expected = $dir_mods ? 6 : 4; + my $c_expected = $dir_mods ? 3 : 1; - if( ($n != 6) || ($a != 1) || ($r != 2) || ($c != 3) ) + if( ($n != $n_expected) || ($a != 1) || ($r != 2) || ($c != $c_expected) ) { twtools::logStatus("Interactive IC failed: $n $a $r $c\n"); $twpassed = 0; diff --git a/src/test-harness/tests/readonly.pm b/src/test-harness/tests/readonly.pm index 3a68139..86e8e5b 100644 --- a/src/test-harness/tests/readonly.pm +++ b/src/test-harness/tests/readonly.pm @@ -71,8 +71,8 @@ EOT sub initialize() { - my $twstr = getPolicyFileString(); - twtools::GeneratePolicyFile($twstr); + my $twstr = getPolicyFileString(); + twtools::GeneratePolicyFile($twstr); } @@ -83,32 +83,37 @@ sub initialize() { # sub run() { - my $twpassed = 1; + twtools::logStatus("\n\n*** Beginning $description\n"); + printf("%-30s", "-- $description"); - twtools::logStatus("\n\n*** Beginning $description\n"); + if ($^O eq "skyos") { + ++$twtools::twskippedtests; + print "SKIPPED; SkyOS doesn't support readonly files.\n"; + return; + } - printf("%-30s", "-- $description"); + my $twpassed = 1; - ######################################################### - # - # Run the tests describe above in the %TESTS structure. - # - $twpassed = twtools::RunIntegrityTests(%TESTS); + ######################################################### + # + # Run the tests describe above in the %TESTS structure. + # + $twpassed = twtools::RunIntegrityTests(%TESTS); - ######################################################### - # - # See if the tests all succeeded... - # - if ($twpassed) { + ######################################################### + # + # See if the tests all succeeded... + # + if ($twpassed) { ++$twtools::twpassedtests; print "PASSED\n"; return 0; - } - else { + } + else { print "*FAILED*\n"; ++$twtools::twfailedtests; - } + } } diff --git a/src/test-harness/tests/siggen.pm b/src/test-harness/tests/siggen.pm index ecde9a2..f73ae90 100644 --- a/src/test-harness/tests/siggen.pm +++ b/src/test-harness/tests/siggen.pm @@ -37,10 +37,13 @@ sub run() { $twpassed = 0; } - twtools::logStatus(`mkfifo $twtools::twrootdir/donthashme.fifo`); - if ( $? != 0 ) { - twtools::logStatus("test fifo creation failed\n"); - $twpassed = 0; + # SkyOS doesn't have FIFOs, so this won't work + if ( $^O ne "skyos") { + twtools::logStatus(`mkfifo $twtools::twrootdir/donthashme.fifo`); + if ( $? != 0 ) { + twtools::logStatus("test fifo creation failed\n"); + $twpassed = 0; + } } twtools::logStatus(`$twtools::twrootdir/bin/siggen`); diff --git a/src/test-harness/twtools.pm b/src/test-harness/twtools.pm index 1252162..218511d 100644 --- a/src/test-harness/twtools.pm +++ b/src/test-harness/twtools.pm @@ -189,7 +189,7 @@ sub AddEncryption { my ($filename) = @_; logStatus "addding crypt to file...\n"; - logStatus(`$twrootdir/bin/twadmin -m E -c $twrootdir/$twcfgloc -P $twlocalpass -Q $twsitepass $filename`); + logStatus(`$twrootdir/bin/twadmin -m E -c $twrootdir/$twcfgloc -P $twlocalpass -Q $twsitepass $filename 2>&1`); return ($? == 0); } @@ -204,7 +204,7 @@ sub RemoveEncryption { my ($filename) = @_; logStatus "removing crypto from file...\n"; - logStatus(`$twrootdir/bin/twadmin -m R -c $twrootdir/$twcfgloc -P $twlocalpass -Q $twsitepass $filename`); + logStatus(`$twrootdir/bin/twadmin -m R -c $twrootdir/$twcfgloc -P $twlocalpass -Q $twsitepass $filename 2>&1`); return ($? == 0); } diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index e692218..4cf28f9 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -446,14 +446,19 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf) // SYSLOG reporting if(cf.Lookup(TSTRING(_T("SYSLOGREPORTING")), str)) { -#if SUPPORTS_SYSLOG if (_tcsicmp(str.c_str(), _T("true")) == 0) + { +#if SUPPORTS_SYSLOG pModeInfo->mbLogToSyslog = true; +#else + eTWSyslogNotSupported e; + e.SetFatality(false); + cErrorReporter::PrintErrorMsg(e); + pModeInfo->mbLogToSyslog = false; +#endif + } else pModeInfo->mbLogToSyslog = false; -#else - throw eTWSyslogNotSupported(); -#endif } else { diff --git a/src/twtest/configfile_t.cpp b/src/twtest/configfile_t.cpp index a2b032f..7b692a2 100644 --- a/src/twtest/configfile_t.cpp +++ b/src/twtest/configfile_t.cpp @@ -197,6 +197,6 @@ void TestConfigFile2(void) void RegisterSuite_ConfigFile() { - RegisterTest("ConfigFile", "Basic 1", TestConfigFile); - RegisterTest("ConfigFile", "Basic 2", TestConfigFile2); + RegisterTest("ConfigFile", "Basic1", TestConfigFile); + RegisterTest("ConfigFile", "Basic2", TestConfigFile2); } diff --git a/src/twtest/displayencoder_t.cpp b/src/twtest/displayencoder_t.cpp index df98865..448d1c4 100644 --- a/src/twtest/displayencoder_t.cpp +++ b/src/twtest/displayencoder_t.cpp @@ -71,7 +71,7 @@ static void util_TestUnprintable( const TSTRING& strCUnprintable ) TSTRING strEncoded = strCUnprintable; e.Encode( strEncoded ); - TCOUT << strEncoded << std::endl; +// TCOUT << strEncoded << std::endl; TSTRING strOut = strEncoded; e.Decode( strOut ); @@ -246,7 +246,7 @@ void TestQuoteAndBackSlash() /////////////////////////////////////////////////////////////////////////// // Basic /////////////////////////////////////////////////////////////////////////// -void TestDisplayEncoderBasic() +void TestDisplayEncoderBasic1() { //============================================================= // TEST UNPRINTABLE ENCODING/ROUNDTRIP @@ -269,7 +269,10 @@ void TestDisplayEncoderBasic() util_TestUnprintable( _T("\xEE\xEEtwo big") ); util_TestUnprintable( _T("small\x01") ); util_TestUnprintable( _T("\x01\x01two small") ); - +} + +void TestDisplayEncoderBasic2() +{ //============================================================= // TEST UNCONVERTABLE CHARS //============================================================= @@ -284,7 +287,10 @@ void TestDisplayEncoderBasic() } } util_TestUnprintable( strMessWithMe ); +} +void TestDisplayEncoderBasic3() +{ //============================================================= // TEST \\ and \x ENCODING/ROUNDTRIP //============================================================= @@ -298,8 +304,10 @@ void TestDisplayEncoderBasic() util_TestUnprintable( _T("Tri\\xcky") ); util_TestUnprintable( _T("Tricky\\x") ); util_TestUnprintable( _T("\\Tricky\\\\x") ); +} - +void TestDisplayEncoderBasic4() +{ //============================================================= // TEST UNCONVERTABLE, UNPRINTABLE, AND \\ and \" CHARS //============================================================= @@ -323,7 +331,10 @@ void TestDisplayEncoderBasic() void RegisterSuite_DisplayEncoder() { - RegisterTest("DisplayEncoder", "Basic", TestDisplayEncoderBasic); + RegisterTest("DisplayEncoder", "Basic1", TestDisplayEncoderBasic1); + RegisterTest("DisplayEncoder", "Basic2", TestDisplayEncoderBasic2); + RegisterTest("DisplayEncoder", "Basic3", TestDisplayEncoderBasic3); + RegisterTest("DisplayEncoder", "Basic4", TestDisplayEncoderBasic4); RegisterTest("DisplayEncoder", "CharToHex", TestCharToHex); RegisterTest("DisplayEncoder", "HexToChar", TestHexToChar); RegisterTest("DisplayEncoder", "StringToHex", TestStringToHex); diff --git a/src/twtest/error_t.cpp b/src/twtest/error_t.cpp index f3ed526..114bcae 100644 --- a/src/twtest/error_t.cpp +++ b/src/twtest/error_t.cpp @@ -44,16 +44,16 @@ void TestError() bool threw = false; try { - std::cout << "Before Exception" << std::endl; - std::cout << "Line number before throw: " << __LINE__ << std::endl; + // std::cout << "Before Exception" << std::endl; + // std::cout << "Line number before throw: " << __LINE__ << std::endl; throw eErrorGeneral(_T("This is an error!")); - std::cout << "After Exception" << std::endl; + // std::cout << "After Exception" << std::endl; } catch(eError& e) { threw = true; TEST(_tcscmp(e.GetMsg().c_str(), _T("This is an error!")) == 0); - TCOUT << _T("Exception caught!\n\nID=") << e.GetID() << _T("\n\t") << e.GetMsg() << std::endl; + // TCOUT << _T("Exception caught!\n\nID=") << e.GetID() << _T("\n\t") << e.GetMsg() << std::endl; } catch(...) { @@ -72,7 +72,7 @@ void TestError() { 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; +// TCOUT << _T("Internal error caught!\n\nID=") << e.GetID() << _T("\n\t") << e.GetMsg() << std::endl; } catch(...) { diff --git a/src/twtest/fconame_t.cpp b/src/twtest/fconame_t.cpp index 7ef2f54..674a276 100644 --- a/src/twtest/fconame_t.cpp +++ b/src/twtest/fconame_t.cpp @@ -43,7 +43,7 @@ #include "core/archive.h" #include "fco/genreswitcher.h" -void TestFCOName() +void TestFCOName1() { // test the relationship operator... cFCOName above (_T("/etc")); @@ -82,7 +82,10 @@ void TestFCOName() TEST(_tcscmp(cat.Pop(),_T("cat")) == 0); TEST(dog.AsString().compare(cat.AsString()) == 0); TEST(dog.GetRelationship(cat) == cFCOName::REL_EQUAL); +} +void TestFCOName2() +{ cFCOName nullName; TEST(*nullName.AsString().c_str() == 0); @@ -141,5 +144,6 @@ void TestFCOName() void RegisterSuite_FCOName() { - RegisterTest("FCOName", "Basic", TestFCOName); + RegisterTest("FCOName", "Basic1", TestFCOName1); + RegisterTest("FCOName", "Basic2", TestFCOName2); } diff --git a/src/twtest/fcospec_t.cpp b/src/twtest/fcospec_t.cpp index 86725d1..ec391c1 100644 --- a/src/twtest/fcospec_t.cpp +++ b/src/twtest/fcospec_t.cpp @@ -41,15 +41,11 @@ using namespace std; void TestFCOSpec() { - cout << "Begin\tTestFCOSpec" << endl; // all it seems I can test here is that the default mask works const iFCOSpecMask* pDefMask = iFCOSpecMask::GetDefaultMask(); - TEST(pDefMask->GetName().compare(TSTRING(_T("Default"))) == 0); + TEST(pDefMask->GetName().compare( TSTRING(_T("Default")) ) == 0); iFCO* pf1 = (iFCO*)0xbad, *pf2 = (iFCO*)0xcab; TEST( pDefMask->Accept(pf1) && pDefMask->Accept(pf2) ); - - cout << "End\tTestFCOSpec" << endl; - return; } void RegisterSuite_FCOSpec() diff --git a/src/twtest/fsspec_t.cpp b/src/twtest/fsspec_t.cpp index fc0a9c9..c354434 100644 --- a/src/twtest/fsspec_t.cpp +++ b/src/twtest/fsspec_t.cpp @@ -78,6 +78,7 @@ void TestFCOSpecImpl1() pSpec->SetStartPoint(cFCOName(TwTestDir())); dataSrc.SeekToFCO(pSpec->GetStartPoint(), false); + TEST(!dataSrc.Done()); iFCO* pFCO = dataSrc.CreateFCO(); TEST(pFCO); //PrintFCOTree(pFCO, d, 0); @@ -101,6 +102,7 @@ void TestFCOSpecImpl2() pSet->Add(cFCOName(_T("/etc/pclient"))); dataSrc.SeekToFCO(pSpec->GetStartPoint(), false); + TEST(!dataSrc.Done()); iFCO* pFCO = dataSrc.CreateFCO(); TEST(pFCO); //PrintFCOTree(pFCO, d, 0); diff --git a/src/twtest/growheap_t.cpp b/src/twtest/growheap_t.cpp index 61eecd2..abe30e7 100644 --- a/src/twtest/growheap_t.cpp +++ b/src/twtest/growheap_t.cpp @@ -48,17 +48,17 @@ void TestGrowHeap() cGrowHeap gh( initSize, growBy, _T("growheap_t.cpp") ); // report initial state - TCOUT << _T("Initial size: ") << initSize << endl; +/* TCOUT << _T("Initial size: ") << initSize << endl; TCOUT << _T("Growby: ") << growBy << endl; TCOUT << _T("Initial Growheap memory usage: ") << gh.TotalMemUsage() << endl << endl; - +*/ const int growFactor = 5; // how much to enlarge requests each time // make it odd so we can see if the growheap // rounds to the alignment size for( size_t size = 1; size < growBy; size *= growFactor ) { // allocate memory - TCOUT << _T("Allocing by ") << size << endl; + //TCOUT << _T("Allocing by ") << size << endl; void* p = gh.Malloc( size ); TEST( p != NULL ); @@ -66,12 +66,12 @@ void TestGrowHeap() if( size > sizeof(int) ) { // read from memory - TCOUT << _T("Reading an int from memory...") << endl; + //TCOUT << _T("Reading an int from memory...") << endl; int* pi = static_cast< int* >( p ); int i = *pi; // write to memory - TCOUT << _T("Writing an int to memory...") << endl; + //TCOUT << _T("Writing an int to memory...") << endl; *pi = i; } @@ -79,19 +79,21 @@ void TestGrowHeap() if( size > sizeof(double) ) { // read from memory - TCOUT << _T("Reading a double from memory...") << endl; + //TCOUT << _T("Reading a double from memory...") << endl; double* pd = static_cast< double* >( p ); double d = *pd; // write to memory - TCOUT << _T("Writing a double to memory...") << endl; + //TCOUT << _T("Writing a double to memory...") << endl; *pd = d; } // report total usage - TCOUT << _T("Growheap memory usage: ") << gh.TotalMemUsage() << endl << endl; + //TCOUT << _T("Growheap memory usage: ") << gh.TotalMemUsage() << endl << endl; } + TEST( gh.TotalMemUsage() > 0); + // free memory gh.Clear(); TEST( gh.TotalMemUsage() == 0 ); diff --git a/src/twtest/platform_t.cpp b/src/twtest/platform_t.cpp index 2612326..ba7aec2 100644 --- a/src/twtest/platform_t.cpp +++ b/src/twtest/platform_t.cpp @@ -82,7 +82,7 @@ AlignMe::AlignMe() // this test exists in the first place. // -bcox #if (!IS_HPUX && !IS_SOLARIS) //Turns out Solaris SPARC is unhappy with this test too, btw - TCOUT << _T("Testing alignment of size ") << ALIGN_SIZE << std::endl; + //TCOUT << _T("Testing alignment of size ") << ALIGN_SIZE << std::endl; // access a double in the byte array to see if it is aligned. if it isn't and the CPU // can't handle it, you'll get a bus error @@ -90,11 +90,11 @@ AlignMe::AlignMe() // this should choke if the CPU can't // handle misaligned memory access int32* pi = (int32*)&a[ALIGN_SIZE]; - TCOUT << _T("Testing alignment of an int32...") << std::endl; - TCOUT << _T("Reading...") << std::endl; + //TCOUT << _T("Testing alignment of an int32...") << std::endl; + //TCOUT << _T("Reading...") << std::endl; int32 i = *pi; // access memory for read - TCOUT << _T("Read succeeded.") << std::endl; - TCOUT << _T("Writing...") << std::endl; + //TCOUT << _T("Read succeeded.") << std::endl; + //TCOUT << _T("Writing...") << std::endl; *pi = i; // access memory for write TCOUT << _T("Write succeeded.") << std::endl; @@ -102,17 +102,17 @@ AlignMe::AlignMe() // this should choke if the CPU can't // handle misaligned memory access int64* pb = (int64*)&a[ALIGN_SIZE]; - TCOUT << _T("Testing alignment of an int64...") << std::endl; - TCOUT << _T("Reading...") << std::endl; + //TCOUT << _T("Testing alignment of an int64...") << std::endl; + //TCOUT << _T("Reading...") << std::endl; int64 I = *pb; // access memory for read - TCOUT << _T("Read succeeded") << std::endl; - TCOUT << _T("Writing...") << std::endl; + //TCOUT << _T("Read succeeded") << std::endl; + //TCOUT << _T("Writing...") << std::endl; *pb = I; // access memory for write - TCOUT << _T("Write succeeded.") << std::endl; + //TCOUT << _T("Write succeeded.") << std::endl; - TCOUT << _T("Alignment of ") << ALIGN_SIZE << _T(" ") << ( ALIGN_SIZE == 1 ? _T("byte") : _T("bytes") ) << _T(" is OK") << std::endl - << _T("=========================================\n"); + /*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. @@ -131,8 +131,8 @@ void TestAlignment() // The last AlignMe to be successfully constructed // - - - - - - - - - - - - - - - - - - - - - - - TCOUT << _T("Testing for byte alignment\n") - << _T("=========================================\n"); +// TCOUT << _T("Testing for byte alignment\n") +// << _T("=========================================\n"); AlignMe<128> a128; AlignMe<64> a64; @@ -156,10 +156,10 @@ void TestAlignment() a[0] = 0xAB; - TCOUT << _T("=========================================\n") +/* TCOUT << _T("=========================================\n") << _T("About to test memory access off by 1 byte\n") << _T("If you do not see a confirmation after this line, the test choked") - << std::endl; + << std::endl; */ // this should choke if the CPU can't // handle misaligned memory access @@ -180,20 +180,20 @@ void TestAlignment() // this should be fine b[0] = 0xAB; - TCOUT << _T("=========================================\n") +/* TCOUT << _T("=========================================\n") << _T("About to test memory access off by ") << BYTE_ALIGN << _T(" ") << ( BYTE_ALIGN == 1 ? _T("byte") : _T("bytes") ) << std::endl << _T("If you do not see a confirmation after this line, the test choked") << std::endl; - +*/ // this should choke if the CPU can't // handle misaligned memory access pi = (int32*)&b[BYTE_ALIGN]; *pi = *pi; // aligned (hopefully) access (read and write) - TCOUT << _T("Aligned access OK. BYTE_ALIGN value of ") << BYTE_ALIGN << _T(" is good.") << std::endl; +/* 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. + TEST("BYTE_ALIGN ok"); // yet again, the test is not falling over a couple of lines up. */ } // Not sure this is a super valuable test, since it just verifies that builtin integer types diff --git a/src/twtest/signature_t.cpp b/src/twtest/signature_t.cpp index 13ad64d..b9dcd43 100644 --- a/src/twtest/signature_t.cpp +++ b/src/twtest/signature_t.cpp @@ -443,10 +443,6 @@ void assertSHA1(const std::string& source, const std::string& expectedHex) shaSig.Update( (const byte*)source.c_str(), source.length() ); shaSig.Finit(); - TCERR << "Source = [" << source << "]" << std::endl; - TCERR << "Expected = " << expectedHex << std::endl; - TCERR << "Observed = " << shaSig.AsStringHex() << std::endl; - TEST( shaSig.AsStringHex() == expectedHex); } diff --git a/src/twtest/stringencoder_t.cpp b/src/twtest/stringencoder_t.cpp index d0b7cf3..bd39f26 100644 --- a/src/twtest/stringencoder_t.cpp +++ b/src/twtest/stringencoder_t.cpp @@ -86,9 +86,9 @@ void OutputString( TSTRING& str ) { cQuoteEncoder qe; - TCOUT << _T("Plain string: <") << str << _T(">") << endl; +/* 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 ; + TCOUT << _T("Decoded string: <") << qe.Unencode( str ) << _T(">") << endl << endl ; */ TEST( str == qe.Unencode(qe.Encode(str)) ); } diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index ff84c76..aeb4c50 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -479,6 +479,7 @@ int _tmain(int argc, TCHAR** argv) //TEST(cRefCountObj::AllRefCountObjDestoryed() == true); std::cout << std::endl << "Ran " << ran_count << " unit tests with " << failed_count << " failures, " << skipped_count << " skipped." << std::endl; + std::cout << "(total test assertions: " << macro_count << ")" << std::endl; if (failed_count) {