Merge branch 'dev/2435' of https://github.com/Tripwire/tripwire-open-source into dev/2435

This commit is contained in:
Brian Cox 2017-03-31 14:34:10 -07:00
commit a0d04d89ad
31 changed files with 506 additions and 471 deletions

View File

@ -1,3 +1,11 @@
2017-03-30 Brian Cox <bcox@tripwire.com>
* Bump version to 2.4.3.5
* Fix install-strip, check, uninstall, and distcheck make targets.
* Fix GCC 7.0.x warnings; use std::unique_ptr instead of deprecated std::auto_ptr where available.
* Add --disable-extrawarnings configure option, for old compilers that dont support the -Wextra compile option.
* Clean up unit tests & enable disabled tests.
* Address more static analyzer warnings, including from CppCheck & Flawfinder
2017-03-05 Brian Cox <bcox@tripwire.com> 2017-03-05 Brian Cox <bcox@tripwire.com>
* Bump version to 2.4.3.4 * Bump version to 2.4.3.4
* Fix issue with printing level 2 reports, introduced by fixing a Clang static analyzer quibble in 2.4.3.3. Sigh. * Fix issue with printing level 2 reports, introduced by fixing a Clang static analyzer quibble in 2.4.3.3. Sigh.

View File

@ -1,4 +1,14 @@
What's new in Open Source Tripwire 2.4.3.2: What's new in Open Source Tripwire 2.4.3.x:
* Useful install-strip, check, uninstall & distcheck make targets as of OST 2.4.3.5. Check target invokes both the test-harness framework and twtest unit tests.
* Verify OST builds without errors w/ GCC 7.0.x; fix new warnings from the new compiler, including deprecation warnings; use std::unique_ptr instead of std::auto_ptr where available.
* Add --disable-extrawarnings configure option, for old compilers that dont support the -Wextra compile option.
* Clean up unit tests, enable various disabled tests, make results more useful.
* Additional cleanup due to static analysis tool results (CppCheck, Flawfinder, Clang analyzer).
* OST now includes optional iconv support when configured with --enable-iconv. * OST now includes optional iconv support when configured with --enable-iconv.
When enabled, binary database & report files store paths as UTF-16, making these files more When enabled, binary database & report files store paths as UTF-16, making these files more
@ -29,11 +39,6 @@ specifying a build directory outside the source dir now works as expected.
* Assorted platform tweaks: Add DOS/FreeDOS + DJGPP as a new platform; support Cygwin * Assorted platform tweaks: Add DOS/FreeDOS + DJGPP as a new platform; support Cygwin
//host/share/path syntax for UNC paths; passphrase & tempfile fixes for AROS. //host/share/path syntax for UNC paths; passphrase & tempfile fixes for AROS.
======================================
What was new in earlier 2.4.3 versions:
* This update fixes compilation errors on modern compilers (GCC 4.7+ and LLVM/clang), * This update fixes compilation errors on modern compilers (GCC 4.7+ and LLVM/clang),
as well as some additional errors encountered on various platforms. This is intended as well as some additional errors encountered on various platforms. This is intended
to supersede patches against 2.4.2.x, e.g. http://www.linuxfromscratch.org/blfs/view/svn/postlfs/tripwire.html to supersede patches against 2.4.2.x, e.g. http://www.linuxfromscratch.org/blfs/view/svn/postlfs/tripwire.html
@ -66,15 +71,22 @@ defined incorrectly otherwise.
The update has been tested on a variety of platforms: The update has been tested on a variety of platforms:
Linuxes Linuxes
- CentOS 7 (amd64) + gcc 4.8.5
- Ubuntu 14.0.4 (amd64) + gcc 4.x
- RHEL 3.4 (Itanium) + gcc 3.4.3
- Alpine Linux 3.3.3 + gcc 5.3.0 - Alpine Linux 3.3.3 + gcc 5.3.0
- Android 6.0 (arm) + gcc 4.9 - Alpine Linux 3.5.1 + gcc 6.2.1
- Raspbian 7 (wheezy) (armv6l) + gcc 4.6.3 - Arch Linux 232 + gcc 6.3.1
- openSuSE Tumbleweed (20160408) (i586) + gcc 5.3.1 - Amazon Linux AMI 2016.09 + gcc 4.8.3
- RHEL 6.0 (powerpc64) + gcc 4.4.4 - Android 6.0 (arm) + gcc 4.9 (NDK)
- CentOS 7 (amd64) + gcc 4.8.5
- Fedora 24 Alpha 7 (amd64) + gcc 6.0.0 - Fedora 24 Alpha 7 (amd64) + gcc 6.0.0
- Fedora 27 Rawhide (amd64) + gcc 7.0.1
- Raspbian 7 (wheezy) (armv6l) + gcc 4.6.3
- RHEL 3.4 (Itanium) + gcc 3.4.3
- RHEL 6.0 (powerpc64) + gcc 4.4.4
- openSuSE Tumbleweed (20160408) (i586) + gcc 5.3.1
- Oracle Linux 6.8 + gcc 4.4.7
- Ubuntu 14.0.4 (amd64) + gcc 4.x
- Ubuntu 16.0.4 (amd64) + gcc 5.4.0
- Wind River Pulsar Linux 8 + gcc 5.2.0
OSX OSX
- Mac OS X 10.11 + LLVM 7.0.2 / clang-700.1.81 - Mac OS X 10.11 + LLVM 7.0.2 / clang-700.1.81
@ -90,7 +102,7 @@ BSDs
UNIXes UNIXes
- Solaris 10 SPARC + gcc 3.4.6 - Solaris 10 SPARC + gcc 3.4.6
- Solaris 10 x86 + gcc 3.4.3 - Solaris 10 x86 + gcc 3.4.3
- OpenIndiana 151 + gcc 4.8.5 [an OpenSolaris/illumos distro] - OpenIndiana 151 + gcc 4.8.5
- AIX 5.2 + gcc 4.3.1 - AIX 5.2 + gcc 4.3.1
- HP-UX 11.23 + gcc 4.2.3 - HP-UX 11.23 + gcc 4.2.3

7
configure vendored
View File

