def ExpectAllFieldsSet(test_case, message):
  """Check all fields for correct values have after Set*Fields() is called."""
  test_case.assertTrue(message.HasField('optional_int32'))
  test_case.assertTrue(message.HasField('optional_int64'))
  test_case.assertTrue(message.HasField('optional_uint32'))
  test_case.assertTrue(message.HasField('optional_uint64'))
  test_case.assertTrue(message.HasField('optional_sint32'))
  test_case.assertTrue(message.HasField('optional_sint64'))
  test_case.assertTrue(message.HasField('optional_fixed32'))
  test_case.assertTrue(message.HasField('optional_fixed64'))
  test_case.assertTrue(message.HasField('optional_sfixed32'))
  test_case.assertTrue(message.HasField('optional_sfixed64'))
  test_case.assertTrue(message.HasField('optional_float'))
  test_case.assertTrue(message.HasField('optional_double'))
  test_case.assertTrue(message.HasField('optional_bool'))
  test_case.assertTrue(message.HasField('optional_string'))
  test_case.assertTrue(message.HasField('optional_bytes'))

  if IsProto2(message):
    test_case.assertTrue(message.HasField('optionalgroup'))
  test_case.assertTrue(message.HasField('optional_nested_message'))
  test_case.assertTrue(message.HasField('optional_foreign_message'))
  test_case.assertTrue(message.HasField('optional_import_message'))

  test_case.assertTrue(message.optionalgroup.HasField('a'))
  test_case.assertTrue(message.optional_nested_message.HasField('bb'))
  test_case.assertTrue(message.optional_foreign_message.HasField('c'))
  test_case.assertTrue(message.optional_import_message.HasField('d'))

  test_case.assertTrue(message.HasField('optional_nested_enum'))
  test_case.assertTrue(message.HasField('optional_foreign_enum'))
  if IsProto2(message):
    test_case.assertTrue(message.HasField('optional_import_enum'))

  test_case.assertTrue(message.HasField('optional_string_piece'))
  test_case.assertTrue(message.HasField('optional_cord'))

  test_case.assertEqual(101, message.optional_int32)
  test_case.assertEqual(102, message.optional_int64)
  test_case.assertEqual(103, message.optional_uint32)
  test_case.assertEqual(104, message.optional_uint64)
  test_case.assertEqual(105, message.optional_sint32)
  test_case.assertEqual(106, message.optional_sint64)
  test_case.assertEqual(107, message.optional_fixed32)
  test_case.assertEqual(108, message.optional_fixed64)
  test_case.assertEqual(109, message.optional_sfixed32)
  test_case.assertEqual(110, message.optional_sfixed64)
  test_case.assertEqual(111, message.optional_float)
  test_case.assertEqual(112, message.optional_double)
  test_case.assertEqual(True, message.optional_bool)
  test_case.assertEqual('115', message.optional_string)
  test_case.assertEqual(b'116', message.optional_bytes)

  if IsProto2(message):
    test_case.assertEqual(117, message.optionalgroup.a)
  test_case.assertEqual(118, message.optional_nested_message.bb)
  test_case.assertEqual(119, message.optional_foreign_message.c)
  test_case.assertEqual(120, message.optional_import_message.d)
  test_case.assertEqual(126, message.optional_public_import_message.e)
  test_case.assertEqual(127, message.optional_lazy_message.bb)

  test_case.assertEqual(unittest_pb2.TestAllTypes.BAZ,
                        message.optional_nested_enum)
  test_case.assertEqual(unittest_pb2.FOREIGN_BAZ,
                        message.optional_foreign_enum)
  if IsProto2(message):
    test_case.assertEqual(unittest_import_pb2.IMPORT_BAZ,
                          message.optional_import_enum)

  # -----------------------------------------------------------------

  test_case.assertEqual(2, len(message.repeated_int32))
  test_case.assertEqual(2, len(message.repeated_int64))
  test_case.assertEqual(2, len(message.repeated_uint32))
  test_case.assertEqual(2, len(message.repeated_uint64))
  test_case.assertEqual(2, len(message.repeated_sint32))
  test_case.assertEqual(2, len(message.repeated_sint64))
  test_case.assertEqual(2, len(message.repeated_fixed32))
  test_case.assertEqual(2, len(message.repeated_fixed64))
  test_case.assertEqual(2, len(message.repeated_sfixed32))
  test_case.assertEqual(2, len(message.repeated_sfixed64))
  test_case.assertEqual(2, len(message.repeated_float))
  test_case.assertEqual(2, len(message.repeated_double))
  test_case.assertEqual(2, len(message.repeated_bool))
  test_case.assertEqual(2, len(message.repeated_string))
  test_case.assertEqual(2, len(message.repeated_bytes))

  if IsProto2(message):
    test_case.assertEqual(2, len(message.repeatedgroup))
  test_case.assertEqual(2, len(message.repeated_nested_message))
  test_case.assertEqual(2, len(message.repeated_foreign_message))
  test_case.assertEqual(2, len(message.repeated_import_message))
  test_case.assertEqual(2, len(message.repeated_nested_enum))
  test_case.assertEqual(2, len(message.repeated_foreign_enum))
  if IsProto2(message):
    test_case.assertEqual(2, len(message.repeated_import_enum))

  test_case.assertEqual(2, len(message.repeated_string_piece))
  test_case.assertEqual(2, len(message.repeated_cord))

  test_case.assertEqual(201, message.repeated_int32[0])
  test_case.assertEqual(202, message.repeated_int64[0])
  test_case.assertEqual(203, message.repeated_uint32[0])
  test_case.assertEqual(204, message.repeated_uint64[0])
  test_case.assertEqual(205, message.repeated_sint32[0])
  test_case.assertEqual(206, message.repeated_sint64[0])
  test_case.assertEqual(207, message.repeated_fixed32[0])
  test_case.assertEqual(208, message.repeated_fixed64[0])
  test_case.assertEqual(209, message.repeated_sfixed32[0])
  test_case.assertEqual(210, message.repeated_sfixed64[0])
  test_case.assertEqual(211, message.repeated_float[0])
  test_case.assertEqual(212, message.repeated_double[0])
  test_case.assertEqual(True, message.repeated_bool[0])
  test_case.assertEqual('215', message.repeated_string[0])
  test_case.assertEqual(b'216', message.repeated_bytes[0])

  if IsProto2(message):
    test_case.assertEqual(217, message.repeatedgroup[0].a)
  test_case.assertEqual(218, message.repeated_nested_message[0].bb)
  test_case.assertEqual(219, message.repeated_foreign_message[0].c)
  test_case.assertEqual(220, message.repeated_import_message[0].d)
  test_case.assertEqual(227, message.repeated_lazy_message[0].bb)

  test_case.assertEqual(unittest_pb2.TestAllTypes.BAR,
                        message.repeated_nested_enum[0])
  test_case.assertEqual(unittest_pb2.FOREIGN_BAR,
                        message.repeated_foreign_enum[0])
  if IsProto2(message):
    test_case.assertEqual(unittest_import_pb2.IMPORT_BAR,
                          message.repeated_import_enum[0])

  test_case.assertEqual(301, message.repeated_int32[1])
  test_case.assertEqual(302, message.repeated_int64[1])
  test_case.assertEqual(303, message.repeated_uint32[1])
  test_case.assertEqual(304, message.repeated_uint64[1])
  test_case.assertEqual(305, message.repeated_sint32[1])
  test_case.assertEqual(306, message.repeated_sint64[1])
  test_case.assertEqual(307, message.repeated_fixed32[1])
  test_case.assertEqual(308, message.repeated_fixed64[1])
  test_case.assertEqual(309, message.repeated_sfixed32[1])
  test_case.assertEqual(310, message.repeated_sfixed64[1])
  test_case.assertEqual(311, message.repeated_float[1])
  test_case.assertEqual(312, message.repeated_double[1])
  test_case.assertEqual(False, message.repeated_bool[1])
  test_case.assertEqual('315', message.repeated_string[1])
  test_case.assertEqual(b'316', message.repeated_bytes[1])

  if IsProto2(message):
    test_case.assertEqual(317, message.repeatedgroup[1].a)
  test_case.assertEqual(318, message.repeated_nested_message[1].bb)
  test_case.assertEqual(319, message.repeated_foreign_message[1].c)
  test_case.assertEqual(320, message.repeated_import_message[1].d)
  test_case.assertEqual(327, message.repeated_lazy_message[1].bb)

  test_case.assertEqual(unittest_pb2.TestAllTypes.BAZ,
                        message.repeated_nested_enum[1])
  test_case.assertEqual(unittest_pb2.FOREIGN_BAZ,
                        message.repeated_foreign_enum[1])
  if IsProto2(message):
    test_case.assertEqual(unittest_import_pb2.IMPORT_BAZ,
                          message.repeated_import_enum[1])

  # -----------------------------------------------------------------

  if IsProto2(message):
    test_case.assertTrue(message.HasField('default_int32'))
    test_case.assertTrue(message.HasField('default_int64'))
    test_case.assertTrue(message.HasField('default_uint32'))
    test_case.assertTrue(message.HasField('default_uint64'))
    test_case.assertTrue(message.HasField('default_sint32'))
    test_case.assertTrue(message.HasField('default_sint64'))
    test_case.assertTrue(message.HasField('default_fixed32'))
    test_case.assertTrue(message.HasField('default_fixed64'))
    test_case.assertTrue(message.HasField('default_sfixed32'))
    test_case.assertTrue(message.HasField('default_sfixed64'))
    test_case.assertTrue(message.HasField('default_float'))
    test_case.assertTrue(message.HasField('default_double'))
    test_case.assertTrue(message.HasField('default_bool'))
    test_case.assertTrue(message.HasField('default_string'))
    test_case.assertTrue(message.HasField('default_bytes'))

    test_case.assertTrue(message.HasField('default_nested_enum'))
    test_case.assertTrue(message.HasField('default_foreign_enum'))
    test_case.assertTrue(message.HasField('default_import_enum'))

    test_case.assertEqual(401, message.default_int32)
    test_case.assertEqual(402, message.default_int64)
    test_case.assertEqual(403, message.default_uint32)
    test_case.assertEqual(404, message.default_uint64)
    test_case.assertEqual(405, message.default_sint32)
    test_case.assertEqual(406, message.default_sint64)
    test_case.assertEqual(407, message.default_fixed32)
    test_case.assertEqual(408, message.default_fixed64)
    test_case.assertEqual(409, message.default_sfixed32)
    test_case.assertEqual(410, message.default_sfixed64)
    test_case.assertEqual(411, message.default_float)
    test_case.assertEqual(412, message.default_double)
    test_case.assertEqual(False, message.default_bool)
    test_case.assertEqual('415', message.default_string)
    test_case.assertEqual(b'416', message.default_bytes)

    test_case.assertEqual(unittest_pb2.TestAllTypes.FOO,
                          message.default_nested_enum)
    test_case.assertEqual(unittest_pb2.FOREIGN_FOO,
                          message.default_foreign_enum)
    test_case.assertEqual(unittest_import_pb2.IMPORT_FOO,
                          message.default_import_enum)
Check all fields for correct values have after Set*Fields() is called.
deps/protobuf/python/google/protobuf/internal/test_util.py