本文整理汇总了C++中RTTestISub函数的典型用法代码示例。如果您正苦于以下问题:C++ RTTestISub函数的具体用法?C++ RTTestISub怎么用?C++ RTTestISub使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTTestISub函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tst1
/**
* Basic API checks.
*/
static void tst1(void)
{
RTTestISub("Manifest creation");
size_t cbSize = 0;
size_t iFailed = 0;
/*
* test1.txt = "This is a test text."
* test2.txt = "Another test text."
*/
static RTMANIFESTTEST /*const*/ s_aFiles[] = /** @todo API misdesign, this should be const. */
{
{ "test1.txt", "794a8cc644b318ae6461aeea62915e399e441e8" },
{ "test2.txt", "f17393902ee94c1e8bbd4bf417cdc70051feca00" }
};
static const char s_szTestPattern[] =
"SHA1 (test1.txt)= 794a8cc644b318ae6461aeea62915e399e441e8\n"
"SHA1 (test2.txt)= f17393902ee94c1e8bbd4bf417cdc70051feca00\n"
;
void *pvBuf = NULL;
RTTESTI_CHECK_RC_RETV(RTManifestWriteFilesBuf(&pvBuf, &cbSize, RTDIGESTTYPE_SHA1, s_aFiles, 2), VINF_SUCCESS);
/* Check returned memory size */
RTTESTI_CHECK_RETV(cbSize == strlen(s_szTestPattern));
/* Check for correct manifest file content */
RTTESTI_CHECK(memcmp(pvBuf, s_szTestPattern, cbSize) == 0);
RTTestISub("Manifest verify");
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VINF_SUCCESS);
/* To little files to check */
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 1, 0), VERR_MANIFEST_FILE_MISMATCH);
/* Make the digest type invalid */
((char*)pvBuf)[0] = 'L';
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VERR_MANIFEST_UNSUPPORTED_DIGEST_TYPE);
((char*)pvBuf)[0] = 'S'; /* Restore */
/* Make the file name invalid */
((char*)pvBuf)[8] = 'z';
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VERR_MANIFEST_FILE_MISMATCH);
((char*)pvBuf)[8] = 's'; /* Restore */
/* Make the second digest invalid */
((char*)pvBuf)[99] = '0';
RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, &iFailed), VERR_MANIFEST_DIGEST_MISMATCH);
RTTESTI_CHECK(iFailed == 1);
/* Cleanup */
RTMemFree(pvBuf);
}
示例2: test1
static void test1(RTTEST hTest, const char *pszBaseDir)
{
char szPath1[RTPATH_MAX];
char szPath2[RTPATH_MAX];
/*
* Making some assumptions about how we are executed from to start with...
*/
RTTestISub("Negative RTSymlinkRead, Exists & IsDangling");
char szExecDir[RTPATH_MAX];
RTTESTI_CHECK_RC_OK_RETV(RTPathExecDir(szExecDir, sizeof(szExecDir)));
size_t cchExecDir = strlen(szExecDir);
RTTESTI_CHECK(RTDirExists(szExecDir));
char szExecFile[RTPATH_MAX];
RTTESTI_CHECK_RETV(RTProcGetExecutablePath(szExecFile, sizeof(szExecFile)) != NULL);
size_t cchExecFile = strlen(szExecFile);
RTTESTI_CHECK(RTFileExists(szExecFile));
RTTESTI_CHECK(!RTSymlinkExists(szExecFile));
RTTESTI_CHECK(!RTSymlinkExists(szExecDir));
RTTESTI_CHECK(!RTSymlinkIsDangling(szExecFile));
RTTESTI_CHECK(!RTSymlinkIsDangling(szExecDir));
RTTESTI_CHECK(!RTSymlinkExists("/"));
RTTESTI_CHECK(!RTSymlinkIsDangling("/"));
RTTESTI_CHECK(!RTSymlinkExists("/some/non-existing/directory/name/iprt"));
RTTESTI_CHECK(!RTSymlinkExists("/some/non-existing/directory/name/iprt/"));
RTTESTI_CHECK(!RTSymlinkIsDangling("/some/non-existing/directory/name/iprt"));
RTTESTI_CHECK(!RTSymlinkIsDangling("/some/non-existing/directory/name/iprt/"));
RTTESTI_CHECK_RC(RTSymlinkRead(szExecFile, szPath1, sizeof(szPath1), 0), VERR_NOT_SYMLINK);
RTTESTI_CHECK_RC(RTSymlinkRead(szExecDir, szPath1, sizeof(szPath1), 0), VERR_NOT_SYMLINK);
/*
* Do some symlinking. ASSUME they are supported on the test file system.
*/
RTTestISub("Basics");
RTTESTI_CHECK_RETV(RTDirExists(pszBaseDir));
test1Worker(hTest, pszBaseDir, szExecFile, RTSYMLINKTYPE_FILE, false /*fDangling*/);
test1Worker(hTest, pszBaseDir, szExecDir, RTSYMLINKTYPE_DIR, false /*fDangling*/);
test1Worker(hTest, pszBaseDir, szExecFile, RTSYMLINKTYPE_UNKNOWN, false /*fDangling*/);
test1Worker(hTest, pszBaseDir, szExecDir, RTSYMLINKTYPE_UNKNOWN, false /*fDangling*/);
/*
* Create a few dangling links.
*/
RTTestISub("Dangling links");
test1Worker(hTest, pszBaseDir, "../dangle/dangle", RTSYMLINKTYPE_FILE, true /*fDangling*/);
test1Worker(hTest, pszBaseDir, "../dangle/dangle", RTSYMLINKTYPE_DIR, true /*fDangling*/);
test1Worker(hTest, pszBaseDir, "../dangle/dangle", RTSYMLINKTYPE_UNKNOWN, true /*fDangling*/);
test1Worker(hTest, pszBaseDir, "../dangle/dangle/", RTSYMLINKTYPE_UNKNOWN, true /*fDangling*/);
}
示例3: tst2
static void tst2(void)
{
RTTestISub("RTGetOptArgvToString / MS_CRT");
for (size_t i = 0; i < RT_ELEMENTS(g_aMscCrtTests); i++)
{
char *pszCmdLine = NULL;
int rc = RTGetOptArgvToString(&pszCmdLine, g_aMscCrtTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);
RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
if (!strcmp(g_aMscCrtTests[i].pszCmdLine, pszCmdLine))
tstCheckNativeMsCrtToArgv(pszCmdLine, -1, g_aMscCrtTests[i].apszArgs);
else
RTTestIFailed("g_aTest[%i] failed:\n"
" got '%s'\n"
" expected '%s'\n",
i, pszCmdLine, g_aMscCrtTests[i].pszCmdLine);
RTStrFree(pszCmdLine);
}
for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
{
char *pszCmdLine = NULL;
int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_MS_CRT);
RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
if (!strcmp(g_aTests[i].pszOutMsCrt, pszCmdLine))
tstCheckNativeMsCrtToArgv(pszCmdLine, g_aTests[i].cArgs, g_aTests[i].apszArgs);
else
RTTestIFailed("g_aTests[%i] failed:\n"
" got |%s|\n"
" expected |%s|\n",
i, pszCmdLine, g_aTests[i].pszOutMsCrt);
RTStrFree(pszCmdLine);
}
RTTestISub("RTGetOptArgvToString / BOURNE_SH");
for (size_t i = 0; i < RT_ELEMENTS(g_aTests); i++)
{
char *pszCmdLine = NULL;
int rc = RTGetOptArgvToString(&pszCmdLine, g_aTests[i].apszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
RTTESTI_CHECK_RC_RETV(rc, VINF_SUCCESS);
if (strcmp(g_aTests[i].pszOutBourneSh, pszCmdLine))
RTTestIFailed("g_aTests[%i] failed:\n"
" got |%s|\n"
" expected |%s|\n",
i, pszCmdLine, g_aTests[i].pszOutBourneSh);
RTStrFree(pszCmdLine);
}
}
示例4: testCopyEx1
static void testCopyEx1(RTTEST hTest)
{
RTTestISub("RTStrCopyEx");
char *pszBuf4H = (char *)RTTestGuardedAllocHead(hTest, 4);
char *pszBuf4T = (char *)RTTestGuardedAllocTail(hTest, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abc", RTSTR_MAX), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abc", RTSTR_MAX), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
RT_BZERO(pszBuf4H, 4); RT_BZERO(pszBuf4T, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abcd", RTSTR_MAX), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abcd", RTSTR_MAX), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
RT_BZERO(pszBuf4H, 4); RT_BZERO(pszBuf4T, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abcd", 3), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abcd", 3), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
RT_BZERO(pszBuf4H, 4); RT_BZERO(pszBuf4T, 4);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4H, 4, "abcd", 2), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "ab") == 0);
RTTESTI_CHECK_RC(RTStrCopyEx(pszBuf4T, 4, "abcd", 2), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "ab") == 0);
}
示例5: test1
static void test1(void)
{
RTTestISub("Three threads");
/*
* Create the threads and let them block on the event multi semaphore.
*/
RTSEMEVENTMULTI hSem;
RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&hSem), VINF_SUCCESS);
RTTHREAD hThread2;
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread2, test1Thread2, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test2"), VINF_SUCCESS);
RTThreadSleep(100);
RTTHREAD hThread1;
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread1, test1Thread1, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1"), VINF_SUCCESS);
/* Force first thread (which has a timeout of 1 second) to timeout in the
* first wait, and the second wait will succeed. */
RTTESTI_CHECK_RC(RTThreadSleep(1500), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadWait(hThread1, 5000, NULL), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadWait(hThread2, 5000, NULL), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTSemEventMultiDestroy(hSem), VINF_SUCCESS);
}
示例6: tstRTPipe5
static void tstRTPipe5(void)
{
RTTestISub("Inherit non-standard pipe handle, read end");
char szPathSelf[RTPATH_MAX];
RTTESTI_CHECK_RETV(RTProcGetExecutablePath(szPathSelf, sizeof(szPathSelf)) == szPathSelf);
RTPIPE hPipeR;
RTPIPE hPipeW;
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, RTPIPE_C_INHERIT_READ), VINF_SUCCESS);
RTHCINTPTR hNative = RTPipeToNative(hPipeR);
RTTESTI_CHECK_RETV(hNative != -1);
char szNative[64];
RTStrPrintf(szNative, sizeof(szNative), "%RHi", hNative);
const char *papszArgs[4] = { szPathSelf, "--child-5", szNative, NULL };
RTPROCESS hChild;
RTTESTI_CHECK_RC_RETV(RTProcCreate(szPathSelf, papszArgs, RTENV_DEFAULT, 0 /*fFlags*/, &hChild), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTPipeClose(hPipeR), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeW, g_szTest5Message, sizeof(g_szTest5Message) - 1, NULL), VINF_SUCCESS);
int rc;
RTTESTI_CHECK_RC(rc = RTPipeClose(hPipeW), VINF_SUCCESS);
if (RT_FAILURE(rc))
RTTESTI_CHECK_RC(RTProcTerminate(hChild), VINF_SUCCESS);
RTPROCSTATUS ProcStatus;
RTTESTI_CHECK_RC(rc = RTProcWait(hChild, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS);
if (RT_FAILURE(rc))
return;
RTTESTI_CHECK( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
&& ProcStatus.iStatus == 0);
}
示例7: test1
static void test1(const char *pszSubTest, const char *pszFilename)
{
int rc;
RTTestISub(pszSubTest);
RTFILE hFile;
rc = RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN);
if (RT_FAILURE(rc))
{
if ( rc == VERR_ACCESS_DENIED
|| rc == VERR_PERMISSION_DENIED
|| rc == VERR_FILE_NOT_FOUND)
{
RTTestIPrintf(RTTESTLVL_ALWAYS, "Cannot access '%s', skipping.", pszFilename);
return;
}
RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN), VINF_SUCCESS);
}
uint64_t cbFile = UINT64_MAX - 42;
RTTESTI_CHECK_RC(rc = RTFileGetSize(hFile, &cbFile), VINF_SUCCESS);
if (RT_SUCCESS(rc))
{
RTTESTI_CHECK(cbFile != UINT64_MAX - 42);
RTTestIValue(pszSubTest, cbFile, RTTESTUNIT_BYTES);
}
RTFileClose(hFile);
RTTestISubDone();
}
示例8: tstRTPipe2
static void tstRTPipe2(void)
{
RTTestISub("Negative");
RTPIPE hPipeR = (RTPIPE)1;
RTPIPE hPipeW = (RTPIPE)1;
RTTESTI_CHECK_RC(RTPipeCreate(&hPipeR, &hPipeW, ~0), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTPipeCreate(NULL, &hPipeW, 0), VERR_INVALID_POINTER);
RTTESTI_CHECK_RC(RTPipeCreate(&hPipeR, NULL, 0), VERR_INVALID_POINTER);
RTTESTI_CHECK(hPipeR == (RTPIPE)1);
RTTESTI_CHECK(hPipeW == (RTPIPE)1);
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, 0), VINF_SUCCESS);
char abBuf[_4K];
size_t cbRead = ~(size_t)3;
RTTESTI_CHECK_RC(RTPipeRead(hPipeW, abBuf, 0, &cbRead), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeRead(hPipeW, abBuf, 1, &cbRead), VERR_ACCESS_DENIED);
RTTESTI_CHECK(cbRead == ~(size_t)3);
RTTESTI_CHECK_RC(RTPipeReadBlocking(hPipeW, abBuf, 0, NULL), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeReadBlocking(hPipeW, abBuf, 1, NULL), VERR_ACCESS_DENIED);
size_t cbWrite = ~(size_t)5;
RTTESTI_CHECK_RC(RTPipeWrite(hPipeR, "asdf", 0, &cbWrite), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeWrite(hPipeR, "asdf", 4, &cbWrite), VERR_ACCESS_DENIED);
RTTESTI_CHECK(cbWrite == ~(size_t)5);
RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeR, "asdf", 0, NULL), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeWriteBlocking(hPipeR, "asdf", 4, NULL), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeFlush(hPipeR), VERR_ACCESS_DENIED);
RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
}
示例9: tstRTProcQueryUsername
static void tstRTProcQueryUsername(void)
{
RTTestISub("Basics");
size_t cbUser;
char szUser[1024];
memset(szUser, '-', sizeof(szUser));
/* negative stuff that may assert: */
bool fMayPanic = RTAssertSetMayPanic(false);
bool fQuiet = RTAssertSetQuiet(true);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 8, &cbUser), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, 0, &cbUser), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 0, NULL), VERR_INVALID_PARAMETER);
RTTESTI_CHECK_RC(RTProcQueryUsernameA(RTProcSelf(), NULL), VERR_INVALID_POINTER);
RTAssertSetMayPanic(fMayPanic);
RTAssertSetQuiet(fQuiet);
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), NULL, 0, &cbUser), VERR_BUFFER_OVERFLOW);
memset(szUser, '-', sizeof(szUser));
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, cbUser - 1, &cbUser), VERR_BUFFER_OVERFLOW);
memset(szUser, '-', sizeof(szUser));
RTTESTI_CHECK_RC(RTProcQueryUsername(RTProcSelf(), szUser, sizeof(szUser), &cbUser), VINF_SUCCESS);
RTTestPrintf(NULL, RTTESTLVL_ALWAYS, "Username: %s\n", szUser); /* */
char *pszUser = NULL;
RTTESTI_CHECK_RC(RTProcQueryUsernameA(RTProcSelf(), &pszUser), VINF_SUCCESS);
RTTestPrintf(NULL, RTTESTLVL_ALWAYS, "Username: %s\n", pszUser);
RTTESTI_CHECK(strcmp(pszUser, szUser) == 0);
RTStrFree(pszUser);
}
示例10: doStandaloneTests
static void doStandaloneTests(void)
{
RTTestISub("Standalone");
PCFGMNODE pRoot;;
RTTESTI_CHECK_RETV((pRoot = CFGMR3CreateTree(NULL)) != NULL);
doGeneralTests(pRoot);
CFGMR3DestroyTree(pRoot);
}
示例11: testBasics
static void testBasics(void)
{
RTTestISub("Basics");
RTSEMEVENTMULTI hSem;
RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&hSem), VINF_SUCCESS);
/* The semaphore is created in a reset state, calling reset explicitly
shouldn't make any difference. */
testBasicsWaitTimeout(hSem, 0);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS);
testBasicsWaitTimeout(hSem, 1);
if (RTTestIErrorCount())
return;
/* When signalling the semaphore all successive wait calls shall
succeed, signalling it again should make no difference. */
RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
testBasicsWaitSuccess(hSem, 2);
if (RTTestIErrorCount())
return;
/* After resetting it we should time out again. */
RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS);
testBasicsWaitTimeout(hSem, 3);
if (RTTestIErrorCount())
return;
/* The number of resets or signal calls shouldn't matter. */
RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS);
testBasicsWaitTimeout(hSem, 4);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
testBasicsWaitSuccess(hSem, 5);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiReset(hSem), VINF_SUCCESS);
testBasicsWaitTimeout(hSem, 6);
/* Destroy it. */
RTTESTI_CHECK_RC_RETV(RTSemEventMultiDestroy(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiDestroy(NIL_RTSEMEVENTMULTI), VINF_SUCCESS);
/* Whether it is reset (above), signalled or not used shouldn't matter. */
RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiDestroy(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC_RETV(RTSemEventMultiDestroy(hSem), VINF_SUCCESS);
RTTestISubDone();
}
示例12: tst2
/**
* Check hash and memory performance.
*/
static void tst2(void)
{
RTTestISub("Hash performance");
/*
* Generate test strings using a specific pseudo random generator.
*/
size_t cbStrings = 0;
char *apszTests[8192];
RTRAND hRand;
RTTESTI_CHECK_RC_RETV(RTRandAdvCreateParkMiller(&hRand), VINF_SUCCESS);
for (uint32_t i = 0; i < 8192; i++)
{
char szBuf[8192];
uint32_t cch = RTRandAdvU32Ex(hRand, 3, sizeof(szBuf) - 1);
RTRandAdvBytes(hRand, szBuf, cch);
szBuf[cch] = '\0';
for (uint32_t off = 0; off < cch; off++)
{
uint8_t b = szBuf[off];
b &= 0x7f;
if (!b || b == 0x7f)
b = ' ';
else if (RTLocCIsCntrl(b) && b != '\n' && b != '\r' && b != '\t')
b += 0x30;
szBuf[off] = b;
}
apszTests[i] = (char *)RTMemDup(szBuf, cch + 1);
RTTESTI_CHECK_RETV(apszTests[i] != NULL);
cbStrings += cch + 1;
}
RTRandAdvDestroy(hRand);
RTTestIValue("Average string", cbStrings / RT_ELEMENTS(apszTests), RTTESTUNIT_BYTES);
/*
* Test new insertion first time around.
*/
RTSTRCACHE hStrCache;
RTTESTI_CHECK_RC_RETV(RTStrCacheCreate(&hStrCache, "hash performance"), VINF_SUCCESS);
uint64_t nsTsStart = RTTimeNanoTS();
for (uint32_t i = 0; i < RT_ELEMENTS(apszTests); i++)
RTTESTI_CHECK_RETV(RTStrCacheEnter(hStrCache, apszTests[i]) != NULL);
uint64_t cNsElapsed = RTTimeNanoTS() - nsTsStart;
RTTestIValue("First insert", cNsElapsed / RT_ELEMENTS(apszTests), RTTESTUNIT_NS_PER_CALL);
/*
* Insert existing strings.
*/
nsTsStart = RTTimeNanoTS();
for (uint32_t i = 0; i < 8192; i++)
RTTESTI_CHECK(RTStrCacheEnter(hStrCache, apszTests[i]) != NULL);
cNsElapsed = RTTimeNanoTS() - nsTsStart;
RTTestIValue("Duplicate insert", cNsElapsed / RT_ELEMENTS(apszTests), RTTESTUNIT_NS_PER_CALL);
tstShowStats(hStrCache);
RTTESTI_CHECK_RC(RTStrCacheDestroy(hStrCache), VINF_SUCCESS);
}
示例13: testCat1
static void testCat1(RTTEST hTest)
{
RTTestISub("RTStrCat");
char *pszBuf4H = (char *)RTTestGuardedAllocHead(hTest, 4);
char *pszBuf4T = (char *)RTTestGuardedAllocTail(hTest, 4);
memset(pszBuf4T, 0xff, 4); *pszBuf4T = '\0';
RTTESTI_CHECK_RC(RTStrCat(pszBuf4H, 4, "abc"), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
memset(pszBuf4H, 0xff, 4); *pszBuf4H = '\0';
RTTESTI_CHECK_RC(RTStrCat(pszBuf4T, 4, "abc"), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
memset(pszBuf4T, 0xff, 4); strcpy(pszBuf4T, "a");
memset(pszBuf4H, 0xff, 4); strcpy(pszBuf4H, "a");
RTTESTI_CHECK_RC(RTStrCat(pszBuf4H, 4, "bc"), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCat(pszBuf4T, 4, "bc"), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
memset(pszBuf4T, 0xff, 4); strcpy(pszBuf4T, "ab");
memset(pszBuf4H, 0xff, 4); strcpy(pszBuf4H, "ab");
RTTESTI_CHECK_RC(RTStrCat(pszBuf4H, 4, "c"), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCat(pszBuf4T, 4, "c"), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
memset(pszBuf4T, 0xff, 4); strcpy(pszBuf4T, "abc");
memset(pszBuf4H, 0xff, 4); strcpy(pszBuf4H, "abc");
RTTESTI_CHECK_RC(RTStrCat(pszBuf4H, 4, ""), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCat(pszBuf4T, 4, ""), VINF_SUCCESS);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
memset(pszBuf4T, 0xff, 4); strcpy(pszBuf4T, "");
memset(pszBuf4H, 0xff, 4); strcpy(pszBuf4H, "");
RTTESTI_CHECK_RC(RTStrCat(pszBuf4H, 4, "abcd"), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCat(pszBuf4T, 4, "abcd"), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
memset(pszBuf4T, 0xff, 4); strcpy(pszBuf4T, "ab");
memset(pszBuf4H, 0xff, 4); strcpy(pszBuf4H, "ab");
RTTESTI_CHECK_RC(RTStrCat(pszBuf4H, 4, "cd"), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCat(pszBuf4T, 4, "cd"), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
memset(pszBuf4T, 0xff, 4); strcpy(pszBuf4T, "abc");
memset(pszBuf4H, 0xff, 4); strcpy(pszBuf4H, "abc");
RTTESTI_CHECK_RC(RTStrCat(pszBuf4H, 4, "d"), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4H, "abc") == 0);
RTTESTI_CHECK_RC(RTStrCat(pszBuf4T, 4, "d"), VERR_BUFFER_OVERFLOW);
RTTESTI_CHECK(strcmp(pszBuf4T, "abc") == 0);
}
示例14: tstRTCreateProcEx2
static void tstRTCreateProcEx2(const char *pszAsUser, const char *pszPassword)
{
RTTestISub("Standard Err");
RTPIPE hPipeR, hPipeW;
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, RTPIPE_C_INHERIT_WRITE), VINF_SUCCESS);
const char * apszArgs[3] =
{
"non-existing-non-executable-file",
"--testcase-child-2",
NULL
};
RTHANDLE Handle;
Handle.enmType = RTHANDLETYPE_PIPE;
Handle.u.hPipe = hPipeW;
RTPROCESS hProc;
RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL,
NULL, &Handle, pszAsUser, pszPassword, &hProc), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
char szOutput[_4K];
size_t offOutput = 0;
for (;;)
{
size_t cbLeft = sizeof(szOutput) - 1 - offOutput;
RTTESTI_CHECK(cbLeft > 0);
if (cbLeft == 0)
break;
size_t cbRead;
int rc = RTPipeReadBlocking(hPipeR, &szOutput[offOutput], cbLeft, &cbRead);
if (RT_FAILURE(rc))
{
RTTESTI_CHECK_RC(rc, VERR_BROKEN_PIPE);
break;
}
offOutput += cbRead;
}
szOutput[offOutput] = '\0';
RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
RTPROCSTATUS ProcStatus = { -1, RTPROCEXITREASON_ABEND };
RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS);
RTThreadSleep(10);
if (ProcStatus.enmReason != RTPROCEXITREASON_NORMAL || ProcStatus.iStatus != 0)
RTTestIFailed("enmReason=%d iStatus=%d", ProcStatus.enmReason, ProcStatus.iStatus);
else if ( offOutput != sizeof("howdy") - 1
|| strcmp(szOutput, "howdy"))
RTTestIFailed("wrong output: \"%s\" (len=%u)", szOutput, offOutput);
else
RTTestIPassed(NULL);
}
示例15: tstRTCreateProcEx4
static void tstRTCreateProcEx4(const char *pszAsUser, const char *pszPassword)
{
RTTestISub("Argument with spaces and stuff");
RTPROCESS hProc;
RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, g_apszArgs4, RTENV_DEFAULT, 0 /*fFlags*/, NULL,
NULL, NULL, pszAsUser, pszPassword, &hProc), VINF_SUCCESS);
RTPROCSTATUS ProcStatus = { -1, RTPROCEXITREASON_ABEND };
RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS);
if (ProcStatus.enmReason != RTPROCEXITREASON_NORMAL || ProcStatus.iStatus != 0)
RTTestIFailed("enmReason=%d iStatus=%d", ProcStatus.enmReason, ProcStatus.iStatus);
}