@ -3462,13 +3462,6 @@ fi
ac_config_headers="$ac_config_headers config.h" ac_config_headers="$ac_config_headers config.h"
rm -f src/tripwire/syslog.h 2> /dev/null
chmod 755 install-sh 2> /dev/null
CFLAGS=${CFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} CFLAGS=${CFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"}
CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"} CXXFLAGS=${CXXFLAGS:-"-O -pipe -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"}

View File

@ -11,12 +11,6 @@ AM_CONFIG_HEADER(config.h)
AC_COPYRIGHT([The developer of the original code and/or files is Tripwire, Inc. Portions created by Tripwire, Inc. are copyright 2000-2017 Tripwire, Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights reserved.]) AC_COPYRIGHT([The developer of the original code and/or files is Tripwire, Inc. Portions created by Tripwire, Inc. are copyright 2000-2017 Tripwire, Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights reserved.])
AC_REVISION([$Revision: 2.4.3.5 $]) AC_REVISION([$Revision: 2.4.3.5 $])
dnl #################################
dnl Cleanup Cruft Leftover From Patch
dnl #################################
rm -f src/tripwire/syslog.h 2> /dev/null
chmod 755 install-sh 2> /dev/null
dnl ############### dnl ###############
dnl Setup defaults dnl Setup defaults
dnl ############### dnl ###############

View File

@ -17,7 +17,7 @@
## from Larry Wall's metaconfig. ## from Larry Wall's metaconfig.
##------------------------------------------------------- ##-------------------------------------------------------
PATH='.:/bin:/usr/bin' PATH=".:/bin:/usr/bin:/usr/local/bin:$PATH"
export PATH || (echo 'You must use sh to run this script'; kill $$) export PATH || (echo 'You must use sh to run this script'; kill $$)
if [ ! -t 0 ] ; then if [ ! -t 0 ] ; then
echo "Say 'sh install.sh', not 'sh < install.sh'" echo "Say 'sh install.sh', not 'sh < install.sh'"
@ -42,18 +42,6 @@ else
c="" c=""
fi fi
##-------------------------------------------------------
## Better have a copy of tar!
## If /bin/sh does not exist or is not readable (seems
## fairly unlikely), then this will fail.
##-------------------------------------------------------
(tar cvf /dev/null /bin/sh) 2> /dev/null 1>&2
if [ $? -ne 0 ]; then
echo "tar command not found -- aborting install."
exit 1
fi
##------------------------------------------------------- ##-------------------------------------------------------
## Can't live without sed. ## Can't live without sed.
##------------------------------------------------------- ##-------------------------------------------------------
@ -78,52 +66,24 @@ for p in $awknames; do
fi fi
done done
##-------------------------------------------------------
## Does this system have a copy of grep we can use?
## Some greps don't return status (amazing, huh?),
## so we look for a copy of grep that
## returns 0 status for an exact match
## returns 0 status for a case-insensitive match
## returns 0 status for a wildcard match
## returns non-zero status for a failed match
##-------------------------------------------------------
GREP=""
grepnames="grep egrep"
lcgrepstr="findensiemich" # all lower case
mcgrepstr="FindenSieMich" # mixed case
wcgrepstr="sie.ich$" # wild card match
nogrepstr="WoBistDu" # should not be able to find this
for p in $grepnames; do
(echo "$lcgrepstr" | $p "$lcgrepstr") 2> /dev/null 1>&2
if [ $? -eq 0 ]; then
(echo "$lcgrepstr" | $p -i "$mcgrepstr") 2> /dev/null 1>&2
if [ $? -eq 0 ]; then
(echo "$lcgrepstr" | $p "$wcgrepstr") 2> /dev/null 1>&2
if [ $? -eq 0 ]; then
(echo "$lcgrepstr" | $p "$nogrepstr") 2> /dev/null 1>&2
if [ $? -ne 0 ]; then
GREP=$p
break
fi
fi
fi
fi
done
##------------------------------------------------------- ##-------------------------------------------------------
## Does this system have a pager that we can use? ## Does this system have a pager that we can use?
## Use cat if desperate. ## Use cat if desperate.
##------------------------------------------------------- ##-------------------------------------------------------
MORE="cat" MORE="cat"
morenames="more less cat" morenames="less more most pg cat"
for p in $morenames; do for p in $morenames; do
($p $0 < /dev/null) 2> /dev/null 1>&2 pagerpath=`command -v $p`
if [ $? -eq 0 ]; then
MORE=$p if [ -z $pagerpath ]; then
break continue
fi fi
if [ -x $pagerpath ]; then
MORE=$pagerpath
break
fi
done done
##------------------------------------------------------- ##-------------------------------------------------------
@ -416,15 +376,21 @@ else
##------------------------------------------------------- ##-------------------------------------------------------
## Verify that the specified editor program exists ## Verify that the specified editor program exists
##------------------------------------------------------- ##-------------------------------------------------------
TWEDITOR=${TWEDITOR:-'/bin/vi'} DEFAULTEDITOR=${EDITOR:-/bin/vi}
TWEDITOR=${TWEDITOR:-$DEFAULTEDITOR}
TWEDITOR_PATH=`command -v $TWEDITOR`
if [ -n ${TWEDITOR_PATH} ]; then
TWEDITOR=$TWEDITOR_PATH
fi
if [ -x ${TWEDITOR} ]; then if [ -x ${TWEDITOR} ]; then
echo "${TWEDITOR} exists. Continuing installation." echo "${TWEDITOR} exists. Continuing installation."
echo echo
else else
echo "${TWEDITOR} does not exist. Exiting." echo "${TWEDITOR} not found. Continuing, but your configuration may need to be edited after installation."
exit 1 echo
fi fi
##------------------------------------------------------- ##-------------------------------------------------------
@ -927,7 +893,7 @@ cat << END_OF_TEXT
---------------------------------------------- ----------------------------------------------
The installation succeeded. The installation succeeded.
Please refer to $README_LOC Please refer to documentation in $TWDOCS
for release information and to the printed user documentation for release information and to the printed user documentation
for further instructions on using Tripwire 2.4 Open Source. for further instructions on using Tripwire 2.4 Open Source.

View File

@ -403,7 +403,6 @@ char *env;
* just include it from the current environment * just include it from the current environment
* (if not defined there, don't define it here) * (if not defined there, don't define it here)
*/ */
size_t p_size=0;
if (strchr(env, '=') == NULL) { if (strchr(env, '=') == NULL) {
q = getenv(env); q = getenv(env);

View File

@ -144,7 +144,7 @@
#define OS OS_OPENBSD #define OS OS_OPENBSD
#define IS_OPENBSD 1 #define IS_OPENBSD 1
#elif defined(_OSX) #elif defined(__APPLE__)
#define OS OS_DARWIN #define OS OS_DARWIN
#define IS_DARWIN 1 #define IS_DARWIN 1
@ -157,7 +157,7 @@
#define IS_MIDNIGHTBSD 1 #define IS_MIDNIGHTBSD 1
#elif defined(_SOLARIS) || defined(__sun) #elif defined(__sun)
#define OS OS_SOLARIS #define OS OS_SOLARIS
#define IS_SOLARIS 1 #define IS_SOLARIS 1
@ -165,11 +165,11 @@
#define OS OS_AIX #define OS OS_AIX
#define IS_AIX 1 #define IS_AIX 1
#elif defined (_HPUX) #elif defined (__hpux)
#define OS OS_HPUX #define OS OS_HPUX
#define IS_HPUX 1 #define IS_HPUX 1
#elif defined(_IRIX) #elif defined(__sgi)
#define OS OS_IRIX #define OS OS_IRIX
#define IS_IRIX 1 #define IS_IRIX 1

View File

@ -43,7 +43,7 @@ void TestBlockFile()
try try
{ {
static const TCHAR fileName[] = _T("c:/tmp/test.bf"); static const TCHAR fileName[] = _T("test.bf");
// truncate the file I am going to use... // truncate the file I am going to use...
// //
cFileArchive a; cFileArchive a;
@ -113,6 +113,7 @@ void TestBlockFile()
} }
catch( eError& e ) catch( eError& e )
{ {
TCERR << "Exception: " << e.GetMsg() << std::endl;
d.TraceError( _T("Exception caught: %d %s\n"), e.GetID(), e.GetMsg().c_str() ); d.TraceError( _T("Exception caught: %d %s\n"), e.GetID(), e.GetMsg().c_str() );
TEST( false ); TEST( false );
} }

View File

@ -42,7 +42,7 @@ void TestBlockRecordArray()
cDebug d( "TestBlockRecordArray" ); cDebug d( "TestBlockRecordArray" );
try try
{ {
static const TCHAR fileName[] = _T("c:/tmp/test.bf"); static const TCHAR fileName[] = _T("test.bf");
cBlockFile bf; cBlockFile bf;
bf.Open( fileName, 2, true ); // opened up with two pages bf.Open( fileName, 2, true ); // opened up with two pages

View File

@ -88,6 +88,7 @@ const TCHAR* argv5[] =
_T("frog") _T("frog")
}; };
#ifdef _DEBUG
static void PrintCmdLine(int argc, const TCHAR** argv, cDebug d) static void PrintCmdLine(int argc, const TCHAR** argv, cDebug d)
{ {
TSTRING str; TSTRING str;
@ -99,6 +100,7 @@ static void PrintCmdLine(int argc, const TCHAR** argv, cDebug d)
} }
d.TraceDebug(_T(">>>%s\n"), str.c_str()); d.TraceDebug(_T(">>>%s\n"), str.c_str());
} }
#endif
static void test_parse(cCmdLineParser& parser, const int argc, const TCHAR** argv, bool should_throw) static void test_parse(cCmdLineParser& parser, const int argc, const TCHAR** argv, bool should_throw)
{ {

View File

@ -142,7 +142,7 @@ size_t DistanceToOne( size_t n )
n = ( n >> 1 ); n = ( n >> 1 );
} }
ASSERT( n == 1 ); // n was not a power of 2! TEST( n == 1 ); // n was not a power of 2!
return dist; return dist;
} }
@ -159,14 +159,14 @@ void ConvertAndCompareString( const std::string& s )
wc16_string ws; wc16_string ws;
ws.resize( s.length() ); ws.resize( s.length() );
nWrote = iCodeConverter::GetInstance()->Convert( (ntdbs_t)ws.c_str(), ws.length(), s.c_str(), ws.length() ); nWrote = iCodeConverter::GetInstance()->Convert( (ntdbs_t)ws.c_str(), ws.length(), s.c_str(), ws.length() );
ASSERT( nWrote != -1 ); TEST( nWrote != -1 );
ws.resize( nWrote ); ws.resize( nWrote );
// convert back to mbchar_t string // convert back to mbchar_t string
std::string s2; std::string s2;
s2.resize( ws.length() * MB_CUR_MAX ); s2.resize( ws.length() * MB_CUR_MAX );
nWrote = iCodeConverter::GetInstance()->Convert( (ntmbs_t)s2.c_str(), s2.length(), ws.c_str(), ws.length() ); nWrote = iCodeConverter::GetInstance()->Convert( (ntmbs_t)s2.c_str(), s2.length(), ws.c_str(), ws.length() );
ASSERT( nWrote != -1 ); TEST( nWrote != -1 );
s2.resize( nWrote ); s2.resize( nWrote );
std::cout << "* Result : "; std::cout << "* Result : ";
@ -195,10 +195,10 @@ void TestMbToDb()
for( size_t j = 0; j < 0x10; j++ ) for( size_t j = 0; j < 0x10; j++ )
{ {
size_t first_byte = ( i & 0xFF00 ) >> 8; size_t first_byte = ( i & 0xFF00 ) >> 8;
ASSERT( first_byte <= 0xFF ); TEST( first_byte <= 0xFF );
size_t second_byte = ( ( i & 0x00F0 ) >> 4 ) | j; size_t second_byte = ( ( i & 0x00F0 ) >> 4 ) | j;
ASSERT( second_byte <= 0xFF ); TEST( second_byte <= 0xFF );
s[ 2 * j ] = NonZeroChar( (char)first_byte ); s[ 2 * j ] = NonZeroChar( (char)first_byte );
s[ ( 2 * j ) + 1 ] = NonZeroChar( (char)second_byte ); s[ ( 2 * j ) + 1 ] = NonZeroChar( (char)second_byte );
@ -221,10 +221,10 @@ void TestMbToDb()
for( size_t j = 0; j < CHARS_AT_A_TIME; j++ ) for( size_t j = 0; j < CHARS_AT_A_TIME; j++ )
{ {
size_t first_byte = ( ( i & FIRST_BYTE_MASK ) >> DistanceToOne( CHARS_AT_A_TIME ) ); size_t first_byte = ( ( i & FIRST_BYTE_MASK ) >> DistanceToOne( CHARS_AT_A_TIME ) );
ASSERT( first_byte <= 0xFF ); TEST( first_byte <= 0xFF );
size_t second_byte = ( ( i & ( SECOND_BYTE_MASK << DistanceToOne( CHARS_AT_A_TIME ) ) | j ); size_t second_byte = ( ( i & ( SECOND_BYTE_MASK << DistanceToOne( CHARS_AT_A_TIME ) ) | j );
ASSERT( second_byte <= 0xFF ); TEST( second_byte <= 0xFF );
s[ 2 * j ] = NonZeroChar( (char)first_byte ); s[ 2 * j ] = NonZeroChar( (char)first_byte );
s[ ( 2 * j ) + 1 ] = NonZeroChar( (char)second_byte ); s[ ( 2 * j ) + 1 ] = NonZeroChar( (char)second_byte );

View File

@ -128,11 +128,11 @@ void TestCrypto()
cRSAPublicKey* pPublic2; cRSAPublicKey* pPublic2;
cRSAPrivateKey* pPrivate2; cRSAPrivateKey* pPrivate2;
ASSERT(pPublic->GetWriteLen() < BUFSIZE); TEST(pPublic->GetWriteLen() < BUFSIZE);
pPublic->Write(buf); pPublic->Write(buf);
pPublic2 = new cRSAPublicKey(buf); pPublic2 = new cRSAPublicKey(buf);
ASSERT(pPrivate->GetWriteLen() < BUFSIZE); TEST(pPrivate->GetWriteLen() < BUFSIZE);
pPrivate->Write(buf); pPrivate->Write(buf);
pPrivate2 = new cRSAPrivateKey(buf); pPrivate2 = new cRSAPrivateKey(buf);
@ -298,11 +298,11 @@ void TestCrypto()
cElGamalSigPublicKey* pPublic2; cElGamalSigPublicKey* pPublic2;
cElGamalSigPrivateKey* pPrivate2; cElGamalSigPrivateKey* pPrivate2;
ASSERT(pPublic->GetWriteLen() < BUFSIZE); TEST(pPublic->GetWriteLen() < BUFSIZE);
pPublic->Write(buf); pPublic->Write(buf);
pPublic2 = new cElGamalSigPublicKey(buf); pPublic2 = new cElGamalSigPublicKey(buf);
ASSERT(pPrivate->GetWriteLen() < BUFSIZE); TEST(pPrivate->GetWriteLen() < BUFSIZE);
pPrivate->Write(buf); pPrivate->Write(buf);
pPrivate2 = new cElGamalSigPrivateKey(buf); pPrivate2 = new cElGamalSigPrivateKey(buf);

View File

@ -75,7 +75,7 @@ static void util_TestUnprintable( const TSTRING& strCUnprintable )
TSTRING strOut = strEncoded; TSTRING strOut = strEncoded;
e.Decode( strOut ); e.Decode( strOut );
ASSERT( strOut == strCUnprintable ); TEST( strOut == strCUnprintable );
} }
@ -186,8 +186,8 @@ void TestUnconvertable()
ch = 0x ## n; \ ch = 0x ## n; \
str = ch; \ str = ch; \
e.Encode( str ); \ e.Encode( str ); \
// ct.tolower( str.begin(), str.end() ); \ ct.tolower( str.begin(), str.end() ); \
ASSERT( str == _T("\\x") _T( #n ) _T("x") ); TEST( str == _T("\\x") _T( #n ) _T("x") );
TSS_UNCONVERTABLE_TEST( fefe ); TSS_UNCONVERTABLE_TEST( fefe );
TSS_UNCONVERTABLE_TEST( 1234 ); TSS_UNCONVERTABLE_TEST( 1234 );
@ -215,8 +215,8 @@ void TestUnprintable()
ch = 0x ## n; \ ch = 0x ## n; \
str = ch; \ str = ch; \
e.Encode( str ); \ e.Encode( str ); \
// ct.tolower( str.begin(), str.end() ); \ ct.tolower( str.begin(), str.end() ); \
ASSERT( str == _T("\\x") _T( #n ) _T("x") ); TEST( str == _T("\\x") _T( #n ) _T("x") );
TSS_UNPRINTABLE_TEST( 000a ); TSS_UNPRINTABLE_TEST( 000a );
TSS_UNPRINTABLE_TEST( 000d ); TSS_UNPRINTABLE_TEST( 000d );
@ -233,11 +233,11 @@ void TestQuoteAndBackSlash()
str = _T("\\"); str = _T("\\");
e.Encode( str ); e.Encode( str );
ASSERT( str == _T("\\\\") ); TEST( str == _T("\\\\") );
str = _T("\""); str = _T("\"");
e.Encode( str ); e.Encode( str );
ASSERT( str == _T("\\\"") ); TEST( str == _T("\\\"") );
} }
// TODO:BAM -- try multibyte now..... // TODO:BAM -- try multibyte now.....
@ -325,7 +325,7 @@ void TestDisplayEncoderBasic()
catch( eError& e ) catch( eError& e )
{ {
cErrorReporter::PrintErrorMsg( e ); cErrorReporter::PrintErrorMsg( e );
ASSERT(false); TEST(false);
} }
} }

View File

@ -125,7 +125,7 @@ void TestFCOCompare()
cFSDataSourceIter ds2; cFSDataSourceIter ds2;
ds2.SeekToFCO(cFCOName(FILE_NAME), false); ds2.SeekToFCO(cFCOName(FILE_NAME), false);
iFCO* pFCO2 = ds2.CreateFCO(); iFCO* pFCO2 = ds2.CreateFCO();
ASSERT(pFCO2); TEST(pFCO2);
pFCO2->AcceptVisitor(&propCalc); pFCO2->AcceptVisitor(&propCalc);
d.TraceDebug("Second FCO's properties:\n"); d.TraceDebug("Second FCO's properties:\n");
PrintProps(pFCO2); PrintProps(pFCO2);

View File

@ -35,5 +35,5 @@
void TestFCODatabaseFile() void TestFCODatabaseFile()
{ {
//TODO - actually test something here
} }

View File

@ -114,6 +114,8 @@ static bool init (cFCOPropVector &testV)
return true; return true;
} //end init } //end init
#if 0 // TODO: rework this so it doesn't need user interaction
static bool addRemove (cFCOPropVector &test1, cFCOPropVector &test2, cDebug& d) static bool addRemove (cFCOPropVector &test1, cFCOPropVector &test2, cDebug& d)
{ {
int var1 = 0 , var2 = 64, var3 = 2; int var1 = 0 , var2 = 64, var3 = 2;
@ -191,6 +193,7 @@ static bool addRemove (cFCOPropVector &test1, cFCOPropVector &test2, cDebug& d)
out &= local; //and-ing of results. out &= local; //and-ing of results.
return out; return out;
}//end addRemove }//end addRemove
#endif
static bool objManip (cFCOPropVector &testV, cDebug& d) static bool objManip (cFCOPropVector &testV, cDebug& d)
{ {

View File

@ -42,6 +42,7 @@
#include "core/errorbucketimpl.h" #include "core/errorbucketimpl.h"
#include "fco/fcospecattr.h" #include "fco/fcospecattr.h"
#include "fco/fcospechelper.h" #include "fco/fcospechelper.h"
#include "fs/fs.h"
#include <ctime> #include <ctime>
// we use this instead of TraceContents() so we can test the report iterators. // we use this instead of TraceContents() so we can test the report iterators.
@ -62,7 +63,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d)
for(specIter.SeekBegin(); ! specIter.Done(); specIter.Next(), ++specCount) for(specIter.SeekBegin(); ! specIter.Done(); specIter.Next(), ++specCount)
{ {
d.TraceDebug(">>> Spec [%d]:\n", specCount); d.TraceDebug(">>> Spec [%d]:\n", specCount);
ASSERT(specIter.GetSpec()); TEST(specIter.GetSpec());
specIter.GetSpec()->TraceContents(); specIter.GetSpec()->TraceContents();
specIter.GetAttr()->TraceContents(); specIter.GetAttr()->TraceContents();
specIter.GetErrorQueue()->TraceContents(); specIter.GetErrorQueue()->TraceContents();
@ -88,86 +89,97 @@ static void TraceReport(const cFCOReport& r, cDebug& d)
} }
} }
//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws
void TestFCOReport() void TestFCOReport()
{ {
cDebug d("TestFCOReport"); cDebug d("TestFCOReport");
try
cFCOSpecImpl* pSpec = new cFCOSpecImpl(_T("/etc"), NULL, new cFCOSpecStopPointSet);
cFCOSpecAttr* pAttr = new cFCOSpecAttr;
cFSObject* addedFCO = new cFSObject(cFCOName(_T("/etc/added_file")));
cFSObject* removedFCO = new cFSObject(cFCOName(_T("/etc/removed_file")));
cFSObject* changedFCO = new cFSObject(cFCOName(_T("/etc/changed_file")));
cFSObject* oldChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file")));
cFSObject* newChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file")));
cFCOPropVector changedPropVector;
//Calculate the time taken to generate the test report:
time_t* dummy_arg = NULL;
time_t time_finish;
//time_t time_begin = time(dummy_arg);
{ {
cFCOReport report; cFCOSpecImpl* pSpec = new cFCOSpecImpl(_T("/etc"), NULL, new cFCOSpecStopPointSet);
cFCOSpecAttr* pAttr = new cFCOSpecAttr;
cFSObject* addedFCO = new cFSObject(cFCOName(_T("/etc/added_file")));
cFSObject* removedFCO = new cFSObject(cFCOName(_T("/etc/removed_file")));
cFSObject* changedFCO = new cFSObject(cFCOName(_T("/etc/changed_file")));
cFSObject* oldChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file")));
cFSObject* newChangedFCO = new cFSObject(cFCOName(_T("/etc/changed_file")));
cFCOPropVector changedPropVector;
changedPropVector.AddItem(cFSPropSet::PROP_SIZE); //Calculate the time taken to generate the test report:
pSpec->SetStartPoint(cFCOName(_T("/etc"))); time_t* dummy_arg = NULL;
pAttr->SetName(_T("/etc")); time_t time_finish;
pAttr->SetSeverity(53); //time_t time_begin = time(dummy_arg);
report.AddSpec(0x00020001, pSpec, pAttr); // TODO:bam - change these
cFCOReportSpecIter it(report, 0x00020001); // to use cFS::Genre
it.GetAddedSet()->Insert(addedFCO);
it.GetRemovedSet()->Insert(removedFCO);
report.AddChangedFCO(it, oldChangedFCO, newChangedFCO, changedPropVector);
//Store the time taken to generate the test report:
time_finish = time(dummy_arg);
//report.SetCreationTime( (int64)difftime(time_finish, time_begin));
//d.TraceDebug("Report calculation time = %I64i seconds.\n", report.GetCreationTime());
d.TraceDebug("Before serializing report:\n");
TraceReport(report, d);
{ {
cFileArchive outFile; cFCOReport report;
outFile.OpenReadWrite(_T("tmp.twr"));
cSerializerImpl outSer(outFile, cSerializerImpl::S_WRITE);
outSer.Init(); changedPropVector.AddItem(cFSPropSet::PROP_SIZE);
outSer.WriteObject(&report); pSpec->SetStartPoint(cFCOName(_T("/etc")));
outSer.Finit(); pAttr->SetName(_T("/etc"));
pAttr->SetSeverity(53);
outFile.Close(); report.AddSpec(cFS::GenreID(), pSpec, pAttr);
cFCOReportSpecIter it(report, cFS::GenreID());
it.GetAddedSet()->Insert(addedFCO);
it.GetRemovedSet()->Insert(removedFCO);
report.AddChangedFCO(it, oldChangedFCO, newChangedFCO, changedPropVector);
cFileArchive inFile; //Store the time taken to generate the test report:
inFile.OpenRead(_T("tmp.twr")); time_finish = time(dummy_arg);
cSerializerImpl inSer(inFile, cSerializerImpl::S_READ); //report.SetCreationTime( (int64)difftime(time_finish, time_begin));
//d.TraceDebug("Report calculation time = %I64i seconds.\n", report.GetCreationTime());
cFCOReport inReport; d.TraceDebug("Before serializing report:\n");
TraceReport(report, d);
{
cFileArchive outFile;
outFile.OpenReadWrite(_T("tmp.twr"));
cSerializerImpl outSer(outFile, cSerializerImpl::S_WRITE);
inSer.Init(); outSer.Init();
inSer.ReadObject(&inReport); outSer.WriteObject(&report);
inSer.Finit(); outSer.Finit();
d.TraceDebug("Read in serialized report:\n"); outFile.Close();
TraceReport(inReport, d);
cFileArchive inFile;
inFile.OpenRead(_T("tmp.twr"));
cSerializerImpl inSer(inFile, cSerializerImpl::S_READ);
cFCOReport inReport;
inSer.Init();
inSer.ReadObject(&inReport);
inSer.Finit();
d.TraceDebug("Read in serialized report:\n");
TraceReport(inReport, d);
}
} }
// TODO -- test cFCOReportSpecIter::Remove()
// TODO -- test cFCOReportChangeIter::Remove()
d.TraceDebug("*** We still need to test Remove() for the two iterator classes!\n");
pSpec->Release();
pAttr->Release();
addedFCO->Release();
removedFCO->Release();
changedFCO->Release();
oldChangedFCO->Release();
newChangedFCO->Release();
} }
catch(const eError& e)
// TODO -- test cFCOReportSpecIter::Remove() {
// TODO -- test cFCOReportChangeIter::Remove() TCERR << std::endl << e.GetMsg() << std::endl;
d.TraceDebug("*** We still need to test Remove() for the two iterator classes!\n"); TEST(false);
}
pSpec->Release(); catch(...)
pAttr->Release(); {
addedFCO->Release(); TEST(false);
removedFCO->Release(); }
changedFCO->Release();
oldChangedFCO->Release();
newChangedFCO->Release();
d.TraceDebug("Leaving...\n"); d.TraceDebug("Leaving...\n");
return;
} }

View File

@ -36,6 +36,7 @@
#include "twtest/test.h" #include "twtest/test.h"
#include "core/archive.h" #include "core/archive.h"
#include "core/serializerimpl.h" #include "core/serializerimpl.h"
#include "twtest/test.h"
static void TraceSpecAttr(const cFCOSpecAttr* pAttr, cDebug d) static void TraceSpecAttr(const cFCOSpecAttr* pAttr, cDebug d)
{ {
@ -50,39 +51,52 @@ static void TraceSpecAttr(const cFCOSpecAttr* pAttr, cDebug d)
} }
} }
//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws
void TestFCOSpecAttr() void TestFCOSpecAttr()
{ {
cDebug d("TestFCOSpecAttr"); cDebug d("TestFCOSpecAttr");
d.TraceDebug("Entering\n");
cFCOSpecAttr* pAttr = new cFCOSpecAttr; try
{
d.TraceDebug("Entering\n");
cFCOSpecAttr* pAttr = new cFCOSpecAttr;
pAttr->SetName (_T("My Name")); d.TraceDebug("Setting Name = My Name\n"); pAttr->SetName (_T("My Name")); d.TraceDebug("Setting Name = My Name\n");
pAttr->SetSeverity (53); d.TraceDebug("Setting Severity = 53\n"); pAttr->SetSeverity (53); d.TraceDebug("Setting Severity = 53\n");
pAttr->AddEmail (_T("dog@bark.com")); d.TraceDebug("Adding email = dog@bark.com\n"); pAttr->AddEmail (_T("dog@bark.com")); d.TraceDebug("Adding email = dog@bark.com\n");
pAttr->AddEmail (_T("cow@moo.com")); d.TraceDebug("Adding email = cow@moo.com\n"); pAttr->AddEmail (_T("cow@moo.com")); d.TraceDebug("Adding email = cow@moo.com\n");
pAttr->AddEmail (_T("cat@meow.com")); d.TraceDebug("Adding email = cat@meow.com\n"); pAttr->AddEmail (_T("cat@meow.com")); d.TraceDebug("Adding email = cat@meow.com\n");
// trace contents... // trace contents...
TraceSpecAttr(pAttr, d); TraceSpecAttr(pAttr, d);
// test serialization... // test serialization...
d.TraceDebug("Testing Serialization; next output should be the same as the previous\n"); d.TraceDebug("Testing Serialization; next output should be the same as the previous\n");
cMemoryArchive a; cMemoryArchive a;
cSerializerImpl s(a, cSerializerImpl::S_WRITE); cSerializerImpl s(a, cSerializerImpl::S_WRITE);
s.Init(); s.Init();
pAttr->Write(&s); pAttr->Write(&s);
s.Finit(); s.Finit();
a.Seek(0, cBidirArchive::BEGINNING); a.Seek(0, cBidirArchive::BEGINNING);
cFCOSpecAttr* pNew = new cFCOSpecAttr; cFCOSpecAttr* pNew = new cFCOSpecAttr;
cSerializerImpl s2(a, cSerializerImpl::S_READ); cSerializerImpl s2(a, cSerializerImpl::S_READ);
s2.Init(); s2.Init();
pNew->Read(&s2); pNew->Read(&s2);
s2.Finit(); s2.Finit();
// trace contents... // trace contents...
TraceSpecAttr(pNew, d); TraceSpecAttr(pNew, d);
pNew->Release(); pNew->Release();
pAttr->Release(); pAttr->Release();
}
catch(const eError& e)
{
TCERR << std::endl << e.GetMsg() << std::endl;
TEST(false);
}
catch(...)
{
TEST(false);
}
} }

