From 02ba913dc7bb5d711471b27f2ea23a897d0f2e28 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 23 四月 2021 15:34:26 +0800
Subject: [PATCH] bind msgi to shm, change offset_ptr to abs offset.

---
 utest/utest.cpp |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/utest/utest.cpp b/utest/utest.cpp
index b2de97f..ff5d2ed 100644
--- a/utest/utest.cpp
+++ b/utest/utest.cpp
@@ -10,7 +10,14 @@
 #include <thread>
 #include <vector>
 
+using namespace bhome_shm;
 using namespace bhome_msg;
+
+SharedMemory &TestShm()
+{
+	static SharedMemory shm("utest_0", 1024 * 1024 * 512);
+	return shm;
+}
 
 template <class A, class B>
 struct IsSameType {
@@ -84,10 +91,9 @@
 
 BOOST_AUTO_TEST_CASE(PubSubTest)
 {
-	const std::string shm_name("ShmPubSub");
-	ShmRemover auto_remove(shm_name); //remove twice? in case of killed?
-	SharedMemory shm(shm_name, 1024 * 1024 * 50);
-	DEFER1(shm.Remove());
+	SharedMemory &shm = TestShm();
+	MsgI::BindShm(shm);
+
 	auto Avail = [&]() { return shm.get_free_memory(); };
 	auto init_avail = Avail();
 	int *flag = shm.find_or_construct<int>("flag")(123);
@@ -196,9 +202,8 @@
 
 BOOST_AUTO_TEST_CASE(ReqRepTest)
 {
-	const std::string shm_name("ShmReqRep");
-	ShmRemover auto_remove(shm_name);
-	SharedMemory shm(shm_name, 1024 * 1024 * 512);
+	SharedMemory &shm = TestShm();
+	MsgI::BindShm(shm);
 
 	auto Avail = [&]() { return shm.get_free_memory(); };
 	auto init_avail = Avail();
@@ -233,7 +238,7 @@
 		boost::timer::auto_cpu_timer timer;
 		for (int i = 0; i < nreq; ++i) {
 			std::string msg_id;
-			if (!client.ClientAsyncRequest(req, msg_id)) {
+			if (!client.ClientAsyncRequest(BHAddress(), req, msg_id)) {
 				printf("client request failed\n");
 				++count;
 			}

--
Gitblit v1.8.0