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:
Brian Cox 2017-09-08 16:31:36 -07:00
parent f05b85726e
commit b648b2493f
8 changed files with 103 additions and 88 deletions

View File

@ -104,6 +104,7 @@ void cTWLocale::InitGlobalLocale()
} }
/*
TSTRING cTWLocale::FormatNumberAsHex( int32 i ) TSTRING cTWLocale::FormatNumberAsHex( int32 i )
{ {
// //
@ -125,6 +126,7 @@ TSTRING cTWLocale::FormatNumberAsHex( int32 i )
// //
return( sstr.str() ); return( sstr.str() );
} }
*/
template< class numT, class CharT > template< class numT, class CharT >
class cFormatNumberUtil class cFormatNumberUtil
@ -190,6 +192,7 @@ public:
} }
}; };
/*
TSTRING cTWLocale::FormatNumberClassic( int32 i ) TSTRING cTWLocale::FormatNumberClassic( int32 i )
{ {
TSTRING s; TSTRING s;
@ -200,7 +203,7 @@ int32 cTWLocale::FormatNumberClassic( const TSTRING& s )
{ {
return cFormatNumberUtil< long, TCHAR >::Format( s, true ); return cFormatNumberUtil< long, TCHAR >::Format( s, true );
} }
*/
TSTRING& cTWLocale::FormatNumber( uint64 ui, TSTRING& strBuf ) TSTRING& cTWLocale::FormatNumber( uint64 ui, TSTRING& strBuf )
{ {

View File

@ -79,12 +79,13 @@ public:
static TSTRING& FormatNumber( uint64 ui, TSTRING& strBuf ); static TSTRING& FormatNumber( uint64 ui, TSTRING& strBuf );
static TSTRING& FormatNumber( double d, TSTRING& strBuf ); static TSTRING& FormatNumber( double d, TSTRING& strBuf );
// returns the locale-specific representation of the given cardinal number // returns the locale-specific representation of the given cardinal number
/*
static TSTRING FormatNumberClassic( int32 i ); static TSTRING FormatNumberClassic( int32 i );
static int32 FormatNumberClassic( const TSTRING& s ); static int32 FormatNumberClassic( const TSTRING& s );
// returns the C-locale representation of the given cardinal number // 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 // locale-independant
static TSTRING& FormatTime( int64 t, TSTRING& strBuf ); static TSTRING& FormatTime( int64 t, TSTRING& strBuf );

View File

@ -37,6 +37,7 @@
#include "core/debug.h" #include "core/debug.h"
#include "core/error.h" #include "core/error.h"
//TODO: This test needs more comprehensive validity checks
void TestBlockRecordArray() void TestBlockRecordArray()
{ {
cDebug d( "TestBlockRecordArray" ); cDebug d( "TestBlockRecordArray" );
@ -57,6 +58,12 @@ void TestBlockRecordArray()
// //
cBlockRecordArray ra1( &bf, 0 ); ra1.InitNewBlock(); cBlockRecordArray ra1( &bf, 0 ); ra1.InitNewBlock();
cBlockRecordArray ra2( &bf, 1 ); ra2.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... // 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 data3[] = "Here is d a t a 3!";
static const char data4[] = "Three cheers for data 4!"; static const char data4[] = "Three cheers for data 4!";
ra1.AddItem( (int8*)data1, sizeof(data1), 1 ); ra1.AddItem( (int8*)data1, sizeof(data1), 1 );
// TEST(ra1.IsItemValid(1));
ra1.AddItem( (int8*)data2, sizeof(data2), 2 ); ra1.AddItem( (int8*)data2, sizeof(data2), 2 );
// TEST(ra1.IsItemValid(2));
ra1.AddItem( (int8*)data3, sizeof(data3), 3 ); ra1.AddItem( (int8*)data3, sizeof(data3), 3 );
// TEST(ra1.IsItemValid(3));
ra1.AddItem( (int8*)data4, sizeof(data4), 4 ); ra1.AddItem( (int8*)data4, sizeof(data4), 4 );
// TEST(ra1.IsItemValid(4));
#ifdef _BLOCKFILE_DEBUG #ifdef _BLOCKFILE_DEBUG
ra1.TraceContents(); ra1.TraceContents();
#endif #endif
@ -77,6 +88,7 @@ void TestBlockRecordArray()
// delete item 2... // delete item 2...
ra1.DeleteItem( 1 ); ra1.DeleteItem( 1 );
TEST(!ra1.IsItemValid(1));
#ifdef _BLOCKFILE_DEBUG #ifdef _BLOCKFILE_DEBUG
ra1.TraceContents(); ra1.TraceContents();
#endif #endif
@ -84,6 +96,7 @@ void TestBlockRecordArray()
// add a new item... // add a new item...
static const char data5[] = "fffiiivvveee!"; static const char data5[] = "fffiiivvveee!";
ra1.AddItem( (int8*)data5, sizeof(data5), 5 ); ra1.AddItem( (int8*)data5, sizeof(data5), 5 );
// TEST(ra1.IsItemValid(5));
#ifdef _BLOCKFILE_DEBUG #ifdef _BLOCKFILE_DEBUG
ra1.TraceContents(); ra1.TraceContents();
#endif #endif
@ -91,10 +104,12 @@ void TestBlockRecordArray()
// delete the second to last and last items to see if we clean up properly... // 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. // note that there are four things here at this point.
ra1.DeleteItem( 2 ); ra1.DeleteItem( 2 );
TEST(!ra1.IsItemValid(2));
#ifdef _BLOCKFILE_DEBUG #ifdef _BLOCKFILE_DEBUG
ra1.TraceContents(); ra1.TraceContents();
#endif #endif
ra1.DeleteItem( 3 ); ra1.DeleteItem( 3 );
TEST(!ra1.IsItemValid(3));
#ifdef _BLOCKFILE_DEBUG #ifdef _BLOCKFILE_DEBUG
ra1.TraceContents(); ra1.TraceContents();
#endif #endif
@ -114,6 +129,8 @@ void TestBlockRecordArray()
ra1.TraceContents(); ra1.TraceContents();
#endif #endif
TEST(ra1.IsClassValid());
// Now, we will close the file, reopen it and see if we can read it ok. // Now, we will close the file, reopen it and see if we can read it ok.
// //
bf.Close(); bf.Close();
@ -123,6 +140,9 @@ void TestBlockRecordArray()
#ifdef _BLOCKFILE_DEBUG #ifdef _BLOCKFILE_DEBUG
ra3.TraceContents(); ra3.TraceContents();
#endif #endif
TEST(ra3.Initialized());
TEST(ra3.IsClassValid());
} }
void RegisterSuite_BlockRecordArray() void RegisterSuite_BlockRecordArray()

View File

@ -149,6 +149,7 @@ void TestGetSymLinkStr()
TEST(fd >= 0); TEST(fd >= 0);
close(fd); close(fd);
unlink(link.c_str());
TEST(0 == symlink(file.c_str(), link.c_str())); TEST(0 == symlink(file.c_str(), link.c_str()));
cMemoryArchive arch(1024*1024); cMemoryArchive arch(1024*1024);

View File

@ -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"); d.TraceDebug("Entering...\n");
cFSDataSourceIter dataSrc; cFSDataSourceIter dataSrc;
// test AllChildStopPoint fcos... // test AllChildStopPoint fcos...
d.TraceDebug("Now testing a spec whose start point is the only thing it maps to (%s)\n", TwTestDir().c_str()); 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); cFCOSpecImpl* pSpec = new cFCOSpecImpl(TwTestDir(), &dataSrc, new cFCOSpecNoChildren);
pSpec2->SetStartPoint(cFCOName(TwTestDir())); pSpec->SetStartPoint(cFCOName(TwTestDir()));
dataSrc.SeekToFCO(pSpec2->GetStartPoint(), false);
dataSrc.SeekToFCO(pSpec->GetStartPoint(), false);
iFCO* pFCO = dataSrc.CreateFCO(); iFCO* pFCO = dataSrc.CreateFCO();
TEST(pFCO); TEST(pFCO);
//PrintFCOTree(pFCO, d, 0); //PrintFCOTree(pFCO, d, 0);
pFCO->Release(); 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... // create an FSSpec and set up some start and stop points...
cFCOSpecStopPointSet* pSet = new cFCOSpecStopPointSet; cFCOSpecStopPointSet* pSet = new cFCOSpecStopPointSet;
cFCOSpecImpl* pSpec = new cFCOSpecImpl(_T("Test FSSpec"), &dataSrc, pSet); 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/open gl")));
pSet->Add(cFCOName(_T("/etc/pclient"))); pSet->Add(cFCOName(_T("/etc/pclient")));
// create all the fcos... dataSrc.SeekToFCO(pSpec->GetStartPoint(), false);
cFSDataSourceIter dataSrc2; iFCO* pFCO = dataSrc.CreateFCO();
dataSrc2.SeekToFCO(pSpec->GetStartPoint(), false); TEST(pFCO);
iFCO* pFCO2 = dataSrc2.CreateFCO();
TEST(pFCO2);
//PrintFCOTree(pFCO, d, 0); //PrintFCOTree(pFCO, d, 0);
pFCO2->Release();
pFCO->Release();
// TODO -- test Clone(), copy ctor, operator= // TODO -- test Clone(), copy ctor, operator=
@ -104,5 +114,6 @@ void TestFCOSpecImpl()
void RegisterSuite_FCOSpecImpl() void RegisterSuite_FCOSpecImpl()
{ {
RegisterTest("FCOSpecImpl", "Basic", TestFCOSpecImpl); RegisterTest("FCOSpecImpl", "Basic1", TestFCOSpecImpl1);
RegisterTest("FCOSpecImpl", "Basic2", TestFCOSpecImpl2);
} }

View File

@ -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] 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 // 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. 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() void TestSizes()
{ {
cDebug d("TestSizes"); cDebug d("TestSizes");
d.TraceError("Fix this!\n"); d.TraceError("Fix this!\n");
skip("TODO: TestSizes needs work");
/* TEST( CanBeRepresentedAs( int8(), int8() ) );
TEST( CanBeRepresentedAs( char(), char() ) ); TEST( ! CanBeRepresentedAs( int8(), uint8() ) );
TEST( CanBeRepresentedAs( char(), unsigned char() ) ); TEST( ! CanBeRepresentedAs( uint8(), int8() ) );
TEST( CanBeRepresentedAs( unsigned char(), char() ) ); TEST( CanBeRepresentedAs( uint8(), uint8() ) );
TEST( CanBeRepresentedAs( unsigned char(), unsigned char() ) );
TEST( CanBeRepresentedAs( signed char(), char() ) ); TEST( CanBeRepresentedAs( int8(), int16() ) );
TEST( CanBeRepresentedAs( char(), signed char() ) ); TEST( CanBeRepresentedAs( int16(), int32() ) );
TEST( CanBeRepresentedAs( signed char(), signed char() ) ); TEST( CanBeRepresentedAs( int32(), int64() ) );
TEST( CanBeRepresentedAs( signed char(), unsigned char() ) );
TEST( CanBeRepresentedAs( char(), signed char() ) ); TEST( CanBeRepresentedAs( uint8(), uint16() ) );
*/ TEST( CanBeRepresentedAs( uint16(), uint32() ) );
TEST( CanBeRepresentedAs( uint32(), uint64() ) );
} }
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////

