Make sure cFile_i is constructed & destructed cleanly; clean up GetSymLinkStr a bit more; improve Debug/Basic & UnixFSServices/GetExecutableFilename unit tests
This commit is contained in:
parent
a4ae3af444
commit
7545beb0e6
|
@ -83,13 +83,14 @@ struct cFile_i
|
||||||
|
|
||||||
//Ctor
|
//Ctor
|
||||||
cFile_i::cFile_i() :
|
cFile_i::cFile_i() :
|
||||||
mpCurrStream(NULL)
|
m_fd(-1), mpCurrStream(NULL), mFlags(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//Dtor
|
//Dtor
|
||||||
cFile_i::~cFile_i()
|
cFile_i::~cFile_i()
|
||||||
{
|
{
|
||||||
if (mpCurrStream != NULL)
|
if (mpCurrStream != NULL)
|
||||||
|
{
|
||||||
fclose( mpCurrStream );
|
fclose( mpCurrStream );
|
||||||
mpCurrStream = NULL;
|
mpCurrStream = NULL;
|
||||||
|
|
||||||
|
@ -103,8 +104,7 @@ cFile_i::~cFile_i()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
mFileName.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -90,7 +90,7 @@ bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t s
|
||||||
std::vector<char> data(size+1);
|
std::vector<char> data(size+1);
|
||||||
char* buf = &data[0];
|
char* buf = &data[0];
|
||||||
|
|
||||||
#if defined(O_PATH)
|
#if defined(O_PATH) // A Linuxism that lets us read symlinks w/o bumping the access time.
|
||||||
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, size);
|
int rtn = readlinkat(fd, 0, buf, size);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -98,7 +98,7 @@ bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t s
|
||||||
int rtn = readlink( strName.c_str(), buf, size );
|
int rtn = readlink( strName.c_str(), buf, size );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(rtn == -1)
|
if(rtn < 0)
|
||||||
{
|
{
|
||||||
// Some OSes (like HP-UX) return ERANGE if buffer is too small.
|
// Some OSes (like HP-UX) return ERANGE if buffer is too small.
|
||||||
// This is nonstandard but better than the usual truncate-and-say-you-succeeded
|
// This is nonstandard but better than the usual truncate-and-say-you-succeeded
|
||||||
|
|
|
@ -88,6 +88,11 @@ void TestDebug()
|
||||||
if(oldOutTarget & cDebug::OUT_FILE) cDebug::AddOutTarget(cDebug::OUT_FILE); else cDebug::RemoveOutTarget(cDebug::OUT_FILE);
|
if(oldOutTarget & cDebug::OUT_FILE) cDebug::AddOutTarget(cDebug::OUT_FILE); else cDebug::RemoveOutTarget(cDebug::OUT_FILE);
|
||||||
|
|
||||||
d.TraceDebug("Exiting...\n");
|
d.TraceDebug("Exiting...\n");
|
||||||
|
|
||||||
|
#ifndef DEBUG
|
||||||
|
TEST("Should always succeed in release builds & cDebug should do nothing");
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterSuite_Debug()
|
void RegisterSuite_Debug()
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
#include "twtest/test.h"
|
#include "twtest/test.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,6 +179,9 @@ void TestGetIPAddress()
|
||||||
|
|
||||||
void TestGetExecutableFilename()
|
void TestGetExecutableFilename()
|
||||||
{
|
{
|
||||||
|
if( -1 == access("/bin/sh", F_OK))
|
||||||
|
skip("/bin/sh not found/accessible");
|
||||||
|
|
||||||
TSTRING filename = _T("sh");
|
TSTRING filename = _T("sh");
|
||||||
TSTRING fullpath = _T("/bin/");
|
TSTRING fullpath = _T("/bin/");
|
||||||
TEST( iFSServices::GetInstance()->GetExecutableFilename(fullpath, filename));
|
TEST( iFSServices::GetInstance()->GetExecutableFilename(fullpath, filename));
|
||||||
|
|
Loading…
Reference in New Issue