Break some big unit tests into smaller ones
This commit is contained in:
parent
e453a81c87
commit
25ddcc0ca6
|
@ -92,4 +92,10 @@ void cFCOSpecAttr::TraceContents(int dl) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cFCOSpecAttr::operator==(const cFCOSpecAttr& rhs) const
|
||||||
|
{
|
||||||
|
return ( (mEmailAddrs == rhs.mEmailAddrs)
|
||||||
|
&& (mName == rhs.mName)
|
||||||
|
&& (mSeverity == rhs.mSeverity));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,8 @@ public:
|
||||||
|
|
||||||
void TraceContents(int dl = -1) const;
|
void TraceContents(int dl = -1) const;
|
||||||
|
|
||||||
|
bool operator==(const cFCOSpecAttr& rhs) const;
|
||||||
|
|
||||||
DECLARE_SERREFCOUNT()
|
DECLARE_SERREFCOUNT()
|
||||||
private:
|
private:
|
||||||
cFCOSpecAttr (const cFCOSpecAttr& rhs); // not impl
|
cFCOSpecAttr (const cFCOSpecAttr& rhs); // not impl
|
||||||
|
|
|
@ -509,4 +509,9 @@ bool cFSPropDisplayer::AddGroupnameMapping( const int64& i64gid, const TSTRING&
|
||||||
return( ret.second = false ); // returns true if key didn't exist before
|
return( ret.second = false ); // returns true if key didn't exist before
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cFSPropDisplayer::operator==(const cFSPropDisplayer& rhs) const
|
||||||
|
{
|
||||||
|
return (mpvPropsWeDisplay == rhs.mpvPropsWeDisplay
|
||||||
|
&& uidToUsername == rhs.uidToUsername
|
||||||
|
&& gidToGroupname == rhs.gidToGroupname);
|
||||||
|
}
|
||||||
|
|
|
@ -114,6 +114,9 @@ public:
|
||||||
virtual bool GetLazy() const;
|
virtual bool GetLazy() const;
|
||||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||||
|
|
||||||
|
bool operator==(const cFSPropDisplayer& rhs) const; // for testing
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AddMapping( const iFCOProp* const pProp, const TSTRING& tstrValue, const int propTypeEnum );
|
void AddMapping( const iFCOProp* const pProp, const TSTRING& tstrValue, const int propTypeEnum );
|
||||||
// pass in a property value and its string representation. for instance: ( FS::PROP_UID --> username )
|
// pass in a property value and its string representation. for instance: ( FS::PROP_UID --> username )
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
TSS_EXCEPTION(eTestArchiveError, eError);
|
TSS_EXCEPTION(eTestArchiveError, eError);
|
||||||
|
|
||||||
void TestArchive()
|
void TestMemoryArchive()
|
||||||
{
|
{
|
||||||
// cMemoryArchive
|
// cMemoryArchive
|
||||||
cMemoryArchive memarch;
|
cMemoryArchive memarch;
|
||||||
|
@ -52,7 +52,7 @@ void TestArchive()
|
||||||
memarch.WriteInt32(3);
|
memarch.WriteInt32(3);
|
||||||
memarch.WriteInt32(4);
|
memarch.WriteInt32(4);
|
||||||
|
|
||||||
TSTRING s = _T("Weenus");
|
TSTRING s = _T("Iridogorgia");
|
||||||
memarch.WriteString(s);
|
memarch.WriteString(s);
|
||||||
|
|
||||||
memarch.WriteInt64(1234567L);
|
memarch.WriteInt64(1234567L);
|
||||||
|
@ -74,7 +74,7 @@ void TestArchive()
|
||||||
|
|
||||||
TSTRING s2;
|
TSTRING s2;
|
||||||
memarch.ReadString(s2);
|
memarch.ReadString(s2);
|
||||||
TEST(s2.compare(_T("Weenus")) == 0);
|
TEST(s2.compare(_T("Iridogorgia")) == 0);
|
||||||
|
|
||||||
memarch.ReadInt64(l);
|
memarch.ReadInt64(l);
|
||||||
TEST(l == 1234567L);
|
TEST(l == 1234567L);
|
||||||
|
@ -101,37 +101,61 @@ void TestArchive()
|
||||||
TEST(memarch.GetMappedOffset() == 4 * sizeof(int32) + sizeof(int32) + 6);
|
TEST(memarch.GetMappedOffset() == 4 * sizeof(int32) + sizeof(int32) + 6);
|
||||||
TEST(memarch.GetMappedLength() == sizeof(int64));
|
TEST(memarch.GetMappedLength() == sizeof(int64));
|
||||||
// TEST(tw_ntohll(*(int64*)memarch.GetMap()) == 1234567L);
|
// TEST(tw_ntohll(*(int64*)memarch.GetMap()) == 1234567L);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestLockedTemporaryArchive()
|
||||||
|
{
|
||||||
|
TSTRING s = _T("Metallogorgia");
|
||||||
|
|
||||||
|
bool threw = false;
|
||||||
// cLockedTemporaryFileArchive
|
// cLockedTemporaryFileArchive
|
||||||
TSTRING lockedFileName = TwTestPath("inaccessable_file.bin");
|
TSTRING lockedFileName = TwTestPath("inaccessable_file.bin");
|
||||||
// lockedFileName += _T("/inaccessable_file.bin");
|
|
||||||
|
|
||||||
cLockedTemporaryFileArchive lockedArch;
|
cLockedTemporaryFileArchive lockedArch;
|
||||||
|
|
||||||
// try to create an archive using a temp file
|
try
|
||||||
lockedArch.OpenReadWrite();
|
{
|
||||||
lockedArch.Close();
|
// try to create an archive using a temp file
|
||||||
|
lockedArch.OpenReadWrite();
|
||||||
|
lockedArch.Close();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
threw = true;
|
||||||
|
}
|
||||||
|
|
||||||
// this should open and lock the file -- shouldn't be able to access it
|
try
|
||||||
lockedArch.OpenReadWrite(lockedFileName.c_str());
|
{
|
||||||
lockedArch.Seek(0, cBidirArchive::BEGINNING);
|
// this should open and lock the file -- shouldn't be able to access it
|
||||||
|
lockedArch.OpenReadWrite(lockedFileName.c_str());
|
||||||
|
lockedArch.Seek(0, cBidirArchive::BEGINNING);
|
||||||
|
|
||||||
// shouldn't be able to see these changes
|
// shouldn't be able to see these changes
|
||||||
lockedArch.WriteInt32(1);
|
lockedArch.WriteInt32(1);
|
||||||
lockedArch.WriteInt32(2);
|
lockedArch.WriteInt32(2);
|
||||||
lockedArch.WriteInt32(3);
|
lockedArch.WriteInt32(3);
|
||||||
lockedArch.WriteInt32(4);
|
lockedArch.WriteInt32(4);
|
||||||
lockedArch.WriteString(s);
|
lockedArch.WriteString(s);
|
||||||
lockedArch.WriteInt64(1234567L);
|
lockedArch.WriteInt64(1234567L);
|
||||||
lockedArch.WriteInt16(42);
|
lockedArch.WriteInt16(42);
|
||||||
|
|
||||||
// this should delete the file
|
// this should delete the file
|
||||||
lockedArch.Close();
|
lockedArch.Close();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
threw = true;
|
||||||
|
}
|
||||||
|
|
||||||
// cFileArchive
|
TEST(!threw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestFileArchive()
|
||||||
|
{
|
||||||
|
bool threw = false;
|
||||||
|
TSTRING s = _T("Acanthogorgia");
|
||||||
|
// cFileArchive
|
||||||
TSTRING fileName = TwTestPath("archive_test.bin");
|
TSTRING fileName = TwTestPath("archive_test.bin");
|
||||||
//fileName += _T("/archive_test.bin");
|
|
||||||
|
|
||||||
cFileArchive filearch;
|
cFileArchive filearch;
|
||||||
filearch.OpenReadWrite(fileName.c_str());
|
filearch.OpenReadWrite(fileName.c_str());
|
||||||
|
@ -163,7 +187,7 @@ void TestArchive()
|
||||||
|
|
||||||
TSTRING s3;
|
TSTRING s3;
|
||||||
filearch.ReadString(s3);
|
filearch.ReadString(s3);
|
||||||
TEST(s3.compare(_T("Weenus")) == 0);
|
TEST(s3.compare(_T("Acanthogorgia")) == 0);
|
||||||
filearch.ReadInt64(k);
|
filearch.ReadInt64(k);
|
||||||
TEST(k == 1234567L);
|
TEST(k == 1234567L);
|
||||||
|
|
||||||
|
@ -181,12 +205,16 @@ void TestArchive()
|
||||||
}
|
}
|
||||||
catch (eError& e)
|
catch (eError& e)
|
||||||
{
|
{
|
||||||
TEST(false);
|
threw=true;
|
||||||
(void)e;
|
(void)e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(!threw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterSuite_Archive()
|
void RegisterSuite_Archive()
|
||||||
{
|
{
|
||||||
RegisterTest("Archive", "Basic", TestArchive);
|
RegisterTest("Archive", "MemoryArchive", TestMemoryArchive);
|
||||||
|
RegisterTest("Archive", "LockedTemporaryArchive)", TestLockedTemporaryArchive);
|
||||||
|
RegisterTest("Archive", "FileArchive", TestFileArchive);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,9 @@
|
||||||
#include "core/debug.h"
|
#include "core/debug.h"
|
||||||
#include "twtest/test.h"
|
#include "twtest/test.h"
|
||||||
|
|
||||||
void TestFCOPropImpl()
|
void TestNumeric()
|
||||||
{
|
{
|
||||||
cDebug d("TestFCOPropImpl");
|
cDebug d("TestNumeric");
|
||||||
d.TraceDebug("Entering...\n");
|
d.TraceDebug("Entering...\n");
|
||||||
|
|
||||||
// print the enum key:
|
// print the enum key:
|
||||||
|
@ -69,12 +69,18 @@ void TestFCOPropImpl()
|
||||||
|
|
||||||
d.TraceDebug("333ui64 == 456ui64 = %d\n", pui64.Compare(&pui64b, iFCOProp::OP_EQ));
|
d.TraceDebug("333ui64 == 456ui64 = %d\n", pui64.Compare(&pui64b, iFCOProp::OP_EQ));
|
||||||
TEST( iFCOProp::CMP_FALSE == p2i64.Compare(&pi64, iFCOProp::OP_EQ));
|
TEST( iFCOProp::CMP_FALSE == p2i64.Compare(&pi64, iFCOProp::OP_EQ));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestStrings()
|
||||||
|
{
|
||||||
|
cDebug d("TestStrings");
|
||||||
cFCOPropTSTRING pt1;
|
cFCOPropTSTRING pt1;
|
||||||
cFCOPropTSTRING pt2;
|
cFCOPropTSTRING pt2;
|
||||||
pt1.SetValue(TSTRING(_T("bar")));
|
pt1.SetValue(TSTRING(_T("bar")));
|
||||||
pt2.SetValue(TSTRING(_T("foo")));
|
pt2.SetValue(TSTRING(_T("foo")));
|
||||||
|
cFCOPropInt64 pi64;
|
||||||
|
pi64.SetValue(8675309);
|
||||||
|
|
||||||
d.TraceDebug(_T("property TSTRING = (should be \"bar\") %s\n"), pt1.AsString().c_str());
|
d.TraceDebug(_T("property TSTRING = (should be \"bar\") %s\n"), pt1.AsString().c_str());
|
||||||
TEST(pt1.AsString() == "bar");
|
TEST(pt1.AsString() == "bar");
|
||||||
|
|
||||||
|
@ -96,5 +102,6 @@ void TestFCOPropImpl()
|
||||||
|
|
||||||
void RegisterSuite_FCOPropImpl()
|
void RegisterSuite_FCOPropImpl()
|
||||||
{
|
{
|
||||||
RegisterTest("FCOPropImpl", "Basic", TestFCOPropImpl);
|
RegisterTest("FCOPropImpl", "Numeric", TestNumeric);
|
||||||
|
RegisterTest("FCOPropImpl", "Strings", TestStrings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,38 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void TestSignature()
|
std::string getTestFile()
|
||||||
|
{
|
||||||
|
// Create a file for which we know the signatures
|
||||||
|
//
|
||||||
|
//% siggen ~/signature_test.bin
|
||||||
|
//crc : AAAAAAAAAAy
|
||||||
|
//md5 : B/Y8ttBnlyw/NPCUu353ao
|
||||||
|
//crc32 : B1kP9v
|
||||||
|
//sha : Oia1aljHD793tfj7M55tND+3OG/
|
||||||
|
//haval : BL6bFSo0EP5zf8lGSueeed
|
||||||
|
|
||||||
|
static TSTRING sigFileName;
|
||||||
|
|
||||||
|
if (sigFileName.empty())
|
||||||
|
{
|
||||||
|
sigFileName = TwTestPath("signature_test.bin");
|
||||||
|
|
||||||
|
cFileArchive fileArc;
|
||||||
|
fileArc.OpenReadWrite(sigFileName.c_str());
|
||||||
|
fileArc.WriteBlob("\x1\x2\x3\x4\x5\x6\x7\x8\x9\x0", 10);
|
||||||
|
fileArc.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return sigFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestSignatureBasic()
|
||||||
{
|
{
|
||||||
// Signature usage example (?)
|
// Signature usage example (?)
|
||||||
cCRC32Signature crcSig;
|
cCRC32Signature crcSig;
|
||||||
cDebug d("TestSignature");
|
cDebug d("TestSignature1");
|
||||||
|
|
||||||
byte abData[ 64 ];
|
byte abData[ 64 ];
|
||||||
int i;
|
int i;
|
||||||
|
@ -58,7 +85,6 @@ void TestSignature()
|
||||||
crcSig.Update( &abData[0], 32 );
|
crcSig.Update( &abData[0], 32 );
|
||||||
crcSig.Update( &abData[32], 32 );
|
crcSig.Update( &abData[32], 32 );
|
||||||
crcSig.Finit();
|
crcSig.Finit();
|
||||||
TCOUT << _T("new way: ") << crcSig.AsString() << endl;
|
|
||||||
|
|
||||||
cMemoryArchive arch;
|
cMemoryArchive arch;
|
||||||
arch.WriteBlob( &abData[0], 32 );
|
arch.WriteBlob( &abData[0], 32 );
|
||||||
|
@ -69,32 +95,19 @@ void TestSignature()
|
||||||
asg.AddSig( &crc );
|
asg.AddSig( &crc );
|
||||||
asg.CalculateSignatures( arch );
|
asg.CalculateSignatures( arch );
|
||||||
|
|
||||||
TCOUT << _T("old way: ") << crc.AsString() << endl;
|
TEST( crc.AsStringHex() == crcSig.AsStringHex());
|
||||||
|
}
|
||||||
|
|
||||||
// Note: The following causes an ASSERT() in iSignature::Compare(), as it should, but
|
// Note: The following causes an ASSERT() in iSignature::Compare(), as it should, but
|
||||||
// we don't want asserts to occur in a working test suite!
|
// we don't want asserts to occur in a working test suite!
|
||||||
// TEST(nullSig.Compare(&checksumSig, iFCOProp::OP_EQ) == iFCOProp::CMP_WRONG_PROP_TYPE);
|
// TEST(nullSig.Compare(&checksumSig, iFCOProp::OP_EQ) == iFCOProp::CMP_WRONG_PROP_TYPE);
|
||||||
|
|
||||||
|
|
||||||
|
void TestChecksum()
|
||||||
// Create a file for which we know the signatures
|
{
|
||||||
//
|
TSTRING sigFileName = getTestFile();
|
||||||
//% siggen ~/signature_test.bin
|
|
||||||
//crc : AAAAAAAAAAy
|
|
||||||
//md5 : B/Y8ttBnlyw/NPCUu353ao
|
|
||||||
//crc32 : B1kP9v
|
|
||||||
//sha : Oia1aljHD793tfj7M55tND+3OG/
|
|
||||||
//haval : BL6bFSo0EP5zf8lGSueeed
|
|
||||||
|
|
||||||
TSTRING sigFileName = TwTestPath("signature_test.bin");
|
|
||||||
|
|
||||||
cFileArchive fileArc;
|
cFileArchive fileArc;
|
||||||
fileArc.OpenReadWrite(sigFileName.c_str());
|
cDebug d("TestChecksum");
|
||||||
fileArc.WriteBlob("\x1\x2\x3\x4\x5\x6\x7\x8\x9\x0", 10);
|
|
||||||
fileArc.Close();
|
|
||||||
|
|
||||||
|
|
||||||
// test begins here
|
// test begins here
|
||||||
|
|
||||||
// general signature & archive variables
|
// general signature & archive variables
|
||||||
|
@ -145,8 +158,19 @@ void TestSignature()
|
||||||
check2.Read(&readSer);
|
check2.Read(&readSer);
|
||||||
TEST(check1.Compare(&check2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
TEST(check1.Compare(&check2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCRC32()
|
||||||
|
{
|
||||||
|
TSTRING sigFileName = getTestFile();
|
||||||
|
cFileArchive fileArc;
|
||||||
|
cDebug d("TestCRC32");
|
||||||
|
|
||||||
|
// general signature & archive variables
|
||||||
|
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
|
||||||
|
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
|
||||||
|
int cbRead;
|
||||||
|
|
||||||
|
|
||||||
// test CRC32
|
// test CRC32
|
||||||
cCRC32Signature crc1, crc2;
|
cCRC32Signature crc1, crc2;
|
||||||
d.TraceDetail("Testing CRC32.\n");
|
d.TraceDetail("Testing CRC32.\n");
|
||||||
|
@ -190,7 +214,18 @@ void TestSignature()
|
||||||
crc2.Read(&readSer);
|
crc2.Read(&readSer);
|
||||||
TEST(crc1.Compare(&crc2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
TEST(crc1.Compare(&crc2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestMD5()
|
||||||
|
{
|
||||||
|
TSTRING sigFileName = getTestFile();
|
||||||
|
cFileArchive fileArc;
|
||||||
|
cDebug d("TestMD5");
|
||||||
|
|
||||||
|
// general signature & archive variables
|
||||||
|
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
|
||||||
|
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
|
||||||
|
int cbRead;
|
||||||
|
|
||||||
// test MD5
|
// test MD5
|
||||||
cMD5Signature md51, md52;
|
cMD5Signature md51, md52;
|
||||||
|
@ -235,7 +270,18 @@ void TestSignature()
|
||||||
md52.Read(&readSer);
|
md52.Read(&readSer);
|
||||||
TEST(md51.Compare(&md52, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
TEST(md51.Compare(&md52, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestSHA1()
|
||||||
|
{
|
||||||
|
TSTRING sigFileName = getTestFile();
|
||||||
|
cFileArchive fileArc;
|
||||||
|
cDebug d("TestSHA1");
|
||||||
|
|
||||||
|
// general signature & archive variables
|
||||||
|
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
|
||||||
|
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
|
||||||
|
int cbRead;
|
||||||
|
|
||||||
// test SHA
|
// test SHA
|
||||||
cSHASignature sha1, sha2;
|
cSHASignature sha1, sha2;
|
||||||
|
@ -280,8 +326,19 @@ void TestSignature()
|
||||||
sha2.Read(&readSer);
|
sha2.Read(&readSer);
|
||||||
TEST(sha1.Compare(&sha2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
TEST(sha1.Compare(&sha2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestHAVAL()
|
||||||
|
{
|
||||||
|
TSTRING sigFileName = getTestFile();
|
||||||
|
cFileArchive fileArc;
|
||||||
|
cDebug d("TestHAVAL");
|
||||||
|
|
||||||
|
// general signature & archive variables
|
||||||
|
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
|
||||||
|
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
|
||||||
|
int cbRead;
|
||||||
|
|
||||||
|
|
||||||
// test HAVAL
|
// test HAVAL
|
||||||
cHAVALSignature haval1, haval2;
|
cHAVALSignature haval1, haval2;
|
||||||
d.TraceDetail("Testing HAVAL.\n");
|
d.TraceDetail("Testing HAVAL.\n");
|
||||||
|
@ -322,10 +379,16 @@ void TestSignature()
|
||||||
haval1.Write(&writeSer);
|
haval1.Write(&writeSer);
|
||||||
sigArchive.Seek(0, cBidirArchive::BEGINNING);
|
sigArchive.Seek(0, cBidirArchive::BEGINNING);
|
||||||
cSerializerImpl readSer(sigArchive, cSerializerImpl::S_READ);
|
cSerializerImpl readSer(sigArchive, cSerializerImpl::S_READ);
|
||||||
md52.Read(&readSer);
|
haval2.Read(&readSer);
|
||||||
TEST(haval1.Compare(&haval2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
TEST(haval1.Compare(&haval2, iFCOProp::OP_EQ) == iFCOProp::CMP_TRUE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestArchiveSigGen()
|
||||||
|
{
|
||||||
|
TSTRING sigFileName = getTestFile();
|
||||||
|
cFileArchive fileArc;
|
||||||
|
cDebug d("TestArchiveSigGen");
|
||||||
|
|
||||||
// test cArchiveSigGen
|
// test cArchiveSigGen
|
||||||
cArchiveSigGen asgtest;
|
cArchiveSigGen asgtest;
|
||||||
|
@ -356,12 +419,16 @@ void TestSignature()
|
||||||
TEST(haval3.AsString().compare(_T("BL6bFSo0EP5zf8lGSueeed")) == 0);
|
TEST(haval3.AsString().compare(_T("BL6bFSo0EP5zf8lGSueeed")) == 0);
|
||||||
TEST(haval3.AsStringHex().compare(_T("4be9b152a3410fe737fc9464ae79e79d")) == 0);
|
TEST(haval3.AsStringHex().compare(_T("4be9b152a3410fe737fc9464ae79e79d")) == 0);
|
||||||
|
|
||||||
fileArc.Close();
|
fileArc.Close();
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterSuite_Signature()
|
void RegisterSuite_Signature()
|
||||||
{
|
{
|
||||||
RegisterTest("Signature", "Basic", TestSignature);
|
RegisterTest("Signature", "Basic", TestSignatureBasic);
|
||||||
|
RegisterTest("Signature", "Checksum", TestChecksum);
|
||||||
|
RegisterTest("Signature", "CRC32", TestCRC32);
|
||||||
|
RegisterTest("Signature", "MD5", TestMD5);
|
||||||
|
RegisterTest("Signature", "SHA1", TestSHA1);
|
||||||
|
RegisterTest("Signature", "HAVAL", TestHAVAL);
|
||||||
|
RegisterTest("Signature", "ArchiveSigGen", TestArchiveSigGen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,12 +44,24 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//Tests the functions that are currently implemented in win32fsservices.
|
|
||||||
void TestUnixFSServices()
|
|
||||||
{
|
|
||||||
cDebug d("TestUnixFSServices");
|
|
||||||
// d.RemoveOutTarget(cDebug::OUT_STDOUT);
|
|
||||||
|
|
||||||
|
std::string makeTestFile(const std::string &filename)
|
||||||
|
{
|
||||||
|
TSTRING testfile = TwTestPath(filename);
|
||||||
|
cFileArchive filearch;
|
||||||
|
filearch.OpenReadWrite(testfile.c_str());
|
||||||
|
filearch.Seek(0, cBidirArchive::BEGINNING);
|
||||||
|
filearch.WriteString(_T("This is a test"));
|
||||||
|
filearch.Close();
|
||||||
|
|
||||||
|
return testfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Tests the functions that are currently implemented in win32fsservices.
|
||||||
|
void TestReadDir()
|
||||||
|
{
|
||||||
|
cDebug d("TestReadDir");
|
||||||
|
// d.RemoveOutTarget(cDebug::OUT_STDOUT);
|
||||||
|
|
||||||
iFSServices* pFSServices = iFSServices::GetInstance();
|
iFSServices* pFSServices = iFSServices::GetInstance();
|
||||||
|
|
||||||
|
@ -75,20 +87,20 @@ void TestUnixFSServices()
|
||||||
|
|
||||||
TEST(n == v.size());
|
TEST(n == v.size());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestStat()
|
||||||
|
{
|
||||||
//Test the Stat method
|
//Test the Stat method
|
||||||
cFSStatArgs stat;
|
cFSStatArgs stat;
|
||||||
|
|
||||||
//TO DO: use archive to create this file
|
std::string testfile = makeTestFile("stat.tmp");
|
||||||
TSTRING testfile = TwTestPath("tmp.tmp");
|
|
||||||
cFileArchive filearch;
|
|
||||||
filearch.OpenReadWrite(testfile.c_str());
|
|
||||||
filearch.Seek(0, cBidirArchive::BEGINNING);
|
|
||||||
filearch.WriteString(_T("This is a test"));
|
|
||||||
filearch.Close();
|
|
||||||
|
|
||||||
pFSServices->Stat(testfile, stat);
|
iFSServices::GetInstance()->Stat(testfile, stat);
|
||||||
|
|
||||||
|
TEST("Stat() did not throw");
|
||||||
|
/*
|
||||||
|
cDebug d("TestStat");
|
||||||
//print out the information returned by Stat
|
//print out the information returned by Stat
|
||||||
d.TraceDetail("Information returned by Stat: \n");
|
d.TraceDetail("Information returned by Stat: \n");
|
||||||
d.TraceDetail("Group ID : %-5d \n", stat.gid);
|
d.TraceDetail("Group ID : %-5d \n", stat.gid);
|
||||||
|
@ -102,65 +114,95 @@ void TestUnixFSServices()
|
||||||
d.TraceDetail("Major/minor dev if special: %d \n", stat.rdev);
|
d.TraceDetail("Major/minor dev if special: %d \n", stat.rdev);
|
||||||
d.TraceDetail("File size: %d \n", stat.size);
|
d.TraceDetail("File size: %d \n", stat.size);
|
||||||
d.TraceDetail("User ID: %d \n", stat.uid);
|
d.TraceDetail("User ID: %d \n", stat.uid);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
//Test GetCurrentDir:
|
void TestGetCurrentDir()
|
||||||
|
{
|
||||||
TSTRING currpath;
|
TSTRING currpath;
|
||||||
pFSServices->GetCurrentDir(currpath);
|
iFSServices::GetInstance()->GetCurrentDir(currpath);
|
||||||
d.TraceDetail("GetCurrentDir returned %s\n", currpath.c_str());
|
|
||||||
|
TEST("GetCurrentDir() did not throw");
|
||||||
|
|
||||||
|
//d.TraceDetail("GetCurrentDir returned %s\n", currpath.c_str());
|
||||||
//TEST(currpath == _T("~"));
|
//TEST(currpath == _T("~"));
|
||||||
//they should both be ~!!
|
//they should both be ~!!
|
||||||
|
}
|
||||||
|
|
||||||
//Test MakeTempFilename
|
void TestMakeTempFilename()
|
||||||
|
{
|
||||||
TSTRING _template(_T("twtempXXXXXX"));
|
TSTRING _template(_T("twtempXXXXXX"));
|
||||||
pFSServices->MakeTempFilename(_template);
|
iFSServices::GetInstance()->MakeTempFilename(_template);
|
||||||
d.TraceDetail("Testing MakeTempFilename: \n");
|
|
||||||
d.TraceDetail("%s \n", _template.c_str() );
|
|
||||||
|
|
||||||
// Test GetMachineName
|
TEST("MakeTempFilename() did not throw");
|
||||||
d.TraceDetail("Testing GetMachineName:\n");
|
}
|
||||||
|
|
||||||
|
void TestGetMachineName()
|
||||||
|
{
|
||||||
TSTRING uname;
|
TSTRING uname;
|
||||||
pFSServices->GetMachineName(uname);
|
iFSServices::GetInstance()->GetMachineName(uname);
|
||||||
d.TraceDetail("GetMachineName returned: %s\n", uname.c_str());
|
|
||||||
|
|
||||||
// Test GetHostID
|
TEST("GetMachineName() did not throw");
|
||||||
d.TraceDetail("Testing GetHostID:\n");
|
}
|
||||||
|
|
||||||
|
void TestGetHostID()
|
||||||
|
{
|
||||||
TSTRING hostid;
|
TSTRING hostid;
|
||||||
pFSServices->GetHostID(hostid);
|
iFSServices::GetInstance()->GetHostID(hostid);
|
||||||
d.TraceDetail("GetHostID returned: %s\n", hostid.c_str());
|
|
||||||
|
|
||||||
// Test GetCurrentUserName
|
TEST("GetHostID() did not throw:");
|
||||||
d.TraceDetail("Testing GetCurrentUserName:\n");
|
}
|
||||||
|
|
||||||
|
void TestGetCurrentUserName()
|
||||||
|
{
|
||||||
TSTRING username;
|
TSTRING username;
|
||||||
TEST( pFSServices->GetCurrentUserName(username) );
|
TEST( iFSServices::GetInstance()->GetCurrentUserName(username) );
|
||||||
d.TraceDetail("GetCurrentUserName returned: %s\n", username.c_str());
|
}
|
||||||
|
|
||||||
// Test GetIPAddress
|
void TestGetIPAddress()
|
||||||
d.TraceDetail("Testing GetIPAddress:\n");
|
{
|
||||||
uint32 ipaddr;
|
uint32 ipaddr;
|
||||||
TEST( pFSServices->GetIPAddress( ipaddr ) );
|
TEST( iFSServices::GetInstance()->GetIPAddress( ipaddr ) );
|
||||||
d.TraceDetail("GetIPAddress returned: %d\n", ipaddr);
|
}
|
||||||
|
|
||||||
// test GetExecutableFilename
|
void TestGetExecutableFilename()
|
||||||
d.TraceDetail("Testing GetExecutableFilename: \n");
|
{
|
||||||
TSTRING filename = _T("sh");
|
TSTRING filename = _T("sh");
|
||||||
TSTRING fullpath = _T("/bin/");
|
TSTRING fullpath = _T("/bin/");
|
||||||
TEST(pFSServices->GetExecutableFilename(fullpath, filename));
|
TEST( iFSServices::GetInstance()->GetExecutableFilename(fullpath, filename));
|
||||||
|
|
||||||
filename = _T("/bin/sh");
|
filename = _T("/bin/sh");
|
||||||
TEST(pFSServices->GetExecutableFilename(fullpath, filename));
|
TEST( iFSServices::GetInstance()->GetExecutableFilename(fullpath, filename));
|
||||||
|
}
|
||||||
|
|
||||||
// test Rename
|
void TestRename()
|
||||||
d.TraceDetail("Testing Rename:\n");
|
{
|
||||||
TSTRING newtestfile = TwTestPath("new.tmp");
|
std::string testfile = makeTestFile("rename_from");
|
||||||
TEST( pFSServices->Rename( testfile, newtestfile ) );
|
|
||||||
|
|
||||||
// test FileDelete
|
TSTRING newtestfile = TwTestPath("rename_to");
|
||||||
d.TraceDetail("Testing FileDelete:\n");
|
TEST( iFSServices::GetInstance()->Rename( testfile, newtestfile ) );
|
||||||
TEST( pFSServices->FileDelete( newtestfile ) );
|
}
|
||||||
|
|
||||||
|
void TestFileDelete()
|
||||||
|
{
|
||||||
|
std::string to_rm = makeTestFile("to_rm");
|
||||||
|
|
||||||
|
TEST( iFSServices::GetInstance()->FileDelete( to_rm ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterSuite_UnixFSServices()
|
void RegisterSuite_UnixFSServices()
|
||||||
{
|
{
|
||||||
RegisterTest("UnixFSServices", "Basic", TestUnixFSServices);
|
RegisterTest("UnixFSServices", "ReadDir", TestReadDir);
|
||||||
|
RegisterTest("UnixFSServices", "Stat", TestStat);
|
||||||
|
RegisterTest("UnixFSServices", "GetCurrentDir", TestGetCurrentDir);
|
||||||
|
RegisterTest("UnixFSServices", "MakeTempFilename", TestMakeTempFilename);
|
||||||
|
RegisterTest("UnixFSServices", "GetMachineName", TestGetMachineName);
|
||||||
|
RegisterTest("UnixFSServices", "GetHostID", TestGetHostID);
|
||||||
|
RegisterTest("UnixFSServices", "GetCurrentUserName", TestGetCurrentUserName);
|
||||||
|
RegisterTest("UnixFSServices", "GetIPAddress", TestGetIPAddress);
|
||||||
|
RegisterTest("UnixFSServices", "GetExecutableFilename", TestGetExecutableFilename);
|
||||||
|
RegisterTest("UnixFSServices", "Rename", TestRename);
|
||||||
|
RegisterTest("UnixFSServices", "FileDelete", TestFileDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue