Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1139847
  • 博文数量: 196
  • 博客积分: 4141
  • 博客等级: 中将
  • 技术积分: 2253
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-21 20:04
文章存档

2019年(31)

2016年(1)

2014年(16)

2011年(8)

2010年(25)

2009年(115)

分类: C/C++

2014-10-07 18:19:23


点击(此处)折叠或打开

  1. #pragma once

  2. #define SetFlags(x, flags) ((x) | (flags))
  3. #define ClrFlags(x, flags) ((x) & (~flags))
  4. #define IsFlags(x, flags) ((x) & (flags))

  5. typedef void* HANDLE;

  6. #define TESTTOOL_SUCCESS 0
  7. #define TESTTOOL_ERROR 1

  8. #define USER_TYPE 0x00F00000
  9. #define USER_INITIATOR 0x00100000
  10. #define USER_ACCEPTOR 0x00200000
  11. #define USER_BOTH 0x00300000
  12. #define USER_UNKNOWN 0x00000000

  13. #define PROTOCOLTYPE_NORMAL 0x1
  14. #define PROTOCOLTYPE_FAST 0x2

  15. /************************************************************************/
  16. /* ∑?????/?????? */
  17. /************************************************************************/

  18. #define TYPE_CASETYPE 0x1F000000
  19. #define TYPE_PROJECT 0xE0000000

  20. #define TYPE_CASETYPEUNKNOW 0x00000000

  21. #define TYPE_PROJECT_CASEIMIX 0x20000000
  22. #define TYPE_PROJECT_CASEINTEG 0x40000000
  23. #define TYPE_PROJECT_CASEDEFINED1 0x60000000
  24. #define TYPE_PROJECT_CASEDEFINED2 0x80000000
  25. #define TYPE_PROJECT_CASEDEFINED3 0xA0000000
  26. #define TYPE_PROJECT_CASEDEFINED4 0xC0000000
  27. #define TYPE_PROJECT_CASEDEFINED5 0xE0000000

  28. // CaseIMIX
  29. #define TYPE_APPINIT 0x01000000
  30. #define TYPE_HEARTBTINT 0x04000000
  31. #define TYPE_IMIXTIMER 0x05000000
  32. #define TYPE_RECONNECT 0x06000000
  33. #define TYPE_IMIXCONFIGFUNC 0x07000000
  34. #define TYPE_SESSIONCASE 0x08000000
  35. #define TYPE_ERRORNO 0x09000000
  36. #define TYPE_CSCASE 0x0A000000
  37. #define TYPE_PERFORMANCECASE 0x0B000000
  38. #define TYPE_IMIXSEQCASE 0x0C000000
  39. #define TYPE_ATESTCASE 0x0D000000
  40. #define TYPE_IMIXAPPLICATIONCASE 0x0E000000

  41. // CaseInteg
  42. #define TYPE_IMIXAPICOMMSVR 0x01000000

