Rework fileutil_t test to not require /etc/hosts; tweak twutil_t test to work properly if run as root

This commit is contained in:
Brian Cox 2017-07-08 16:29:34 -07:00
parent 122010acc2
commit 65d97e2892
3 changed files with 32 additions and 15 deletions

View File

@ -99,7 +99,7 @@ void TestFCOPropVector()
d.TraceDetail("Object manipulation tests are not successful\n");
return;
}//end TestPropVector
}
static bool init (cFCOPropVector &testV)
{
@ -111,7 +111,7 @@ static bool init (cFCOPropVector &testV)
return false;
} //end for
return true;
} //end init
}
static bool addRemove (cFCOPropVector &test1, cFCOPropVector &test2, cDebug& d)
@ -141,7 +141,7 @@ static bool addRemove (cFCOPropVector &test1, cFCOPropVector &test2, cDebug& d)
out &= local; //and-ing of results.
return out;
}//end addRemove
}
static bool objManip (cFCOPropVector &testV, cDebug& d)
{
@ -201,4 +201,4 @@ static bool objManip (cFCOPropVector &testV, cDebug& d)
TEST((v1 ^ v2) == v3);
return out;
}//end objManip
}

View File

@ -38,6 +38,8 @@
#include "util/stdutil.h"
#include "util/fileutil.h"
#include "core/debug.h"
#include "test.h"
#include <unistd.h>
using namespace std;
@ -47,15 +49,27 @@ using namespace std;
void TestFileUtil()
{
if(cFileUtil::FileExists("/etc/hosts"))
{
TSTRING source, dest;
TSTRING source = TEMP_DIR;
source += _T("/copy_src");
source = _T("/etc/hosts");
dest = _T("/tmp/dest");
bool blah = cFileUtil::Copy(source, dest);
(void)blah;
// TCOUT << _T("<") << wstr3 << _T(">") << std::endl;
}
//Create a temporary file for testing:
FILE* testStream;
testStream = _tfopen( source.c_str(), _T("w+b"));
TEST(testStream);
TSTRING testString( _T("This is a test") );
int iTestStringLength = testString.length();
//Write some data to the stream...
fwrite( testString.c_str(), sizeof(TCHAR), iTestStringLength, testStream );
fclose( testStream );
TSTRING dest = TEMP_DIR;
dest += "/copy_dest";
TEST(cFileUtil::Copy(source, dest));
unlink(dest.c_str());
unlink(source.c_str());
}

View File

@ -80,7 +80,10 @@ void TestTWUtil()
// 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);
TEST(cFileUtil::FileWritable(tmpFN) == false);
bool is_root = (0 == getuid());
TEST(cFileUtil::FileWritable(tmpFN) == is_root);
chmod(tmpDir.c_str(), 0700);
// create the file
@ -91,7 +94,7 @@ void TestTWUtil()
// test a read only file
chmod(tmpFN.c_str(), 0400);
TEST(cFileUtil::FileWritable(tmpFN) == false);
TEST(cFileUtil::FileWritable(tmpFN) == is_root);
// test a writable file
chmod(tmpFN.c_str(), 0666);