Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
0
 def testZero(self):
   with self.assertRaisesRegex(ValueError,
                               "Too many bytes when decoding varint"):
     rdf_structs.VarintReader(b"", 0)
Ejemplo n.º 4
0
 def testNonCanonicalZeroDoesNotRaise(self):
     self.assertEqual(rdf_structs.VarintReader(b"\x80\x80\x80\x00", 0),
                      (0, 4))
Ejemplo n.º 5
0
 def testDecodingValueLargerThan64BitReturnsTruncatedValue(self):
     self.assertEqual(
         rdf_structs.VarintReader(
             b"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02", 0), (0, 10))
Ejemplo n.º 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)))