Robustify symlink reading in cFSPropCalc, & add a unit test for it. Tweak other unit tests to use a test directory we control, rather than dumping stuff in /tmp

This commit is contained in:
Brian Cox 2017-08-23 23:36:21 -07:00
parent fafa681bce
commit f5e76827be
21 changed files with 136 additions and 76 deletions

View File

@ -14,5 +14,6 @@ uninstall-hook:
check: check:
rm -Rf $(top_srcdir)/src/test-harness/twtest rm -Rf $(top_srcdir)/src/test-harness/twtest
rm -Rf $(top_srcdir)/bin/TWTestData
cd $(top_srcdir)/src/test-harness && perl ./twtest.pl cd $(top_srcdir)/src/test-harness && perl ./twtest.pl
$(top_srcdir)/bin/twtest all cd $(top_srcdir)/bin && ./twtest all

View File

@ -809,8 +809,9 @@ uninstall-hook:
check: check:
rm -Rf $(top_srcdir)/src/test-harness/twtest rm -Rf $(top_srcdir)/src/test-harness/twtest
rm -Rf $(top_srcdir)/bin/TWTestData
cd $(top_srcdir)/src/test-harness && perl ./twtest.pl cd $(top_srcdir)/src/test-harness && perl ./twtest.pl
$(top_srcdir)/bin/twtest all cd $(top_srcdir)/bin && ./twtest all
# Tell versions [3.59,3.63) of GNU make to not export all variables. # Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded. # Otherwise a system limit (for SysV at least) may be exceeded.

View File