View File

@ -42,10 +42,7 @@
#define __STRINGUTIL_T_H #define __STRINGUTIL_T_H
#include "core/ntmbs.h" #include "core/ntmbs.h"
#if USING_NTDBS_STUFF
#include "core/ntdbs.h" #include "core/ntdbs.h"
#endif // USING_NTDBS_STUFF
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Char traits for WCHAR16 (aka dbchar_t) and NTMBCS (mctype_t) // Char traits for WCHAR16 (aka dbchar_t) and NTMBCS (mctype_t)
@ -54,7 +51,6 @@
inline inline
void TestStringUtil() void TestStringUtil()
{ {
#if USING_NTDBS_STUFF
cDebug db("Test std::char_traits<dbchar_t>"); cDebug db("Test std::char_traits<dbchar_t>");
db.TraceAlways("Entering...\n"); db.TraceAlways("Entering...\n");
@ -63,12 +59,10 @@ void TestStringUtil()
tss::dbstring b; tss::dbstring b;
std::string c; // Control String std::string c; // Control String
//#if !IS_UNIX // need to get the L"" stuff working
static char NTMBS1[] = { 65, 66, 67, 68, 0 }; static char NTMBS1[] = { 65, 66, 67, 68, 0 };
static dbchar_t NTDBS1[] = { 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 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 ); c.assign( NTMBS1 );
a.assign( NTDBS1 ); a.assign( NTDBS1 );
@ -126,7 +120,6 @@ void TestStringUtil()
tss::dbstring x( NTDBS1 ); tss::dbstring x( NTDBS1 );
tss::dbstring ref = x; tss::dbstring ref = x;
TEST( x.c_str() == ref.c_str() );
TEST( x == ref ); TEST( x == ref );
TEST( std::equal( x.begin(), x.end(), ref.begin() ) ); TEST( std::equal( x.begin(), x.end(), ref.begin() ) );
TEST( x.size() == ref.size() ); TEST( x.size() == ref.size() );
@ -167,9 +160,6 @@ void TestStringUtil()
TEST(tStr.length() == 9); TEST(tStr.length() == 9);
db.TraceAlways("Done...\n"); db.TraceAlways("Done...\n");
#else
skip("Implement this for non-DBS, i.e. most everywhere.");
#endif // USING_NTDBS_STUFF
} }

