Browse Source

Z991239-385 #comment 添加对 CBlob 的测试案例

gifur 5 years ago
parent
commit
41fd517ce7
4 changed files with 67 additions and 7 deletions
  1. 4 0
      Common/Blob.h
  2. 5 2
      README.md
  3. 50 1
      spbase/test/SpCommTest.cpp
  4. 8 4
      spshell/svc.cpp

+ 4 - 0
Common/Blob.h

@@ -1,3 +1,6 @@
+#ifndef _RVC_COMM_CBLOB_H_
+#define _RVC_COMM_CBLOB_H_
+
 #pragma once
 
 struct CBlob
@@ -119,3 +122,4 @@ struct CBlob
 	}
 };
 
+#endif //_RVC_COMM_CBLOB_H_

+ 5 - 2
README.md

@@ -10,7 +10,10 @@
 * 每个实体运行在自己的进程中,模块间相对独立,结构间松耦合,而在功能上表现为统一的整体
 * 前端界面与后台独立,聚合后台服务,提供统一服务入口,让后台服务对前台透明(API 网关)
 
-
+## 更新记录
+* 2020-04-23: SpHelper.h 新增 `IFFAILRET`,`REQUIRE`,`REQUIRE_FALSE` 宏用于测试案例编写
+* 2020-04-22: Spbase.h 新增 `SpStrError` 接口用于将 ErrorCodeEnum 转成 字符串描述
+* 
 
 ## 依赖情况
 
@@ -26,7 +29,7 @@
 
 ### sphost
 
-## 更新记录
+
 
 
 

+ 50 - 1
spbase/test/SpCommTest.cpp

@@ -167,5 +167,54 @@ TEST(SimpleStringTest, WideCharTransferTest)
 	ASSERT_TRUE(wstr.Compare(L"testString") == 0);
 }
 
+#endif //_WIN32
 
-#endif //_WIN32
+#include "Blob.h"
+TEST(CommonTest, CBlobTest)
+{
+	uint64_t* t = new uint64_t;
+	ASSERT_TRUE(t != NULL);
+	*t = 1024;
+	CBlob blob;
+	ASSERT_TRUE(blob.m_pData == NULL);
+	ASSERT_TRUE(blob.m_iLength == 0);
+	ASSERT_TRUE(blob.m_bManaged == false);
+
+	blob.Attach(t, sizeof(uint64_t));
+	ASSERT_TRUE(blob.m_pData == t);
+	ASSERT_TRUE(blob.m_iLength == sizeof(uint64_t));
+	ASSERT_TRUE(blob.m_bManaged);
+
+	CBlob blob2;
+	blob2 = blob;
+	ASSERT_FALSE(blob2.m_pData == NULL);
+	ASSERT_FALSE(blob2.m_iLength == 0);
+	ASSERT_FALSE(blob2.m_bManaged == false);
+	ASSERT_TRUE((*(uint64_t*)(blob2.m_pData)) == 1024);
+
+	blob2.Clear();
+	ASSERT_TRUE(blob2.m_pData == NULL);
+	ASSERT_TRUE(blob2.m_iLength == 0);
+	ASSERT_TRUE(blob2.m_bManaged == false);
+	ASSERT_TRUE((*(uint64_t*)(blob.m_pData)) == 1024);
+
+	blob2 = blob;
+	blob2.Refer(t, sizeof(uint64_t));
+	ASSERT_TRUE(blob2.m_bManaged == false);
+	ASSERT_TRUE((*(uint64_t*)(blob2.m_pData)) == 1024);
+
+	blob2.Clear();
+	ASSERT_TRUE(*t == 1024);
+
+	//convey blob to blob2
+	blob.AssignAndClear(blob2);
+	ASSERT_TRUE(blob2.m_pData == t);
+	ASSERT_TRUE(blob2.m_iLength == sizeof(uint64_t));
+	ASSERT_TRUE(blob2.m_bManaged);
+
+	//Clear, t would be destroy by blob2
+	blob2.Resize(0);
+	ASSERT_TRUE(blob2.m_pData == NULL);
+	ASSERT_TRUE(blob2.m_iLength == 0);
+	ASSERT_TRUE(blob2.m_bManaged == false);
+}

+ 8 - 4
spshell/svc.cpp

@@ -162,19 +162,23 @@ void on_entity_quit(sp_rpc_server_t *server, int epid, int svc_id, int call_type
 void on_output_console_on(sp_rpc_server_t *server, int epid, int svc_id, int call_type, iobuffer_t **info_pkt)
 {
 	Dbg("set output console on");
-	//sp_dbg_start_console("可视柜台终端运行监控");	
-
+#ifdef _WIN32
 	auto app = get_app_instance();
 	sp_gui_display(app->bsc_gui);
+#else
+	//sp_dbg_start_console("可视柜台终端运行监控");
+#endif //_WIN32
 }
 
 void on_output_console_off(sp_rpc_server_t *server, int epid, int svc_id, int call_type, iobuffer_t **info_pkt)
 {
 	Dbg("set output console off");
-	//sp_dbg_close_console();
-
+#ifdef _WIN32
 	auto app = get_app_instance();
 	sp_gui_undisplay(app->bsc_gui);
+#else
+	//sp_dbg_close_console();
+#endif //_WIN32
 }
 
 typedef struct