View File

@ -37,44 +37,57 @@
#include "twtest/test.h" #include "twtest/test.h"
#include <stdio.h> #include <stdio.h>
//TODO: This doesn't actually TEST() anything right now, & will only fail if something throws
void TestFile() void TestFile()
{ {
try
{
TSTRING fileName = TEMP_DIR;
fileName += _T("/file_test.bin");
TSTRING fileName = TEMP_DIR; //Create a temporary file for testing:
fileName += _T("/file_test.bin"); FILE* testStream;
testStream = _tfopen( fileName.c_str(), _T("w+b"));
TEST(testStream);
TSTRING testString( _T("This is a test") );
int iTestStringLength = testString.length();
//Create a temporary file for testing: //Write some data to the stream...
FILE* testStream; fwrite( testString.c_str(), sizeof(TCHAR), iTestStringLength, testStream );
testStream = _tfopen( fileName.c_str(), _T("w+b")); fclose( testStream );
TSTRING testString( _T("This is a test") );
int iTestStringLength = testString.length();
//Write some data to the stream... //Open the file again, for reading only this time.
fwrite( testString.c_str(), sizeof(TCHAR), iTestStringLength, testStream ); testStream = _tfopen( fileName.c_str(), _T("rb") );
fclose( testStream ); TEST(testStream);
cFile fTempFile;
//Try attaching one of our file objects to the stream.
//TODO: fTempFile.AttachRead( testStream );
//Open the file again, for reading only this time. //Try reading something from the file object
testStream = _tfopen( fileName.c_str(), _T("rb") ); TCHAR buffer[40];
TCHAR buffer2[40];
cFile fTempFile; fTempFile.Read( buffer, sizeof(TCHAR) * iTestStringLength );
//Try attaching one of our file objects to the stream. fTempFile.Close();
//TODO: fTempFile.AttachRead( testStream );
//Try reading something from the file object testStream = _tfopen( fileName.c_str(), _T("a+b") );
TCHAR buffer[40]; TEST(testStream);
TCHAR buffer2[40]; //TODO: fTempFile.AttachReadWrite( testStream );
fTempFile.Read( buffer, sizeof(TCHAR) * iTestStringLength );
fTempFile.Close();
testStream = _tfopen( fileName.c_str(), _T("a+b") );
//TODO: fTempFile.AttachReadWrite( testStream );
//Now try writing something to the stream.
fTempFile.Write( testString.c_str(), sizeof(TCHAR) * iTestStringLength );
fTempFile.Rewind();
fTempFile.Read( buffer2, sizeof(TCHAR) * iTestStringLength * 2 );
//Now try writing something to the stream.
fTempFile.Write( testString.c_str(), sizeof(TCHAR) * iTestStringLength );
fTempFile.Rewind();
fTempFile.Read( buffer2, sizeof(TCHAR) * iTestStringLength * 2 );
}
catch(const eError& e)
{
TCERR << std::endl << e.GetMsg() << std::endl;
TEST(false);
}
catch(...)
{
TEST(false);
}
} }