View File

@ -55,21 +55,7 @@ void TestHex();
TEST( false ); \ TEST( false ); \
} catch( error& ) {} } catch( error& ) {}
void TestTWLocale() /* We don't do atoi stuff in cTWLocale anymore
{
skip("TWLocale tests are ifdef'd out, need to revisit them");
#ifdef DOESNTWORK
TestHex();
TestAtoi();
TestItoa();
TestFlags();
TestRoundtrip();
#endif//NOTDONE
}
#ifdef DOESNTWORK
void TestAtoi() void TestAtoi()
{ {
// //
@ -81,24 +67,25 @@ void TestAtoi()
// //
// Try formatting with our default locale // Try formatting with our default locale
// //
cTWLocale::InitGlobalLocale(); TWLocale::InitGlobalLocale();
n = cTWLocale::FormatNumber( str ); n = cTWLocale::FormatNumberClassic( str );
TEST( n == 123456 ); TEST( n == 123456 );
// //
// Try formatting with "" locale // Try formatting with "" locale
// //
std::locale::global( std::locale("") ); std::locale::global( std::locale("") );
n = cTWLocale::FormatNumber( str ); n = cTWLocale::FormatNumberClassic( str );
TEST( n == 123456 ); TEST( n == 123456 );
// //
// Try formatting with "C" locale // Try formatting with "C" locale
// //
std::locale::global( std::locale("") ); std::locale::global( std::locale("") );
n = cTWLocale::FormatNumber( str ); n = cTWLocale::FormatNumberClassic( str );
TEST( n == 123456 ); TEST( n == 123456 );
} }
*/
void TestItoa() void TestItoa()
{ {
@ -118,23 +105,24 @@ void TestItoa()
// //
cTWLocale::InitGlobalLocale(); cTWLocale::InitGlobalLocale();
cTWLocale::FormatNumber( n, str ); cTWLocale::FormatNumber( n, str );
TCOUT << str << std::endl; TEST( str == "123456" );
// //
// Try formatting with "" locale // Try formatting with "" locale
// //
std::locale::global( std::locale("") ); std::locale::global( std::locale("") );
cTWLocale::FormatNumber( n, str ); cTWLocale::FormatNumber( n, str );
TCOUT << str << std::endl; TEST( str == "123,456" );
// //
// Try formatting with "C" locale // Try formatting with "C" locale
// //
std::locale::global( std::locale("") ); std::locale::global( std::locale("") );
cTWLocale::FormatNumber( n, str ); 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() void TestRoundtrip()
{ {
// //
@ -147,10 +135,10 @@ void TestRoundtrip()
// //
TSTRING strIn = _T("123456"); TSTRING strIn = _T("123456");
TSTRING strOut; 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 // don't know if string will be the same due to possible changes in formatting from locale
// ASSERT( strOut == strIn ); <---- can't do this ^^^ // 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 nIn = 654321;
int32 nOut; int32 nOut;
nOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( nIn, strIn ) ); nOut = cTWLocale::FormatNumberClassic( cTWLocale::FormatNumber( nIn, strIn ) );
TEST( nOut == nIn ); TEST( nOut == nIn );
} }
*/
void TestFlags() void TestFlags()
{ {
skip("Modernize & re-enable this");
#if 0
// //
// init // init
// //
@ -207,29 +197,35 @@ void TestFlags()
// try bad oct // try bad oct
// //
ASSERT_THAT_IT_THROWS( cTWLocale::FormatNumber( _T("99"), std::ios_base::oct ), eError ); 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() void TestHex()
{ {
TSTRING str; TSTRING str;
str = cTWLocale::FormatNumberAsHex( 0x1234 ); doTestHex( 0x1234, _T("1234") );
TEST( str == _T("1234") ); doTestHex( 16, _T("10") );
doTestHex( 0x12344321, _T("12344321") );
str = cTWLocale::FormatNumberAsHex( 16 ); doTestHex( 0xFFFFFFFF, _T("FFFFFFFF"), _T("ffffffff"));
TEST( str == _T("10") );
str = cTWLocale::FormatNumberAsHex( 0x12344321 );
TEST( str == _T("12344321") );
str = cTWLocale::FormatNumberAsHex( 0xFFFFFFFF );
TEST( str == _T("FFFFFFFF") || str == _T("ffffffff") );
} }
#endif//DOESNTWORK */
void RegisterSuite_TWLocale() 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);
} }