aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/ptr_ut.pyx
blob: 759681a2cbb28ee6315f0cdc1d14c6a714d72bad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from libcpp.utility cimport pair
from util.generic.ptr cimport MakeAtomicShared, TAtomicSharedPtr, THolder
from util.generic.string cimport TString
from util.system.types cimport ui64

import pytest
import unittest


class TestHolder(unittest.TestCase):

    def test_basic(self):
        cdef THolder[TString] holder
        holder.Reset(new TString("aaa"))
        assert holder.Get()[0] == "aaa"
        holder.Destroy()
        assert holder.Get() == NULL
        holder.Reset(new TString("bbb"))
        assert holder.Get()[0] == "bbb"
        holder.Reset(new TString("ccc"))
        assert holder.Get()[0] == "ccc"

    def test_make_atomic_shared(self):
        cdef TAtomicSharedPtr[pair[ui64, TString]] atomic_shared_ptr = MakeAtomicShared[pair[ui64, TString]](15, "Some string")
        assert atomic_shared_ptr.Get().first == 15
        assert atomic_shared_ptr.Get().second == "Some string"