Ejemplo n.º 1
0
 def testNotShared(self):
     a = ClassNonDefConstImpl(12, 30)
     # |a| is not shared with C++. So, the call to DoUniq should invalidate it.
     a.invalidated = True
     self.assertEqual(virtual_funcs.DoUniq(a), -1)
     with self.assertRaises(ValueError):
         _ = a.a
     with self.assertRaises(ValueError):
         virtual_funcs.DoUniq(a)
Ejemplo n.º 2
0
 def testShared(self):
     a = ClassNonDefConstImpl(1, 23)
     b = virtual_funcs.Manager(a)
     # |a| is shared between C++ and Python. So, cannot give it to Func.
     self.assertEqual(b.DoIt(), 23)
     with self.assertRaises(ValueError):
         virtual_funcs.DoUniq(a)
     # Check |a| is intact.
     self.assertEqual(a.a, 1)
Ejemplo n.º 3
0
 def testSharedFreeAfterUse(self):
     a = ClassNonDefConstImpl(2, 3)
     b = virtual_funcs.Manager(a)
     self.assertEqual(b.DoIt(), 6)
     # Remove the reference in |b|
     del b
     # We should be able to call Func again
     a.invalidated = True
     self.assertEqual(virtual_funcs.DoUniq(a), -1)
     with self.assertRaises(ValueError):
         _ = a.a