def testDefaultsTestSerializationDeserialization(self):
   v1 = sample_service_mojom.DefaultsTest()
   v1.a18 = []
   v1.a19 = ""
   v1.a21 = sample_import_mojom.Point()
   v1.a22.location = sample_import_mojom.Point()
   v1.a22.size = sample_import2_mojom.Size()
   (data, handles) = v1.Serialize()
   v2 = sample_service_mojom.DefaultsTest.Deserialize(data, handles)
   self.assertTrue(_TestEquality(v1, v2))
Exemple #2
0
    def testPositionalConstructor(self):
        p = sample_import_mojom.Point()
        self.assertEquals(p.x, 0)
        self.assertEquals(p.y, 0)

        p = sample_import_mojom.Point(34)
        self.assertEquals(p.x, 34)
        self.assertEquals(p.y, 0)

        p = sample_import_mojom.Point(34, 12)
        self.assertEquals(p.x, 34)
        self.assertEquals(p.y, 12)

        p = sample_import_mojom.Point(x=34, y=12)
        self.assertEquals(p.x, 34)
        self.assertEquals(p.y, 12)

        p = sample_import_mojom.Point(34, y=12)
        self.assertEquals(p.x, 34)
        self.assertEquals(p.y, 12)

        with self.assertRaises(TypeError):
            p = sample_import_mojom.Point(0, 0, 0)
        with self.assertRaises(TypeError):
            p = sample_import_mojom.Point(0, x=0)
        with self.assertRaises(TypeError):
            p = sample_import_mojom.Point(c=0)
 def testDefaultsTestSerializationDeserialization(self):
     v1 = sample_service_mojom.DefaultsTest()
     v1.a18 = []
     v1.a19 = ""
     v1.a21 = sample_import_mojom.Point()
     v1.a22.location = sample_import_mojom.Point()
     v1.a22.size = sample_import2_mojom.Size()
     (data, handles) = v1.Serialize()
     v2 = sample_service_mojom.DefaultsTest.Deserialize(data, handles)
     # NaN needs to be a special case.
     self.assertNotEquals(v1, v2)
     self.assertTrue(math.isnan(v2.a28))
     self.assertTrue(math.isnan(v2.a31))
     v1.a28 = v2.a28 = v1.a31 = v2.a31 = 0
     self.assertEquals(v1, v2)
    def testTypes(self):
        defaults_test = sample_service_mojom.DefaultsTest()
        # Integer types
        self._TestIntegerField(defaults_test, 'a0', 8, True)
        self._TestIntegerField(defaults_test, 'a1', 8, False)
        self._TestIntegerField(defaults_test, 'a2', 16, True)
        self._TestIntegerField(defaults_test, 'a3', 16, False)
        self._TestIntegerField(defaults_test, 'a4', 32, True)
        self._TestIntegerField(defaults_test, 'a5', 32, False)
        self._TestIntegerField(defaults_test, 'a6', 64, True)
        self._TestIntegerField(defaults_test, 'a7', 64, False)

        # Boolean types
        defaults_test.a11 = False
        self.assertEquals(defaults_test.a11, False)
        defaults_test.a11 = None
        self.assertEquals(defaults_test.a11, False)
        defaults_test.a11 = []
        self.assertEquals(defaults_test.a11, False)
        defaults_test.a12 = True
        self.assertEquals(defaults_test.a12, True)
        defaults_test.a12 = 1
        self.assertEquals(defaults_test.a12, True)
        defaults_test.a12 = [[]]
        self.assertEquals(defaults_test.a12, True)

        # Floating point types
        with self.assertRaises(TypeError):
            defaults_test.a13 = 'hello'
        with self.assertRaises(TypeError):
            defaults_test.a14 = 'hello'

        # Array type
        defaults_test.a18 = None
        defaults_test.a18 = []
        defaults_test.a18 = [0]
        defaults_test.a18 = [255]
        defaults_test.a18 = [0, 255]
        with self.assertRaises(TypeError):
            defaults_test.a18 = [[]]
        with self.assertRaises(OverflowError):
            defaults_test.a18 = [-1]
        with self.assertRaises(OverflowError):
            defaults_test.a18 = [256]

        # String type
        defaults_test.a19 = None
        defaults_test.a19 = ''
        defaults_test.a19 = 'hello world'
        with self.assertRaises(TypeError):
            defaults_test.a19 = [[]]
        with self.assertRaises(TypeError):
            defaults_test.a19 = [-1]
        with self.assertRaises(TypeError):
            defaults_test.a19 = [256]

        # Structs
        defaults_test.a21 = None
        defaults_test.a21 = sample_import_mojom.Point()
        with self.assertRaises(TypeError):
            defaults_test.a21 = 1
        with self.assertRaises(TypeError):
            defaults_test.a21 = sample_import2_mojom.Thing()

        # Handles
        foo_instance = sample_service_mojom.Foo()
        foo_instance.source = None
        foo_instance.source = mojo.system.Handle()
        with self.assertRaises(TypeError):
            foo_instance.source = 1
        with self.assertRaises(TypeError):
            foo_instance.source = object()