|
|
@@ -172,6 +172,7 @@ public:
|
|
|
|
|
|
MethodTestCaseT(CEntityBase* ent, ToTestFuncProto testFunc)
|
|
|
:SpReqAnsContext(m_spMockTransactionContext),m_enti(ent), m_testFunc(testFunc)
|
|
|
+ ,m_errorCode(Error_IgnoreAll),m_dwUserCode(0)
|
|
|
{ }
|
|
|
|
|
|
virtual void PreTest() {/*To Set member Req value*/}
|
|
|
@@ -196,10 +197,12 @@ public:
|
|
|
TestObjectPointer that = static_cast<TestObjectPointer>(m_enti);
|
|
|
|
|
|
(that->*m_testFunc)(GetCtx());
|
|
|
-
|
|
|
+#if 0
|
|
|
DWORD dwUserCode = 0, dwNoUsed = 0;
|
|
|
ErrorCodeEnum result = m_spMockTransactionContext->GetExpireTime(dwUserCode, dwNoUsed);
|
|
|
-
|
|
|
+#else
|
|
|
+ ErrorCodeEnum result = m_errorCode;
|
|
|
+#endif
|
|
|
Dbg("errorCode: %s", SpStrError(result));
|
|
|
|
|
|
return (((result == Error_Succeed) ? PostTest() : result));
|
|
|
@@ -208,6 +211,23 @@ public:
|
|
|
return Error_IgnoreAll;
|
|
|
}
|
|
|
|
|
|
+ ErrorCodeEnum Answer(ErrorCodeEnum Error = Error_Succeed)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_errorCode = Error;
|
|
|
+
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+
|
|
|
+ ErrorCodeEnum Answer(ErrorCodeEnum eSysError, DWORD dwUserError)
|
|
|
+ {
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_errorCode = eSysError;
|
|
|
+ m_dwUserCode = dwUserError;
|
|
|
+
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
Pointer GetCtx()
|
|
|
{
|
|
|
@@ -221,6 +241,9 @@ public:
|
|
|
CEntityBase* m_enti;
|
|
|
ToTestFuncProto m_testFunc;
|
|
|
|
|
|
+ ErrorCodeEnum m_errorCode;
|
|
|
+ DWORD m_dwUserCode;
|
|
|
+
|
|
|
};
|
|
|
|
|
|
typedef std::vector<TestCaseEntry> TestCaseSet;
|
|
|
@@ -235,6 +258,10 @@ protected:
|
|
|
|
|
|
virtual ErrorCodeEnum RunTestCase();
|
|
|
|
|
|
+ /** user can override this function to add any other test, but do not
|
|
|
+ invoke 'AddTestCaseEntry' and 'AddTestMethodEntry' method at this scope!!!!*/
|
|
|
+ virtual ErrorCodeEnum CustomTestCase() { return Error_Succeed; }
|
|
|
+
|
|
|
private:
|
|
|
|
|
|
TestCaseSet m_testCases;
|
|
|
@@ -254,6 +281,7 @@ private:
|
|
|
* hook it to mock real test result without changing any functional code which I really unwill to see it!
|
|
|
* 2. subclass MethodTestCaseT inherited from SpReqAnsContext cannot initialize earlier than SpReqAnsContext as children class, so we
|
|
|
* cannot declare a 'CSmartPointer<ITransactionContext>' type member and initialze it first then convey it to SpReqAnsContext.
|
|
|
+ * 3. multi-thead unsafe !!!
|
|
|
*/
|
|
|
template<typename TClass>
|
|
|
CSmartPointer<ITransactionContext> ITestCaseSuite<TClass>::m_spMockTransactionContext = CreateMockTransactionContext(nullptr);
|
|
|
@@ -269,6 +297,9 @@ ITestCaseSuite<T>::~ITestCaseSuite()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/** 'TestCaseEntry' Prototype: void Entity::Function(CSmartPointer<ITransactionContext> pTransactionContext)
|
|
|
+ * User should declare and implement it.
|
|
|
+ */
|
|
|
template<typename TClass>
|
|
|
void ITestCaseSuite<TClass>::AddTestCaseEntry(TestCaseEntry entry)
|
|
|
{
|
|
|
@@ -341,6 +372,20 @@ ErrorCodeEnum ITestCaseSuite<TClass>::RunTestCase()
|
|
|
}
|
|
|
|
|
|
|
|
|
+#define TESTCASE_OVERRIDE_ON_EXAM_AND_IMPLEMENT() \
|
|
|
+void OnExam(CSmartPointer<ITransactionContext> pTransactionContext) override \
|
|
|
+{ \
|
|
|
+ LOG_FUNCTION(); \
|
|
|
+ ErrorCodeEnum testResult = RunTestCase(); \
|
|
|
+ if (testResult == Error_Succeed || testResult == Error_IgnoreAll) { \
|
|
|
+ testResult = CustomTestCase(); \
|
|
|
+ pTransactionContext->SendAnswer(testResult); \
|
|
|
+ } else { \
|
|
|
+ pTransactionContext->SendAnswer(testResult); \
|
|
|
+ } \
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
#define TESTCASE_DECLARE_BEGIN(serviceName, testFuncName) \
|
|
|
void Test_##testFuncName(CSmartPointer<ITransactionContext> pTransactionContext) {\
|
|
|
SpReqAnsContext< serviceName##_##testFuncName##_Req, serviceName##_##testFuncName##_Ans>::Pointer ctx = \
|