/trunk/Examples/test-suite/python/refcount_runme.py

# · Python · 61 lines · 37 code · 20 blank · 4 comment · 9 complexity · a229094f13b2876b99066aa3d357f9ea MD5 · raw file

  1. from refcount import *
  2. #
  3. # very innocent example
  4. #
  5. a = A3()
  6. b1 = B(a)
  7. b2 = B.create(a)
  8. if a.ref_count() != 3:
  9. raise RuntimeError("Count = %d" % a.ref_count())
  10. rca = b2.get_rca()
  11. b3 = B.create(rca)
  12. if a.ref_count() != 5:
  13. raise RuntimeError("Count = %d" % a.ref_count())
  14. v = vector_A(2)
  15. v[0] = a
  16. v[1] = a
  17. x = v[0]
  18. del v
  19. if a.ref_count() != 6:
  20. raise RuntimeError("Count = %d" % a.ref_count())
  21. # Check %newobject
  22. b4 = b2.cloner()
  23. if b4.ref_count() != 1:
  24. raise RuntimeError
  25. b5 = global_create(a)
  26. if b5.ref_count() != 1:
  27. raise RuntimeError
  28. b6 = Factory.create(a)
  29. if b6.ref_count() != 1:
  30. raise RuntimeError
  31. b7 = Factory().create2(a)
  32. if b7.ref_count() != 1:
  33. raise RuntimeError
  34. if a.ref_count() != 10:
  35. raise RuntimeError("Count = %d" % a.ref_count())
  36. del b4
  37. del b5
  38. del b6
  39. del b7
  40. if a.ref_count() != 6:
  41. raise RuntimeError("Count = %d" % a.ref_count())