def testNoAliasing(self):
        foo1 = sample_service_mojom.Foo()
        foo2 = sample_service_mojom.Foo()
        foo1.name = "foo1"
        foo2.name = "foo2"
        self.assertEquals(foo1.name, "foo1")
        self.assertEquals(foo2.name, "foo2")

        defaults_test1 = sample_service_mojom.DefaultsTest()
        defaults_test2 = sample_service_mojom.DefaultsTest()
        self.assertNotEquals(defaults_test1.a22, defaults_test2.a22)
def _NewFoo():
    foo_instance = sample_service_mojom.Foo()
    foo_instance.name = "Foo.name"
    foo_instance.x = 23
    foo_instance.y = -23
    foo_instance.a = False
    foo_instance.b = True
    foo_instance.c = True
    foo_instance.bar = _NewBar()
    foo_instance.extra_bars = [
        _NewBar(),
        _NewBar(),
    ]
    foo_instance.data = 'Hello world'
    foo_instance.source = _NewHandle()
    foo_instance.input_streams = [_NewHandle()]
    foo_instance.output_streams = [_NewHandle(), _NewHandle()]
    foo_instance.array_of_array_of_bools = [[True, False], []]
    foo_instance.multi_array_of_strings = [
        [
            ["1", "2"],
            [],
            ["3", "4"],
        ],
        [],
    ]
    foo_instance.array_of_bools = [True, 0, 1, 2, 0, 0, 0, 0, 0, True]
    return foo_instance
 def testConstructor(self):
     bar_instance = sample_service_mojom.Bar()
     foo_instance = sample_service_mojom.Foo(name="Foo",
                                             x=-1,
                                             y=5,
                                             a=False,
                                             bar=bar_instance)
     self.assertEquals(foo_instance.name, "Foo")
     self.assertEquals(foo_instance.x, -1)
     self.assertEquals(foo_instance.y, 5)
     self.assertEquals(foo_instance.a, False)
     self.assertEquals(foo_instance.bar, bar_instance)
    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()
 def testImmutableAttributeSet(self):
     foo_instance = sample_service_mojom.Foo()
     with self.assertRaises(AttributeError):
         foo_instance.new_attribute = None
     with self.assertRaises(AttributeError):
         del foo_instance.name