📄 ihxfiletest.cpp
字号:
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file, are
* subject to the current version of the RealNetworks Public Source License
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
* in which case the RCSL will apply. You may also obtain the license terms
* directly from RealNetworks. You may not use this file except in
* compliance with the RPSL or, if you have a valid RCSL with RealNetworks
* applicable to this file, the RCSL. Please see the applicable RPSL or
* RCSL for the rights, obligations and limitations governing use of the
* contents of the file.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the portions
* it created.
*
* This file, and the files included with this file, is distributed and made
* available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
#include "hx_ut_debug.h"
#include "datffact.h"
#include "hxbuffer.h"
#include "hlxclib/sys/stat.h"
#include "chxdataf.h"
#include "cihx2chxdataf.h"
#include "ut_param_util.h"
#include "filetestutil.h"
#include "ihxfiletest.h"
HLXIHXFileTest::HLXIHXFileTest(const char* pModeString)
: m_pIHXDataFile(NULL)
, m_pCHXDataFile(NULL)
, m_pCHXDirectory(NULL)
, m_DataFileMode('i')
, m_bTestDir(false)
{
if ((!pModeString) || (strncmp(pModeString, "ihx", 3) == 0))
{
m_DataFileMode = 'i';
// Use "ihx" file object test
HXDataFileFactory* pDataFileFactory = new HXDataFileFactory;
if (pDataFileFactory)
{
IUnknown* pPersistentObj = NULL;
pDataFileFactory->AddRef();
pDataFileFactory->CreateFile(m_pIHXDataFile,
NULL, // context
pPersistentObj,
TRUE, // mem. mapped I/O
0, // page size
FALSE, // file locking
FALSE); // prefer sync. object
pDataFileFactory->Release();
HX_RELEASE(pPersistentObj);
}
m_bTestDir = (strcmp(pModeString, "ihxdir") == 0);
}
else if (strncmp(pModeString, "chx", 3) == 0)
{
m_DataFileMode = 'c';
CIHX2CHXDataFile* pIHX2CHXDataFile = new CIHX2CHXDataFile();
if (pIHX2CHXDataFile)
{
pIHX2CHXDataFile->AddRef();
m_pIHXDataFile = pIHX2CHXDataFile;
m_pCHXDataFile = pIHX2CHXDataFile->GetCHXDataFile();
pIHX2CHXDataFile = NULL;
}
HX_RELEASE(pIHX2CHXDataFile);
m_bTestDir = (strcmp(pModeString, "chxdir") == 0);
}
if (m_bTestDir)
{
m_pCHXDirectory = new CHXDirectory();
}
}
HLXIHXFileTest::~HLXIHXFileTest()
{
HX_RELEASE(m_pIHXDataFile);
HX_DELETE(m_pCHXDirectory);
}
void HLXIHXFileTest::GetCommandInfo(UTVector<HLXUnitTestCmdInfo*>& cmds)
{
cmds.Resize(28);
cmds[0] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Bind",
&HLXIHXFileTest::HandleBindCmd,
2);
cmds[1] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Create",
&HLXIHXFileTest::HandleCreateCmd,
3);
cmds[2] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Open",
&HLXIHXFileTest::HandleOpenCmd,
3);
cmds[3] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Close",
&HLXIHXFileTest::HandleCloseCmd,
2);
cmds[4] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Name",
&HLXIHXFileTest::HandleNameCmd,
2,
3);
cmds[5] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"IsOpen",
&HLXIHXFileTest::HandleIsOpenCmd,
2);
cmds[6] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Write",
&HLXIHXFileTest::HandleWriteCmd,
3);
cmds[7] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Read",
&HLXIHXFileTest::HandleReadCmd,
3,
4);
cmds[8] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Flush",
&HLXIHXFileTest::HandleFlushCmd,
2);
cmds[9] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Seek",
&HLXIHXFileTest::HandleSeekCmd,
4);
cmds[10] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Tell",
&HLXIHXFileTest::HandleTellCmd,
1,
2);
cmds[11] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Stat",
&HLXIHXFileTest::HandleStatCmd,
2,
3);
cmds[12] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Delete",
&HLXIHXFileTest::HandleDeleteCmd,
2,
3);
cmds[13] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"GetFd",
&HLXIHXFileTest::HandleGetFdCmd,
2);
cmds[14] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"GetLastErrorCode",
&HLXIHXFileTest::HandleGetLastErrorCodeCmd,
2);
cmds[15] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"GetLastErrorString",
&HLXIHXFileTest::HandleGetLastErrorStringCmd,
1);
cmds[16] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Rewind",
&HLXIHXFileTest::HandleRewindCmd,
2);
cmds[17] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"GetTempName",
&HLXIHXFileTest::HandleGetTempNameCmd,
1);
cmds[18] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"SetDirPath",
&HLXIHXFileTest::HandleSetDirPathCmd,
2);
cmds[19] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"GetDirPath",
&HLXIHXFileTest::HandleGetDirPathCmd,
2,
3);
cmds[20] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"CreateDir",
&HLXIHXFileTest::HandleCreateDirCmd,
2);
cmds[21] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"IsDirValid",
&HLXIHXFileTest::HandleIsDirValidCmd,
2);
cmds[22] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"DestroyDir",
&HLXIHXFileTest::HandleDestroyDirCmd,
2,
3);
cmds[23] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"DeleteDirFile",
&HLXIHXFileTest::HandleDeleteDirFileCmd,
3);
cmds[24] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"MakeCurrentDir",
&HLXIHXFileTest::HandleMakeCurrentDirCmd,
2);
cmds[25] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"FindFirstInDir",
&HLXIHXFileTest::HandleFindFirstInDirCmd,
4,
5);
cmds[26] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"FindNextInDir",
&HLXIHXFileTest::HandleFindNextInDirCmd,
3,
4);
cmds[27] = new HLXUnitTestCmdInfoDisp<HLXIHXFileTest>(this,
"Rename",
&HLXIHXFileTest::HandleRenameCmd,
4);
}
HLXCmdBasedTest* HLXIHXFileTest::Clone() const
{
char pModeString[10]; /* Flawfinder: ignore */
if (m_DataFileMode == 'c')
{
strcpy(pModeString, "chx"); /* Flawfinder: ignore */
}
else
{
strcpy(pModeString, "ihx"); /* Flawfinder: ignore */
}
if (m_bTestDir)
{
strcat(pModeString, "dir"); /* Flawfinder: ignore */
}
return new HLXIHXFileTest(pModeString);
}
/*****************************************************************************
* DataFile Commands
*/
bool HLXIHXFileTest::HandleBindCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
m_pIHXDataFile->Bind((const char*) info[1]);
bRetVal = true;
}
return bRetVal;
}
bool HLXIHXFileTest::HandleCreateCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
HX_RESULT retVal = m_pIHXDataFile->Create(
CFileTestUtil::ParseModeString(info[1]));
bRetVal = (retVal == HXR_OK);
bRetVal = (bRetVal == CFileTestUtil::ParseResultString(info[2]));
}
return bRetVal;
}
bool HLXIHXFileTest::HandleOpenCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
HX_RESULT retVal = m_pIHXDataFile->Open(
CFileTestUtil::ParseModeString(info[1]));
bRetVal = (retVal == HXR_OK);
bRetVal = (bRetVal == CFileTestUtil::ParseResultString(info[2]));
}
return bRetVal;
}
bool HLXIHXFileTest::HandleCloseCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
HX_RESULT retVal = m_pIHXDataFile->Close();
bRetVal = (retVal == HXR_OK);
bRetVal = (bRetVal == CFileTestUtil::ParseResultString(info[1]));
}
return bRetVal;
}
bool HLXIHXFileTest::HandleFlushCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
HX_RESULT retVal = m_pIHXDataFile->Flush();
bRetVal = (retVal == HXR_OK);
bRetVal = (bRetVal == CFileTestUtil::ParseResultString(info[1]));
}
return bRetVal;
}
bool HLXIHXFileTest::HandleNameCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
IHXBuffer* pHXBuffer = NULL;
BOOL bResultVal;
bResultVal = m_pIHXDataFile->Name(pHXBuffer);
bRetVal = (bResultVal ? true : false);
bRetVal = (bRetVal == (CFileTestUtil::ParseResultString(info[1]) ? true : false));
if (bRetVal && bResultVal)
{
bRetVal = false;
if (pHXBuffer)
{
if (info.Nelements() > 2)
{
bRetVal = CFileTestUtil::CheckString(info[2], pHXBuffer);
}
else
{
bRetVal = true;
}
}
}
HX_RELEASE(pHXBuffer);
}
return bRetVal;
}
bool HLXIHXFileTest::HandleGetTempNameCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
if (m_pCHXDataFile)
{
char* pTempName = new char [_MAX_PATH + 1];
if (pTempName)
{
pTempName[0] = '\0';
bRetVal = (m_pCHXDataFile->
GetTemporaryFileName("test", pTempName, _MAX_PATH + 1) != 0);
if (bRetVal)
{
bRetVal = false;
if ((strlen(pTempName) > 0) &&
(strlen(pTempName) <= _MAX_PATH))
{
bRetVal = true;
}
}
delete [] pTempName;
}
}
else
{
bRetVal = true;
}
}
return bRetVal;
}
bool HLXIHXFileTest::HandleIsOpenCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
bRetVal = (m_pIHXDataFile->IsOpen() != FALSE);
bRetVal = (bRetVal == CFileTestUtil::ParseBoolString(info[1]));
}
return bRetVal;
}
bool HLXIHXFileTest::HandleWriteCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
IHXBuffer* pHXBuffer = new CHXBuffer();
if (pHXBuffer)
{
pHXBuffer->AddRef();
if (pHXBuffer->Set((const UINT8*) ((const char*) info[1]),
strlen(info[1])) == HXR_OK)
{
ULONG32 ulRetSize;
ULONG32 ulInSize;
ulInSize = pHXBuffer->GetSize();
ulRetSize = m_pIHXDataFile->Write(pHXBuffer);
bRetVal = (ulRetSize == ulInSize);
bRetVal = (bRetVal == CFileTestUtil::ParseResultString(info[2]));
}
pHXBuffer->Release();
}
}
return bRetVal;
}
bool HLXIHXFileTest::HandleReadCmd(const UTVector<UTString>& info)
{
bool bRetVal = false;
if (m_pIHXDataFile)
{
unsigned int uiReadSize = 0;
if (UTParamUtil::GetUInt(info[1], uiReadSize))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -