Răsfoiți Sursa

Z991239-632 #comment feature: 添加测试实体的测试案例

gifur 5 ani în urmă
părinte
comite
d3737e5163

+ 15 - 0
Common/SpTest.h

@@ -410,6 +410,21 @@ struct TestCaseStatistics
 		ignoreTestCaseNum = 0;
 	}
 
+	void ConvertFormUserCode(const DWORD& dwUserCode)
+	{
+		Reset();
+		totalTestCaseNum = ((dwUserCode >> 16) & 0x0000FFFF);
+		failureTestCaseNum = (dwUserCode & 0x0000FFFF);
+		passedTestCaseNum = totalTestCaseNum - failureTestCaseNum;
+	}
+
+	double FailureRate() const 
+	{
+		double failed = 1.0 * failureTestCaseNum;
+		double rate = failed / (double)(totalTestCaseNum);
+		return rate * 100;
+	}
+
 	void Clear() 
 	{
 		const std::size_t oldCaseNum = totalTestCaseNum;

+ 2 - 1
addin/cfg/shell.ini.in

@@ -117,13 +117,14 @@ Number=4
 4=CenterSetting
 
 [Test]
-Number=6
+Number=7
 1=TestDeamon TestMode=ON Level=3 Entity=BlackSheep -D
 2=TestSubscribe
 3=SampleEntity
 4=TestLogSender
 5=TestNormalEntity
 6=TestPrivilegeEntity
+7=BlackSheep
 
 [SysEvent]
 SampleState=SampleEntity;TestDeamon;HelloClient HelloService,"0"

+ 7 - 1
test/module/mod_blackSheep/CMakeLists.txt

@@ -2,7 +2,13 @@
 define_moudle("blackSheep")
 
 set(${MODULE_PREFIX}_SRCS
-	mod_blackSheep.cpp)
+	mod_blackSheep.hpp)
+
+if(BUILD_MOUDLE_TEST)
+	list(APPEND ${MODULE_PREFIX}_SRCS 
+	test/TestBlackSheep.cpp 
+	)
+endif(BUILD_MOUDLE_TEST)
 
 set(MOD_VERSION_STRING "2.0.0-dev5")
 

+ 4 - 2
test/module/mod_blackSheep/mod_blackSheep.cpp → test/module/mod_blackSheep/mod_blackSheep.hpp

@@ -1,6 +1,6 @@
 #include "stdafx.h"
 #include "SpBase.h"
-
+#include "SpTest.h"
 #include "modVer.h"
 
 /*one of test module: use to test error: erro startup*/
@@ -14,10 +14,12 @@ public:
 
 	const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
 
+	TEST_CASE_OVERRIDE_ON_EXAM_DECLAER()
+
 	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
 	{
 		LOG_FUNCTION();
-		pTransactionContext->SendAnswer(Error_Unexpect);
+		pTransactionContext->SendAnswer(Error_Succeed);
 	}
 
 	virtual void OnStarted()

+ 9 - 0
test/module/mod_blackSheep/test/TestBlackSheep.cpp

@@ -0,0 +1,9 @@
+#include "mod_blackSheep.hpp"
+
+
+
+TEST_CASE_ENTITY_CLASS(CBlackSheep, "TestForCBlackSheep")
+{
+	Dbg("TestForCBlackSheep Debug:  %s", GetEntityVersion());
+	return Error_Succeed;
+}

+ 6 - 0
test/module/mod_testNormalEntity/CMakeLists.txt

@@ -4,6 +4,12 @@ define_moudle("testNormalEntity")
 set(${MODULE_PREFIX}_SRCS
 	mod_testNormalEntity.cpp)
 
+if(BUILD_MOUDLE_TEST)
+	list(APPEND ${MODULE_PREFIX}_SRCS 
+	test/TestNormalEntity.cpp 
+	)
+endif(BUILD_MOUDLE_TEST)
+
 set(MOD_VERSION_STRING "2.0.0-dev1")
 add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
 