View File

@ -91,7 +91,7 @@ void TestFSPropCalc()
// get the fco but none of its children... // get the fco but none of its children...
ds.SeekToFCO(cFCOName(foo_bin), false); ds.SeekToFCO(cFCOName(foo_bin), false);
iFCO* pFCO = ds.CreateFCO(); iFCO* pFCO = ds.CreateFCO();
ASSERT(pFCO); TEST(pFCO);
// create the calculator and set some properties to calculate... // create the calculator and set some properties to calculate...
cFSPropCalc propCalc; cFSPropCalc propCalc;

View File

@ -34,13 +34,14 @@
#include "fco/stdfco.h" #include "fco/stdfco.h"
#include "fco/fcospecimpl.h" #include "fco/fcospecimpl.h"
#include "core/debug.h" #include "core/debug.h"
//#include "fs/fsdatasource.h" #include "fs/fsdatasourceiter.h"
#include "fco/iterproxy.h" #include "fco/iterproxy.h"
#include "core/error.h" #include "core/error.h"
#include "twtest/test.h" #include "twtest/test.h"
#include "fco/fcospechelper.h" #include "fco/fcospechelper.h"
#include "core/fsservices.h" #include "core/fsservices.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// PrintFCOTree -- recursively prints an fco's name and all of it's children's // PrintFCOTree -- recursively prints an fco's name and all of it's children's
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -69,43 +70,35 @@ void TestFCOSpecImpl()
cDebug d("TestFCOSpecImpl"); cDebug d("TestFCOSpecImpl");
d.TraceDebug("Entering...\n"); d.TraceDebug("Entering...\n");
//********************* cFSDataSourceIter dataSrc;
//
// TODO -- As of tripwire 2.1, this needs to be updated!
// 28 Jan 99 mdb
//
//*********************
ASSERT( false );
/*
cFSDataSource dataSrc;
iFSServices* pFSS = iFSServices::GetInstance();
// test AllChildStopPoint fcos... // test AllChildStopPoint fcos...
d.TraceDebug("Now testing a spec whose start point is the only thing it maps to (%s)\n", TEMP_DIR); d.TraceDebug("Now testing a spec whose start point is the only thing it maps to (%s)\n", TEMP_DIR);
cFCOSpecImpl* pSpec2 = new cFCOSpecImpl(TEMP_DIR, &dataSrc, new cFCOSpecNoChildren); cFCOSpecImpl* pSpec2 = new cFCOSpecImpl(TEMP_DIR, &dataSrc, new cFCOSpecNoChildren);
pSpec2->SetStartPoint(cFCOName(TEMP_DIR)); pSpec2->SetStartPoint(cFCOName(TEMP_DIR));
iFCO* pFCO = pSpec2->CreateFCO(pSpec2->GetStartPoint(), iFCODataSource::CHILDREN_ALL); dataSrc.SeekToFCO(pSpec2->GetStartPoint(), false);
PrintFCOTree(pFCO, d, 0); iFCO* pFCO = dataSrc.CreateFCO();
TEST(pFCO);
//PrintFCOTree(pFCO, d, 0);
pFCO->Release(); pFCO->Release();
// 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);
pSpec->SetStartPoint(cFCOName(_T("d:/code"))); pSpec->SetStartPoint(cFCOName(_T("/etc")));
pSet->Add(cFCOName(_T("d:/code/open gl"))); pSet->Add(cFCOName(_T("/etc/open gl")));
pSet->Add(cFCOName(_T("d:/code/pclient"))); pSet->Add(cFCOName(_T("/etc/pclient")));
// create all the fcos... // create all the fcos...
pFCO = pSpec->CreateFCO(pSpec->GetStartPoint(), iFCODataSource::CHILDREN_ALL); cFSDataSourceIter dataSrc2;
ASSERT(pFCO); dataSrc2.SeekToFCO(pSpec->GetStartPoint(), false);
PrintFCOTree(pFCO, d, 0); iFCO* pFCO2 = dataSrc2.CreateFCO();
pFCO->Release(); TEST(pFCO2);
//PrintFCOTree(pFCO, d, 0);
pFCO2->Release();
// TODO -- test Clone(), copy ctor, operator= // TODO -- test Clone(), copy ctor, operator=
pSpec->Release(); pSpec->Release();
return;
*/
} }

