VirtualBox

Ignore:
Timestamp:
Jul 21, 2023 2:19:42 PM (18 months ago)
Author:
vboxsync
Message:

Shared Clipboard: More code for HTTP server testcase to make it fully automatic; now creates a random test file which then gets downloaded. bugref:9437

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/testcase/tstClipboardHttpServer.cpp

    r100676 r100679  
    3333#include <iprt/message.h>
    3434#include <iprt/path.h>
     35#include <iprt/rand.h>
    3536#include <iprt/string.h>
    3637#include <iprt/test.h>
     
    6869
    6970    return RTTimeMilliTS() - msStartTS <= g_msRuntime ? VINF_SUCCESS : VERR_TIMEOUT;
     71}
     72
     73static void tstCreateTransferSingle(RTTEST hTest, PSHCLTRANSFERCTX pTransferCtx, PSHCLHTTPSERVER pSrv,
     74                                    const char *pszFile, PSHCLTXPROVIDER pProvider)
     75{
     76    PSHCLTRANSFER pTx;
     77    RTTEST_CHECK_RC_OK(hTest, ShClTransferCreate(SHCLTRANSFERDIR_TO_REMOTE, SHCLSOURCE_LOCAL, NULL /* Callbacks */, &pTx));
     78    RTTEST_CHECK_RC_OK(hTest, ShClTransferSetProvider(pTx, pProvider));
     79    RTTEST_CHECK_RC_OK(hTest, ShClTransferInit(pTx));
     80    RTTEST_CHECK_RC_OK(hTest, ShClTransferRootsInitFromFile(pTx, pszFile));
     81    RTTEST_CHECK_RC_OK(hTest, ShClTransferCtxRegister(pTransferCtx, pTx, NULL));
     82    RTTEST_CHECK_RC_OK(hTest, ShClTransferHttpServerRegisterTransfer(pSrv, pTx));
    7083}
    7184
     
    211224            case VINF_GETOPT_NOT_OPTION:
    212225            {
    213                 PSHCLTRANSFER pTx;
    214                 RTTEST_CHECK_RC_OK(hTest, ShClTransferCreate(SHCLTRANSFERDIR_TO_REMOTE, SHCLSOURCE_LOCAL, NULL /* Callbacks */, &pTx));
    215                 RTTEST_CHECK_RC_OK(hTest, ShClTransferSetProvider(pTx, &Provider));
    216                 RTTEST_CHECK_RC_OK(hTest, ShClTransferInit(pTx));
    217                 RTTEST_CHECK_RC_OK(hTest, ShClTransferRootsInitFromFile(pTx, ValueUnion.psz));
    218                 RTTEST_CHECK_RC_OK(hTest, ShClTransferCtxRegister(&TxCtx, pTx, NULL));
    219                 RTTEST_CHECK_RC_OK(hTest, ShClTransferHttpServerRegisterTransfer(&HttpSrv, pTx));
     226                tstCreateTransferSingle(hTest, &TxCtx, &HttpSrv, ValueUnion.psz, &Provider);
    220227                break;
    221228            }
     
    226233    }
    227234
     235    char szRandomTestFile[RTPATH_MAX] = { 0 };
     236
    228237    uint32_t const cTx = ShClTransferCtxGetTotalTransfers(&TxCtx);
    229238    if (!cTx)
    230         return RTMsgErrorExit(RTEXITCODE_SYNTAX, "No files to serve specified!\n");
     239    {
     240        RTTEST_CHECK_RC_OK(hTest, RTPathTemp(szRandomTestFile, sizeof(szRandomTestFile)));
     241        RTTEST_CHECK_RC_OK(hTest, RTPathAppend(szRandomTestFile, sizeof(szRandomTestFile), "tstClipboardHttpServer-XXXXXX"));
     242        RTTEST_CHECK_RC_OK(hTest, RTFileCreateTemp(szRandomTestFile, 0600));
     243
     244        size_t cbExist = RTRandU32Ex(0, _256M);
     245
     246        RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Random test file (%zu bytes): %s\n", cbExist, szRandomTestFile);
     247
     248        RTFILE hFile;
     249        rc = RTFileOpen(&hFile, szRandomTestFile, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE);
     250        if (RT_SUCCESS(rc))
     251        {
     252            uint8_t abBuf[_64K] = { 42 };
     253
     254            while (cbExist > 0)
     255            {
     256                size_t cbToWrite = sizeof(abBuf);
     257                if (cbToWrite > cbExist)
     258                    cbToWrite = cbExist;
     259                rc = RTFileWrite(hFile, abBuf, cbToWrite, NULL);
     260                if (RT_FAILURE(rc))
     261                {
     262                    RTTestIFailed("RTFileWrite(%#x) -> %Rrc\n", cbToWrite, rc);
     263                    break;
     264                }
     265                cbExist -= cbToWrite;
     266            }
     267
     268            RTTESTI_CHECK_RC(RTFileClose(hFile), VINF_SUCCESS);
     269
     270            if (RT_SUCCESS(rc))
     271            {
     272                tstCreateTransferSingle(hTest, &TxCtx, &HttpSrv, szRandomTestFile, &Provider);
     273            }
     274        }
     275        else
     276            RTTestIFailed("RTFileOpen(%s) -> %Rrc\n", szRandomTestFile, rc);
     277    }
     278
     279    if (RTTestErrorCount(hTest))
     280        return RTTestSummaryAndDestroy(hTest);
    231281
    232282    /* Create  thread for our HTTP server. */
     
    241291    }
    242292
    243 
    244293    if (RT_SUCCESS(rc))
    245294    {
     
    270319                for (unsigned a = 0; a < 3; a++) /* Repeat downloads to stress things. */
    271320                {
    272                     for (uint32_t i = 0; i < cTx; i++)
     321                    for (uint32_t i = 0; i < ShClTransferCtxGetTotalTransfers(&TxCtx); i++)
    273322                    {
    274323                        PSHCLTRANSFER pTx = ShClTransferCtxGetTransferByIndex(&TxCtx, i);
     
    299348    ShClTransferCtxDestroy(&TxCtx);
    300349
     350    if (strlen(szRandomTestFile))
     351        RTTEST_CHECK_RC_OK(hTest, RTFileDelete(szRandomTestFile));
     352
    301353    /*
    302354     * Summary
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette