VirtualBox

Changeset 78472 in vbox


Ignore:
Timestamp:
May 12, 2019 6:28:36 PM (6 years ago)
Author:
vboxsync
Message:

validationkit/common/utils.py: areBytesEqual adjustment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r78464 r78472  
    20832083    # If both have the same type, use the compare operator of the class:
    20842084    if type(oLeft) is type(oRight):
     2085        #print('same type: %s' % (oLeft == oRight,));
    20852086        return oLeft == oRight;
    20862087
    20872088    # On the offchance that they're both strings, but of different types.
    20882089    if isString(oLeft) and isString(oRight):
     2090        #print('string compare: %s' % (oLeft == oRight,));
    20892091        return oLeft == oRight;
    20902092
     
    21072109    # Check if we now have the same type for both:
    21082110    if type(oLeft) is type(oRight):
     2111        #print('same type now: %s' % (oLeft == oRight,));
    21092112        return oLeft == oRight;
    21102113
    21112114    # Do item by item comparison:
    21122115    if len(oLeft) != len(oRight):
     2116        #print('different length: %s vs %s' % (len(oLeft), len(oRight)));
    21132117        return False;
    21142118    i = len(oLeft);
    21152119    while i > 0:
    21162120        i = i - 1;
    2117         if oLeft[i] != oRight[i]:
     2121
     2122        iElmLeft = oLeft[i];
     2123        if not isinstance(iElmLeft, int) and not isinstance(iElmLeft, long):
     2124            iElmLeft = ord(iElmLeft);
     2125
     2126        iElmRight = oRight[i];
     2127        if not isinstance(iElmRight, int) and not isinstance(iElmRight, long):
     2128            iElmRight = ord(iElmRight);
     2129
     2130        if iElmLeft != iElmRight:
     2131            #print('element %d differs: %x %x' % (i, iElmLeft, iElmRight,));
    21182132            return False;
    21192133    return True;
     
    21252139
    21262140# pylint: disable=C0111
     2141# pylint: disable=undefined-variable
    21272142class BuildCategoryDataTestCase(unittest.TestCase):
    21282143    def testIntervalSeconds(self):
     
    21632178        self.assertEqual(areBytesEqual(b'1234', bytearray([0x31,0x32,0x33,0x34])), True);
    21642179        self.assertEqual(areBytesEqual('1234', bytearray([0x31,0x32,0x33,0x34])), True);
     2180        self.assertEqual(areBytesEqual(u'1234', bytearray([0x31,0x32,0x33,0x34])), True);
    21652181        self.assertEqual(areBytesEqual(bytearray([0x31,0x32,0x33,0x34]), bytearray([0x31,0x32,0x33,0x34])), True);
    21662182        self.assertEqual(areBytesEqual(bytearray([0x31,0x32,0x33,0x34]), '1224'), False);
    21672183        self.assertEqual(areBytesEqual(bytearray([0x31,0x32,0x33,0x34]), bytearray([0x31,0x32,0x32,0x34])), False);
     2184        if sys.version_info[0] >= 3:
     2185            pass;
     2186        else:
     2187            self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1),
     2188                                           bytearray([0x31,0x32,0x32,0x34])), False);
     2189            self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1),
     2190                                           buffer(bytearray([0x31,0x32,0x33,0x34,0x34]), 0, 4)), True);
     2191            self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), b'1234'), True);
     2192            self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1),  '1234'), True);
     2193            self.assertEqual(areBytesEqual(buffer(bytearray([0x30,0x31,0x32,0x33,0x34]), 1), u'1234'), True);
    21682194
    21692195if __name__ == '__main__':
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