View File

@ -36,38 +36,26 @@
#include "fco/stdfco.h" #include "fco/stdfco.h"
#include "fco/genreswitcher.h" #include "fco/genreswitcher.h"
#include "twtest/test.h" #include "twtest/test.h"
#include "fs/fs.h"
#ifdef _CPPRTTI
#include "fs/fsfactory.h" #include "fs/fsfactory.h"
#include "ntfs/ntfsfactory.h"
#endif
void TestGenreSwitcher() void TestGenreSwitcher()
{ {
#pragma message( __FILE__ "(1) : TODO - implement this test file")
#if 0
cDebug d("TestGenreSwitcher"); cDebug d("TestGenreSwitcher");
d.TraceDebug("Entering...\n"); d.TraceDebug("Entering...\n");
// normally we use the cGenreSwitcher::GetInstance() interface cGenreSwitcher* genreSwitcher = cGenreSwitcher::GetInstance();
// to get access the class singleton. But for testing purposes
// we will put have one reside on the stack.
cGenreSwitcher genreSwitcher;
TEST(genreSwitcher.CurrentGenre() == cGenre::GENRE_INVALID); TEST(genreSwitcher->CurrentGenre() == cFS::GenreID());
// can't switch to invalid genre
//genreSwitcher->SelectGenre(cGenre::GENRE_INVALID);
//TEST(genreSwitcher->CurrentGenre() == cGenre::GENRE_INVALID);
genreSwitcher.SelectGenre(cGenre::FS); genreSwitcher->SelectGenre(cFS::GenreID());
TEST(genreSwitcher.CurrentGenre() == cGenre::FS); TEST(genreSwitcher->CurrentGenre() == cFS::GenreID());
#ifdef _CPPRTTI
TEST(typeid(*iTWFactory::GetInstance()) == typeid(cFSFactory)); TEST(typeid(*iTWFactory::GetInstance()) == typeid(cFSFactory));
#endif
genreSwitcher.SelectGenre(cGenre::NTFS);
TEST(genreSwitcher.CurrentGenre() == cGenre::NTFS);
#ifdef _CPPRTTI
TEST(typeid(*iTWFactory::GetInstance()) == typeid(cNTFSFactory));
#endif
d.TraceDebug("All tests passed.\n"); d.TraceDebug("All tests passed.\n");
#endif //#if 0
} }

View File

@ -73,12 +73,15 @@ static void GetNoun( TSTRING& noun )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void TestHierDatabaseInteractive() void TestHierDatabaseInteractive()
{ {
TCERR << std::endl << "TestHierDatabaseInteractive needs to be redesigned (& renamed) to not require user interaction" << std::endl;
#if 0
cDebug d( "TestHierDatabaseInteractive" ); cDebug d( "TestHierDatabaseInteractive" );
try try
{ {
cHierDatabase db; cHierDatabase db;
//db.Open( _T("c:/tmp/tw.hdb"), 5, true); //db.Open( _T("c:/tmp/tw.hdb"), 5, true);
db.Open( _T("c:/tmp/tw.db"), 5, false); db.Open( _T("tw.db"), 5, false);
cHierDatabase::iterator iter(&db); cHierDatabase::iterator iter(&db);
while( true ) while( true )
@ -346,5 +349,5 @@ void TestHierDatabaseInteractive()
d.TraceError( "Exception caught: %d %s\n", e.GetID(), e.GetMsg().c_str() ); d.TraceError( "Exception caught: %d %s\n", e.GetID(), e.GetMsg().c_str() );
TEST( false ); TEST( false );
} }
#endif
} }

View File

