Exemplo n.º 1
0
    def testReadInt64(self):
        """Asserts that longs are read correctly.
        """
        number = 68719476836
        self.stream = MockStream.concat_int64(self.stream, number)
        p = parser.GcovStreamParserUtil(self.stream, MAGIC)
        self.assertEqual(number, p.ReadInt64())

        self.stream = MockStream(format='>')
        self.stream = MockStream.concat_int64(self.stream, number)
        p = parser.GcovStreamParserUtil(self.stream, MAGIC)
        self.assertEqual(number, p.ReadInt64())
Exemplo n.º 2
0
    def testLittleEndiannessInitialization(self):
        """Tests parser init  with little-endian byte order.

        Verifies that the byte-order is correctly detected.
        """
        p = parser.GcovStreamParserUtil(self.stream, MAGIC)
        self.assertEqual(p.format, '<')
Exemplo n.º 3
0
    def testBigEndiannessInitialization(self):
        """Tests parser init with big-endian byte order.

        Verifies that the byte-order is correctly detected.
        """
        self.stream = MockStream(format='>')
        p = parser.GcovStreamParserUtil(self.stream, MAGIC)
        self.assertEqual(p.format, '>')
Exemplo n.º 4
0
    def testReadStringNormal(self):
        """Asserts that strings are correctly read from the stream.

        Tests the normal case--when the string is correctly formatted.
        """
        test_string = "This is a test."
        self.stream = MockStream.concat_string(self.stream, test_string)
        p = parser.GcovStreamParserUtil(self.stream, MAGIC)
        self.assertEqual(p.ReadString(), test_string)
Exemplo n.º 5
0
    def testReadIntNormal(self):
        """Asserts that integers are correctly read from the stream.

        Tests the normal case--when the value is actually an integer.
        """
        integer = 2016
        self.stream = MockStream.concat_int(self.stream, integer)
        p = parser.GcovStreamParserUtil(self.stream, MAGIC)
        self.assertEqual(p.ReadInt(), integer)
Exemplo n.º 6
0
    def testReadStringError(self):
        """Asserts that invalid string format raises error.

        Tests when the string length is too short and EOF is reached.
        """
        test_string = "This is a test."
        byte_count = len(test_string)
        word_count = int(round(byte_count / 4.0))
        padding = '\x00' * (4 * word_count - byte_count)
        test_string_padded = test_string + padding
        content = struct.pack('<I', word_count + 1)  #  will cause EOF error
        content += bytes(test_string_padded)
        self.stream.content += content
        p = parser.GcovStreamParserUtil(self.stream, MAGIC)
        self.assertRaises(parser.FileFormatError, p.ReadString)
Exemplo n.º 7
0
 def testReadIntEof(self):
     """Asserts that an error is thrown when the EOF is reached.
     """
     p = parser.GcovStreamParserUtil(self.stream, MAGIC)
     self.assertRaises(parser.FileFormatError, p.ReadInt)