示例#1
0
 def testGoldenPackedMessage(self):
     golden_data = test_util.GoldenFile(
         'golden_packed_fields_message').read()
     golden_message = unittest_pb2.TestPackedTypes()
     golden_message.ParseFromString(golden_data)
     all_set = unittest_pb2.TestPackedTypes()
     test_util.SetAllPackedFields(all_set)
     self.assertEquals(all_set, golden_message)
     self.assertTrue(all_set.SerializeToString() == golden_data)
示例#2
0
 def testGoldenPackedMessage(self):
     golden_data = test_util.GoldenFileData('golden_packed_fields_message')
     golden_message = unittest_pb2.TestPackedTypes()
     golden_message.ParseFromString(golden_data)
     all_set = unittest_pb2.TestPackedTypes()
     test_util.SetAllPackedFields(all_set)
     self.assertEquals(all_set, golden_message)
     self.assertEqual(golden_data, all_set.SerializeToString())
     golden_copy = copy.deepcopy(golden_message)
     self.assertEqual(golden_data, golden_copy.SerializeToString())
示例#3
0
    def testNotANumberPacked(self):
        golden_data = ('\xA2\x06\x04\x00\x00\xC0\x7F'
                       '\xAA\x06\x08\x00\x00\x00\x00\x00\x00\xF8\x7F')
        golden_message = unittest_pb2.TestPackedTypes()
        golden_message.ParseFromString(golden_data)
        self.assertTrue(isnan(golden_message.packed_float[0]))
        self.assertTrue(isnan(golden_message.packed_double[0]))

        serialized = golden_message.SerializeToString()
        message = unittest_pb2.TestPackedTypes()
        message.ParseFromString(serialized)
        self.assertTrue(isnan(message.packed_float[0]))
        self.assertTrue(isnan(message.packed_double[0]))
示例#4
0
 def testNegativeInfinityPacked(self):
     golden_data = ('\xA2\x06\x04\x00\x00\x80\xFF'
                    '\xAA\x06\x08\x00\x00\x00\x00\x00\x00\xF0\xFF')
     golden_message = unittest_pb2.TestPackedTypes()
     golden_message.ParseFromString(golden_data)
     self.assertTrue(IsNegInf(golden_message.packed_float[0]))
     self.assertTrue(IsNegInf(golden_message.packed_double[0]))
     self.assertEqual(golden_data, golden_message.SerializeToString())