@ -70,8 +70,8 @@ void TestKeyFile()
{ {
cElGamalSig elGamal(*keyfile.GetPublicKey()); cElGamalSig elGamal(*keyfile.GetPublicKey());
ASSERT(elGamal.GetBlockSizePlain() < 9000); TEST(elGamal.GetBlockSizePlain() < 9000);
ASSERT(elGamal.GetBlockSizeCipher() < 9000); TEST(elGamal.GetBlockSizeCipher() < 9000);
std::string s = "haybaby"; std::string s = "haybaby";
cPrivateKeyProxy key; cPrivateKeyProxy key;
TEST(key.AquireKey(keyfile, (int8*)s.data(), 7)); TEST(key.AquireKey(keyfile, (int8*)s.data(), 7));

View File

@ -203,15 +203,15 @@ void TestAlignment()
void TestSizes() void TestSizes()
{ {
/* /*
ASSERT( CanBeRepresentedAs( char(), char() ) ); TEST( CanBeRepresentedAs( char(), char() ) );
ASSERT( CanBeRepresentedAs( char(), unsigned char() ) ); TEST( CanBeRepresentedAs( char(), unsigned char() ) );
ASSERT( CanBeRepresentedAs( unsigned char(), char() ) ); TEST( CanBeRepresentedAs( unsigned char(), char() ) );
ASSERT( CanBeRepresentedAs( unsigned char(), unsigned char() ) ); TEST( CanBeRepresentedAs( unsigned char(), unsigned char() ) );
ASSERT( CanBeRepresentedAs( signed char(), char() ) ); TEST( CanBeRepresentedAs( signed char(), char() ) );
ASSERT( CanBeRepresentedAs( char(), signed char() ) ); TEST( CanBeRepresentedAs( char(), signed char() ) );
ASSERT( CanBeRepresentedAs( signed char(), signed char() ) ); TEST( CanBeRepresentedAs( signed char(), signed char() ) );
ASSERT( CanBeRepresentedAs( signed char(), unsigned char() ) ); TEST( CanBeRepresentedAs( signed char(), unsigned char() ) );
ASSERT( CanBeRepresentedAs( char(), signed char() ) ); TEST( CanBeRepresentedAs( char(), signed char() ) );
*/ */
} }

View File

@ -119,7 +119,7 @@ void TestRefCountObj()
db.TraceAlways("Entering...\n"); db.TraceAlways("Entering...\n");
// Note the following test of Reference counted objects containing // Note the following test of Reference counted objects containing
// copies of themselves failed. Perhaps someday we will upgrade the // copies of themselves failed. Perhaps someday we will upgrade the
// reference counting interface to allow this type of structure. // reference counting interface to allow this type of structure.
/* /*
@ -157,11 +157,12 @@ void TestRefCountObj()
} }
} }
//These fields only exist in debug builds, so we can't use TEST() here.
ASSERT(cRefCountObj::objectCounter == 0); ASSERT(cRefCountObj::objectCounter == 0);
ASSERT(cRefCountObj::referenceCounter == 0); ASSERT(cRefCountObj::referenceCounter == 0);
db.TraceAlways("Done...\n"); db.TraceAlways("Done...\n");
return; return;
} }

View File

@ -71,13 +71,11 @@ void TestFCOSpec();
void TestFCOPropVector(); void TestFCOPropVector();
void TestFileHeader(); void TestFileHeader();
void TestFSPropSet(); void TestFSPropSet();
void TestFSDataSource();
void TestFCOSpecImpl(); void TestFCOSpecImpl();
void TestFSPropCalc(); void TestFSPropCalc();
void TestFCOPropImpl(); void TestFCOPropImpl();
void TestFCOCompare(); void TestFCOCompare();
//void TestTripwire(); //void TestTripwire();
void TestFCOSetUtil();
void TestWin32FSServices(); void TestWin32FSServices();
void TestFCOSpecList(); void TestFCOSpecList();
void TestFCOReport(); void TestFCOReport();
@ -88,7 +86,6 @@ void TestRefCountObj();
void TestSignature(); void TestSignature();
void TestSerRefCountObj(); void TestSerRefCountObj();
void TestUnixFSServices(); void TestUnixFSServices();
//void TestFCODatabase();
void TestError(); void TestError();
void TestDebug(); void TestDebug();
void TestFcoSpecUtil(); void TestFcoSpecUtil();
@ -96,7 +93,7 @@ void TestTypes();
void TestTCHAR(); void TestTCHAR();
void TestErrorBucketImpl(); void TestErrorBucketImpl();
void TestHashTable(); void TestHashTable();
//void TestTextReportViewer(); void TestTextReportViewer();
void TestFCONameTbl(); void TestFCONameTbl();
void TestConfigFile(); void TestConfigFile();
@ -108,16 +105,14 @@ void TestCryptoArchive();
void TestFCOSpecAttr(); void TestFCOSpecAttr();
void TestCmdLineParser(); void TestCmdLineParser();
void TestTaskTimer(); void TestTaskTimer();
//void TestObjectPool();
void TestKeyFile(); void TestKeyFile();
void TestFCOSetCached();
void TestTWUtil(); void TestTWUtil();
void TestFSPropDisplayer(); void TestFSPropDisplayer();
void TestFSPropDisplayer(); void TestFSPropDisplayer();
void TestGenre(); void TestGenre();
void TestFSDataSourceIter(); void TestFSDataSourceIter();
void TestGenerateDb(); void TestGenerateDb();
//void TestHierDatabaseInteractive(); void TestHierDatabaseInteractive();
void TestGenreSwitcher(); void TestGenreSwitcher();
void TestDbDataSource(); void TestDbDataSource();
void TestGenreSpecList(); void TestGenreSpecList();
@ -125,12 +120,11 @@ void TestIntegrityCheck();
void TestFCODatabaseFile(); void TestFCODatabaseFile();
void TestWchar16(); void TestWchar16();
void TestStringEncoder(); void TestStringEncoder();
//void TestDisplayEncoder();
void TestGrowHeap(); void TestGrowHeap();
void TestPlatform(); void TestPlatform();
//void TestBlockFile(); void TestBlockFile();
//void TestBlockRecordArray(); void TestBlockRecordArray();
//void TestHierDatabaseInteractive();
void TestTWLocale(); void TestTWLocale();
void TestFileUtil(); void TestFileUtil();
void TestFCONameTranslator(); void TestFCONameTranslator();
@ -158,92 +152,114 @@ void Usage()
_T("(runs test id's 1, 2, 3, and 12)\n\n"); _T("(runs test id's 1, 2, 3, and 12)\n\n");
} }
const int MAX_TEST_ID = 100; const int MAX_TEST_ID = 88;
static int failed_count = 0;
static void Test(int testID) static void Test(int testID)
{ {
switch (testID) TCERR << std::endl << "=== Running test ID #" << testID << " ===" << std::endl;
{
case 1: TestArchive(); break; try {
case 2: TestCmdLineParser(); break;
case 3: TestCrypto(); break; switch (testID)
case 4: TestCryptoArchive(); break; {
case 5: TestDebug(); break; case 1: TestArchive(); break;
case 6: TestError(); break; case 2: TestCmdLineParser(); break;
case 7: TestErrorBucketImpl(); break; case 3: TestCrypto(); break;
case 8: TestFCOCompare(); break; case 4: TestCryptoArchive(); break;
//case 9: TestFCODatabase(); break; case 5: TestDebug(); break;
//case 11: TestFCOErrorQueue(); break; case 6: TestError(); break;
case 12: TestFCOName(); break; case 7: TestErrorBucketImpl(); break;
case 13: TestFCONameTbl(); break; case 8: TestFCOCompare(); break;
case 14: TestFCOPropVector(); break;
case 15: TestFCOPropImpl(); break; case 12: TestFCOName(); break;
case 16: TestFCOReport(); break; case 13: TestFCONameTbl(); break;
//case 17: TestFCOSetCached(); break; case 14: TestFCOPropVector(); break;
case 18: TestFCOSetImpl(); break; case 15: TestFCOPropImpl(); break;
//case 19: TestFCOSetUtil(); break; case 16: TestFCOReport(); break;
case 20: TestFCOSpecAttr(); break;
case 21: TestFCOSpecHelper(); break; case 18: TestFCOSetImpl(); break;
case 22: TestFCOSpecList(); break;
case 23: TestFcoSpecUtil(); break; case 20: TestFCOSpecAttr(); break;
case 24: TestFileHeader(); break; case 21: TestFCOSpecHelper(); break;
//case 25: TestFSDataSource(); break; case 22: TestFCOSpecList(); break;
case 26: TestFSPropSet(); break; case 23: TestFcoSpecUtil(); break;
case 27: TestFSPropCalc(); break; case 24: TestFileHeader(); break;
case 28: TestFCOSpecImpl(); break;
case 29: TestHashTable(); break; case 26: TestFSPropSet(); break;
// case 30: TestObjectPool(); break; case 27: TestFSPropCalc(); break;
case 31: TestRefCountObj(); break; case 28: TestFCOSpecImpl(); break;
case 32: TestSerializerImpl(); break; case 29: TestHashTable(); break;
case 33: TestSerRefCountObj(); break;
case 34: TestSignature(); break; case 31: TestRefCountObj(); break;
case 35: TestTaskTimer(); break; case 32: TestSerializerImpl(); break;
//case 36: TestTripwire(); break; case 33: TestSerRefCountObj(); break;
//case 37: TestTextReportViewer(); break; case 34: TestSignature(); break;
case 39: TestSerRefCountObj(); break; case 35: TestTaskTimer(); break;
case 40: TestError(); break; //case 36: TestTripwire(); break;
//case 41: TestFCODatabase(); break; case 37: TestTextReportViewer(); break;
case 42: TestHashTable(); break; case 39: TestSerRefCountObj(); break;
case 43: TestTCHAR(); break; case 40: TestError(); break;
case 44: TestUnixFSServices(); break; case 41: TestFCODatabaseFile(); break;
case 46: TestConfigFile(); break; case 42: TestHashTable(); break;
case 47: TestPolicyParser(); break; case 43: TestTCHAR(); break;
case 48: TestKeyFile(); break; case 44: TestUnixFSServices(); break;
case 49: TestTWUtil(); break; case 46: TestConfigFile(); break;
case 50: TestFSPropDisplayer(); break; case 47: TestPolicyParser(); break;
case 52: TestGenre(); break; case 48: TestKeyFile(); break;
case 53: TestFSDataSourceIter(); break; case 49: TestTWUtil(); break;
//case 54: TestGenerateDb(); break; case 50: TestFSPropDisplayer(); break;
//case 55: TestHierDatabaseInteractive(); break; case 52: TestGenre(); break;
case 56: TestGenreSwitcher(); break; case 53: TestFSDataSourceIter(); break;
case 57: TestDbDataSource(); break; //case 54: TestGenerateDb(); break;
case 58: TestGenreSpecList(); break; case 55: TestHierDatabaseInteractive(); break;
//case 59: TestIntegrityCheck(); break; case 56: TestGenreSwitcher(); break;
case 65: TestWchar16(); break; case 57: TestDbDataSource(); break;
case 66: TestStringEncoder(); break; case 58: TestGenreSpecList(); break;
//case 67: TestDisplayEncoder(); break; //case 59: TestIntegrityCheck(); break;
case 69: TestGrowHeap(); break;
case 70: TestPlatform(); break; case 65: TestWchar16(); break;
//case 71: TestBlockFile(); break; case 66: TestStringEncoder(); break;
//case 72: TestBlockRecordArray(); break;
//case 73: TestHierDatabaseInteractive(); break; case 69: TestGrowHeap(); break;
case 74: TestFileUtil(); break; case 70: TestPlatform(); break;
case 75: TestTWLocale(); break; case 71: TestBlockFile(); break;
case 76: TestFCONameTranslator(); break; case 72: TestBlockRecordArray(); break;
case 77: TestStringUtil(); break; case 74: TestFileUtil(); break;
case 78: TestCodeConverter(); break; case 75: TestTWLocale(); break;
case 76: TestFCONameTranslator(); break;
case 79: TestCharToHex(); break; case 77: TestStringUtil(); break;
case 80: TestHexToChar(); break; case 78: TestCodeConverter(); break;
case 81: TestStringToHex(); break;
case 82: TestHexToString(); break; case 79: TestCharToHex(); break;
// case 83: TestUnconvertable(); break; case 80: TestHexToChar(); break;
// case 84: TestUnprintable(); break; case 81: TestStringToHex(); break;
case 85: TestQuoteAndBackSlash(); break; case 82: TestHexToString(); break;
case 86: TestDisplayEncoderBasic(); break; // case 83: TestUnconvertable(); break;
case 87: TestCharUtilBasic(); break; // case 84: TestUnprintable(); break;
case 88: TestConfigFile2(); break; case 85: TestQuoteAndBackSlash(); break;
case 86: TestDisplayEncoderBasic(); break;
case 87: TestCharUtilBasic(); break;
case 88: TestConfigFile2(); break;
}
} }
catch (eError& error)
{
cTWUtil::PrintErrorMsg(error);
failed_count++;
}
catch (std::exception& e) {
TCERR << "FAILED: " << e.what() << std::endl;
failed_count++;
}
catch (...) {
TCERR << "FAILED: <unknown>" << std::endl;
failed_count++;
}
TCERR << std::endl << "=== test ID #" << testID << " completed ===" << std::endl;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -336,9 +352,9 @@ int _tmain(int argc, TCHAR** argv)
// force user to hit <CR> // force user to hit <CR>
std::cout << std::endl << "Tests completed" << std::endl; std::cout << std::endl << "Tests completed with " << failed_count << " failures." << std::endl;
return 0; return failed_count ? -1 : 0;
} }

View File

@ -49,6 +49,8 @@
#endif #endif
#include <iostream> #include <iostream>
#include <stdexcept>
using namespace std; using namespace std;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -69,7 +71,7 @@ TSS_EndPackage( cTest )
#define TEST(exp) if (!(exp)) \ #define TEST(exp) if (!(exp)) \
{ \ { \
std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \ std::cerr<<"TEST(" << #exp << ") failure, file " << __FILE__ << " line " << __LINE__ << std::endl; \
exit(-1); \ throw std::runtime_error(#exp); \
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -36,6 +36,7 @@
#include "tw/stdtw.h" #include "tw/stdtw.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include "tw/fcoreport.h" #include "tw/fcoreport.h"
#include "fco/fcospecimpl.h" #include "fco/fcospecimpl.h"
@ -56,7 +57,7 @@
#include "tw/fcoreportutil.h" #include "tw/fcoreportutil.h"
#include "tw/headerinfo.h" #include "tw/headerinfo.h"
#ifdef FIXED_TRV_TEST_SUITE //#ifdef FIXED_TRV_TEST_SUITE
void MakeFile( TSTRING& fcoNameMakeMe ); void MakeFile( TSTRING& fcoNameMakeMe );
void MakeDir( const TCHAR* const lpszDirName ); void MakeDir( const TCHAR* const lpszDirName );
@ -80,7 +81,7 @@ static void TraceReport(const cFCOReport& r, cDebug& d)
for(specIter.SeekBegin(); ! specIter.Done(); specIter.Next(), ct++) for(specIter.SeekBegin(); ! specIter.Done(); specIter.Next(), ct++)
{ {
d.TraceDebug(">>> Spec [%d]:\n", ct); d.TraceDebug(">>> Spec [%d]:\n", ct);
ASSERT(specIter.GetSpec()); TEST(specIter.GetSpec());
specIter.GetSpec()->TraceContents(); specIter.GetSpec()->TraceContents();
specIter.GetErrorQueue()->TraceContents(); specIter.GetErrorQueue()->TraceContents();
@ -105,8 +106,30 @@ static void TraceReport(const cFCOReport& r, cDebug& d)
} }
} }
/*
//
// basic functionality
//
void DisplayReportAndHaveUserUpdateIt( const TSTRING& edName, ReportingLevel level = FULL_REPORT ); //throw (eFSServices, eTextReportViewer, eInternal);
// outputs the given report to a temp file, opens an editor, has
// the user view changes to the database, and, by selecting FCO entries,
// chooses which changes to write to the database. Unchecked entries
// are removed from the report
// edName is the name of the editor to use to update the report
virtual void PrintTextReport( const TSTRING& strFilename, ReportingLevel level = FULL_REPORT ); //throw (eTextReportViewer);
// if strFilename is "-", will print to TCOUT
virtual void PrintTextReport( TOSTREAM& ostr, ReportingLevel level = FULL_REPORT ); //throw (eTextReportViewer);
// prints the report to the specified ostream
*/
void TestTextReportViewer() void TestTextReportViewer()
{ {
TCERR << std::endl << "TestTextReportViewer needs to be cleaned up & fixed, currently disabled" << std::endl;
#if 0
cFCOReport report; cFCOReport report;
cFCOReportGenreIter genreIter(report); cFCOReportGenreIter genreIter(report);
cFCOReportSpecIter specIter(genreIter); cFCOReportSpecIter specIter(genreIter);
@ -119,7 +142,7 @@ void TestTextReportViewer()
try try
{ {
iFSServices* pFSServices = iFSServices::GetInstance(); iFSServices* pFSServices = iFSServices::GetInstance();
ASSERT( pFSServices ); TEST( pFSServices );
TSTRING fcoNameTempDir; TSTRING fcoNameTempDir;
pFSServices->GetTempDirName( fcoNameTempDir ); pFSServices->GetTempDirName( fcoNameTempDir );
@ -127,9 +150,9 @@ void TestTextReportViewer()
fcoNameSpec1 = fcoNameTempDir += _T("SPEC1/"); fcoNameSpec1 = fcoNameTempDir += _T("SPEC1/");
fcoNameSpec2 = fcoNameTempDir += _T("SPEC2/"); fcoNameSpec2 = fcoNameTempDir += _T("SPEC2/");
pFSServices->Mkdir( fcoNameTempDir ); mkdir( fcoNameTempDir.c_str(), 0777 );
pFSServices->Mkdir( fcoNameSpec1.AsString() ); mkdir( fcoNameSpec1.AsString().c_str(), 0777 );
pFSServices->Mkdir( fcoNameSpec2.AsString() ); mkdir( fcoNameSpec2.AsString().c_str(), 0777 );
fcoNameTempFile = fcoNameTempDir += _T("twtempXXXXXX"); fcoNameTempFile = fcoNameTempDir += _T("twtempXXXXXX");
pFSServices->MakeTempFilename( fcoNameTempFile ); pFSServices->MakeTempFilename( fcoNameTempFile );
@ -137,12 +160,12 @@ void TestTextReportViewer()
catch(eFSServices& /* e */) catch(eFSServices& /* e */)
{ {
// TODO: properly handle error // TODO: properly handle error
ASSERT( false ); TEST( false );
} }
// need two prop calcs because..... // need two prop calcs because.....
// if cFSPropCalc::VisitFSObject succeeds, cFSPropCalc stores the FCO in // if cFSPropCalc::VisitFSObject succeeds, cFSPropCalc stores the FCO in
// an internal set (why, I don't know), and the cFCOSet ASSERTs that the same // an internal set (why, I don't know), and the cFCOSet TESTs that the same
// FCO isn't inserted more than once. But since we visit changed FCOs twice // FCO isn't inserted more than once. But since we visit changed FCOs twice
// in this test routine, we need two calcs. Make sense? Oh, well. // in this test routine, we need two calcs. Make sense? Oh, well.
cFSPropCalc* pPropCalc = new cFSPropCalc; cFSPropCalc* pPropCalc = new cFSPropCalc;
@ -153,7 +176,7 @@ void TestTextReportViewer()
cFCOSpecImpl* pSpec = new cFCOSpecImpl( fcoNameSpec1.AsString(), NULL, pStopPts); cFCOSpecImpl* pSpec = new cFCOSpecImpl( fcoNameSpec1.AsString(), NULL, pStopPts);
cFCOSpecAttr* pAttr = new cFCOSpecAttr; cFCOSpecAttr* pAttr = new cFCOSpecAttr;
cFCOPropVector v; cFCOPropVector v;
for( int i = 0; i < 32; i++ ) for( int i = 0; i < 32; i++ )
v.AddItem( i ); v.AddItem( i );
@ -161,7 +184,6 @@ void TestTextReportViewer()
pPropCalc->SetPropVector(v); pPropCalc->SetPropVector(v);
pPropCalc2->SetPropVector(v); pPropCalc2->SetPropVector(v);
TSTRING fcoNameMakeMe; TSTRING fcoNameMakeMe;
fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/added_fileXXXXXX"); fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/added_fileXXXXXX");
MakeFile( fcoNameMakeMe ); MakeFile( fcoNameMakeMe );
@ -172,9 +194,10 @@ void TestTextReportViewer()
// MakeTempFile can't handle strings with escaped quotes, so we'll have to do this ourselves // MakeTempFile can't handle strings with escaped quotes, so we'll have to do this ourselves
fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/\"quoted\\_and_backslashed_file1\""); fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/\"quoted\\_and_backslashed_file1\"");
//TOFSTREAM file1( fcoNameMakeMe.c_str() ); //TOFSTREAM file1( fcoNameMakeMe.c_str() );
//ASSERT( file1 ); //TEST( file1 );
//file1.close(); //file1.close();
cFSObject* addedFCO2 = new cFSObject( cFCOName(fcoNameMakeMe) ); cFSObject* addedFCO2 = new cFSObject( cFCOName(fcoNameMakeMe) );
//pPropCalc->VisitFSObject( *addedFCO2 ); //pPropCalc->VisitFSObject( *addedFCO2 );
@ -182,7 +205,7 @@ void TestTextReportViewer()
// MakeTempFile can't handle strings with escaped quotes, so we'll have to do this ourselves // MakeTempFile can't handle strings with escaped quotes, so we'll have to do this ourselves
fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/quoted_file\"2\"XXXXXX"); fcoNameMakeMe = fcoNameSpec1.AsString() + _T("/quoted_file\"2\"XXXXXX");
//TOFSTREAM file2( fcoNameMakeMe.c_str() ); //TOFSTREAM file2( fcoNameMakeMe.c_str() );
//ASSERT( file2 ); //TEST( file2 );
//file2.close(); //file2.close();
cFSObject* addedFCO3 = new cFSObject( cFCOName(fcoNameMakeMe) ); cFSObject* addedFCO3 = new cFSObject( cFCOName(fcoNameMakeMe) );
@ -199,6 +222,7 @@ void TestTextReportViewer()
MakeFile( fcoNameMakeMe ); MakeFile( fcoNameMakeMe );
cFSObject* removedFCO2 = new cFSObject( cFCOName(fcoNameMakeMe) ); cFSObject* removedFCO2 = new cFSObject( cFCOName(fcoNameMakeMe) );
pPropCalc->VisitFSObject( *removedFCO2 ); pPropCalc->VisitFSObject( *removedFCO2 );
pSpec->SetStartPoint( fcoNameSpec1 ); pSpec->SetStartPoint( fcoNameSpec1 );
pAttr->SetName( fcoNameSpec1.AsString() ); pAttr->SetName( fcoNameSpec1.AsString() );
@ -207,7 +231,9 @@ void TestTextReportViewer()
report.AddSpec(0x00020001, pSpec, pAttr, &specIter); // TODO:bam - use cFS::Genre report.AddSpec(0x00020001, pSpec, pAttr, &specIter); // TODO:bam - use cFS::Genre
pAttr->Release(); pAttr->Release();
TEST(specIter.GetAddedSet());
TEST(specIter.GetRemovedSet());
specIter.GetAddedSet()->Insert(addedFCO); specIter.GetAddedSet()->Insert(addedFCO);
specIter.GetAddedSet()->Insert(addedFCO2); specIter.GetAddedSet()->Insert(addedFCO2);
specIter.GetAddedSet()->Insert(addedFCO3); specIter.GetAddedSet()->Insert(addedFCO3);
@ -234,6 +260,7 @@ void TestTextReportViewer()
changedPropVector1.AddItem(cFSPropSet::PROP_UID); changedPropVector1.AddItem(cFSPropSet::PROP_UID);
report.AddChangedFCO(specIter, oldChangedFCO, newChangedFCO, changedPropVector1); report.AddChangedFCO(specIter, oldChangedFCO, newChangedFCO, changedPropVector1);
// make changed FCO2 // make changed FCO2
cFCOPropVector changedPropVector2; cFCOPropVector changedPropVector2;
@ -280,7 +307,7 @@ void TestTextReportViewer()
specIter.GetAddedSet()->Insert(addedFCO5); specIter.GetAddedSet()->Insert(addedFCO5);
specIter.GetRemovedSet()->Insert(removedFCO5); specIter.GetRemovedSet()->Insert(removedFCO5);
// make changed FCO3 // make changed FCO3
cFCOPropVector changedPropVector3; cFCOPropVector changedPropVector3;
@ -321,14 +348,13 @@ void TestTextReportViewer()
specIter.Next(); specIter.Next();
//specIter.GetErrorQueue()->AddError(2, "this is an \"/etc2\" spec error",NULL); //specIter.GetErrorQueue()->AddError(2, "this is an \"/etc2\" spec error",NULL);
d.TraceDebug(_T("\n======================================================\nStart PrintTextReport...\n======================================================\n\n\n")); d.TraceDebug(_T("\n======================================================\nStart PrintTextReport...\n======================================================\n\n\n"));
TSTRING tstrEmpty( _T("") ); TSTRING tstrEmpty( _T("") );
cFCOReportHeader rhi; cFCOReportHeader rhi;
cFCOReportUtil::FinalizeReport( report ); cFCOReportUtil::FinalizeReport( report );
cTextReportViewer trv; cTextReportViewer trv(rhi, report);
trv.DisplayReportAndHaveUserUpdateIt( rhi, report, _T("") ); trv.DisplayReportAndHaveUserUpdateIt( _T("") );
// test writing of USID // test writing of USID
cFileArchive outFile; cFileArchive outFile;
@ -354,20 +380,20 @@ void TestTextReportViewer()
d.TraceDebug("Read in serialized report:\n"); d.TraceDebug("Read in serialized report:\n");
//TraceReport(inReport, d); //TraceReport(inReport, d);
trv.PrintTextReport( rhi, inReport, TSTRING( TEMP_DIR _T( "/test2.txt" ) ) ); trv.PrintTextReport(TSTRING( TEMP_DIR _T( "/test2.txt" ) ) );
//TODO: this does not work any more //TODO: this does not work any more
//trv.LaunchEditorOnFile( TSTRING( TEMP_DIR _T("/test2.txt") ), _T("") ); //trv.LaunchEditorOnFile( TSTRING( TEMP_DIR _T("/test2.txt") ), _T("") );
// look at results // look at results
trv.PrintTextReport( rhi, report, fcoNameTempFile ); trv.PrintTextReport(fcoNameTempFile );
//TODO: this does not work any more //TODO: this does not work any more
//cTextReportViewer::LaunchEditorOnFile( fcoNameTempFile, _T("") ); //cTextReportViewer::LaunchEditorOnFile( fcoNameTempFile, _T("") );
iFSServices* pFSServices = iFSServices::GetInstance(); iFSServices* pFSServices = iFSServices::GetInstance();
ASSERT( pFSServices ); TEST( pFSServices );
pFSServices->FileDelete( addedFCO->GetName().AsString() ); pFSServices->FileDelete( addedFCO->GetName().AsString() );
pFSServices->FileDelete( addedFCO2->GetName().AsString() ); pFSServices->FileDelete( addedFCO2->GetName().AsString() );
pFSServices->FileDelete( addedFCO3->GetName().AsString() ); pFSServices->FileDelete( addedFCO3->GetName().AsString() );
@ -382,8 +408,8 @@ void TestTextReportViewer()
pFSServices->FileDelete( fcoNameTempFile ); pFSServices->FileDelete( fcoNameTempFile );
// don't remove TEMP_DIR since other people may be using it // don't remove TEMP_DIR since other people may be using it
pFSServices->Rmdir( fcoNameSpec1.AsString() ); rmdir( fcoNameSpec1.AsString().c_str() );
pFSServices->Rmdir( fcoNameSpec2.AsString() ); rmdir( fcoNameSpec2.AsString().c_str() );
pSpec->Release(); pSpec->Release();
pSpec2->Release(); pSpec2->Release();
@ -404,7 +430,8 @@ void TestTextReportViewer()
newChangedFCO3->Release(); newChangedFCO3->Release();
oldChangedFCO4->Release(); oldChangedFCO4->Release();
newChangedFCO4->Release(); newChangedFCO4->Release();
#endif
return; return;
} }
@ -412,50 +439,40 @@ void MakeFile( TSTRING& strNameMakeMe )
{ {
try try
{ {
iFSServices* pFSServices = iFSServices::GetInstance(); ASSERT( pFSServices ); iFSServices* pFSServices = iFSServices::GetInstance(); TEST( pFSServices );
pFSServices->MakeTempFilename( strNameMakeMe ); pFSServices->MakeTempFilename( strNameMakeMe );
std::string strA; std::string strA;
for( TSTRING::iterator i = strNameMakeMe.begin(); i != strNameMakeMe.end(); ++i ) for( TSTRING::iterator i = strNameMakeMe.begin(); i != strNameMakeMe.end(); ++i )
{ {
char ach[6]; char ach[6];
ASSERT( MB_CUR_MAX <= 6 ); TEST( MB_CUR_MAX <= 6 );
int n = wctomb( ach, *i ); int n = wctomb( ach, *i );
ASSERT( n != -1 ); TEST( n != -1 );
for( int j = 0; j < n; j++ ) for( int j = 0; j < n; j++ )
strA += ach[j]; strA += ach[j];
} }
TOFSTREAM file( strA.c_str() ); TOFSTREAM file( strA.c_str() );
ASSERT( file ); TEST( file );
file.close(); file.close();
} }
catch( eFSServices e ) catch( eFSServices e )
{ {
ASSERT( false ); TEST( false );
} }
catch( ... ) catch( ... )
{ {
ASSERT( false ); TEST( false );
} }
} }
void MakeDir( const TCHAR* const lpszDirName ) void MakeDir( const TCHAR* const lpszDirName )
{ {
try TEST(0 == mkdir(lpszDirName, 0777 ))
{
iFSServices* pFSServices = iFSServices::GetInstance();
TSTRING newdir(lpszDirName);
pFSServices->Mkdir( newdir );
}
catch( eFSServices e )
{
ASSERT( false );
}
} }
#endif //FIXED_TRV_TEST_SUITE //#endif //FIXED_TRV_TEST_SUITE

