diff --git a/src/twtest/charutil_t.cpp b/src/twtest/charutil_t.cpp index 27db91c..4c04bf2 100644 --- a/src/twtest/charutil_t.cpp +++ b/src/twtest/charutil_t.cpp @@ -37,69 +37,56 @@ #include "core/stdcore.h" -#ifdef TSS_TEST - -#include "test/utx.h" -#include "charutil.h" -#include "debug.h" -#include "errorbucketimpl.h" +#include "core/charutil.h" +#include "core/debug.h" +#include "core/errorbucketimpl.h" -/////////////////////////////////////////////////////////////////////////////// -// cCharEncoderTest -/////////////////////////////////////////////////////////////////////////////// -class cCharEncoderTest +void PrintChars( const TSTRING& str ) { -public: - - void PrintChars( const TSTRING& str ) + TSTRING::const_iterator cur = str.begin(); + TSTRING::const_iterator end = str.end(); + TSTRING::const_iterator first, last; + + while( cCharUtil::PopNextChar( cur, end, first, last ) ) { - const TCHAR* cur = str.begin(); - const TCHAR* end = str.end(); - const TCHAR* first = NULL; - const TCHAR* last = NULL; + TCOUT << _T("char length: ") << (int)(last - first) << std::endl; - while( cCharUtil::PopNextChar( cur, end, first, last ) ) + TCOUT << _T("char: <"); + for( TSTRING::const_iterator at = first; at != last; at++ ) { - TCOUT << _T("char length: ") << (int)(last - first) << std::endl; - - TCOUT << _T("char: <"); - for( const TCHAR* at = first; at != last; at++ ) - { - if( at != first ) - TCOUT << _T(","); - TCOUT << (int)*at; - } - TCOUT << _T(">") << std::endl; + if( at != first ) + TCOUT << _T(","); + TCOUT << (int)*at; } - - TCOUT << _T("----------------------------") << std::endl; + TCOUT << _T(">") << std::endl; } + + TCOUT << _T("----------------------------") << std::endl; +} - /////////////////////////////////////////////////////////////////////////// - // Basic - /////////////////////////////////////////////////////////////////////////// - void Basic( tss::TestContext& ctx ) +/////////////////////////////////////////////////////////////////////////// +// Basic +/////////////////////////////////////////////////////////////////////////// +void TestCharUtilBasic() +{ + try { - try - { - PrintChars( _T("foo") ); - PrintChars( _T("fo\x2354") ); - } - catch( eError& e ) - { - cErrorReporter::PrintErrorMsg( e ); - ASSERT(false); - } + PrintChars( _T("foo") ); + PrintChars( _T("fo\x23 54") ); } -}; + catch( eError& e ) + { + cErrorReporter::PrintErrorMsg( e ); + ASSERT(false); + } +} + +/* TSS_BeginTestSuiteFrom( cCharEncoderTest ) TSS_AddTestCase( Basic ); TSS_EndTestSuite( cCharEncoderTest ) - -#endif // TSS_TEST - -// eof: charutil_t.cpp +*/ diff --git a/src/twtest/displayencoder_t.cpp b/src/twtest/displayencoder_t.cpp index b2595d4..88c4618 100644 --- a/src/twtest/displayencoder_t.cpp +++ b/src/twtest/displayencoder_t.cpp @@ -37,14 +37,12 @@ #include "core/stdcore.h" -#ifdef TSS_TEST - -#include "test/utx.h" -#include "displayencoder.h" -#include "debug.h" -#include "twlocale.h" -#include "errorbucketimpl.h" +#include "core/displayencoder.h" +#include "core/debug.h" +#include "core/twlocale.h" +#include "core/errorbucketimpl.h" +#include "twtest/test.h" /////////////////////////////////////////////////////////////////////////////// // UTIL @@ -53,7 +51,7 @@ #define TSS_TCHAR_MIN CHAR_MIN #define TSS_TCHAR_MAX CHAR_MAX - +/* template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str ) { const std::ctype< CharT > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); @@ -65,6 +63,7 @@ template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str return true; } +*/ static void util_TestUnprintable( const TSTRING& strCUnprintable ) { @@ -80,264 +79,253 @@ static void util_TestUnprintable( const TSTRING& strCUnprintable ) } -/////////////////////////////////////////////////////////////////////////////// -// cDisplayEncoderTest -/////////////////////////////////////////////////////////////////////////////// -class cDisplayEncoderTest + +/////////////////////////////////////////////////////////////////////////// +// TestCharToHex +/////////////////////////////////////////////////////////////////////////// +void test_char_to_hex(char ch, const TSTRING& expected) { -public: + TSTRING observed = cCharEncoderUtil::char_to_hex( ch ); + TEST(expected == observed); +} - /////////////////////////////////////////////////////////////////////////// - // TestCharToHex - /////////////////////////////////////////////////////////////////////////// - void TestCharToHex( tss::TestContext& ctx ) - { - TCHAR ch; - TSTRING str; - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - // only use lowercase strings with this define - #define TSS_CHAR_TO_HEX_TEST( s ) \ - ch = 0x ## s; \ - str = cCharEncoderUtil::char_to_hex( ch ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T( #s ) ); +void TestCharToHex() +{ + test_char_to_hex( 0xfe, "fe"); + test_char_to_hex( 0xff, "ff"); + test_char_to_hex( 0x00, "00"); + test_char_to_hex( 0x01, "01"); + test_char_to_hex( 0x7f, "7f"); + test_char_to_hex( 0x80, "80"); +} - TSS_CHAR_TO_HEX_TEST( fefe ); - TSS_CHAR_TO_HEX_TEST( 0000 ); - TSS_CHAR_TO_HEX_TEST( 1234 ); - TSS_CHAR_TO_HEX_TEST( ffff ); - TSS_CHAR_TO_HEX_TEST( 0001 ); - TSS_CHAR_TO_HEX_TEST( 543c ); - TSS_CHAR_TO_HEX_TEST( cccc ); - TSS_CHAR_TO_HEX_TEST( 9999 ); - TSS_CHAR_TO_HEX_TEST( abcd ); - } - /////////////////////////////////////////////////////////////////////////// - // TestHexToChar - /////////////////////////////////////////////////////////////////////////// - void TestHexToChar( tss::TestContext& ctx ) - { - TCHAR ch; - TSTRING str; +/////////////////////////////////////////////////////////////////////////// +// TestHexToChar +/////////////////////////////////////////////////////////////////////////// +void test_hex_to_char(const TSTRING& str, char expected) +{ + char observed = cCharEncoderUtil::hex_to_char( str.begin(), str.end() ); + TEST(expected == observed); +} - // only use lowercase strings with this define - #define TSS_HEX_TO_CHAR_TEST( s ) \ - str = _T( #s ); \ - ch = cCharEncoderUtil::hex_to_char( str.begin(), str.end() ); \ - ASSERT( ch == 0x ## s ); - TSS_HEX_TO_CHAR_TEST( fefe ); - TSS_HEX_TO_CHAR_TEST( 0000 ); - TSS_HEX_TO_CHAR_TEST( 1234 ); - TSS_HEX_TO_CHAR_TEST( ffff ); - TSS_HEX_TO_CHAR_TEST( 0001 ); - TSS_HEX_TO_CHAR_TEST( 543c ); - TSS_HEX_TO_CHAR_TEST( cccc ); - TSS_HEX_TO_CHAR_TEST( 9999 ); - TSS_HEX_TO_CHAR_TEST( abcd ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestStringToHex -- locale specific test -- only works in ASCII - /////////////////////////////////////////////////////////////////////////// - void TestStringToHex( tss::TestContext& ctx ) - { - TSTRING str; - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - - // only use lowercase strings with this define - #define TSS_STRING_TO_HEX_TEST( s, n ) \ - str = cCharEncoderUtil::CharStringToHexValue( _T( #s ) ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T( #n ) ); - - TSS_STRING_TO_HEX_TEST( \n, 000a ); - TSS_STRING_TO_HEX_TEST( \r, 000d ); - TSS_STRING_TO_HEX_TEST( \r\n, 000d000a ); - TSS_STRING_TO_HEX_TEST( a\r\nb, 0061000d000a0062 ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestHexToString -- locale specific test -- only works in Unicode - /////////////////////////////////////////////////////////////////////////// - void TestHexToString( tss::TestContext& ctx ) - { - TSTRING str; - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - - // only use lowercase strings with this define - #define TSS_HEX_TO_STRING_TEST( s, n ) \ - str = cCharEncoderUtil::HexValueToCharString( _T( #n ) ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T( #s ) ); - - TSS_HEX_TO_STRING_TEST( \n, 000a ); - TSS_HEX_TO_STRING_TEST( \r, 000d ); - TSS_HEX_TO_STRING_TEST( \r\n, 000d000a ); - TSS_HEX_TO_STRING_TEST( a\r\nb, 0061000d000a0062 ); - } +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 ); + test_hex_to_char( "01", 0x01 ); + test_hex_to_char( "7f", 0x7f ); + test_hex_to_char( "80", 0x80 ); - ////////////////////////////////////////////////////////////////////////// - // TestUnconvertable -- locale specific test -- only works in Unicode - /////////////////////////////////////////////////////////////////////////// - void TestUnconvertable( tss::TestContext& ctx ) - { - cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - TSTRING str; - TCHAR ch; - - // only use lowercase strings with this define - #define TSS_UNCONVERTABLE_TEST( n ) \ - ch = 0x ## n; \ - str = ch; \ - e.Encode( str ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T("\\x") _T( #n ) _T("x") ); - - TSS_UNCONVERTABLE_TEST( fefe ); - TSS_UNCONVERTABLE_TEST( 1234 ); - TSS_UNCONVERTABLE_TEST( ffff ); - TSS_UNCONVERTABLE_TEST( 1000 ); - TSS_UNCONVERTABLE_TEST( 543c ); - TSS_UNCONVERTABLE_TEST( cccc ); - TSS_UNCONVERTABLE_TEST( 9999 ); - TSS_UNCONVERTABLE_TEST( 0123 ); - TSS_UNCONVERTABLE_TEST( 0100 ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestUnprintable -- locale specific test -- only works in Unicode - /////////////////////////////////////////////////////////////////////////// - void TestUnprintable( tss::TestContext& ctx ) - { - cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); - const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); - TSTRING str; - TCHAR ch; - - // only use lowercase strings with this define - #define TSS_UNPRINTABLE_TEST( n ) \ - ch = 0x ## n; \ - str = ch; \ - e.Encode( str ); \ - ct.tolower( str.begin(), str.end() ); \ - ASSERT( str == _T("\\x") _T( #n ) _T("x") ); - - TSS_UNPRINTABLE_TEST( 000a ); - TSS_UNPRINTABLE_TEST( 000d ); - } - - ////////////////////////////////////////////////////////////////////////// - // TestQuoteAndBackSlash - /////////////////////////////////////////////////////////////////////////// - void TestQuoteAndBackSlash( tss::TestContext& ctx ) - { - cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); - TSTRING str; - - str = _T("\\"); - e.Encode( str ); - ASSERT( str == _T("\\\\") ); - - str = _T("\""); - e.Encode( str ); - ASSERT( str == _T("\\\"") ); - } - - // TODO:BAM -- try multibyte now..... + test_hex_to_char( "100", 0); // should throw + test_hex_to_char( "-01", 0); // should throw +#endif +} - /////////////////////////////////////////////////////////////////////////// - // Basic - /////////////////////////////////////////////////////////////////////////// - void Basic( tss::TestContext& ctx ) - { - try - { - //============================================================= - // TEST UNPRINTABLE ENCODING/ROUNDTRIP - //============================================================= - - util_TestUnprintable( _T("normal string") ); +////////////////////////////////////////////////////////////////////////// +// TestStringToHex -- locale specific test -- only works in ASCII +/////////////////////////////////////////////////////////////////////////// +void test_string_to_hex(const std::string& str, const std::string& expected) +{ + std::string observed = cCharEncoderUtil::CharStringToHexValue(str); + TEST(expected == observed); +} - util_TestUnprintable( _T("return\n") ); - util_TestUnprintable( _T("ret\rurn\n") ); - util_TestUnprintable( _T("ret\rnurn\n") ); +void TestStringToHex() +{ + test_string_to_hex( "\n", "0a" ); + test_string_to_hex( "\r", "0d" ); + test_string_to_hex( "\r\n", "0d0a" ); + test_string_to_hex( "a\r\nb", "610d0a62" ); +} - util_TestUnprintable( _T("bell\x08") ); - util_TestUnprintable( _T("\x08 bell") ); - util_TestUnprintable( _T("be\x08ll") ); - util_TestUnprintable( _T("\x1F\x1F\x1F") ); +////////////////////////////////////////////////////////////////////////// +// TestHexToString -- locale specific test -- only works in Unicode +/////////////////////////////////////////////////////////////////////////// +void test_hex_to_string(const std::string& str, const std::string& expected) +{ + std::string observed = cCharEncoderUtil::HexValueToCharString(str); + TEST(expected == observed); +} - util_TestUnprintable( _T("big\xFF") ); - util_TestUnprintable( _T("\xEE big") ); - util_TestUnprintable( _T("\xEE\xEEtwo big") ); - util_TestUnprintable( _T("small\x01") ); - util_TestUnprintable( _T("\x01\x01two small") ); - - //============================================================= - // TEST UNCONVERTABLE CHARS - //============================================================= - TSTRING strMessWithMe = _T("Mess with me..."); - for( size_t c = TSS_TCHAR_MIN; - c < TSS_TCHAR_MAX; - c++ ) - { - if( ( c != '\0' ) ) - { - strMessWithMe += c; - } - } - util_TestUnprintable( strMessWithMe ); +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 +////////////////////////////////////////////////////////////////////////// +// TestUnconvertable -- locale specific test -- only works in Unicode +/////////////////////////////////////////////////////////////////////////// +void TestUnconvertable() +{ + cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); + const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); + TSTRING str; + TCHAR ch; + + // only use lowercase strings with this define + #define TSS_UNCONVERTABLE_TEST( n ) \ + ch = 0x ## n; \ + str = ch; \ + e.Encode( str ); \ +// ct.tolower( str.begin(), str.end() ); \ + ASSERT( str == _T("\\x") _T( #n ) _T("x") ); + + TSS_UNCONVERTABLE_TEST( fefe ); + TSS_UNCONVERTABLE_TEST( 1234 ); + TSS_UNCONVERTABLE_TEST( ffff ); + TSS_UNCONVERTABLE_TEST( 1000 ); + TSS_UNCONVERTABLE_TEST( 543c ); + TSS_UNCONVERTABLE_TEST( cccc ); + TSS_UNCONVERTABLE_TEST( 9999 ); + TSS_UNCONVERTABLE_TEST( 0123 ); + TSS_UNCONVERTABLE_TEST( 0100 ); +} + +////////////////////////////////////////////////////////////////////////// +// TestUnprintable -- locale specific test -- only works in Unicode +/////////////////////////////////////////////////////////////////////////// +void TestUnprintable() +{ + cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); + const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct ); + TSTRING str; + TCHAR ch; + + // only use lowercase strings with this define + #define TSS_UNPRINTABLE_TEST( n ) \ + ch = 0x ## n; \ + str = ch; \ + e.Encode( str ); \ +// ct.tolower( str.begin(), str.end() ); \ + ASSERT( str == _T("\\x") _T( #n ) _T("x") ); + + TSS_UNPRINTABLE_TEST( 000a ); + TSS_UNPRINTABLE_TEST( 000d ); +} +#endif + +////////////////////////////////////////////////////////////////////////// +// TestQuoteAndBackSlash +/////////////////////////////////////////////////////////////////////////// +void TestQuoteAndBackSlash() +{ + cDisplayEncoder e( cDisplayEncoder::ROUNDTRIP ); + TSTRING str; + + str = _T("\\"); + e.Encode( str ); + ASSERT( str == _T("\\\\") ); - //============================================================= - // TEST \\ and \x ENCODING/ROUNDTRIP - //============================================================= + str = _T("\""); + e.Encode( str ); + ASSERT( str == _T("\\\"") ); +} - util_TestUnprintable( _T("\\Other \\\\slashes") ); - util_TestUnprintable( _T("\\Other slashes\\\\") ); - util_TestUnprintable( _T("O\\ther slashes\\\\") ); - util_TestUnprintable( _T("\\\\\\") ); +// TODO:BAM -- try multibyte now..... + + +/////////////////////////////////////////////////////////////////////////// +// Basic +/////////////////////////////////////////////////////////////////////////// +void TestDisplayEncoderBasic() +{ + try + { + //============================================================= + // TEST UNPRINTABLE ENCODING/ROUNDTRIP + //============================================================= + + util_TestUnprintable( _T("normal string") ); + + util_TestUnprintable( _T("return\n") ); + util_TestUnprintable( _T("ret\rurn\n") ); + util_TestUnprintable( _T("ret\rnurn\n") ); + + util_TestUnprintable( _T("bell\x08") ); + util_TestUnprintable( _T("\x08 bell") ); + util_TestUnprintable( _T("be\x08ll") ); + + util_TestUnprintable( _T("\x1F\x1F\x1F") ); + + util_TestUnprintable( _T("big\xFF") ); + util_TestUnprintable( _T("\xEE big") ); + util_TestUnprintable( _T("\xEE\xEEtwo big") ); + util_TestUnprintable( _T("small\x01") ); + util_TestUnprintable( _T("\x01\x01two small") ); - util_TestUnprintable( _T("\\xTricky") ); - util_TestUnprintable( _T("Tri\\xcky") ); - util_TestUnprintable( _T("Tricky\\x") ); - util_TestUnprintable( _T("\\Tricky\\\\x") ); - - - //============================================================= - // TEST UNCONVERTABLE, UNPRINTABLE, AND \\ and \" CHARS - //============================================================= - TSTRING strMessWithMe2 = _T("Mess with me..."); - for( size_t ch = TSS_TCHAR_MIN; - ch < TSS_TCHAR_MAX; - ch++ ) - { - if( ( ch != '\0' ) ) - { - strMessWithMe2 += ch; - } - } - - strMessWithMe2 += _T("\r\n\t\b\\\"\\\\\\\"\v\""); - util_TestUnprintable( strMessWithMe2 ); - - // TODO:BAM -- create multibyte tests (create a mb string at random, then test it. - // make sure there are '\' and '"' in it ) - } - catch( eError& e ) + //============================================================= + // TEST UNCONVERTABLE CHARS + //============================================================= + TSTRING strMessWithMe = _T("Mess with me..."); + for( size_t c = TSS_TCHAR_MIN; + c < TSS_TCHAR_MAX; + c++ ) { - cErrorReporter::PrintErrorMsg( e ); - ASSERT(false); + if( ( c != '\0' ) ) + { + strMessWithMe += c; + } } - } -}; + util_TestUnprintable( strMessWithMe ); + + //============================================================= + // TEST \\ and \x ENCODING/ROUNDTRIP + //============================================================= -TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) + util_TestUnprintable( _T("\\Other \\\\slashes") ); + util_TestUnprintable( _T("\\Other slashes\\\\") ); + util_TestUnprintable( _T("O\\ther slashes\\\\") ); + util_TestUnprintable( _T("\\\\\\") ); + + util_TestUnprintable( _T("\\xTricky") ); + util_TestUnprintable( _T("Tri\\xcky") ); + util_TestUnprintable( _T("Tricky\\x") ); + util_TestUnprintable( _T("\\Tricky\\\\x") ); + + + //============================================================= + // TEST UNCONVERTABLE, UNPRINTABLE, AND \\ and \" CHARS + //============================================================= + TSTRING strMessWithMe2 = _T("Mess with me..."); + for( size_t ch = TSS_TCHAR_MIN; + ch < TSS_TCHAR_MAX; + ch++ ) + { + if( ( ch != '\0' ) ) + { + strMessWithMe2 += ch; + } + } + + strMessWithMe2 += _T("\r\n\t\b\\\"\\\\\\\"\v\""); + util_TestUnprintable( strMessWithMe2 ); + + // TODO:BAM -- create multibyte tests (create a mb string at random, then test it. + // make sure there are '\' and '"' in it ) + } + catch( eError& e ) + { + cErrorReporter::PrintErrorMsg( e ); + ASSERT(false); + } +} + +/*TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) TSS_AddTestCase( Basic ); TSS_AddTestCase( TestHexToChar ); @@ -348,8 +336,6 @@ TSS_BeginTestSuiteFrom( cDisplayEncoderTest ) TSS_AddTestCase( TestUnprintable ); TSS_AddTestCase( TestQuoteAndBackSlash ); -TSS_EndTestSuite( cDisplayEncoderTest ) +TSS_EndTestSuite( cDisplayEncoderTest )*/ -#endif // TSS_TEST -// eof: displayencoder_t.cpp diff --git a/src/twtest/policyparser_t.cpp b/src/twtest/policyparser_t.cpp index d1f4fb3..2353f14 100644 --- a/src/twtest/policyparser_t.cpp +++ b/src/twtest/policyparser_t.cpp @@ -44,6 +44,7 @@ #include "fs/fspropset.h" #include "fco/fcospeclist.h" #include "twtest/test.h" +#include "util/fileutil.h" #include // helper class that checks output of each fcospec @@ -52,44 +53,70 @@ public: static bool VerifyNameAndStartPoint(iFCOSpec *pfsspec, TSTRING &name); }; -void TestPolicyParser() +TSTRING get_test_file_dir() { - cDebug d("TestPolicyParser()"); + if(cFileUtil::IsDir("../src/parser/testfiles")) + return "../src/parser/testfiles"; + + if(cFileUtil::IsDir("src/parser/testfiles")) + return "src/parser/testfiles"; + + return ""; +} - // - // file: pol.txt - // +void test_policy_file(const std::string& polfile) +{ try { cDebug::AddOutTarget(cDebug::OUT_STDOUT); - + + TSTRING pol_path = get_test_file_dir(); + pol_path.append("/"); + pol_path.append(polfile); + std::ifstream in; - in.open( "../twparser/testfiles/pol.txt" ); + in.open(pol_path); if( ! in.good() ) throw eParserHelper( _T("couldn't open test file") ); - + cPolicyParser parser( in ); - + cGenreSpecListVector policy; cErrorQueue errorQ; cErrorReporter errorR; cErrorTracer errorT; - + // set up an error bucket that will spit things to stderr errorT.SetChild( &errorR ); errorQ.SetChild( &errorT ); - + parser.Execute( policy, &errorQ ); - return; } catch(eError& e) { TCERR << (int)e.GetID() << " : " << e.GetMsg().c_str() << std::endl; return; } - + + TCERR << "Parsed policy test file " << polfile << std::endl; return; } + + + +void TestPolicyParser() +{ + cDebug d("TestPolicyParser()"); + + test_policy_file("pol.txt"); +// 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). + +/* test_policy_file("poleasy.txt"); + test_policy_file("polhard.txt"); + test_policy_file("polruleattr.txt"); */ +} diff --git a/src/twtest/test.cpp b/src/twtest/test.cpp index 7cec46e..019282a 100644 --- a/src/twtest/test.cpp +++ b/src/twtest/test.cpp @@ -39,11 +39,7 @@ #include "core/core.h" #include "db/db.h" #include "twcrypto/twcrypto.h" - -#ifdef PARSER_PRESENT -#include "parser/parser.h" -#endif - +#include "twparser/twparser.h" #include "tw/tw.h" #include "fco/fco.h" @@ -104,9 +100,7 @@ void TestHashTable(); void TestFCONameTbl(); void TestConfigFile(); -#ifdef PARSER_PRESENT void TestPolicyParser(); -#endif//PARSER_PRESENT void TestFCOSpecHelper(); void TestCrypto(); @@ -131,9 +125,7 @@ void TestIntegrityCheck(); void TestFCODatabaseFile(); void TestWchar16(); void TestStringEncoder(); -#ifdef TSS_TEST -void TestDisplayEncoder(); -#endif +//void TestDisplayEncoder(); void TestGrowHeap(); void TestPlatform(); //void TestBlockFile(); @@ -143,6 +135,17 @@ 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(); + /// This is easier than all the (cpp) files and declarations #include "stringutil_t.h" @@ -203,9 +206,7 @@ static void Test(int testID) case 43: TestTCHAR(); break; case 44: TestUnixFSServices(); break; case 46: TestConfigFile(); break; -#ifdef PARSER_PRESENT case 47: TestPolicyParser(); break; -#endif//PARSER_PRESENT case 48: TestKeyFile(); break; case 49: TestTWUtil(); break; case 50: TestFSPropDisplayer(); break; @@ -218,10 +219,8 @@ static void Test(int testID) case 58: TestGenreSpecList(); break; //case 59: TestIntegrityCheck(); break; case 65: TestWchar16(); break; - case 66: TestStringEncoder(); break; -#ifdef TSS_TEST - case 67: TestDisplayEncoder(); break; -#endif + case 66: TestStringEncoder(); break; + //case 67: TestDisplayEncoder(); break; case 69: TestGrowHeap(); break; case 70: TestPlatform(); break; //case 71: TestBlockFile(); break; @@ -231,7 +230,17 @@ static void Test(int testID) case 75: TestTWLocale(); break; case 76: TestFCONameTranslator(); break; case 77: TestStringUtil(); break; - case 78: TestCodeConverter(); 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; } } @@ -245,9 +254,7 @@ cTest::cTest() TSS_Dependency( cCore ); TSS_Dependency( cDb ); TSS_Dependency( cTWCrypto ); -#ifdef PARSER_PRESENT - TSS_Dependency( cParser ); -#endif//PARSER_PRESENT + TSS_Dependency( cTWParser ); TSS_Dependency( cTW ); TSS_Dependency( cFCO ); TSS_Dependency( cFS );