+ 1 - 0
test/module/mod_testNormalEntity/test/TestNormalEntity.cpp

@@ -0,0 +1 @@
+#include "SpTest.h"

+ 6 - 0
test/module/mod_testPassiveEntity/CMakeLists.txt

@@ -6,6 +6,12 @@ set(${MODULE_PREFIX}_SRCS
 	mod_viceEntities.hpp
 	)
 
+if(BUILD_MOUDLE_TEST)
+	list(APPEND ${MODULE_PREFIX}_SRCS 
+	test/TestPassiveEntity.cpp 
+	)
+endif(BUILD_MOUDLE_TEST)
+
 set(MOD_VERSION_STRING "2.0.0-dev5")
 add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
 

+ 3 - 0
test/module/mod_testPassiveEntity/mod_testPassiveEntity.cpp

@@ -23,6 +23,9 @@ public:
 		}
 		pTransactionContext->SendAnswer(result);
 	}
+
+	TEST_CASE_OVERRIDE_ON_EXAM_DECLAER()
+
 	void OnStarted()
 	{
 		LOG_FUNCTION();

+ 1 - 0
test/module/mod_testPassiveEntity/test/TestPassiveEntity.cpp

@@ -0,0 +1 @@
+#include "SpTest.h"

+ 1 - 1
test/module/mod_testPrivilegeEntity/mod_testPrivilegeEntity.cpp

@@ -120,7 +120,7 @@ ErrorCodeEnum CPrivilegeEntityTest::_onTest()
 	IFFAILRET(privilegeFunc->TestEntity(CHILD_TEST_ENTITY_NAME, Test_Examine, spWait));
 	REQUIRE(spWait != NULL);
 	const auto ec = spWait->WaitAnswer(10000);
-	REQUIRE(ec == Error_Succeed || ec == Error_NotImpl);
+	REQUIRE(ec == Error_IgnoreAll);
 
 	//test entity in reset mode.
 	spWait = NULL;

+ 0 - 0
test/module/mod_validityVertifier/ChangeLog


+ 9 - 4
test/module/mod_validityVertifier/mod_validityVertifier.cpp

@@ -266,10 +266,12 @@ public:
 		const auto ec = pAsynWaitSp->AsyncGetAnswer(dwUserCode);
 		if (result->op == OP_START) 
 		{
-			if (IS_FAILURED(ec)) {
+			if (IS_FAILURED(ec)) 
+			{
 				THROW_ERROR("Start %s failed return %s!", result->strEntityName.GetData(), SpStrError(ec));
 			}
-			else {
+			else 
+			{
 				Dbg("Start entity %s succ.", result->strEntityName.GetData());
 				_arrTestEntities[_dwStartedTestEntities++] = result->strEntityName;
 			}
@@ -279,7 +281,7 @@ public:
 			if (Error_IgnoreAll == ec || Error_NotImpl == ec) 
 			{
 				LogWarn(Severity_Middle, Error_NotImpl, 0, CSimpleStringA::Format(
-					"Test for entity [%s] is not OK: detect no any test case!!", result->strEntityName.GetData()));
+					"Test for entity [%s] is not OK: Detect no any TestCase!!", result->strEntityName.GetData()));
 			}
 			else if (Error_Accept == ec || Error_Succeed == ec)
 			{
@@ -287,7 +289,10 @@ public:
 			}
 			else
 			{
-				THROW_ERROR("Test for entity[%s] failed return %s!", result->strEntityName.GetData(), SpStrError(ec));
+				TestCaseStatistics statistic;
+				statistic.ConvertFormUserCode(dwUserCode);
+				THROW_ERROR("Test for entity[%s] failed return %s: %.2lf percent tests passed, %u test failed out of %u cases",
+					result->strEntityName.GetData(), SpStrError(ec), statistic.FailureRate(), statistic.Failures(), statistic.Total());
 			}
 			Dbg("return usercode: 0x%08X", dwUserCode);
 		}