View File

@ -51,7 +51,7 @@ void TestHex();
try \ try \
{ \ { \
x; \ x; \
ASSERT( false ); \ TEST( false ); \
} catch( error& ) {} } catch( error& ) {}
void TestTWLocale() void TestTWLocale()
@ -80,21 +80,21 @@ void TestAtoi()
// //
cTWLocale::InitGlobalLocale(); cTWLocale::InitGlobalLocale();
n = cTWLocale::FormatNumber( str ); n = cTWLocale::FormatNumber( str );
ASSERT( 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::FormatNumber( str );
ASSERT( 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::FormatNumber( str );
ASSERT( n == 123456 ); TEST( n == 123456 );
} }
void TestItoa() void TestItoa()
@ -147,7 +147,7 @@ void TestRoundtrip()
strOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( strIn ), strOut ); strOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( 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 ^^^
ASSERT( 123456 == cTWLocale::FormatNumber( strOut ) ); TEST( 123456 == cTWLocale::FormatNumber( strOut ) );
// //
@ -156,7 +156,7 @@ void TestRoundtrip()
int32 nIn = 654321; int32 nIn = 654321;
int32 nOut; int32 nOut;
nOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( nIn, strIn ) ); nOut = cTWLocale::FormatNumber( cTWLocale::FormatNumber( nIn, strIn ) );
ASSERT( nOut == nIn ); TEST( nOut == nIn );
} }
@ -172,7 +172,7 @@ void TestFlags()
// //
TSTRING str = _T("FF"); TSTRING str = _T("FF");
int n = cTWLocale::FormatNumber( str, std::ios_base::hex ); int n = cTWLocale::FormatNumber( str, std::ios_base::hex );
ASSERT( n == 0xFF ); TEST( n == 0xFF );
// //
// bad number for dec // bad number for dec
@ -184,21 +184,21 @@ void TestFlags()
// //
TSTRING strOct = _T("0712"); TSTRING strOct = _T("0712");
n = cTWLocale::FormatNumber( strOct, std::ios_base::oct ); n = cTWLocale::FormatNumber( strOct, std::ios_base::oct );
ASSERT( n == 0712 ); TEST( n == 0712 );
// //
// oct again // oct again
// //
strOct = _T("00712"); strOct = _T("00712");
n = cTWLocale::FormatNumber( strOct, std::ios_base::oct ); n = cTWLocale::FormatNumber( strOct, std::ios_base::oct );
ASSERT( n == 0712 ); TEST( n == 0712 );
// //
// oct again again // oct again again
// //
strOct = _T("712"); strOct = _T("712");
n = cTWLocale::FormatNumber( strOct, std::ios_base::oct ); n = cTWLocale::FormatNumber( strOct, std::ios_base::oct );
ASSERT( n == 0712 ); TEST( n == 0712 );
// //
// try bad oct // try bad oct
@ -212,16 +212,16 @@ void TestHex()
TSTRING str; TSTRING str;
str = cTWLocale::FormatNumberAsHex( 0x1234 ); str = cTWLocale::FormatNumberAsHex( 0x1234 );
ASSERT( str == _T("1234") ); TEST( str == _T("1234") );
str = cTWLocale::FormatNumberAsHex( 16 ); str = cTWLocale::FormatNumberAsHex( 16 );
ASSERT( str == _T("10") ); TEST( str == _T("10") );
str = cTWLocale::FormatNumberAsHex( 0x12344321 ); str = cTWLocale::FormatNumberAsHex( 0x12344321 );
ASSERT( str == _T("12344321") ); TEST( str == _T("12344321") );
str = cTWLocale::FormatNumberAsHex( 0xFFFFFFFF ); str = cTWLocale::FormatNumberAsHex( 0xFFFFFFFF );
ASSERT( str == _T("FFFFFFFF") || str == _T("ffffffff") ); TEST( str == _T("FFFFFFFF") || str == _T("ffffffff") );
} }
#endif//DOESNTWORK #endif//DOESNTWORK

