コード例 #1
0
    def testStructDefinition(self):
        """Ensure that errors in struct definitions are raised."""
        # A descriptor without a field number should raise.
        self.assertRaises(type_info.TypeValueError,
                          rdf_structs.ProtoEmbedded,
                          name="name")

        # Adding a duplicate field number should raise.
        self.assertRaises(
            type_info.TypeValueError, TestStruct.AddDescriptor,
            rdf_structs.ProtoUnsignedInteger(name="int", field_number=2))

        # Adding a descriptor which is not a Proto* descriptor is not allowed for
        # Struct fields:
        self.assertRaises(type_info.TypeValueError, TestStruct.AddDescriptor,
                          type_info.String(name="int"))
コード例 #2
0
ファイル: structs_test.py プロジェクト: micrictor/grr
class TestStruct(rdf_structs.RDFProtoStruct):
  """A test struct object."""

  type_description = type_info.TypeDescriptorSet(
      rdf_structs.ProtoString(
          name="foobar",
          field_number=1,
          default="string",
          description="A string value",
          labels=[rdf_structs.SemanticDescriptor.Labels.HIDDEN]),
      rdf_structs.ProtoUnsignedInteger(
          name="int", field_number=2, default=5,
          description="An integer value"),
      rdf_structs.ProtoList(
          rdf_structs.ProtoString(
              name="repeated",
              field_number=3,
              description="A repeated string value")),

      # We can serialize an arbitrary RDFValue. This will be serialized into a
      # binary string and parsed on demand.
      rdf_structs.ProtoRDFValue(
          name="urn",
          field_number=6,
          default=rdfvalue.RDFURN("www.google.com"),
          rdf_type="RDFURN",
          description="An arbitrary RDFValue field."),
      rdf_structs.ProtoEnum(
          name="type",
          field_number=7,
          enum_name="Type",
          enum={
              "FIRST": 1,
              "SECOND": 2,
              "THIRD": 3
          },
          default=3,
          description="An enum field"),
      rdf_structs.ProtoFloat(
          name="float",
          field_number=8,
          description="A float number",
          default=1.1),
  )
コード例 #3
0
ファイル: structs_test.py プロジェクト: hfakar/grr
class UnionTest(rdf_structs.RDFProtoStruct):
    union_field = "struct_flavor"

    type_description = type_info.TypeDescriptorSet(
        rdf_structs.ProtoEnum(name="struct_flavor",
                              field_number=1,
                              enum_name="Type",
                              enum=dict(FIRST=1, SECOND=2, THIRD=3),
                              default=3,
                              description="An union enum field"),
        rdf_structs.ProtoFloat(name="first",
                               field_number=2,
                               description="A float number",
                               default=1.1),
        rdf_structs.ProtoString(name="second",
                                field_number=3,
                                default="string",
                                description="A string value"),
        rdf_structs.ProtoUnsignedInteger(name="third",
                                         field_number=4,
                                         default=5,
                                         description="An integer value"),
    )
コード例 #4
0
ファイル: structs_test.py プロジェクト: micrictor/grr
class PartialTest1(rdf_structs.RDFProtoStruct):
  """This is a protobuf with fewer fields than TestStruct."""
  type_description = type_info.TypeDescriptorSet(
      rdf_structs.ProtoUnsignedInteger(name="int", field_number=2),)