Rune Halvorsen avatar Rune Halvorsen committed 167d88e

Added some tests for repeated messages

Comments (0)

Files changed (2)

tests/test_reference.py

         assert r.SerializeToString() == p.serialize()
 
 
-
     testprop(optional_int32=1)
     testprop(optional_int32=0)
     testprop(optional_int32=-1)
     testprop(optional_double=0.5)
     testprop(optional_double=-1.2)
 
+    testprop(optional_bool=True)
+    testprop(optional_bool=False)
 
     testprop(optional_string="")
     testprop(optional_string="abc")
     testprop(optional_bytes="\0\0\0\0\0")
 
 
+def test_reference_serialization_repeated():
+    referencetool.compile_proto(pb.make_proto_data(unitmsg), "ref")
+    from ref_pb2 import TestAllTypes as Ref
+    Pbl = unitmsg.TestAllTypes
+
+    def testprop(**kwargs):
+        p = Pbl()
+        r = Ref()
+
+        for key, val in kwargs.items():
+            rl = getattr(r, key)
+            pl = getattr(p, key)
+            for e in val:
+                rl.append(e)
+                pl.append(e)
+
+        if r.SerializeToString() != p.serialize():
+            print "ref", [hex(ord(e)) for e in r.SerializeToString()]
+            print "pbl", [hex(ord(e)) for e in p.serialize()]
+
+        assert r.SerializeToString() == p.serialize()
+
+    testprop(repeated_int32=[1,2,-3131, 0, 123123])
+    testprop(repeated_int64=[1,2,-3131, 0, 123123])
+
+    testprop(repeated_sint32=[1,2,-3131, 0, 123123])
+    testprop(repeated_sint64=[1,2,-3131, 0, 123123])
+
+    testprop(repeated_uint32=[1,2, 0, 123123])
+    testprop(repeated_uint64=[1,2, 0, 123123])
+
+    testprop(repeated_sint32=[1,2,-3131, 0, 123123])
+    testprop(repeated_sint64=[1,2,-3131, 0, 123123])
+
+    testprop(repeated_fixed32=[1,2, 3131, 0, 123123])
+    testprop(repeated_fixed64=[1,2, 3131, 0, 123123])
+
+    testprop(repeated_sfixed32=[1,2,-3131, 0, 123123])
+    testprop(repeated_sfixed64=[1,2,-3131, 0, 123123])
+
+
 def test_reference_nested_serialization():
     referencetool.compile_proto(pb.make_proto_data(unitmsg), "ref")
     from ref_pb2 import TestAllTypes as Ref
     optional_bytes = pb.BytesField(15, type="optional")
 
     optional_nested_message = pb.MessageField(18, NestedMessage, type="optional")
+
+
+    repeated_int32 = pb.Int32Field(31, type="repeated")
+    repeated_int64 = pb.Int64Field(32, type="repeated")
+    repeated_uint32 = pb.UInt32Field(33, type="repeated")
+    repeated_uint64 = pb.UInt64Field(34, type="repeated")
+    repeated_sint32 = pb.SInt32Field(35, type="repeated")
+    repeated_sint64 = pb.SInt64Field(36, type="repeated")
+
+    repeated_fixed32 = pb.Fixed32Field(37, type="repeated")
+    repeated_fixed64 = pb.Fixed64Field(38, type="repeated")
+    repeated_sfixed32 = pb.SFixed32Field(39, type="repeated")
+    repeated_sfixed64 = pb.SFixed64Field(40, type="repeated")
+
+    repeated_float = pb.FloatField(41, type="repeated")
+    repeated_double = pb.DoubleField(42, type="repeated")
+    repeated_bool = pb.BoolField(43, type="repeated")
+    repeated_string = pb.StringField(44, type="repeated")
+    repeated_bytes = pb.BytesField(45, type="repeated")
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.