View File

@ -34,6 +34,7 @@
#include "tw/stdtw.h" #include "tw/stdtw.h"
#include "tw/twutil.h" #include "tw/twutil.h"
#include "util/fileutil.h"
#include "twtest/test.h" #include "twtest/test.h"
#include <fstream> #include <fstream>
@ -45,8 +46,6 @@ std::string WideToNarrow( const TSTRING& strWide );
void TestTWUtil() void TestTWUtil()
{ {
#pragma message( __FILE__ "(1) : TODO - implement this test file")
#if 0
// TODO: we should test more than the file exists stuff, but that // TODO: we should test more than the file exists stuff, but that
// is all I need to do for right now. // is all I need to do for right now.
cDebug d("TestTWUtil"); cDebug d("TestTWUtil");
@ -57,7 +56,7 @@ void TestTWUtil()
d.TraceAlways("Testing FileExists() and FileWritable()\n"); d.TraceAlways("Testing FileExists() and FileWritable()\n");
// assuming the current dir is writable, this test should succeed // assuming the current dir is writable, this test should succeed
TEST(cTWUtil::FileWritable(_T("afilethatdoesnotexist.tmp")) == true); TEST(cFileUtil::FileWritable(_T("afilethatdoesnotexist.tmp")) == true);
TSTRING tmpDir = TEMP_DIR; TSTRING tmpDir = TEMP_DIR;
tmpDir += _T("/fileexistdir"); tmpDir += _T("/fileexistdir");
@ -65,43 +64,42 @@ void TestTWUtil()
tmpFN += _T("/fileexiststest.tmp"); tmpFN += _T("/fileexiststest.tmp");
// make a subdir in the TEMP_DIR // make a subdir in the TEMP_DIR
_tmkdir(tmpDir.c_str(), 0700); mkdir(tmpDir.c_str(), 0700);
_tchmod(tmpDir.c_str(), 0700); chmod(tmpDir.c_str(), 0700);
// make sure file is not there // make sure file is not there
_tchmod(tmpFN.c_str(), 0777); chmod(tmpFN.c_str(), 0777);
_tunlink(tmpFN.c_str()); unlink(tmpFN.c_str());
// make sure exists tests false, writable is true // make sure exists tests false, writable is true
// and checking writable should not create the file // and checking writable should not create the file
TEST(cTWUtil::FileExists(tmpFN) == false); TEST(cFileUtil::FileExists(tmpFN) == false);
TEST(cTWUtil::FileWritable(tmpFN) == true) TEST(cFileUtil::FileWritable(tmpFN) == true)
TEST(cTWUtil::FileExists(tmpFN) == false); TEST(cFileUtil::FileExists(tmpFN) == false);
// make the dir read only and make sure write tests false // make the dir read only and make sure write tests false
// windows fails this test, perhaps because I am an administrator? // windows fails this test, perhaps because I am an administrator?
_tchmod(tmpDir.c_str(), 0500); chmod(tmpDir.c_str(), 0500);
TEST(cTWUtil::FileWritable(tmpFN) == false); TEST(cFileUtil::FileWritable(tmpFN) == false);
_tchmod(tmpDir.c_str(), 0700); chmod(tmpDir.c_str(), 0700);
// create the file // create the file
{ {
std::ofstream ostr(WideToNarrow(tmpFN).c_str()); std::ofstream ostr(WideToNarrow(tmpFN).c_str());
ostr << "Hey there.\n"; ostr << "Hey there.\n";
} }
// test a read only file // test a read only file
_tchmod(tmpFN.c_str(), 0400); chmod(tmpFN.c_str(), 0400);
TEST(cTWUtil::FileWritable(tmpFN) == false); TEST(cFileUtil::FileWritable(tmpFN) == false);
// test a writable file // test a writable file
_tchmod(tmpFN.c_str(), 0666); chmod(tmpFN.c_str(), 0666);
TEST(cTWUtil::FileWritable(tmpFN) == true); TEST(cFileUtil::FileWritable(tmpFN) == true);
// delete the test file and dir // delete the test file and dir
_tunlink(tmpFN.c_str()); unlink(tmpFN.c_str());
_tunlink(tmpDir.c_str()); unlink(tmpDir.c_str());
#endif
} }
std::string WideToNarrow( const TSTRING& strWide ) std::string WideToNarrow( const TSTRING& strWide )