VirtualBox

Changeset 66038 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Mar 10, 2017 3:18:45 PM (8 years ago)
Author:
vboxsync
Message:

tstSharedFolderService: Added testcase for case-insensitive create-file.

Location:
trunk/src/VBox/HostServices/SharedFolders
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.cpp

    r66014 r66038  
    3737#include <iprt/stream.h>
    3838#include <iprt/test.h>
     39#include <iprt/string.h>
     40#include <iprt/utf16.h>
    3941
    4042#include "teststubs.h"
     
    116118*   Stub functions and data                                                                                                      *
    117119*********************************************************************************************************************************/
     120static bool g_fFailIfNotLowercase = false;
    118121
    119122static PRTDIR g_testRTDirClosepDir;
     
    134137 /* RTPrintf("%s: pszPath=%s, fMode=0x%llx\n", __PRETTY_FUNCTION__, pszPath,
    135138             LLUIFY(fMode)); */
     139    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszPath, "/\\")))
     140        return VERR_FILE_NOT_FOUND;
    136141    ARRAY_FROM_PATH(testRTDirCreatePath, pszPath);
    137142    return 0;
     
    139144
    140145static char testRTDirOpenName[256];
     146static struct TESTDIRHANDLE
     147{
     148    int iEntry;
     149    int iDir;
     150} g_aTestDirHandles[4];
     151static int g_iNextDirHandle = 0;
    141152static PRTDIR testRTDirOpenpDir;
    142153
     
    144155{
    145156 /* RTPrintf("%s: pszPath=%s\n", __PRETTY_FUNCTION__, pszPath); */
     157    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszPath, "/\\")))
     158        return VERR_FILE_NOT_FOUND;
    146159    ARRAY_FROM_PATH(testRTDirOpenName, pszPath);
    147160    *ppDir = testRTDirOpenpDir;
    148161    testRTDirOpenpDir = 0;
     162    if (!*ppDir && g_fFailIfNotLowercase)
     163        *ppDir = (PRTDIR)&g_aTestDirHandles[g_iNextDirHandle++ % RT_ELEMENTS(g_aTestDirHandles)];
     164    if (*ppDir)
     165    {
     166        struct TESTDIRHANDLE *pRealDir = (struct TESTDIRHANDLE *)*ppDir;
     167        pRealDir->iEntry = 0;
     168        pRealDir->iDir   = 0;
     169        const char *pszSlash = pszPath - 1;
     170        while ((pszSlash = strpbrk(pszSlash + 1, "\\/")) != NULL)
     171            pRealDir->iDir += 1;
     172        /*RTPrintf("opendir %s = %d \n", pszPath, pRealDir->iDir);*/
     173    }
    149174    return VINF_SUCCESS;
    150175}
     
    154179{
    155180 /* RTPrintf("%s: pszPath=%s\n", __PRETTY_FUNCTION__, pszPath); */
     181    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszPath, "/\\")))
     182        return VERR_FILE_NOT_FOUND;
    156183    ARRAY_FROM_PATH(testRTDirOpenName, pszPath);
    157184    *ppDir = testRTDirOpenpDir;
    158185    testRTDirOpenpDir = 0;
     186    if (!*ppDir && g_fFailIfNotLowercase)
     187        *ppDir = (PRTDIR)&g_aTestDirHandles[g_iNextDirHandle++ % RT_ELEMENTS(g_aTestDirHandles)];
     188    if (*ppDir)
     189    {
     190        struct TESTDIRHANDLE *pRealDir = (struct TESTDIRHANDLE *)*ppDir;
     191        pRealDir->iEntry = 0;
     192        pRealDir->iDir   = 0;
     193        const char *pszSlash = pszPath - 1;
     194        while ((pszSlash = strpbrk(pszSlash + 1, "\\/")) != NULL)
     195            pRealDir->iDir += 1;
     196        pRealDir->iDir -= 1;
     197        /*RTPrintf("openfiltered %s = %d\n", pszPath, pRealDir->iDir);*/
     198    }
    159199    return VINF_SUCCESS;
    160200}
     
    177217extern int testRTDirRemove(const char *pszPath)
    178218{
    179     RT_NOREF1(pszPath);
     219    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszPath, "/\\")))
     220        return VERR_FILE_NOT_FOUND;
    180221    RTPrintf("%s\n", __PRETTY_FUNCTION__);
    181222    return 0;
     
    192233             LLUIFY(enmAdditionalAttribs), LLUIFY(fFlags)); */
    193234    g_testRTDirReadExDir = pDir;
     235    if (g_fFailIfNotLowercase && pDir)
     236    {
     237        struct TESTDIRHANDLE *pRealDir = (struct TESTDIRHANDLE *)pDir;
     238        if (pRealDir->iDir == 2) /* /test/mapping/ */
     239        {
     240            if (pRealDir->iEntry == 0)
     241            {
     242                pRealDir->iEntry++;
     243                RT_ZERO(*pDirEntry);
     244                pDirEntry->Info.Attr.fMode = RTFS_TYPE_DIRECTORY | RTFS_DOS_DIRECTORY | RTFS_UNIX_IROTH | RTFS_UNIX_IXOTH;
     245                pDirEntry->cbName = 4;
     246                pDirEntry->cwcShortName = 4;
     247                strcpy(pDirEntry->szName, "test");
     248                RTUtf16CopyAscii(pDirEntry->wszShortName, RT_ELEMENTS(pDirEntry->wszShortName), "test");
     249                /*RTPrintf("readdir: 'test'\n");*/
     250                return VINF_SUCCESS;
     251            }
     252        }
     253        else if (pRealDir->iDir == 3) /* /test/mapping/test/ */
     254        {
     255            if (pRealDir->iEntry == 0)
     256            {
     257                pRealDir->iEntry++;
     258                RT_ZERO(*pDirEntry);
     259                pDirEntry->Info.Attr.fMode = RTFS_TYPE_FILE | RTFS_DOS_NT_NORMAL | RTFS_UNIX_IROTH | RTFS_UNIX_IXOTH;
     260                pDirEntry->cbName = 4;
     261                pDirEntry->cwcShortName = 4;
     262                strcpy(pDirEntry->szName, "file");
     263                RTUtf16CopyAscii(pDirEntry->wszShortName, RT_ELEMENTS(pDirEntry->wszShortName), "file");
     264                /*RTPrintf("readdir: 'file'\n");*/
     265                return VINF_SUCCESS;
     266            }
     267        }
     268        /*else RTPrintf("%s: iDir=%d\n", pRealDir->iDir);*/
     269    }
    194270    return VERR_NO_MORE_FILES;
    195271}
     
    226302extern int  testRTFileDelete(const char *pszFilename)
    227303{
    228     RT_NOREF1(pszFilename);
     304    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszFilename, "/\\")))
     305        return VERR_FILE_NOT_FOUND;
    229306    RTPrintf("%s\n", __PRETTY_FUNCTION__);
    230307    return 0;
     
    267344    ARRAY_FROM_PATH(testRTFileOpenName, pszFilename);
    268345    testRTFileOpenFlags = fOpen;
     346    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszFilename, "/\\")))
     347        return VERR_FILE_NOT_FOUND;
    269348    *pFile = testRTFileOpenpFile;
    270349    testRTFileOpenpFile = 0;
     
    408487extern int testRTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags)
    409488{
    410     RT_NOREF3(pszPath, enmAdditionalAttribs, fFlags);
     489    RT_NOREF2(enmAdditionalAttribs, fFlags);
    411490 /* RTPrintf("%s: pszPath=%s, enmAdditionalAttribs=0x%x, fFlags=0x%x\n",
    412491             __PRETTY_FUNCTION__, pszPath, (unsigned) enmAdditionalAttribs,
    413492             (unsigned) fFlags); */
     493    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszPath, "/\\")))
     494        return VERR_FILE_NOT_FOUND;
    414495    RT_ZERO(*pObjInfo);
    415496    return VINF_SUCCESS;
     
    419500{
    420501    RT_NOREF2(pszSymlink, fDelete);
     502    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszSymlink, "/\\")))
     503        return VERR_FILE_NOT_FOUND;
    421504    RTPrintf("%s\n", __PRETTY_FUNCTION__);
    422505    return 0;
     
    425508extern int testRTSymlinkRead(const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead)
    426509{
     510    if (g_fFailIfNotLowercase && !RTStrIsLowerCased(strpbrk(pszSymlink, "/\\")))
     511        return VERR_FILE_NOT_FOUND;
    427512    RT_NOREF4(pszSymlink, pszTarget, cbTarget, fRead);
    428513    RTPrintf("%s\n", __PRETTY_FUNCTION__);
     
    525610                                        VBOXHGCMSVCHELPERS *psvcHelpers,
    526611                                        const char *pcszFolderName,
    527                                         const char *pcszMapping)
     612                                        const char *pcszMapping,
     613                                        bool fCaseSensitive = true)
    528614{
    529615    VBOXHGCMSVCPARM aParms[RT_MAX(SHFL_CPARMS_ADD_MAPPING,
     
    553639    aParms[1].setUInt32(0);  /* root */
    554640    aParms[2].setUInt32('/');  /* delimiter */
    555     aParms[3].setUInt32(1);  /* case sensitive */
     641    aParms[3].setUInt32(fCaseSensitive);
    556642    psvcTable->pfnCall(psvcTable->pvService, &callHandle, 0,
    557643                       psvcTable->pvService, SHFL_FN_MAP_FOLDER,
     
    767853}
    768854
    769 void testCreateDirSimple(RTTEST hTest)
     855void testCreateFileSimpleCaseInsensitive(RTTEST hTest)
    770856{
    771857    VBOXHGCMSVCFNTABLE  svcTable;
    772858    VBOXHGCMSVCHELPERS  svcHelpers;
    773859    SHFLROOT Root;
    774     PRTDIR pcDir = (PRTDIR)0x10000;
     860    const RTFILE hcFile = (RTFILE) 0x10000;
     861    SHFLCREATERESULT Result;
     862    int rc;
     863
     864    g_fFailIfNotLowercase = true;
     865
     866    RTTestSub(hTest, "Create file case insensitive");
     867    Root = initWithWritableMapping(hTest, &svcTable, &svcHelpers,
     868                                   "/test/mapping", "testname", false /*fCaseSensitive*/);
     869    testRTFileOpenpFile = hcFile;
     870    rc = createFile(&svcTable, Root, "/TesT/FilE", SHFL_CF_ACCESS_READ, NULL,
     871                    &Result);
     872    RTTEST_CHECK_RC_OK(hTest, rc);
     873
     874    RTTEST_CHECK_MSG(hTest,
     875                     !strcmp(&testRTFileOpenName[RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS ? 2 : 0],
     876                             "/test/mapping/test/file"),
     877                     (hTest, "pszFilename=%s\n", &testRTFileOpenName[RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS ? 2 : 0]));
     878    RTTEST_CHECK_MSG(hTest, testRTFileOpenFlags == 0x181,
     879                     (hTest, "fOpen=%llu\n", LLUIFY(testRTFileOpenFlags)));
     880    RTTEST_CHECK_MSG(hTest, Result == SHFL_FILE_CREATED,
     881                     (hTest, "Result=%d\n", (int) Result));
     882    unmapAndRemoveMapping(hTest, &svcTable, Root, "testname");
     883    AssertReleaseRC(svcTable.pfnDisconnect(NULL, 0, svcTable.pvService));
     884    RTTestGuardedFree(hTest, svcTable.pvService);
     885    RTTEST_CHECK_MSG(hTest, g_testRTFileCloseFile == hcFile,
     886                     (hTest, "File=%u\n", (uintptr_t)g_testRTFileCloseFile));
     887
     888    g_fFailIfNotLowercase = false;
     889}
     890
     891void testCreateDirSimple(RTTEST hTest)
     892{
     893    VBOXHGCMSVCFNTABLE  svcTable;
     894    VBOXHGCMSVCHELPERS  svcHelpers;
     895    SHFLROOT Root;
     896    PRTDIR pDir = (PRTDIR)&g_aTestDirHandles[g_iNextDirHandle++ % RT_ELEMENTS(g_aTestDirHandles)];
    775897    SHFLCREATERESULT Result;
    776898    int rc;
     
    779901    Root = initWithWritableMapping(hTest, &svcTable, &svcHelpers,
    780902                                   "/test/mapping", "testname");
    781     testRTDirOpenpDir = pcDir;
     903    testRTDirOpenpDir = pDir;
    782904    rc = createFile(&svcTable, Root, "test/dir",
    783905                    SHFL_CF_DIRECTORY | SHFL_CF_ACCESS_READ, NULL, &Result);
     
    796918    AssertReleaseRC(svcTable.pfnDisconnect(NULL, 0, svcTable.pvService));
    797919    RTTestGuardedFree(hTest, svcTable.pvService);
    798     RTTEST_CHECK_MSG(hTest, g_testRTDirClosepDir == pcDir, (hTest, "pDir=%p\n", g_testRTDirClosepDir));
     920    RTTEST_CHECK_MSG(hTest, g_testRTDirClosepDir == pDir, (hTest, "pDir=%p\n", g_testRTDirClosepDir));
    799921}
    800922
     
    8961018    VBOXHGCMSVCHELPERS  svcHelpers;
    8971019    SHFLROOT Root;
    898     PRTDIR pcDir = (PRTDIR)0x10000;
     1020    PRTDIR pDir = (PRTDIR)&g_aTestDirHandles[g_iNextDirHandle++ % RT_ELEMENTS(g_aTestDirHandles)];
    8991021    SHFLHANDLE Handle;
    9001022    SHFLDIRINFO DirInfo;
     
    9051027    Root = initWithWritableMapping(hTest, &svcTable, &svcHelpers,
    9061028                                   "/test/mapping", "testname");
    907     testRTDirOpenpDir = pcDir;
     1029    testRTDirOpenpDir = pDir;
    9081030    rc = createFile(&svcTable, Root, "test/dir",
    9091031                    SHFL_CF_DIRECTORY | SHFL_CF_ACCESS_READ, &Handle, NULL);
     
    9121034                 &DirInfo, sizeof(DirInfo), 0, &cFiles);
    9131035    RTTEST_CHECK_RC(hTest, rc, VERR_NO_MORE_FILES);
    914     RTTEST_CHECK_MSG(hTest, g_testRTDirReadExDir == pcDir, (hTest, "Dir=%p\n", g_testRTDirReadExDir));
     1036    RTTEST_CHECK_MSG(hTest, g_testRTDirReadExDir == pDir, (hTest, "Dir=%p\n", g_testRTDirReadExDir));
    9151037    RTTEST_CHECK_MSG(hTest, cFiles == 0,
    9161038                     (hTest, "cFiles=%llu\n", LLUIFY(cFiles)));
     
    9181040    AssertReleaseRC(svcTable.pfnDisconnect(NULL, 0, svcTable.pvService));
    9191041    RTTestGuardedFree(hTest, svcTable.pvService);
    920     RTTEST_CHECK_MSG(hTest, g_testRTDirClosepDir == pcDir, (hTest, "pDir=%p\n", g_testRTDirClosepDir));
     1042    RTTEST_CHECK_MSG(hTest, g_testRTDirClosepDir == pDir, (hTest, "pDir=%p\n", g_testRTDirClosepDir));
    9211043}
    9221044
     
    9661088    VBOXHGCMSVCHELPERS  svcHelpers;
    9671089    SHFLROOT Root;
    968     const PRTDIR pcDir = (PRTDIR) 0x10000;
     1090    const PRTDIR pDir = (PRTDIR)&g_aTestDirHandles[g_iNextDirHandle++ % RT_ELEMENTS(g_aTestDirHandles)];
    9691091    const int64_t ccAtimeNano = 100000;
    9701092    SHFLFSOBJINFO Info;
     
    9751097    Root = initWithWritableMapping(hTest, &svcTable, &svcHelpers,
    9761098                                   "/test/mapping", "testname");
    977     testRTDirOpenpDir = pcDir;
     1099    testRTDirOpenpDir = pDir;
    9781100    rc = createFile(&svcTable, Root, "test/dir",
    9791101                    SHFL_CF_DIRECTORY | SHFL_CF_ACCESS_READ, &Handle, NULL);
     
    9841106                       &Info);
    9851107    RTTEST_CHECK_RC_OK(hTest, rc);
    986     RTTEST_CHECK_MSG(hTest, g_testRTDirQueryInfoDir == pcDir, (hTest, "Dir=%p\n", g_testRTDirQueryInfoDir));
     1108    RTTEST_CHECK_MSG(hTest, g_testRTDirQueryInfoDir == pDir, (hTest, "Dir=%p\n", g_testRTDirQueryInfoDir));
    9871109    RTTEST_CHECK_MSG(hTest, RTTimeSpecGetNano(&Info.AccessTime) == ccAtimeNano,
    9881110                     (hTest, "ATime=%llu\n",
     
    10001122    AssertReleaseRC(svcTable.pfnDisconnect(NULL, 0, svcTable.pvService));
    10011123    RTTestGuardedFree(hTest, svcTable.pvService);
    1002     RTTEST_CHECK_MSG(hTest, g_testRTDirClosepDir == pcDir, (hTest, "pDir=%p\n", g_testRTDirClosepDir));
     1124    RTTEST_CHECK_MSG(hTest, g_testRTDirClosepDir == pDir, (hTest, "pDir=%p\n", g_testRTDirClosepDir));
    10031125}
    10041126
  • trunk/src/VBox/HostServices/SharedFolders/testcase/tstSharedFolderService.h

    r62489 r66038  
    5454/* Sub-tests for testCreate(). */
    5555void testCreateFileSimple(RTTEST hTest);
     56void testCreateFileSimpleCaseInsensitive(RTTEST hTest);
    5657void testCreateDirSimple(RTTEST hTest);
    5758void testCreateBadParameters(RTTEST hTest);
  • trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp

    r65999 r66038  
    812812    /* Simple opening of an existing file. */
    813813    testCreateFileSimple(hTest);
     814    testCreateFileSimpleCaseInsensitive(hTest);
    814815    /* Simple opening of an existing directory. */
    815816    /** @todo How do wildcards in the path name work? */
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