Exemple #1
0
 def testRaisesWhenBufferIsTooLong(self):
     with self.assertRaisesRegex(ValueError,
                                 "Too many bytes when decoding varint"):
         rdf_structs.VarintReader(
             b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01\x00\x00",
             0)
     with self.assertRaisesRegex(ValueError,
                                 "Too many bytes when decoding varint"):
         rdf_structs.VarintReader(
             b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 0)
Exemple #2
0
 def testReaderCanReadWhatEncoderHasEncoded(self):
     for v in [
             0, 1, 2, 10, 20, 63, 64, 65, 127, 128, 129, 255, 256, 257,
             1 << 63 - 1, 1 << 64 - 1
     ]:
         with self.subTest(value=v):
             buf = rdf_structs.VarintEncode(v)
             r, p = rdf_structs.VarintReader(buf, 0)
             self.assertEqual(v, r)
             self.assertLen(buf, p)
Exemple #3
0
 def testZero(self):
   with self.assertRaisesRegex(ValueError,
                               "Too many bytes when decoding varint"):
     rdf_structs.VarintReader(b"", 0)
Exemple #4
0
 def testNonCanonicalZeroDoesNotRaise(self):
     self.assertEqual(rdf_structs.VarintReader(b"\x80\x80\x80\x00", 0),
                      (0, 4))
Exemple #5
0
 def testDecodingValueLargerThan64BitReturnsTruncatedValue(self):
     self.assertEqual(
         rdf_structs.VarintReader(
             b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02", 0), (0, 10))
Exemple #6
0
 def testCorrectlyReadsEncodedIntegers(self):
     for src_val, b in self._ENCODED_VARINTS:
         with self.subTest(buffer=b):
             self.assertEqual(rdf_structs.VarintReader(b, 0),
                              (src_val, len(b)))