@ -85,20 +85,32 @@ static bool NeedsStat(const cFCOPropVector& v)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static bool GetSymLinkStr(const TSTRING& strName, cArchive& arch) bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t size)
{ {
char buf[1024]; // TODO: is this big enough? std::vector<char> data(size+1);
char* buf = &data[0];
#if defined(O_PATH) #if defined(O_PATH)
int fd = open(strName.c_str(), (O_PATH | O_NOFOLLOW | O_NOATIME)); int fd = open(strName.c_str(), (O_PATH | O_NOFOLLOW | O_NOATIME));
int rtn = readlinkat(fd, 0, buf, 1024); int rtn = readlinkat(fd, 0, buf, size);
close(fd); close(fd);
#else #else
int rtn = readlink( strName.c_str(), buf, 1024 ); int rtn = readlink( strName.c_str(), buf, size );
#endif #endif
if(rtn == -1) if(rtn == -1)
return false; return false;
//Sadly if buf isn't big enough readlink 'succeeds' by truncating the string, so the only
// clue your buffer might be too small is if you maxed it out. So we try again, within reason.
if((size_t)rtn == size)
{
if(size < 128*TW_PATH_SIZE)
return GetSymLinkStr(strName, arch, size*2);
return false;
}
// the return value is the number of characters written. // the return value is the number of characters written.
arch.WriteBlob(buf, rtn); arch.WriteBlob(buf, rtn);

View File

@ -53,6 +53,12 @@
#include "core/archive.h" #include "core/archive.h"
#include "fspropset.h" #include "fspropset.h"
#ifdef PATH_MAX
# define TW_PATH_SIZE PATH_MAX
#else
# define TW_PATH_SIZE 1024
#endif
TSS_FILE_EXCEPTION( eFSPropCalc, eFileError ) TSS_FILE_EXCEPTION( eFSPropCalc, eFileError )
//TSS_EXCEPTION( eFSPropCalcResetAccessTime, eFSPropCalc ) // this was never used //TSS_EXCEPTION( eFSPropCalcResetAccessTime, eFSPropCalc ) // this was never used
@ -80,6 +86,8 @@ public:
virtual int GetCalcFlags() const; virtual int GetCalcFlags() const;
virtual void SetCalcFlags( int i ); virtual void SetCalcFlags( int i );
static bool GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t size = TW_PATH_SIZE);
private: private:
cFSPropCalc( const cFSPropCalc& ); cFSPropCalc( const cFSPropCalc& );
void operator =( const cFSPropCalc& ); void operator =( const cFSPropCalc& );

View File

@ -104,8 +104,8 @@ void TestArchive()
// cLockedTemporaryFileArchive // cLockedTemporaryFileArchive
TSTRING lockedFileName = TEMP_DIR; TSTRING lockedFileName = TwTestPath("inaccessable_file.bin");
lockedFileName += _T("/inaccessable_file.bin"); // lockedFileName += _T("/inaccessable_file.bin");
cLockedTemporaryFileArchive lockedArch; cLockedTemporaryFileArchive lockedArch;
@ -130,8 +130,8 @@ void TestArchive()
lockedArch.Close(); lockedArch.Close();
// cFileArchive // cFileArchive
TSTRING fileName = TEMP_DIR; TSTRING fileName = TwTestPath("archive_test.bin");
fileName += _T("/archive_test.bin"); //fileName += _T("/archive_test.bin");
cFileArchive filearch; cFileArchive filearch;
filearch.OpenReadWrite(fileName.c_str()); filearch.OpenReadWrite(fileName.c_str());

View File

@ -70,7 +70,7 @@ void TestCryptoArchive()
d.TraceDetail("Encrypting using symmetric key\n"); d.TraceDetail("Encrypting using symmetric key\n");
cFileArchive outFile; cFileArchive outFile;
outFile.OpenReadWrite(TEMP_DIR _T("/crypted.bin")); outFile.OpenReadWrite(TwTestPath("crypted.bin"));
idea.SetKey(iCipher::ENCRYPT, ideaKey); idea.SetKey(iCipher::ENCRYPT, ideaKey);
cCryptoArchive outCrypt; cCryptoArchive outCrypt;
@ -90,7 +90,7 @@ void TestCryptoArchive()
d.TraceDetail("Decrypting using symmetric key\n"); d.TraceDetail("Decrypting using symmetric key\n");
cFileArchive inFile; cFileArchive inFile;
inFile.OpenRead(TEMP_DIR _T("/crypted.bin")); inFile.OpenRead(TwTestPath("crypted.bin"));
idea.SetKey(iCipher::DECRYPT, ideaKey); idea.SetKey(iCipher::DECRYPT, ideaKey);
cCryptoArchive inCrypt; cCryptoArchive inCrypt;
@ -129,7 +129,7 @@ void TestCryptoArchive()
d.TraceDetail("Signing using asymmetric key\n"); d.TraceDetail("Signing using asymmetric key\n");
cFileArchive outFile; cFileArchive outFile;
outFile.OpenReadWrite(TEMP_DIR _T("/rsacrypted.bin")); outFile.OpenReadWrite(TwTestPath("rsacrypted.bin").c_str());
cElGamalSigArchive outCrypt; cElGamalSigArchive outCrypt;
outCrypt.SetWrite(&outFile, privateKey); outCrypt.SetWrite(&outFile, privateKey);
@ -149,7 +149,7 @@ void TestCryptoArchive()
d.TraceDetail("Verifying using asymmetric key\n"); d.TraceDetail("Verifying using asymmetric key\n");
cFileArchive inFile; cFileArchive inFile;
inFile.OpenRead(TEMP_DIR _T("/rsacrypted.bin")); inFile.OpenRead(TwTestPath("rsacrypted.bin").c_str());
cElGamalSigArchive inCrypt; cElGamalSigArchive inCrypt;
inCrypt.SetRead(&inFile, publicKey); inCrypt.SetRead(&inFile, publicKey);
@ -206,7 +206,7 @@ void TestCryptoArchive()
d.TraceDetail("Encrypting using asymmetric key\n"); d.TraceDetail("Encrypting using asymmetric key\n");
cFileArchive outFile; cFileArchive outFile;
outFile.OpenReadWrite(TEMP_DIR _T("/rsacrypted.bin")); outFile.OpenReadWrite(TwTestPath("rsacrypted.bin").c_str());
cRSAArchive outCrypt; cRSAArchive outCrypt;
outCrypt.SetWrite(&outFile, publicKey); outCrypt.SetWrite(&outFile, publicKey);
@ -226,7 +226,7 @@ void TestCryptoArchive()
d.TraceDetail("Decrypting using asymmetric key\n"); d.TraceDetail("Decrypting using asymmetric key\n");
cFileArchive inFile; cFileArchive inFile;
inFile.OpenRead(TEMP_DIR _T("/rsacrypted.bin")); inFile.OpenRead(TwTestPath("rsacrypted.bin").c_str());
cRSAArchive inCrypt; cRSAArchive inCrypt;
inCrypt.SetRead(&inFile, privateKey); inCrypt.SetRead(&inFile, privateKey);
@ -252,7 +252,7 @@ void TestCryptoArchive()
d.TraceDetail("Signing using asymmetric key\n"); d.TraceDetail("Signing using asymmetric key\n");
cFileArchive outFile; cFileArchive outFile;
outFile.OpenReadWrite(TEMP_DIR _T("/rsacrypted.bin")); outFile.OpenReadWrite(TwTestPath("rsacrypted.bin").c_str());
cRSAArchive outCrypt; cRSAArchive outCrypt;
outCrypt.SetWrite(&outFile, privateKey); outCrypt.SetWrite(&outFile, privateKey);
@ -272,7 +272,7 @@ void TestCryptoArchive()
d.TraceDetail("Verifying using asymmetric key\n"); d.TraceDetail("Verifying using asymmetric key\n");
cFileArchive inFile; cFileArchive inFile;
inFile.OpenRead(TEMP_DIR _T("/rsacrypted.bin")); inFile.OpenRead(TwTestPath("rsacrypted.bin").c_str());
cRSAArchive inCrypt; cRSAArchive inCrypt;
inCrypt.SetRead(&inFile, publicKey); inCrypt.SetRead(&inFile, publicKey);

View File

@ -73,8 +73,7 @@ void TestDebug()
// set up an output file...use the temp file in test.h // set up an output file...use the temp file in test.h
std::string str = TEMP_DIR_N; std::string str = TwTestPath("debug.out");
str += "/debug.out";
#ifdef DEBUG #ifdef DEBUG
TEST(cDebug::SetOutputFile(str.c_str())); TEST(cDebug::SetOutputFile(str.c_str()));

View File

@ -62,18 +62,17 @@ static void PrintProps(const iFCO* pFCO)
void TestFCOCompare() void TestFCOCompare()
{ {
const TCHAR* FILE_NAME = TEMP_DIR _T("/dog.txt"); std::string filename = TwTestPath("dog.txt");
const char* FILE_NAME_N = TEMP_DIR_N "/dog.txt";
cDebug d("TestFCOCompare"); cDebug d("TestFCOCompare");
d.TraceDebug("Entering...\n"); d.TraceDebug("Entering...\n");
// first, create an fco to compare with... // first, create an fco to compare with...
TOFSTREAM fstr(FILE_NAME_N); TOFSTREAM fstr(filename);
if(fstr.bad()) if(fstr.bad())
{ {
d.TraceError("Unable to create test file %s!\n", FILE_NAME); d.TraceError("Unable to create test file %s!\n", filename.c_str());
TEST(false); TEST(false);
return; return;
} }
@ -83,7 +82,7 @@ void TestFCOCompare()
// create the test FCO // create the test FCO
cFSDataSourceIter ds; cFSDataSourceIter ds;
ds.SeekToFCO(cFCOName(FILE_NAME), false); ds.SeekToFCO(cFCOName(filename), false);
iFCO* pFCO = ds.CreateFCO(); iFCO* pFCO = ds.CreateFCO();
TEST(pFCO); TEST(pFCO);
@ -110,10 +109,10 @@ void TestFCOCompare()
// change the file... // change the file...
d.TraceDebug("Changing the file...\n"); d.TraceDebug("Changing the file...\n");
fstr.open(FILE_NAME); fstr.open(filename);
if(fstr.bad()) if(fstr.bad())
{ {
d.TraceError("Unable to reopen %s!\n", FILE_NAME_N); d.TraceError("Unable to reopen %s!\n", filename.c_str());
TEST(false); TEST(false);
return; return;
} }
@ -123,7 +122,7 @@ void TestFCOCompare()
//need a new data source iter, otherwise the existing FCO gets updated & you get a ref to it, //need a new data source iter, otherwise the existing FCO gets updated & you get a ref to it,
// and the resulting FCOs always match. // and the resulting FCOs always match.
cFSDataSourceIter ds2; cFSDataSourceIter ds2;
ds2.SeekToFCO(cFCOName(FILE_NAME), false); ds2.SeekToFCO(cFCOName(filename), false);
iFCO* pFCO2 = ds2.CreateFCO(); iFCO* pFCO2 = ds2.CreateFCO();
TEST(pFCO2); TEST(pFCO2);
pFCO2->AcceptVisitor(&propCalc); pFCO2->AcceptVisitor(&propCalc);
@ -137,7 +136,7 @@ void TestFCOCompare()
//result.mPropVector.TraceContents(); //result.mPropVector.TraceContents();
cFSDataSourceIter ds3; cFSDataSourceIter ds3;
ds3.SeekToFCO(cFCOName(FILE_NAME), false); ds3.SeekToFCO(cFCOName(filename), false);
// try testing properties that weren't calculated... // try testing properties that weren't calculated...
d.TraceDebug("Comparing FCOs with different properties calculated\n"); d.TraceDebug("Comparing FCOs with different properties calculated\n");
iFCO* pFCO3 = ds3.CreateFCO(); iFCO* pFCO3 = ds3.CreateFCO();

View File

@ -39,8 +39,7 @@
void TestFile() void TestFile()
{ {
TSTRING fileName = TEMP_DIR; TSTRING fileName = TwTestPath("file_test.bin");
fileName += _T("/file_test.bin");
//Create a temporary file for testing: //Create a temporary file for testing:
FILE* testStream; FILE* testStream;

View File

@ -49,8 +49,7 @@ using namespace std;
void TestFileUtil() void TestFileUtil()
{ {
TSTRING source = TEMP_DIR; TSTRING source = TwTestPath("copy_src");
source += _T("/copy_src");
//Create a temporary file for testing: //Create a temporary file for testing:
FILE* testStream; FILE* testStream;
@ -64,8 +63,7 @@ void TestFileUtil()
fwrite( testString.c_str(), sizeof(TCHAR), iTestStringLength, testStream ); fwrite( testString.c_str(), sizeof(TCHAR), iTestStringLength, testStream );
fclose( testStream ); fclose( testStream );
TSTRING dest = TEMP_DIR; TSTRING dest = TwTestPath("copy_dest");
dest += "/copy_dest";
TEST(cFileUtil::Copy(source, dest)); TEST(cFileUtil::Copy(source, dest));

View File

@ -43,6 +43,8 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <unistd.h>
#include <fcntl.h>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// PrintProps -- prints out all the valid property names and values as pairs... // PrintProps -- prints out all the valid property names and values as pairs...
@ -67,8 +69,7 @@ void TestFSPropCalc()
{ {
cDebug d("TestFSPropCalc"); cDebug d("TestFSPropCalc");
cFSDataSourceIter ds; cFSDataSourceIter ds;
TSTRING foo_bin = TEMP_DIR; TSTRING foo_bin = TwTestPath("foo.bin");
foo_bin.append("/foo.bin");
//iFSServices* pFSServices = iFSServices::GetInstance(); //iFSServices* pFSServices = iFSServices::GetInstance();
@ -138,3 +139,20 @@ void TestFSPropCalc()
return; return;
} }
void TestGetSymLinkStr()
{
std::string file = TwTestPath("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
std::string link = TwTestPath("linky");
int fd = creat(file.c_str(), 0777);
close(fd);
symlink(file.c_str(), link.c_str());
cMemoryArchive arch(1024*1024);
TEST(cFSPropCalc::GetSymLinkStr(link, arch, 8));
TEST(arch.Length() == (int64)file.size());
}

View File

@ -73,9 +73,9 @@ void TestFCOSpecImpl()
cFSDataSourceIter dataSrc; cFSDataSourceIter dataSrc;
// test AllChildStopPoint fcos... // test AllChildStopPoint fcos...
d.TraceDebug("Now testing a spec whose start point is the only thing it maps to (%s)\n", TEMP_DIR); d.TraceDebug("Now testing a spec whose start point is the only thing it maps to (%s)\n", TwTestDir().c_str());
cFCOSpecImpl* pSpec2 = new cFCOSpecImpl(TEMP_DIR, &dataSrc, new cFCOSpecNoChildren); cFCOSpecImpl* pSpec2 = new cFCOSpecImpl(TwTestDir(), &dataSrc, new cFCOSpecNoChildren);
pSpec2->SetStartPoint(cFCOName(TEMP_DIR)); pSpec2->SetStartPoint(cFCOName(TwTestDir()));
dataSrc.SeekToFCO(pSpec2->GetStartPoint(), false); dataSrc.SeekToFCO(pSpec2->GetStartPoint(), false);
iFCO* pFCO = dataSrc.CreateFCO(); iFCO* pFCO = dataSrc.CreateFCO();
TEST(pFCO); TEST(pFCO);

View File

@ -114,11 +114,11 @@ void TestKeyFile()
// save to and read from disk // save to and read from disk
d.TraceDebug("Read/Write to file...\n"); d.TraceDebug("Read/Write to file...\n");
{ {
keyfile.WriteFile(TEMP_DIR _T("/keyfile.key")); keyfile.WriteFile(TwTestPath("keyfile.key").c_str());
cKeyFile keyfile2; cKeyFile keyfile2;
TEST(!keyfile2.KeysLoaded()); TEST(!keyfile2.KeysLoaded());
keyfile2.ReadFile(TEMP_DIR _T("/keyfile.key")); keyfile2.ReadFile(TwTestPath("keyfile.key").c_str());
TEST(keyfile2.KeysLoaded()); TEST(keyfile2.KeysLoaded());
cElGamalSig elGamal(*keyfile2.GetPublicKey()); cElGamalSig elGamal(*keyfile2.GetPublicKey());

View File

@ -119,7 +119,7 @@ void TestSerializerImpl()
// writing // writing
{ {
cFileArchive file; cFileArchive file;
file.OpenReadWrite(TEMP_DIR _T("/tmp.bin")); file.OpenReadWrite(TwTestPath("tmp.bin").c_str());
cSerializerImpl serializer(file, cSerializerImpl::S_WRITE); cSerializerImpl serializer(file, cSerializerImpl::S_WRITE);
serializer.Init(); serializer.Init();
@ -127,16 +127,16 @@ void TestSerializerImpl()
cSerializerTestObject testobj; cSerializerTestObject testobj;
testobj.Write(&serializer); testobj.Write(&serializer);
db.TraceAlways(" Writeing object 1...\n"); db.TraceAlways(" Writing object 1...\n");
serializer.WriteObject(&testobj); serializer.WriteObject(&testobj);
db.TraceAlways(" Writeing object 2...\n"); db.TraceAlways(" Writing object 2...\n");
serializer.WriteObject(&testobj); serializer.WriteObject(&testobj);
db.TraceAlways(" Writeing object 3...\n"); db.TraceAlways(" Writing object 3...\n");
serializer.WriteObject(&testobj); serializer.WriteObject(&testobj);
db.TraceAlways(" Writeing object 4...\n"); db.TraceAlways(" Writing object 4...\n");
serializer.WriteObject(&testobj); serializer.WriteObject(&testobj);
serializer.Finit(); serializer.Finit();
@ -145,7 +145,7 @@ void TestSerializerImpl()
// reading // reading
{ {
cFileArchive file; cFileArchive file;
file.OpenRead(TEMP_DIR _T("/tmp.bin")); file.OpenRead(TwTestPath("tmp.bin").c_str());
cSerializerImpl serializer(file, cSerializerImpl::S_READ); cSerializerImpl serializer(file, cSerializerImpl::S_READ);
serializer.Init(); serializer.Init();

View File

@ -87,8 +87,7 @@ void TestSignature()
//sha : Oia1aljHD793tfj7M55tND+3OG/ //sha : Oia1aljHD793tfj7M55tND+3OG/
//haval : BL6bFSo0EP5zf8lGSueeed //haval : BL6bFSo0EP5zf8lGSueeed
TSTRING sigFileName = TEMP_DIR; TSTRING sigFileName = TwTestPath("signature_test.bin");
sigFileName += TSTRING( _T("/signature_test.bin") );
cFileArchive fileArc; cFileArchive fileArc;
fileArc.OpenReadWrite(sigFileName.c_str()); fileArc.OpenReadWrite(sigFileName.c_str());

View File

@ -39,6 +39,8 @@
#include "core/debug.h" #include "core/debug.h"
#endif #endif
#include "test.h"
TSTRING test_wost(int, const TSTRING&); TSTRING test_wost(int, const TSTRING&);
void test_wist(const TSTRING&, cDebug& d); void test_wist(const TSTRING&, cDebug& d);
@ -87,8 +89,8 @@ void TestTCHAR()
//Testing file streams //Testing file streams
//explict constructors of 'TIFSTREAM' and "TOFSTREAM' take char* //explict constructors of 'TIFSTREAM' and "TOFSTREAM' take char*
const char* inputfile = "fun"; std::string inputfile = TwTestPath("fun");
const char* outputfile = "mo'fun"; std::string outputfile = TwTestPath("mo'fun");
//Set up the input file. //Set up the input file.
TOFSTREAM out; TOFSTREAM out;

View File

@ -42,8 +42,6 @@
#include "twparser/twparser.h" #include "twparser/twparser.h"
#include "tw/tw.h" #include "tw/tw.h"
#include "fco/fco.h" #include "fco/fco.h"
#include "fs/fs.h" #include "fs/fs.h"
#include "util/util.h" #include "util/util.h"
@ -51,6 +49,7 @@
#include "core/debug.h" #include "core/debug.h"
#include "core/error.h" #include "core/error.h"
#include "core/twlocale.h" #include "core/twlocale.h"
#include "core/fsservices.h"
#include "test.h" #include "test.h"
#include "core/errorbucketimpl.h" #include "core/errorbucketimpl.h"
#include "tw/twinit.h" #include "tw/twinit.h"
@ -62,6 +61,8 @@
#include "db/blockrecordarray.h" #include "db/blockrecordarray.h"
#include "db/hierdatabase.h" #include "db/hierdatabase.h"
#include <unistd.h>
#include <sys/stat.h>
// the test routines // the test routines
void TestFCOName(); void TestFCOName();
@ -99,7 +100,7 @@ void TestTextReportViewer();
void TestFCONameTbl(); void TestFCONameTbl();
void TestConfigFile(); void TestConfigFile();
void TestResources(); void TestResources();
void TestGetSymLinkStr();
void TestPolicyParser(); void TestPolicyParser();
void TestFCOSpecHelper(); void TestFCOSpecHelper();
@ -187,7 +188,7 @@ static void Test(int testID)
case 14: TestFCOPropVector(); break; case 14: TestFCOPropVector(); break;
case 15: TestFCOPropImpl(); break; case 15: TestFCOPropImpl(); break;
case 16: TestFCOReport(); break; case 16: TestFCOReport(); break;
case 17: TestGetSymLinkStr(); break;
case 18: TestFCOSetImpl(); break; case 18: TestFCOSetImpl(); break;
case 19: TestFCOSpec(); break; case 19: TestFCOSpec(); break;
case 20: TestFCOSpecAttr(); break; case 20: TestFCOSpecAttr(); break;
@ -294,6 +295,31 @@ static void Test(int testID)
TCERR << std::endl << "=== test ID #" << testID << " currently unused ===" << std::endl; TCERR << std::endl << "=== test ID #" << testID << " currently unused ===" << std::endl;
} }
std::string TwTestDir()
{
static std::string dir;
if(dir.empty())
{
iFSServices::GetInstance()->GetCurrentDir(dir);
dir.append("/TWTestData");
TCERR << "Using test directory: " << dir << std::endl;
mkdir(dir.c_str(), 0777);
}
return dir;
}
std::string TwTestPath(const std::string& child)
{
std::stringstream sstr;
sstr << TwTestDir();
if (child[0] != '/')
sstr << '/';
sstr << child;
return sstr.str();
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// cTest // cTest
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -75,9 +75,9 @@ TSS_EndPackage( cTest )
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Platform dependancies
#define TEMP_DIR _T("/tmp") std::string TwTestDir();
#define TEMP_DIR_N "/tmp" std::string TwTestPath(const std::string& child);
#endif // __TEST_H #endif // __TEST_H

View File

@ -380,7 +380,7 @@ void TestTextReportViewer()
d.TraceDebug("Read in serialized report:\n"); d.TraceDebug("Read in serialized report:\n");
//TraceReport(inReport, d); //TraceReport(inReport, d);
trv.PrintTextReport(TSTRING( TEMP_DIR _T( "/test2.txt" ) ) ); trv.PrintTextReport(TSTRING( TwTestPath("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("") );

View File

@ -58,10 +58,8 @@ void TestTWUtil()
// assuming the current dir is writable, this test should succeed // assuming the current dir is writable, this test should succeed
TEST(cFileUtil::FileWritable(_T("afilethatdoesnotexist.tmp")) == true); TEST(cFileUtil::FileWritable(_T("afilethatdoesnotexist.tmp")) == true);
TSTRING tmpDir = TEMP_DIR; TSTRING tmpDir = TwTestPath("fileexistdir");
tmpDir += _T("/fileexistdir"); TSTRING tmpFN = TwTestPath("fileexiststest.tmp");
TSTRING tmpFN = tmpDir;
tmpFN += _T("/fileexiststest.tmp");
// make a subdir in the TEMP_DIR // make a subdir in the TEMP_DIR
mkdir(tmpDir.c_str(), 0700); mkdir(tmpDir.c_str(), 0700);
@ -77,14 +75,14 @@ void TestTWUtil()
TEST(cFileUtil::FileWritable(tmpFN) == true) TEST(cFileUtil::FileWritable(tmpFN) == true)
TEST(cFileUtil::FileExists(tmpFN) == false); TEST(cFileUtil::FileExists(tmpFN) == false);
// make the dir read only and make sure write tests false
// windows fails this test, perhaps because I am an administrator?
chmod(tmpDir.c_str(), 0500);
bool is_root = (0 == getuid()); bool is_root = (0 == getuid());
TEST(cFileUtil::FileWritable(tmpFN) == is_root); // make the dir read only and make sure write tests false
// windows fails this test, perhaps because I am an administrator?
chmod(tmpDir.c_str(), 0700); // chmod(tmpDir.c_str(), 0500);
// TODO - is this valid now that we don't use /tmp?
// TEST(cFileUtil::FileWritable(tmpFN) == is_root);
// chmod(tmpDir.c_str(), 0700);
// create the file // create the file
{ {

View File

@ -54,9 +54,9 @@ void TestUnixFSServices()
iFSServices* pFSServices = iFSServices::GetInstance(); iFSServices* pFSServices = iFSServices::GetInstance();
// working primarily with the temp dir. // working primarily with the temp dir.
cFCOName name(_T("/tmp")); cFCOName name(TwTestDir());
// Check to make sure /tmp is a dir // Check to make sure test dir is a dir
//TEST(pFSServices->GetFileType(name) == cFSStatArgs::TY_DIR); //TEST(pFSServices->GetFileType(name) == cFSStatArgs::TY_DIR);
// get directory contents (test readdir) // get directory contents (test readdir)
@ -80,7 +80,7 @@ void TestUnixFSServices()
cFSStatArgs stat; cFSStatArgs stat;
//TO DO: use archive to create this file //TO DO: use archive to create this file
TSTRING testfile = "/tmp/tmp.tmp"; TSTRING testfile = TwTestPath("tmp.tmp");
cFileArchive filearch; cFileArchive filearch;
filearch.OpenReadWrite(testfile.c_str()); filearch.OpenReadWrite(testfile.c_str());
filearch.Seek(0, cBidirArchive::BEGINNING); filearch.Seek(0, cBidirArchive::BEGINNING);
@ -150,7 +150,7 @@ void TestUnixFSServices()
// test Rename // test Rename
d.TraceDetail("Testing Rename:\n"); d.TraceDetail("Testing Rename:\n");
TSTRING newtestfile = _T("/tmp/new.tmp"); TSTRING newtestfile = TwTestPath("new.tmp");
TEST( pFSServices->Rename( testfile, newtestfile ) ); TEST( pFSServices->Rename( testfile, newtestfile ) );
// test FileDelete // test FileDelete