ptr_ut.pyx 904 B

1234567891011121314151617181920212223242526
  1. from libcpp.utility cimport pair
  2. from util.generic.ptr cimport MakeAtomicShared, TAtomicSharedPtr, THolder
  3. from util.generic.string cimport TString
  4. from util.system.types cimport ui64
  5. import pytest
  6. import unittest
  7. class TestHolder(unittest.TestCase):
  8. def test_basic(self):
  9. cdef THolder[TString] holder
  10. holder.Reset(new TString("aaa"))
  11. assert holder.Get()[0] == "aaa"
  12. holder.Destroy()
  13. assert holder.Get() == NULL
  14. holder.Reset(new TString("bbb"))
  15. assert holder.Get()[0] == "bbb"
  16. holder.Reset(new TString("ccc"))
  17. assert holder.Get()[0] == "ccc"
  18. def test_make_atomic_shared(self):
  19. cdef TAtomicSharedPtr[pair[ui64, TString]] atomic_shared_ptr = MakeAtomicShared[pair[ui64, TString]](15, "Some string")
  20. assert atomic_shared_ptr.Get().first == 15
  21. assert atomic_shared_ptr.Get().second == "Some string"