点击(此处)折叠或打开

  1. #ifndef TEST_CONFIG_H
  2. #define TEST_CONFIG_H

  3. /********************************************************************************************
  4. ** ’?∏?≤? ‘”√?????∞∑÷????≤??∫
  5. ** ??“?≤??∫??????∑÷?¨±?????IMIX°?CommFrameWork°?Utility
  6. ** ????≤??∫π?????∑÷?∫±?????IMIX??–???π???°?÷??¨π???????
  7. ** ????≤??∫????≤? ‘—???
  8. ********************************************************************************************/

  9. #define TESTTOOLPROJECT 100
  10. #define TESTTOOLPROJECT_UTILITY (TESTTOOLPROJECT + 1)
  11. #define TESTTOOLPROJECT_IMIX (TESTTOOLPROJECT + 2)
  12. #define TESTTOOLPROJECT_CFW (TESTTOOLPROJECT + 3)
  13. #define TESTTOOLPROJECT_PROTOCOL (TESTTOOLPROJECT + 4)
  14. #define TESTTOOLPROJECT_INTEG (TESTTOOLPROJECT + 5)

  15. class CTestObject;

  16. /*********************************************************************************************
  17. ** ≤? ‘π????????”
  18. *********************************************************************************************/
  19. class CaseType
  20. {
  21. public:
  22.     string name;
  23.     string coment;
  24.     CTestObject *testobject;

  25. public:
  26.     int operator==(const CaseType &item)
  27.     {
  28.         if ((this->name == item.name) && (this->coment == item.coment))
  29.             return 0;
  30.         else
  31.             return 1;
  32.     }
  33. };
  34. /*************************************************************************************/

  35. /**************************************************************************************
  36. ** ≤? ‘???????”π???
  37. **************************************************************************************/
  38. class ModuleInfo
  39. {
  40. public:
  41.     map<string, CaseType*> m_casetypemap;
  42.     string m_modulename;
  43.     int m_moduletype;
  44. };
  45. /*************************************************************************************/

  46. /**************************************************************************************
  47. ** ≤? ‘”√?????”
  48. **************************************************************************************/
  49. typedef int (CTestObject::*TestCasePtr)();
  50. class CaseInfo
  51. {
  52. public:
  53.     CTestObject *testobject;
  54.     TestCasePtr caseitemptr;
  55.     string funcname;
  56.     string casedescp;
  57.     string expectresult;
  58.     string result;
  59.     string testresult;
  60. };

  61. #define TestCaseDeclaration void InitCaseItem();
  62. #define BeginTestCase(classname) \
  63.     void classname::InitCaseItem(){ \
  64.     CaseInfo *caseinfo;
  65. #define EndTestClass }
  66. #define ON_ADD_CASE(fname, descp, result, memfuncptr) \
  67.     caseinfo = new CaseInfo; \
  68.     caseinfo->caseitemptr=(TestCasePtr)memfuncptr;caseinfo->funcname = fname;\
  69.     caseinfo->casedescp=descp;caseinfo->expectresult=result;\
  70.     caseinfo->testobject=this;\
  71.     m_caseinfovector.push_back(caseinfo);
  72. /***********************************************************************************************************/

  73. class CTestObject
  74. {
  75. private:
  76.     static CMUTEX s_mutex;
  77.     static map<int, ModuleInfo*> m_modulemap;

  78. public:
  79.     vector<CaseInfo*> m_caseinfovector;
  80.     CaseType* m_casetype;

  81. public:
  82.     CTestObject();
  83.     ~CTestObject();

  84.     virtual void InitCaseItem() = 0;
  85.     virtual int ExecTest(CaseInfo *pCaseInfo);

  86.     static CTestObject* GetInstance(){ return NULL;}

  87.     static int StartExec(string path, unsigned short show, int *dwProcessId);
  88.     static int CloseProcess(int dwProcessId);

  89.     string GetTestFileName();
  90.     void OutFile(string label, string cstr);

  91.     void AddCaseType(string name, string comment, CTestObject *object, int type);
  92.     map<string, CaseType*>* GetCaseTypeMap(int type);

  93.     int GetModuleSize();
  94.     ModuleInfo *GetModuleAt(int index);
  95.     ModuleInfo *GetModuleByName(string name);
  96. };

  97. #endif

点击(此处)折叠或打开

  1. #pragma once

  2. class CTestFactory : public CTestObject
  3. {
  4. private:
  5.     static CMUTEX m_mutex;

  6.     CTestFactory(void);

  7. public:
  8.     static CTestObject *m_hinstance;

  9.     TestCaseDeclaration

  10.     ~CTestFactory(void);

  11.     static CTestObject *GetInstance();

  12. public:
  13.     void Init();
  14. };

点击(此处)折叠或打开

  1. #include <string>
  2. #include <map>
  3. #include <vector>
  4. #include <cstdio>
  5. #include <cstdlib>

  6. using namespace std;

  7. #include "UTILITY/Mutex.h"

  8. #include "Platform.h"
  9. #include "Common.h"
  10. #include "ConfigGen.h"

  11. #include "TestObject.h"

  12. CMUTEX CTestObject::s_mutex;
  13. map<int, ModuleInfo*> CTestObject::m_modulemap;

  14. CTestObject::CTestObject()
  15. {
  16.     ModuleInfo *pInfo;
  17.     m_casetype = NULL;

  18.     if (m_modulemap.size() == 0)
  19.     {
  20.         pInfo = new ModuleInfo;
  21.         pInfo->m_moduletype = TESTTOOLPROJECT_UTILITY;
  22.         pInfo->m_modulename = "CaseUtility";
  23.         m_modulemap.insert(make_pair(TESTTOOLPROJECT_UTILITY, pInfo));

  24.         /*pInfo = new ModuleInfo;
  25.         pInfo->m_moduletype = TESTTOOLPROJECT_CFW;
  26.         pInfo->m_modulename = "CaseCFW";
  27.         m_modulemap.insert(make_pair(TESTTOOLPROJECT_CFW, pInfo));*/

  28.         pInfo = new ModuleInfo;
  29.         pInfo->m_moduletype = TESTTOOLPROJECT_IMIX;
  30.         pInfo->m_modulename = "CaseIMIX";
  31.         m_modulemap.insert(make_pair(TESTTOOLPROJECT_IMIX, pInfo));

  32.         pInfo = new ModuleInfo;
  33.         pInfo->m_moduletype = TESTTOOLPROJECT_PROTOCOL;
  34.         pInfo->m_modulename = "CaseProtocol";
  35.         m_modulemap.insert(make_pair(TESTTOOLPROJECT_PROTOCOL, pInfo));

  36.         pInfo = new ModuleInfo;
  37.         pInfo->m_moduletype = TESTTOOLPROJECT_INTEG;
  38.         pInfo->m_modulename = "CaseInteg";
  39.         m_modulemap.insert(make_pair(TESTTOOLPROJECT_INTEG, pInfo));
  40.     }
  41. }

  42. CTestObject::~CTestObject()
  43. {

  44. }

  45. void CTestObject::AddCaseType(string name, string comment, CTestObject *object, int type)
  46. {
  47.     AutoLock autolock(&s_mutex);

  48.     map<int, ModuleInfo*>::iterator iter = m_modulemap.find(type);
  49.     if (iter == m_modulemap.end())
  50.     {
  51.         return;
  52.     }
  53.     map<string, CaseType*> *casetypemap = &(iter->second->m_casetypemap);

  54.     if (casetypemap->find(name) == casetypemap->end())
  55.     {
  56.         m_casetype = new CaseType;
  57.         m_casetype->name = name;
  58.         m_casetype->coment = comment;
  59.         m_casetype->testobject = object;

  60.         casetypemap->insert(pair<string, CaseType*>(name, m_casetype));
  61.     }
  62.     else
  63.         m_casetype = (CaseType*)(*casetypemap)[name];
  64. }

  65. int CTestObject::ExecTest(CaseInfo *pCaseInfo)
  66. {
  67.     int status = 0;
  68.     char logname[1000];

  69.     CConfigGen *pGen = CConfigGen::GetInstance();

  70.     sprintf(logname, "%s", pCaseInfo->funcname.c_str());
  71.     pGen->SetTemplateField(0, TEST_ConfigField_LogAppName, logname);

  72.     MemCheckTop
  73.     status = (this->*(pCaseInfo->caseitemptr))();
  74.     MemCheckBottom

  75.     return status;
  76. }


  77. map<string, CaseType*>* CTestObject::GetCaseTypeMap(int type)
  78. {
  79.     map<int, ModuleInfo*>::iterator iter = m_modulemap.find(type);
  80.     if (iter == m_modulemap.end())
  81.         return NULL;

  82.     return &(iter->second->m_casetypemap);
  83. }

  84. string CTestObject::GetTestFileName()
  85. {
  86.     char tmp[100];
  87.     string filename;

  88.     /*SYSTEMTIME st;
  89.     GetSystemTime(&st);

  90.     if (PathFileExists("log") == FALSE)
  91.     {
  92.         CreateDirectory("log", NULL);
  93.     }*/

  94.     time_t timer;
  95.     struct tm* t_tm;
  96.     time(&timer);
  97.     t_tm = localtime(&timer);

  98.     sprintf(tmp, "%d_%d_%d.txt", t_tm->tm_year+1900, t_tm->tm_mon+1, t_tm->tm_mday);

  99.     if (ACCESS("log", 0) != 0)
  100.     {
  101.         MKDIR("log");
  102.     }

  103.     filename = tmp;

  104.     return filename;
  105. }

  106. void CTestObject::OutFile(string label, string cstr)
  107. {
  108.     FILE *fp;

  109.     string filename = GetTestFileName();

  110.     fp = fopen(filename.c_str(), "a+");

  111.     if (fp == NULL)
  112.     {
  113.         return;
  114.     }
  115.     fprintf(fp, "%s\n%s\n\n", label.c_str(), cstr.c_str());

  116.     fclose(fp);
  117. }

  118. int CTestObject::StartExec(string path, unsigned short show, int *dwProcessId)
  119. {
  120.     return NewProcess(path, show, dwProcessId);
  121. }

  122. int CTestObject::CloseProcess(int dwProcessId)
  123. {
  124.     return DeleteProcess(dwProcessId);
  125. }

  126. int CTestObject::GetModuleSize()
  127. {
  128.     return m_modulemap.size();
  129. }

  130. ModuleInfo *CTestObject::GetModuleAt(int index)
  131. {
  132.     int i;
  133.     map<int, ModuleInfo*>::iterator iter;

  134.     if (index >= GetModuleSize())
  135.         return NULL;

  136.     for (i = 0, iter = m_modulemap.begin(); i < index && iter != m_modulemap.end(); ++i, ++iter);

  137.     return iter->second;
  138. }

  139. ModuleInfo *CTestObject::GetModuleByName(string name)
  140. {
  141.     map<int, ModuleInfo*>::iterator iter;

  142.     for (iter = m_modulemap.begin(); iter != m_modulemap.end(); ++iter)
  143.     {
  144.         if (iter->second->m_modulename == name)
  145.             break;
  146.     }
  147.     if (iter == m_modulemap.end())
  148.         return NULL;

  149.     return iter->second;
  150. }

点击(此处)折叠或打开

  1. #include <string>
  2. #include <map>
  3. #include <vector>
  4. #include <cstdio>
  5. #include <cstdlib>

  6. using namespace std;

  7. #include "UTILITY/Mutex.h"

  8. #include "Common.h"
  9. #include "ConfigGen.h"
  10. #include "TerminalConfig.h"

  11. #include "TestObject.h"

  12. #include "ProtocolInc.h"
  13. #include "ImixInc.h"
  14. #include "IntegInc.h"
  15. //#include "CaseCFW/Include/CFWInc.h"
  16. #include "SmartPtrTest.h"

  17. #include "TestFactory.h"

  18. CMUTEX CTestFactory::m_mutex;
  19. CTestObject *CTestFactory::m_hinstance = NULL;

  20. CTestFactory::CTestFactory(void)
  21. {
  22. }

  23. CTestFactory::~CTestFactory(void)
  24. {
  25. }

  26. BeginTestCase(CTestFactory)
  27. EndTestClass

  28. void CTestFactory::Init()
  29. {
  30.     /************************************************************************/
  31.     /* ??≥…≤? ‘ ≤? ‘”√?? */
  32.     /************************************************************************/
  33.     CTestObject *integMsg = CImixApiCommServer::GetInstance();
  34.     AddCaseType("IntegTest", "", integMsg, TESTTOOLPROJECT_INTEG);

  35.     /************************************************************************/
  36.     /* IMIX Protocol≤? ‘”√?? */
  37.     /************************************************************************/
  38.     CTestObject *basicmsg = CBasicProtocolCase::GetInstance();
  39.     AddCaseType("BasicProtocol", "", basicmsg, TESTTOOLPROJECT_PROTOCOL);

  40.     CTestObject *commsg = CAppProtocolCase::GetInstance();
  41.     AddCaseType("AppProtocol", "", commsg, TESTTOOLPROJECT_PROTOCOL);

  42.     /************************************************************************/
  43.     /* IMIXAPI≤? ‘”√?? */
  44.     /************************************************************************/
  45.     CTestObject *appinit = CAppInit::GetInstance();
  46.     AddCaseType("AppInit", "", appinit, TESTTOOLPROJECT_IMIX);

  47.     CTestObject *configfunc = CIMIXConfigFunc::GetInstance();
  48.     AddCaseType("ConfigFunc", "", configfunc, TESTTOOLPROJECT_IMIX);

  49.     CTestObject *imixtimercase = CIMIXTimerCase::GetInstance();
  50.     AddCaseType("Timer", "", imixtimercase, TESTTOOLPROJECT_IMIX);

  51.     CTestObject *heartbtcase = CHeartBtIntCase::GetInstance();
  52.     AddCaseType("HeartBeat", "", heartbtcase, TESTTOOLPROJECT_IMIX);

  53.     CTestObject *reconnectcase = CReConnectCase::GetInstance();
  54.     AddCaseType("ReConnect", "", reconnectcase, TESTTOOLPROJECT_IMIX);

  55.     CTestObject *sessioncase = CSessionCase::GetInstance();
  56.     AddCaseType("SingleProcessVSMultiSession", "", sessioncase, TESTTOOLPROJECT_IMIX);

  57.     CTestObject *errornocase = CErrorNoCase::GetInstance();
  58.     AddCaseType("ErrorNo", "", errornocase, TESTTOOLPROJECT_IMIX);

  59.     CTestObject *cscase = CCSCase::GetInstance();
  60.     AddCaseType("ServerVSClient", "", cscase, TESTTOOLPROJECT_IMIX);

  61.     CTestObject *atest = CATest::GetInstance();
  62.     AddCaseType("ATest", "", atest, TESTTOOLPROJECT_IMIX);

  63.     CTestObject *performanceTest = CIMIXPerformanceCase::GetInstance();
  64.     AddCaseType("PerformanceTest", "", performanceTest, TESTTOOLPROJECT_IMIX);

  65.     CTestObject *imixSeqCase = CIMIXSeqCase::GetInstance();
  66.     AddCaseType("SeqVerify", "", imixSeqCase, TESTTOOLPROJECT_IMIX);

  67.     CTestObject *imixApplicationCase = CIMIXApplicationCase::GetInstance();
  68.     AddCaseType("IMIXApplicationCase", "", imixApplicationCase, TESTTOOLPROJECT_IMIX);

  69.     /************************************************************************/
  70.     /* DEP≤? ‘”√?? */
  71.     /************************************************************************/
  72.     /*CTestObject *cfwperformancetest = CCFWPerformanceCase::GetInstance();
  73.     AddCaseType("–‘??≤? ‘", "", cfwperformancetest, TESTTOOLPROJECT_CFW);*/

  74.     /************************************************************************/
  75.     /* Utility≤? ‘”√?? */
  76.     /************************************************************************/
  77.     CTestObject *smartptrtest = CSmartPtrTest::GetInstance();
  78.     AddCaseType("SmartPtrTest", "", smartptrtest, TESTTOOLPROJECT_UTILITY);
  79. }

  80. CTestObject *CTestFactory::GetInstance()
  81. {
  82.     AutoLock autolock(&m_mutex);

  83.     if (m_hinstance == NULL)
  84.     {
  85.         m_hinstance = new CTestFactory;
  86.         ((CTestFactory *)m_hinstance)->Init();
  87.     }

  88.     return m_hinstance;
  89. }


阅读(3194) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~