From 7c8e2433992aac41bdeb0d7d0861b738d9866628 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 01 六月 2021 17:34:29 +0800 Subject: [PATCH] use default if request port is 0. --- utest/simple_tests.cpp | 43 ++++++++++++++----------------------------- 1 files changed, 14 insertions(+), 29 deletions(-) diff --git a/utest/simple_tests.cpp b/utest/simple_tests.cpp index cbbcc2a..87933ac 100644 --- a/utest/simple_tests.cpp +++ b/utest/simple_tests.cpp @@ -50,12 +50,12 @@ typedef ShmObject<s1000> Int; std::string name = std::to_string(id); auto a0 = Avail(); - Int i1(shm, name); + Int i1(shm, name, eOpenOrCreate); auto a1 = Avail(); BOOST_CHECK_LT(a1, a0); printf("s1000 size: %ld\n", a0 - a1); i1->a[0] = 5; - Int i2(shm, name); + Int i2(shm, name, eOpenOrCreate); auto a2 = Avail(); BOOST_CHECK_EQUAL(a1, a2); BOOST_CHECK_EQUAL(i1.data(), i2.data()); @@ -104,37 +104,22 @@ } } -BOOST_AUTO_TEST_CASE(TimedWaitTest) -{ - const std::string shm_name("shm_wait"); - ShmRemover auto_remove(shm_name); - SharedMemory shm(shm_name, 1024 * 1024); - ShmMsgQueue q(shm, 64); - for (int i = 0; i < 2; ++i) { - int ms = i * 100; - printf("Timeout Test %4d: ", ms); - boost::timer::auto_cpu_timer timer; - MsgI msg; - bool r = q.Recv(msg, ms); - BOOST_CHECK(!r); - } -} - BOOST_AUTO_TEST_CASE(RefCountTest) { - const std::string shm_name("ShmRefCount"); - ShmRemover auto_remove(shm_name); - SharedMemory shm(shm_name, 1024 * 1024); + SharedMemory &shm = TestShm(); + typedef MsgI Msg; + GlobalInit(shm); - MsgI m0(shm.Alloc(1000), shm.New<RefCount>()); - BOOST_CHECK(m0.IsCounted()); + Msg m0(1000, shm); + BOOST_CHECK(!m0.valid()); + m0.Make(100); BOOST_CHECK_EQUAL(m0.Count(), 1); - MsgI m1 = m0; - BOOST_CHECK(m1.IsCounted()); + Msg m1 = m0; + BOOST_CHECK(m1.valid()); BOOST_CHECK_EQUAL(m1.AddRef(), 2); BOOST_CHECK_EQUAL(m0.AddRef(), 3); - BOOST_CHECK_EQUAL(m0.Release(shm), 2); - BOOST_CHECK_EQUAL(m0.Release(shm), 1); - BOOST_CHECK_EQUAL(m1.Release(shm), 0); - BOOST_CHECK(!m1.IsCounted()); + BOOST_CHECK_EQUAL(m0.Release(), 2); + BOOST_CHECK_EQUAL(m0.Release(), 1); + BOOST_CHECK_EQUAL(m1.Release(), 0); + BOOST_CHECK(!m1.valid()); } -- Gitblit v1.8.0