Enable & (at least partly) fix charutil, displayencoder, & policyparser tests, which weren't running until now.
This commit is contained in:
parent
be0b374cad
commit
cdb7310dae
|
@ -37,69 +37,56 @@
|
||||||
|
|
||||||
#include "core/stdcore.h"
|
#include "core/stdcore.h"
|
||||||
|
|
||||||
#ifdef TSS_TEST
|
#include "core/charutil.h"
|
||||||
|
#include "core/debug.h"
|
||||||
#include "test/utx.h"
|
#include "core/errorbucketimpl.h"
|
||||||
#include "charutil.h"
|
|
||||||
#include "debug.h"
|
|
||||||
#include "errorbucketimpl.h"
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
void PrintChars( const TSTRING& str )
|
||||||
// cCharEncoderTest
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
class cCharEncoderTest
|
|
||||||
{
|
{
|
||||||
public:
|
TSTRING::const_iterator cur = str.begin();
|
||||||
|
TSTRING::const_iterator end = str.end();
|
||||||
|
TSTRING::const_iterator first, last;
|
||||||
|
|
||||||
void PrintChars( const TSTRING& str )
|
while( cCharUtil::PopNextChar( cur, end, first, last ) )
|
||||||
{
|
{
|
||||||
const TCHAR* cur = str.begin();
|
TCOUT << _T("char length: ") << (int)(last - first) << std::endl;
|
||||||
const TCHAR* end = str.end();
|
|
||||||
const TCHAR* first = NULL;
|
|
||||||
const TCHAR* last = NULL;
|
|
||||||
|
|
||||||
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;
|
if( at != first )
|
||||||
|
TCOUT << _T(",");
|
||||||
TCOUT << _T("char: <");
|
TCOUT << (int)*at;
|
||||||
for( const TCHAR* at = first; at != last; at++ )
|
|
||||||
{
|
|
||||||
if( at != first )
|
|
||||||
TCOUT << _T(",");
|
|
||||||
TCOUT << (int)*at;
|
|
||||||
}
|
|
||||||
TCOUT << _T(">") << std::endl;
|
|
||||||
}
|
}
|
||||||
|
TCOUT << _T(">") << std::endl;
|
||||||
TCOUT << _T("----------------------------") << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
TCOUT << _T("----------------------------") << std::endl;
|
||||||
// Basic
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
void Basic( tss::TestContext& ctx )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PrintChars( _T("foo") );
|
|
||||||
PrintChars( _T("fo\x2354") );
|
|
||||||
}
|
|
||||||
catch( eError& e )
|
|
||||||
{
|
|
||||||
cErrorReporter::PrintErrorMsg( e );
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Basic
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void TestCharUtilBasic()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PrintChars( _T("foo") );
|
||||||
|
PrintChars( _T("fo\x23 54") );
|
||||||
|
}
|
||||||
|
catch( eError& e )
|
||||||
|
{
|
||||||
|
cErrorReporter::PrintErrorMsg( e );
|
||||||
|
ASSERT(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
TSS_BeginTestSuiteFrom( cCharEncoderTest )
|
TSS_BeginTestSuiteFrom( cCharEncoderTest )
|
||||||
|
|
||||||
TSS_AddTestCase( Basic );
|
TSS_AddTestCase( Basic );
|
||||||
|
|
||||||
TSS_EndTestSuite( cCharEncoderTest )
|
TSS_EndTestSuite( cCharEncoderTest )
|
||||||
|
*/
|
||||||
#endif // TSS_TEST
|
|
||||||
|
|
||||||
// eof: charutil_t.cpp
|
|
||||||
|
|
|
@ -37,14 +37,12 @@
|
||||||
|
|
||||||
#include "core/stdcore.h"
|
#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
|
// UTIL
|
||||||
|
@ -53,7 +51,7 @@
|
||||||
#define TSS_TCHAR_MIN CHAR_MIN
|
#define TSS_TCHAR_MIN CHAR_MIN
|
||||||
#define TSS_TCHAR_MAX CHAR_MAX
|
#define TSS_TCHAR_MAX CHAR_MAX
|
||||||
|
|
||||||
|
/*
|
||||||
template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str )
|
template< class CharT > bool IsPrintable( const std::basic_string< CharT >& str )
|
||||||
{
|
{
|
||||||
const std::ctype< CharT > *pct = 0, &ct = tss::GetFacet( std::locale(), pct );
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static void util_TestUnprintable( const TSTRING& strCUnprintable )
|
static void util_TestUnprintable( const TSTRING& strCUnprintable )
|
||||||
{
|
{
|
||||||
|
@ -80,264 +79,253 @@ static void util_TestUnprintable( const TSTRING& strCUnprintable )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// cDisplayEncoderTest
|
///////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
// TestCharToHex
|
||||||
class cDisplayEncoderTest
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void test_char_to_hex(char ch, const TSTRING& expected)
|
||||||
{
|
{
|
||||||
public:
|
TSTRING observed = cCharEncoderUtil::char_to_hex( ch );
|
||||||
|
TEST(expected == observed);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// TestCharToHex
|
void TestCharToHex()
|
||||||
///////////////////////////////////////////////////////////////////////////
|
{
|
||||||
void TestCharToHex( tss::TestContext& ctx )
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// TestHexToChar
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void test_hex_to_char(const TSTRING& str, char expected)
|
||||||
|
{
|
||||||
|
char observed = cCharEncoderUtil::hex_to_char( str.begin(), str.end() );
|
||||||
|
TEST(expected == observed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
test_hex_to_char( "100", 0); // should throw
|
||||||
|
test_hex_to_char( "-01", 0); // should throw
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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("\\\\") );
|
||||||
|
|
||||||
|
str = _T("\"");
|
||||||
|
e.Encode( str );
|
||||||
|
ASSERT( str == _T("\\\"") );
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO:BAM -- try multibyte now.....
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// Basic
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
void TestDisplayEncoderBasic()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
TCHAR ch;
|
//=============================================================
|
||||||
TSTRING str;
|
// TEST UNPRINTABLE ENCODING/ROUNDTRIP
|
||||||
const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct );
|
//=============================================================
|
||||||
|
|
||||||
// only use lowercase strings with this define
|
util_TestUnprintable( _T("normal string") );
|
||||||
#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 ) );
|
|
||||||
|
|
||||||
TSS_CHAR_TO_HEX_TEST( fefe );
|
util_TestUnprintable( _T("return\n") );
|
||||||
TSS_CHAR_TO_HEX_TEST( 0000 );
|
util_TestUnprintable( _T("ret\rurn\n") );
|
||||||
TSS_CHAR_TO_HEX_TEST( 1234 );
|
util_TestUnprintable( _T("ret\rnurn\n") );
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
util_TestUnprintable( _T("bell\x08") );
|
||||||
// TestHexToChar
|
util_TestUnprintable( _T("\x08 bell") );
|
||||||
///////////////////////////////////////////////////////////////////////////
|
util_TestUnprintable( _T("be\x08ll") );
|
||||||
void TestHexToChar( tss::TestContext& ctx )
|
|
||||||
{
|
|
||||||
TCHAR ch;
|
|
||||||
TSTRING str;
|
|
||||||
|
|
||||||
// only use lowercase strings with this define
|
util_TestUnprintable( _T("\x1F\x1F\x1F") );
|
||||||
#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 );
|
util_TestUnprintable( _T("big\xFF") );
|
||||||
TSS_HEX_TO_CHAR_TEST( 0000 );
|
util_TestUnprintable( _T("\xEE big") );
|
||||||
TSS_HEX_TO_CHAR_TEST( 1234 );
|
util_TestUnprintable( _T("\xEE\xEEtwo big") );
|
||||||
TSS_HEX_TO_CHAR_TEST( ffff );
|
util_TestUnprintable( _T("small\x01") );
|
||||||
TSS_HEX_TO_CHAR_TEST( 0001 );
|
util_TestUnprintable( _T("\x01\x01two small") );
|
||||||
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
|
// TEST UNCONVERTABLE CHARS
|
||||||
///////////////////////////////////////////////////////////////////////////
|
//=============================================================
|
||||||
void TestStringToHex( tss::TestContext& ctx )
|
TSTRING strMessWithMe = _T("Mess with me...");
|
||||||
{
|
for( size_t c = TSS_TCHAR_MIN;
|
||||||
TSTRING str;
|
c < TSS_TCHAR_MAX;
|
||||||
const std::ctype< TCHAR > *pct = 0, &ct = tss::GetFacet( std::locale(), pct );
|
c++ )
|
||||||
|
|
||||||
// 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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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.....
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// Basic
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
void Basic( tss::TestContext& ctx )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
//=============================================================
|
if( ( c != '\0' ) )
|
||||||
// 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") );
|
|
||||||
|
|
||||||
//=============================================================
|
|
||||||
// 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;
|
||||||
{
|
|
||||||
strMessWithMe += c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
util_TestUnprintable( strMessWithMe );
|
|
||||||
|
|
||||||
//=============================================================
|
|
||||||
// TEST \\ and \x ENCODING/ROUNDTRIP
|
|
||||||
//=============================================================
|
|
||||||
|
|
||||||
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 )
|
util_TestUnprintable( strMessWithMe );
|
||||||
|
|
||||||
|
//=============================================================
|
||||||
|
// TEST \\ and \x ENCODING/ROUNDTRIP
|
||||||
|
//=============================================================
|
||||||
|
|
||||||
|
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++ )
|
||||||
{
|
{
|
||||||
cErrorReporter::PrintErrorMsg( e );
|
if( ( ch != '\0' ) )
|
||||||
ASSERT(false);
|
{
|
||||||
|
strMessWithMe2 += ch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TSS_BeginTestSuiteFrom( cDisplayEncoderTest )
|
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( Basic );
|
||||||
TSS_AddTestCase( TestHexToChar );
|
TSS_AddTestCase( TestHexToChar );
|
||||||
|
@ -348,8 +336,6 @@ TSS_BeginTestSuiteFrom( cDisplayEncoderTest )
|
||||||
TSS_AddTestCase( TestUnprintable );
|
TSS_AddTestCase( TestUnprintable );
|
||||||
TSS_AddTestCase( TestQuoteAndBackSlash );
|
TSS_AddTestCase( TestQuoteAndBackSlash );
|
||||||
|
|
||||||
TSS_EndTestSuite( cDisplayEncoderTest )
|
TSS_EndTestSuite( cDisplayEncoderTest )*/
|
||||||
|
|
||||||
#endif // TSS_TEST
|
|
||||||
|
|
||||||
// eof: displayencoder_t.cpp
|
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include "fs/fspropset.h"
|
#include "fs/fspropset.h"
|
||||||
#include "fco/fcospeclist.h"
|
#include "fco/fcospeclist.h"
|
||||||
#include "twtest/test.h"
|
#include "twtest/test.h"
|
||||||
|
#include "util/fileutil.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
// helper class that checks output of each fcospec
|
// helper class that checks output of each fcospec
|
||||||
|
@ -52,19 +53,29 @@ public:
|
||||||
static bool VerifyNameAndStartPoint(iFCOSpec *pfsspec, TSTRING &name);
|
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"))
|
||||||
// file: pol.txt
|
return "src/parser/testfiles";
|
||||||
//
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_policy_file(const std::string& polfile)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cDebug::AddOutTarget(cDebug::OUT_STDOUT);
|
cDebug::AddOutTarget(cDebug::OUT_STDOUT);
|
||||||
|
|
||||||
|
TSTRING pol_path = get_test_file_dir();
|
||||||
|
pol_path.append("/");
|
||||||
|
pol_path.append(polfile);
|
||||||
|
|
||||||
std::ifstream in;
|
std::ifstream in;
|
||||||
in.open( "../twparser/testfiles/pol.txt" );
|
in.open(pol_path);
|
||||||
if( ! in.good() )
|
if( ! in.good() )
|
||||||
throw eParserHelper( _T("couldn't open test file") );
|
throw eParserHelper( _T("couldn't open test file") );
|
||||||
|
|
||||||
|
@ -81,7 +92,6 @@ void TestPolicyParser()
|
||||||
|
|
||||||
parser.Execute( policy, &errorQ );
|
parser.Execute( policy, &errorQ );
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
catch(eError& e)
|
catch(eError& e)
|
||||||
{
|
{
|
||||||
|
@ -89,7 +99,24 @@ void TestPolicyParser()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TCERR << "Parsed policy test file " << polfile << std::endl;
|
||||||
return;
|
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"); */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,7 @@
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "db/db.h"
|
#include "db/db.h"
|
||||||
#include "twcrypto/twcrypto.h"
|
#include "twcrypto/twcrypto.h"
|
||||||
|
#include "twparser/twparser.h"
|
||||||
#ifdef PARSER_PRESENT
|
|
||||||
#include "parser/parser.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "tw/tw.h"
|
#include "tw/tw.h"
|
||||||
#include "fco/fco.h"
|
#include "fco/fco.h"
|
||||||
|
|
||||||
|
@ -104,9 +100,7 @@ void TestHashTable();
|
||||||
void TestFCONameTbl();
|
void TestFCONameTbl();
|
||||||
void TestConfigFile();
|
void TestConfigFile();
|
||||||
|
|
||||||
#ifdef PARSER_PRESENT
|
|
||||||
void TestPolicyParser();
|
void TestPolicyParser();
|
||||||
#endif//PARSER_PRESENT
|
|
||||||
|
|
||||||
void TestFCOSpecHelper();
|
void TestFCOSpecHelper();
|
||||||
void TestCrypto();
|
void TestCrypto();
|
||||||
|
@ -131,9 +125,7 @@ void TestIntegrityCheck();
|
||||||
void TestFCODatabaseFile();
|
void TestFCODatabaseFile();
|
||||||
void TestWchar16();
|
void TestWchar16();
|
||||||
void TestStringEncoder();
|
void TestStringEncoder();
|
||||||
#ifdef TSS_TEST
|
//void TestDisplayEncoder();
|
||||||
void TestDisplayEncoder();
|
|
||||||
#endif
|
|
||||||
void TestGrowHeap();
|
void TestGrowHeap();
|
||||||
void TestPlatform();
|
void TestPlatform();
|
||||||
//void TestBlockFile();
|
//void TestBlockFile();
|
||||||
|
@ -143,6 +135,17 @@ void TestTWLocale();
|
||||||
void TestFileUtil();
|
void TestFileUtil();
|
||||||
void TestFCONameTranslator();
|
void TestFCONameTranslator();
|
||||||
void TestCodeConverter();
|
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
|
/// This is easier than all the (cpp) files and declarations
|
||||||
#include "stringutil_t.h"
|
#include "stringutil_t.h"
|
||||||
|
|
||||||
|
@ -203,9 +206,7 @@ static void Test(int testID)
|
||||||
case 43: TestTCHAR(); break;
|
case 43: TestTCHAR(); break;
|
||||||
case 44: TestUnixFSServices(); break;
|
case 44: TestUnixFSServices(); break;
|
||||||
case 46: TestConfigFile(); break;
|
case 46: TestConfigFile(); break;
|
||||||
#ifdef PARSER_PRESENT
|
|
||||||
case 47: TestPolicyParser(); break;
|
case 47: TestPolicyParser(); break;
|
||||||
#endif//PARSER_PRESENT
|
|
||||||
case 48: TestKeyFile(); break;
|
case 48: TestKeyFile(); break;
|
||||||
case 49: TestTWUtil(); break;
|
case 49: TestTWUtil(); break;
|
||||||
case 50: TestFSPropDisplayer(); break;
|
case 50: TestFSPropDisplayer(); break;
|
||||||
|
@ -219,9 +220,7 @@ static void Test(int testID)
|
||||||
//case 59: TestIntegrityCheck(); break;
|
//case 59: TestIntegrityCheck(); break;
|
||||||
case 65: TestWchar16(); break;
|
case 65: TestWchar16(); break;
|
||||||
case 66: TestStringEncoder(); break;
|
case 66: TestStringEncoder(); break;
|
||||||
#ifdef TSS_TEST
|
//case 67: TestDisplayEncoder(); break;
|
||||||
case 67: TestDisplayEncoder(); break;
|
|
||||||
#endif
|
|
||||||
case 69: TestGrowHeap(); break;
|
case 69: TestGrowHeap(); break;
|
||||||
case 70: TestPlatform(); break;
|
case 70: TestPlatform(); break;
|
||||||
//case 71: TestBlockFile(); break;
|
//case 71: TestBlockFile(); break;
|
||||||
|
@ -232,6 +231,16 @@ static void Test(int testID)
|
||||||
case 76: TestFCONameTranslator(); break;
|
case 76: TestFCONameTranslator(); break;
|
||||||
case 77: TestStringUtil(); 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( cCore );
|
||||||
TSS_Dependency( cDb );
|
TSS_Dependency( cDb );
|
||||||
TSS_Dependency( cTWCrypto );
|
TSS_Dependency( cTWCrypto );
|
||||||
#ifdef PARSER_PRESENT
|
TSS_Dependency( cTWParser );
|
||||||
TSS_Dependency( cParser );
|
|
||||||
#endif//PARSER_PRESENT
|
|
||||||
TSS_Dependency( cTW );
|
TSS_Dependency( cTW );
|
||||||
TSS_Dependency( cFCO );
|
TSS_Dependency( cFCO );
|
||||||
TSS_Dependency( cFS );
|
TSS_Dependency( cFS );
|
||||||
|
|
Loading…
Reference in New Issue