Fix various unit tests that didn't test anything, or needed cleanup; disable some cTWLocale methods that were unused outside of their own unit tests.
This commit is contained in:
parent
f05b85726e
commit
b648b2493f
|
@ -104,6 +104,7 @@ void cTWLocale::InitGlobalLocale()
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
TSTRING cTWLocale::FormatNumberAsHex( int32 i )
|
||||
{
|
||||
//
|
||||
|
@ -125,6 +126,7 @@ TSTRING cTWLocale::FormatNumberAsHex( int32 i )
|
|||
//
|
||||
return( sstr.str() );
|
||||
}
|
||||
*/
|
||||
|
||||
template< class numT, class CharT >
|
||||
class cFormatNumberUtil
|
||||
|
@ -190,6 +192,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/*
|
||||
TSTRING cTWLocale::FormatNumberClassic( int32 i )
|
||||
{
|
||||
TSTRING s;
|
||||
|
@ -200,7 +203,7 @@ int32 cTWLocale::FormatNumberClassic( const TSTRING& s )
|
|||
{
|
||||
return cFormatNumberUtil< long, TCHAR >::Format( s, true );
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( uint64 ui, TSTRING& strBuf )
|
||||
{
|
||||
|
|
|
@ -79,12 +79,13 @@ public:
|
|||
static TSTRING& FormatNumber( uint64 ui, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( double d, TSTRING& strBuf );
|
||||
// returns the locale-specific representation of the given cardinal number
|
||||
|
||||
/*
|
||||
static TSTRING FormatNumberClassic( int32 i );
|
||||
static int32 FormatNumberClassic( const TSTRING& s );
|
||||
// returns the C-locale representation of the given cardinal number
|
||||
|
||||
static TSTRING FormatNumberAsHex( int32 x );
|
||||
*/
|
||||
// disabled this since nobody's using it
|
||||
// static TSTRING FormatNumberAsHex( int32 x );
|
||||
// locale-independant
|
||||
|
||||
static TSTRING& FormatTime( int64 t, TSTRING& strBuf );
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "core/debug.h"
|
||||
#include "core/error.h"
|
||||
|
||||
//TODO: This test needs more comprehensive validity checks
|
||||
void TestBlockRecordArray()
|
||||
{
|
||||
cDebug d( "TestBlockRecordArray" );
|
||||
|
@ -57,6 +58,12 @@ void TestBlockRecordArray()
|
|||
//
|
||||
cBlockRecordArray ra1( &bf, 0 ); ra1.InitNewBlock();
|
||||
cBlockRecordArray ra2( &bf, 1 ); ra2.InitNewBlock();
|
||||
|
||||
TEST(ra1.IsClassValid());
|
||||
TEST(ra2.IsClassValid());
|
||||
|
||||
TEST(ra1.Initialized());
|
||||
|
||||
//
|
||||
// now, start adding and removing things from the arrays...
|
||||
//
|
||||
|
@ -65,9 +72,13 @@ void TestBlockRecordArray()
|
|||
static const char data3[] = "Here is d a t a 3!";
|
||||
static const char data4[] = "Three cheers for data 4!";
|
||||
ra1.AddItem( (int8*)data1, sizeof(data1), 1 );
|
||||
// TEST(ra1.IsItemValid(1));
|
||||
ra1.AddItem( (int8*)data2, sizeof(data2), 2 );
|
||||
// TEST(ra1.IsItemValid(2));
|
||||
ra1.AddItem( (int8*)data3, sizeof(data3), 3 );
|
||||
// TEST(ra1.IsItemValid(3));
|
||||
ra1.AddItem( (int8*)data4, sizeof(data4), 4 );
|
||||
// TEST(ra1.IsItemValid(4));
|
||||
#ifdef _BLOCKFILE_DEBUG
|
||||
ra1.TraceContents();
|
||||
#endif
|
||||
|
@ -77,6 +88,7 @@ void TestBlockRecordArray()
|
|||
|
||||
// delete item 2...
|
||||
ra1.DeleteItem( 1 );
|
||||
TEST(!ra1.IsItemValid(1));
|
||||
#ifdef _BLOCKFILE_DEBUG
|
||||
ra1.TraceContents();
|
||||
#endif
|
||||
|
@ -84,6 +96,7 @@ void TestBlockRecordArray()
|
|||
// add a new item...
|
||||
static const char data5[] = "fffiiivvveee!";
|
||||
ra1.AddItem( (int8*)data5, sizeof(data5), 5 );
|
||||
// TEST(ra1.IsItemValid(5));
|
||||
#ifdef _BLOCKFILE_DEBUG
|
||||
ra1.TraceContents();
|
||||
#endif
|
||||
|
@ -91,10 +104,12 @@ void TestBlockRecordArray()
|
|||
// delete the second to last and last items to see if we clean up properly...
|
||||
// note that there are four things here at this point.
|
||||
ra1.DeleteItem( 2 );
|
||||
TEST(!ra1.IsItemValid(2));
|
||||
#ifdef _BLOCKFILE_DEBUG
|
||||
ra1.TraceContents();
|
||||
#endif
|
||||
ra1.DeleteItem( 3 );
|
||||
TEST(!ra1.IsItemValid(3));
|
||||
#ifdef _BLOCKFILE_DEBUG
|
||||
ra1.TraceContents();
|
||||
#endif
|
||||
|
@ -114,6 +129,8 @@ void TestBlockRecordArray()
|
|||
ra1.TraceContents();
|
||||
#endif
|
||||
|
||||
TEST(ra1.IsClassValid());
|
||||
|
||||
// Now, we will close the file, reopen it and see if we can read it ok.
|
||||
//
|
||||
bf.Close();
|
||||
|
@ -123,6 +140,9 @@ void TestBlockRecordArray()
|
|||
#ifdef _BLOCKFILE_DEBUG
|
||||
ra3.TraceContents();
|
||||
#endif
|
||||
|
||||
TEST(ra3.Initialized());
|
||||
TEST(ra3.IsClassValid());
|
||||
}
|
||||
|
||||
void RegisterSuite_BlockRecordArray()
|
||||
|
|
|
@ -149,6 +149,7 @@ void TestGetSymLinkStr()
|
|||
TEST(fd >= 0);
|
||||
close(fd);
|
||||
|
||||
unlink(link.c_str());
|
||||
TEST(0 == symlink(file.c_str(), link.c_str()));
|
||||
|
||||
cMemoryArchive arch(1024*1024);
|
||||
|
|
|
@ -65,23 +65,34 @@ static void PrintFCOTree(const iFCO* pFCO, cDebug d, int depth)
|
|||
}
|
||||
*/
|
||||
|
||||
void TestFCOSpecImpl()
|
||||
void TestFCOSpecImpl1()
|
||||
{
|
||||
cDebug d("TestFCOSpecImpl");
|
||||
cDebug d("TestFCOSpecImpl1");
|
||||
d.TraceDebug("Entering...\n");
|
||||
|
||||
cFSDataSourceIter dataSrc;
|
||||
|
||||
// test AllChildStopPoint fcos...
|
||||
d.TraceDebug("Now testing a spec whose start point is the only thing it maps to (%s)\n", TwTestDir().c_str());
|
||||
cFCOSpecImpl* pSpec2 = new cFCOSpecImpl(TwTestDir(), &dataSrc, new cFCOSpecNoChildren);
|
||||
pSpec2->SetStartPoint(cFCOName(TwTestDir()));
|
||||
dataSrc.SeekToFCO(pSpec2->GetStartPoint(), false);
|
||||
cFCOSpecImpl* pSpec = new cFCOSpecImpl(TwTestDir(), &dataSrc, new cFCOSpecNoChildren);
|
||||
pSpec->SetStartPoint(cFCOName(TwTestDir()));
|
||||
|
||||
dataSrc.SeekToFCO(pSpec->GetStartPoint(), false);
|
||||
iFCO* pFCO = dataSrc.CreateFCO();
|
||||
TEST(pFCO);
|
||||
//PrintFCOTree(pFCO, d, 0);
|
||||
pFCO->Release();
|
||||
|
||||
pSpec->Release();
|
||||
}
|
||||
|
||||
void TestFCOSpecImpl2()
|
||||
{
|
||||
cDebug d("TestFCOSpecImpl2");
|
||||
d.TraceDebug("Entering...\n");
|
||||
|
||||
cFSDataSourceIter dataSrc;
|
||||
|
||||
// create an FSSpec and set up some start and stop points...
|
||||
cFCOSpecStopPointSet* pSet = new cFCOSpecStopPointSet;
|
||||
cFCOSpecImpl* pSpec = new cFCOSpecImpl(_T("Test FSSpec"), &dataSrc, pSet);
|
||||
|
@ -89,13 +100,12 @@ void TestFCOSpecImpl()
|
|||
pSet->Add(cFCOName(_T("/etc/open gl")));
|
||||
pSet->Add(cFCOName(_T("/etc/pclient")));
|
||||
|
||||
// create all the fcos...
|
||||
cFSDataSourceIter dataSrc2;
|
||||
dataSrc2.SeekToFCO(pSpec->GetStartPoint(), false);
|
||||
iFCO* pFCO2 = dataSrc2.CreateFCO();
|
||||
TEST(pFCO2);
|
||||
dataSrc.SeekToFCO(pSpec->GetStartPoint(), false);
|
||||
iFCO* pFCO = dataSrc.CreateFCO();
|
||||
TEST(pFCO);
|
||||
//PrintFCOTree(pFCO, d, 0);
|
||||
pFCO2->Release();
|
||||
|
||||
pFCO->Release();
|
||||
|
||||
// TODO -- test Clone(), copy ctor, operator=
|
||||
|
||||
|
@ -104,5 +114,6 @@ void TestFCOSpecImpl()
|
|||
|
||||
void RegisterSuite_FCOSpecImpl()
|
||||
{
|
||||
RegisterTest("FCOSpecImpl", "Basic", TestFCOSpecImpl);
|
||||
RegisterTest("FCOSpecImpl", "Basic1", TestFCOSpecImpl1);
|
||||
RegisterTest("FCOSpecImpl", "Basic2", TestFCOSpecImpl2);
|
||||
}
|
||||
|
|
|
@ -68,16 +68,6 @@ class AlignMe
|
|||
byte a[sizeof(int64)+ALIGN_SIZE]; // we want to be able to access a int64 at address [ALIGN_SIZE]
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// MAIN TEST FUNCTION
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
void TestPlatform()
|
||||
{
|
||||
TestAlignment();
|
||||
TestSizes();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// TEMPLATIZED UTIL CLASSES IMPLEMENTATIONS
|
||||
/////////////////////////////////////////////////////////
|
||||
|
@ -206,22 +196,25 @@ void TestAlignment()
|
|||
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
|
||||
// work the way we think they do.
|
||||
void TestSizes()
|
||||
{
|
||||
cDebug d("TestSizes");
|
||||
d.TraceError("Fix this!\n");
|
||||
skip("TODO: TestSizes needs work");
|
||||
/*
|
||||
TEST( CanBeRepresentedAs( char(), char() ) );
|
||||
TEST( CanBeRepresentedAs( char(), unsigned char() ) );
|
||||
TEST( CanBeRepresentedAs( unsigned char(), char() ) );
|
||||
TEST( CanBeRepresentedAs( unsigned char(), unsigned char() ) );
|
||||
TEST( CanBeRepresentedAs( signed char(), char() ) );
|
||||
TEST( CanBeRepresentedAs( char(), signed char() ) );
|
||||
TEST( CanBeRepresentedAs( signed char(), signed char() ) );
|
||||
TEST( CanBeRepresentedAs( signed char(), unsigned char() ) );
|
||||
TEST( CanBeRepresentedAs( char(), signed char() ) );
|
||||
*/
|
||||
|
||||
TEST( CanBeRepresentedAs( int8(), int8() ) );
|
||||
TEST( ! CanBeRepresentedAs( int8(), uint8() ) );
|
||||
TEST( ! CanBeRepresentedAs( uint8(), int8() ) );
|
||||
TEST( CanBeRepresentedAs( uint8(), uint8() ) );
|
||||
|
||||
TEST( CanBeRepresentedAs( int8(), int16() ) );
|
||||
TEST( CanBeRepresentedAs( int16(), int32() ) );
|
||||
TEST( CanBeRepresentedAs( int32(), int64() ) );
|
||||
|
||||
TEST( CanBeRepresentedAs( uint8(), uint16() ) );
|
||||
TEST( CanBeRepresentedAs( uint16(), uint32() ) );
|
||||
TEST( CanBeRepresentedAs( uint32(), uint64() ) );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
|
|
@ -42,10 +42,7 @@
|
|||
#define __STRINGUTIL_T_H
|
||||
|
||||
#include "core/ntmbs.h"
|
||||
|
||||
#if USING_NTDBS_STUFF
|
||||
#include "core/ntdbs.h"
|
||||
#endif // USING_NTDBS_STUFF
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Char traits for WCHAR16 (aka dbchar_t) and NTMBCS (mctype_t)
|
||||
|
@ -54,7 +51,6 @@
|
|||
inline
|
||||
void TestStringUtil()
|
||||
{
|
||||
#if USING_NTDBS_STUFF
|
||||
cDebug db("Test std::char_traits<dbchar_t>");
|
||||
|
||||
db.TraceAlways("Entering...\n");
|
||||
|
@ -63,12 +59,10 @@ void TestStringUtil()
|
|||
tss::dbstring b;
|
||||
std::string c; // Control String
|
||||
|
||||
//#if !IS_UNIX // need to get the L"" stuff working
|
||||
|
||||
static char NTMBS1[] = { 65, 66, 67, 68, 0 };
|
||||
static dbchar_t NTDBS1[] = { 65, 66, 67, 68, 0 };
|
||||
static dbchar_t NTDBS2[] = { 40, 66, 67, 68, 0 };
|
||||
static dbchar_t NTDBS0[] = { 65, 66, 67, 68, 0, 0 };
|
||||
// static dbchar_t NTDBS0[] = { 65, 66, 67, 68, 0, 0 };
|
||||
|
||||
c.assign( NTMBS1 );
|
||||
a.assign( NTDBS1 );
|
||||
|
@ -126,7 +120,6 @@ void TestStringUtil()
|
|||
tss::dbstring x( NTDBS1 );
|
||||
tss::dbstring ref = x;
|
||||
|
||||
TEST( x.c_str() == ref.c_str() );
|
||||
TEST( x == ref );
|
||||
TEST( std::equal( x.begin(), x.end(), ref.begin() ) );
|
||||
TEST( x.size() == ref.size() );
|
||||
|
@ -167,9 +160,6 @@ 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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,21 +55,7 @@ void TestHex();
|
|||
TEST( false ); \
|
||||
} catch( error& ) {}
|
||||
|
||||
void TestTWLocale()
|
||||
{
|
||||
skip("TWLocale tests are ifdef'd out, need to revisit them");
|
||||
|
||||
#ifdef DOESNTWORK
|
||||
TestHex();
|
||||
TestAtoi();
|
||||
TestItoa();
|
||||
TestFlags();
|
||||
TestRoundtrip();
|
||||
#endif//NOTDONE
|
||||
}
|
||||
|
||||
#ifdef DOESNTWORK
|
||||
|
||||
/* We don't do atoi stuff in cTWLocale anymore
|
||||
void TestAtoi()
|
||||
{
|
||||
//
|
||||
|
@ -81,24 +67,25 @@ void TestAtoi()
|
|||
//
|
||||
// Try formatting with our default locale
|
||||
//
|
||||
cTWLocale::InitGlobalLocale();
|
||||
n = cTWLocale::FormatNumber( str );
|
||||
TWLocale::InitGlobalLocale();
|
||||
n = cTWLocale::FormatNumberClassic( str );
|
||||
TEST( n == 123456 );
|
||||
|
||||
//
|
||||
// Try formatting with "" locale
|
||||
//
|
||||
std::locale::global( std::locale("") );
|
||||
n = cTWLocale::FormatNumber( str );
|
||||
n = cTWLocale::FormatNumberClassic( str );
|
||||
TEST( n == 123456 );
|
||||
|
||||
//
|
||||
// Try formatting with "C" locale
|
||||
//
|
||||
std::locale::global( std::locale("") );
|
||||
n = cTWLocale::FormatNumber( str );
|
||||
n = cTWLocale::FormatNumberClassic( str );
|
||||
TEST( n == 123456 );
|
||||
}
|
||||
*/
|
||||
|
||||
void TestItoa()
|
||||
{
|
||||
|
@ -118,23 +105,24 @@ void TestItoa()
|
|||
//
|
||||
cTWLocale::InitGlobalLocale();
|
||||
cTWLocale::FormatNumber( n, str );
|
||||
TCOUT << str << std::endl;
|
||||
TEST( str == "123456" );
|
||||
|
||||
//
|
||||
// Try formatting with "" locale
|
||||
//
|
||||
std::locale::global( std::locale("") );
|
||||
cTWLocale::FormatNumber( n, str );
|
||||
TCOUT << str << std::endl;
|
||||
TEST( str == "123,456" );
|
||||
|
||||
//
|
||||
// Try formatting with "C" locale
|
||||
//
|
||||
std::locale::global( std::locale("") );
|
||||
cTWLocale::FormatNumber( n, str );
|
||||
TCOUT << str << std::endl;
|
||||
TEST( str == "123,456" );
|
||||
}
|
||||
|
||||
/* We don't do atoi stuff in cTWLocale anymore, so no roundtrip
|
||||
void TestRoundtrip()
|
||||
{
|
||||
//
|
||||
|
@ -147,10 +135,10 @@ void TestRoundtrip()
|
|||
//
|
||||
TSTRING strIn = _T("123456");
|
||||
TSTRING strOut;
|
||||
strOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( strIn ), strOut );
|
||||
strOut = cTWLocale::FormatNumber( cTWLocale::FormatNumberClassic( strIn ), strOut );
|
||||
// don't know if string will be the same due to possible changes in formatting from locale
|
||||
// ASSERT( strOut == strIn ); <---- can't do this ^^^
|
||||
TEST( 123456 == cTWLocale::FormatNumber( strOut ) );
|
||||
TEST( 123456 == cTWLocale::FormatNumberClassic( strOut ) );
|
||||
|
||||
|
||||
//
|
||||
|
@ -158,13 +146,15 @@ void TestRoundtrip()
|
|||
//
|
||||
int32 nIn = 654321;
|
||||
int32 nOut;
|
||||
nOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( nIn, strIn ) );
|
||||
nOut = cTWLocale::FormatNumberClassic( cTWLocale::FormatNumber( nIn, strIn ) );
|
||||
TEST( nOut == nIn );
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void TestFlags()
|
||||
{
|
||||
skip("Modernize & re-enable this");
|
||||
#if 0
|
||||
//
|
||||
// init
|
||||
//
|
||||
|
@ -207,29 +197,35 @@ void TestFlags()
|
|||
// try bad oct
|
||||
//
|
||||
ASSERT_THAT_IT_THROWS( cTWLocale::FormatNumber( _T("99"), std::ios_base::oct ), eError );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void doTestHex(const uint32 value, const std::string& expected, const std::string& expected2 = "")
|
||||
{
|
||||
TSTRING str = cTWLocale::FormatNumberAsHex( value );
|
||||
TCERR << "STR = " << str << " | Expected = " << expected << " | Expected2 = " << expected2 << std::endl;
|
||||
TEST( str == expected || (!expected2.empty() && str == expected2) );
|
||||
}
|
||||
|
||||
void TestHex()
|
||||
{
|
||||
TSTRING str;
|
||||
|
||||
str = cTWLocale::FormatNumberAsHex( 0x1234 );
|
||||
TEST( str == _T("1234") );
|
||||
|
||||
str = cTWLocale::FormatNumberAsHex( 16 );
|
||||
TEST( str == _T("10") );
|
||||
|
||||
str = cTWLocale::FormatNumberAsHex( 0x12344321 );
|
||||
TEST( str == _T("12344321") );
|
||||
|
||||
str = cTWLocale::FormatNumberAsHex( 0xFFFFFFFF );
|
||||
TEST( str == _T("FFFFFFFF") || str == _T("ffffffff") );
|
||||
doTestHex( 0x1234, _T("1234") );
|
||||
doTestHex( 16, _T("10") );
|
||||
doTestHex( 0x12344321, _T("12344321") );
|
||||
doTestHex( 0xFFFFFFFF, _T("FFFFFFFF"), _T("ffffffff"));
|
||||
}
|
||||
#endif//DOESNTWORK
|
||||
*/
|
||||
|
||||
void RegisterSuite_TWLocale()
|
||||
{
|
||||
RegisterTest("TWLocale", "Basic", TestTWLocale);
|
||||
// RegisterTest("TWLocale", "Hex", TestHex);
|
||||
// RegisterTest("TWLocale", "Atoi", TestAtoi);
|
||||
RegisterTest("TWLocale", "Itoa", TestItoa);
|
||||
RegisterTest("TWLocale", "Flags", TestFlags);
|
||||
// RegisterTest("TWLocale", "Roundtrip", TestRoundtrip);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue