VirtualBox

Ignore:
Timestamp:
Jun 16, 2019 3:27:39 AM (5 years ago)
Author:
vboxsync
Message:

tdAddGuestCtrl.py: Extended directory listing test to check names, sizes and types against the vboxtestfileset.TestFileSet object. bugref:9151 bugref:9320

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/vboxtestfileset.py

    r79158 r79159  
    4747
    4848
     49
     50class GstFsObj(object):
     51    """ A file system object we created in the guest for test purposes. """
     52    def __init__(self, oParent, sPath):
     53        self.oParent   = oParent    # type: GstDir
     54        self.sPath     = sPath      # type: str
     55        self.sName     = sPath      # type: str
     56        if oParent:
     57            assert sPath.startswith(oParent.sPath);
     58            self.sName = sPath[len(oParent.sPath) + 1:];
     59            # Add to parent.
     60            oParent.aoChildren.append(self);
     61            oParent.dChildrenUpper[self.sName.upper()] = self;
     62
     63class GstFile(GstFsObj):
     64    """ A file object in the guest. """
     65    def __init__(self, oParent, sPath, abContent):
     66        GstFsObj.__init__(self, oParent, sPath);
     67        self.abContent = abContent          # type: bytearray
     68        self.cbContent = len(abContent);
     69        self.off       = 0;
     70
     71    def read(self, cbToRead):
     72        assert self.off <= self.cbContent;
     73        cbLeft = self.cbContent - self.off;
     74        if cbLeft < cbToRead:
     75            cbToRead = cbLeft;
     76        abRet = self.abContent[self.off:(self.off + cbToRead)];
     77        assert len(abRet) == cbToRead;
     78        self.off += cbToRead;
     79        return abRet;
     80
     81class GstDir(GstFsObj):
     82    """ A file object in the guest. """
     83    def __init__(self, oParent, sPath):
     84        GstFsObj.__init__(self, oParent, sPath);
     85        self.aoChildren     = []  # type: list(GsFsObj)
     86        self.dChildrenUpper = {}  # type: dict(str,GsFsObj)
     87
     88    def contains(self, sName):
     89        """ Checks if the directory contains the given name. """
     90        return sName.upper() in self.dChildrenUpper
     91
     92
    4993class TestFileSet(object):
    5094    """
     
    5498    utility from the validation kit.
    5599    """
    56 
    57     class GstFsObj(object):
    58         """ A file system object we created in the guest for test purposes. """
    59         def __init__(self, oParent, sPath):
    60             self.oParent   = oParent    # type: GstDir
    61             self.sPath     = sPath      # type: str
    62             self.sName     = sPath      # type: str
    63             if oParent:
    64                 assert sPath.startswith(oParent.sPath);
    65                 self.sName = sPath[len(oParent.sPath) + 1:];
    66                 # Add to parent.
    67                 oParent.aoChildren.append(self);
    68                 oParent.dChildrenUpper[self.sName.upper()] = self;
    69 
    70     class GstFile(GstFsObj):
    71         """ A file object in the guest. """
    72         def __init__(self, oParent, sPath, abContent):
    73             TestFileSet.GstFsObj.__init__(self, oParent, sPath);
    74             self.abContent = abContent          # type: bytearray
    75             self.cbContent = len(abContent);
    76             self.off       = 0;
    77 
    78         def read(self, cbToRead):
    79             assert self.off <= self.cbContent;
    80             cbLeft = self.cbContent - self.off;
    81             if cbLeft < cbToRead:
    82                 cbToRead = cbLeft;
    83             abRet = self.abContent[self.off:(self.off + cbToRead)];
    84             assert len(abRet) == cbToRead;
    85             self.off += cbToRead;
    86             return abRet;
    87 
    88     class GstDir(GstFsObj):
    89         """ A file object in the guest. """
    90         def __init__(self, oParent, sPath):
    91             TestFileSet.GstFsObj.__init__(self, oParent, sPath);
    92             self.aoChildren     = []  # type: list(GsFsObj)
    93             self.dChildrenUpper = {}  # type: dict(str,GsFsObj)
    94 
    95         def contains(self, sName):
    96             """ Checks if the directory contains the given name. """
    97             return sName.upper() in self.dChildrenUpper
    98 
    99100
    100101    ksReservedWinOS2         = '/\\"*:<>?|\t\v\n\r\f\a\b';
     
    164165        ## Number of directories under oTreeDir.
    165166        self.cTreeDirs  = 0;
     167        ## Number of other file types under oTreeDir.
     168        self.cTreeOthers = 0;
    166169
    167170        ## All directories in creation order.
     
    242245        Creates a test directory.
    243246        """
    244         oDir = TestFileSet.GstDir(oParent, sDir);
     247        oDir = GstDir(oParent, sDir);
    245248        self.aoDirs.append(oDir);
    246249        self.dPaths[sDir] = oDir;
     
    254257        abContent = bytearray(self.oRandom.getrandbits(8) for _ in xrange(cbFile));
    255258
    256         oFile = TestFileSet.GstFile(oParent, sFile, abContent);
     259        oFile = GstFile(oParent, sFile, abContent);
    257260        self.aoFiles.append(oFile);
    258261        self.dPaths[sFile] = oFile;
     
    418421        return True;
    419422
    420 
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