《tcl集成测试环境搭建指南(Console版)15708.docx》由会员分享,可在线阅读,更多相关《tcl集成测试环境搭建指南(Console版)15708.docx(18页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Tcl集成测试环境搭建指南博为峰软件技术有限公司2006年1月修订记录日期修订版本修改章节修改描述作者2006-1-171.0初稿完成周峰第一步:获取tcll8.3的的安装包,安安装到c:目录下下(安装时时一定要选选取libb库安装)。第二步:利用Vissual C+建建立一个WWin322 Coonsolle Apppliccatioon 工程程,工程的的名字为CCountterTeest。因为被测对对象有MFFC类,所所以该工程程应该支持持MFC:第三步:参照下面两两个图,分分别创建ttest.h和teest.ccpp文件件。这两个文件均均为空文件件。第四步:添加被测试试模块的代代码1)把
2、下面面的代码拷拷贝到文件件testt.cppp中:2)把下面面的代码拷拷贝到文件件testt.h中第五步:添加tcll扩展指令令代码1)把下面面的代码拷拷贝到文件件CounnterTTest.cpp中中:#incllude tcll.h#incllude tesst.h第六步:1)定义ttcl解释释器:通过过使用TCCL内部的的数据类型型Tcl_Inteerp定义义TCL解解释器全局局变量。在在文件CoounteerTesst.cppp中定义义tcl解解释器,即即全局变量量:Tcll_Intterp* MyIInterrp;例如:(红红色部分为为添加的代代码)/定义解解释器Tcl_IInter
3、rp* MMyIntterp;2)创建解解释器:通通过使用TTCL函数数Tcl_CreaateInnterpp()创建建解释器。在文件CoounteerTesst.cppp中创建建tcl解解释器,例例如:(红红色部分代代码)int _tmaiin(innt arrgc, TCHAAR* aargv, TTCHARR* ennvp)int nRettCodee = 00;/ iinitiializze MFFC annd prrint and erroor onn faiilureeif (!AfxxWinIInit(:GeetModduleHHandlle(NUULL), NULLL, :Ge
4、ttCommmandLLine(), 00)/ TODOO: chhangee errror ccode to ssuit yourr neeedscerrr _T(Fattal EErrorr: MFFC innitiaalizaationn faiiled) enddl;nReetCodde = 1;elsee/ TODOO: coode yyour appllicattions beehaviior hhere./创创建tcll解释器MyIInterrp = Tcl_CreaateInnterpp();/初始化化Tcl解解释器Tcll_Iniit(MyyInteerp);/创创建外部命命
5、令COUUNTERR,该外部部命令可以以被tcll解释器识识别,并且且执行COOUNTEER命令的的时候,直直/接调调用外部命命令函数TTclExx_Couunterr。Tcll_CreeateCCommaand(MMyIntterp,COUUNTERR,TcclEx_Counnter,NULLL,NULLL);intt rCoode;chaar sSScrippt2555;/CCStriing ssScriipt;whiile(11)/通过嵌入入集成测试试框架的TTcl解释释器MyIInterrp,运行行外部传入入的tcll脚本prrintff(请输输入要执行行的TCLL脚本文件件名:nn)
6、;sccanf(%s,&sSScrippt);rCCode = Tccl_EvvalFiile(MMyIntterp,(chaar *)sScrript );iff (TTCL_OOK != rCoode )pprinttf(TTheree aree errrors in yyour Tcl Fileen); ellse prinntf(Testting Succceed!n);/CStrring strHHelloo;/strHHelloo.LoaadStrring(IDS_HELLLO);/coutt (LPCCTSTRR)strrHelllo enddl;retuurn nnRetCCo
7、de;3)初始化化解释器:通过使用用TCL函函数Tcll_Iniit()初初始化解释释器。在文件CoounteerTesst.cppp中初始始化tcll解释器,例例如:(红红色部分代代码)int _tmaiin(innt arrgc, TCHAAR* aargv, TTCHARR* ennvp)int nRettCodee = 00;/ iinitiializze MFFC annd prrint and erroor onn faiilureeif (!AfxxWinIInit(:GeetModduleHHandlle(NUULL), NULLL, :GettCommmandLLine(),
8、 00)/ TODOO: chhangee errror ccode to ssuit yourr neeedscerrr _T(Fattal EErrorr: MFFC innitiaalizaationn faiiled) enddl;nReetCodde = 1;elsee/ TODOO: coode yyour appllicattions beehaviior hhere./创建ttcl解释释器MyIInterrp = Tcl_CreaateInnterpp();/初始化化Tcl解解释器Tcll_Iniit(MyyInteerp);/创创建外部命命令COUUNTERR,该外部部命令可
9、以以被tcll解释器识识别,并且且执行COOUNTEER命令的的时候,直直/接调调用外部命命令函数TTclExx_Couunterr。Tcll_CreeateCCommaand(MMyIntterp,COUUNTERR,TcclEx_Counnter,NULLL,NULLL);intt rCoode;chaar sSScrippt2555;/CCStriing ssScriipt;whiile(11)/通过嵌入入集成测试试框架的TTcl解释释器MyIInterrp,运行行外部传入入的tcll脚本prrintff(请输输入要执行行的TCLL脚本文件件名:nn);sccanf(%s,&sSScri
10、ppt);rCCode = Tccl_EvvalFiile(MMyIntterp,(chaar *)sScrript );iff (TTCL_OOK != rCoode )pprinttf(TTheree aree errrors in yyour Tcl Fileen); ellse prinntf(Testting Succceed!n);/CStrring strHHelloo;/strHHelloo.LoaadStrring(IDS_HELLLO);/coutt (LPCCTSTRR)strrHelllo enddl;retuurn nnRetCCode;4)向解释释器注册扩扩展指令:
11、通过使用用TCL函函数Tcll_CreeateCCommaand()向解释器注册册自定义扩扩展指令。在文件CoounteerTesst.cppp中注册册扩展指令令,例如:(红色部部分代码)int _tmaiin(innt arrgc, TCHAAR* aargv, TTCHARR* ennvp)int nRettCodee = 00;/ iinitiializze MFFC annd prrint and erroor onn faiilureeif (!AfxxWinIInit(:GeetModduleHHandlle(NUULL), NULLL, :GettCommmandLLine(),
12、 00)/ TODOO: chhangee errror ccode to ssuit yourr neeedscerrr _T(Fattal EErrorr: MFFC innitiaalizaationn faiiled) enddl;nReetCodde = 1;elsee/ TODOO: coode yyour appllicattions beehaviior hhere./创建ttcl解释释器MyIInterrp = Tcl_CreaateInnterpp();/初始化化Tcl解解释器Tcll_Iniit(MyyInteerp);/注册扩扩展指令CCOUNTTER,该该扩展指令令可
13、以被ttcl解释释器识别,并并且执行CCOUNTTER的时时候,直接接调用扩展展指令对应应处理函数数TclEEx_Coounteer。Tcll_CreeateCCommaand(MMyIntterp,COUUNTERR,TcclEx_Counnter,NULLL,NULLL);intt rCoode;chaar sSScrippt2555;/CCStriing ssScriipt;whiile(11)/通过嵌入入集成测试试框架的TTcl解释释器MyIInterrp,运行行外部传入入的tcll脚本prrintff(请输输入要执行行的TCLL脚本文件件名:nn);sccanf(%s,&sSScri
14、ppt);rCCode = Tccl_EvvalFiile(MMyIntterp,(chaar *)sScrript );iff (TTCL_OOK != rCoode )pprinttf(TTheree aree errrors in yyour Tcl Fileen); ellse prinntf(Testting Succceed!n);/CStrring strHHelloo;/strHHelloo.LoaadStrring(IDS_HELLLO);/coutt (LPCCTSTRR)strrHelllo enddl;retuurn nnRetCCode;5)定义扩扩展指令CCOUNT
15、TER对应应的处理函函数TcllEx_CCountter()#incllude stddafx.h#incllude CouunterrTestt.h#incllude tcll.h#incllude tesst.hint TTclExx_Couunterr(CliientDData clieentDaata,TTcl_IInterrp * inteerp,iint aargc, chhar* argvv)retuurn TTCL_OOK;6)执行外外部传入的的TCL脚脚本文件:通过使用用TCL函函数Tcll_EvaalFille()执执行外部传传入的TCCL脚本文文件。在文件Coountee
16、rTesst.cppp中添加加执行外部部脚本文件件的代码,例例如:(红红色部分代代码)int _tmaiin(innt arrgc, TCHAAR* aargv, TTCHARR* ennvp)int nRettCodee = 00;/ iinitiializze MFFC annd prrint and erroor onn faiilureeif (!AfxxWinIInit(:GeetModduleHHandlle(NUULL), NULLL, :GettCommmandLLine(), 00)/ TODOO: chhangee errror ccode to ssuit yourr n
17、eeedscerrr _T(Fattal EErrorr: MFFC innitiaalizaationn faiiled) enddl;nReetCodde = 1;elsee/ TODOO: coode yyour appllicattions beehaviior hhere./创建ttcl解释释器MyIInterrp = Tcl_CreaateInnterpp();/初始化化Tcl解解释器Tcll_Iniit(MyyInteerp);/创建外外部命令CCOUNTTER,该该外部命令令可以被ttcl解释释器识别,并并且执行CCOUNTTER命令令的时候,直直/接调调用外部命命令函数TTc
18、lExx_Couunterr。Tcll_CreeateCCommaand(MMyIntterp,COUUNTERR,TcclEx_Counnter,NULLL,NULLL);int rrCodee;chaar sSScrippt2555;/CCStriing ssScriipt;whiile(11)/通过嵌入入集成测试试框架的TTcl解释释器MyIInterrp,运行行外部传入入的tcll脚本prrintff(请输输入要执行行的TCLL脚本文件件名:nn);sccanf(%s,&sSScrippt);rCCode = Tccl_EvvalFiile(MMyIntterp,(chaar *)sS
19、crript );iff (TTCL_OOK != rCoode )pprinttf(TTheree aree errrors in yyour Tcl Fileen); ellse prinntf(Testting Succceed!n);/CStrring strHHelloo;/strHHelloo.LoaadStrring(IDS_HELLLO);/coutt (LPCCTSTRR)strrHelllo Optiion-Direectorry.菜单中,设设置tcll83包的的头文件路路径:3)在ttool-Optiion-Direectorry.菜单中,设设置tcll83包的的库文件路
20、路径:第九步:实实现扩展指指令。参考代码码:int TTclExx_Couunterr(CliientDData clieentDaata,TTcl_IInterrp * inteerp,iint aargc, chhar* argvv)/定义义实际输出出int aRett; /实际输输出空行行行数int bRett; /实际输输出注释行行行数int cRett; /实际输输出代码行行行数int dRett; /实际输输出总行行行数/定义义期望输出出int aExccepteedRett; /期望输输出空行行行数int bExccepteedRett; /期望输输出注释行行行数int cExc
21、cepteedRett; /期望输输出代码行行行数int dExccepteedRett; /期望输输出总行行行数/定义义被测对象象CTesst Myytestt;/第一一步:检查查参数个数数if (10 != arrgc)intterp-ressult = EErrorr parra nuumberr!;retturn TCL_OK;/第二二步:取出出参数Myteest.gg_szSStatFFileNName = arrgv11; /取文件件路径/sttr = argvv1;/取统统计空行标标志位if (TCL_OK != Tccl_GeetIntt(intterp,argvv2,&g_b
22、bStattBlannkLinneFlaag) intterp-ressult = ppara22 errror;retturn TCL_OK; /取统计计注释行标标志位if (TCL_OK != Tccl_GeetIntt(intterp,argvv3,&g_bbStattCommmLineeFlagg) intterp-ressult = ppara33 errror;retturn TCL_OK;/取统统计代码行行标志位if (TCL_OK != Tccl_GeetIntt(intterp,argvv4,&g_bbStattCodeeLineeFlagg) intterp-ressult
23、 = ppara44 errror;retturn TCL_OK;/取统统计总行行行标志位if (TCL_OK != Tccl_GeetIntt(intterp,argvv5,&g_bbStattTotaalLinneFlaag) intterp-ressult = ppara55 errror;retturn TCL_OK;/取期期望输出空空行行数if (TCL_OK != Tccl_GeetIntt(intterp,argvv6,&aExxcepttedReet) intterp-ressult = ppara66 errror;retturn TCL_OK;/取期期望输出注注释行行数数i
24、f (TCL_OK != Tccl_GeetIntt(intterp,argvv7,&bExxcepttedReet) intterp-ressult = ppara77 errror;retturn TCL_OK;/取期期望输出代代码行行数数if (TCL_OK != Tccl_GeetIntt(intterp,argvv8,&cExxcepttedReet) intterp-ressult = ppara88 errror;retturn TCL_OK;/取期期望输出总总行行数if (TCL_OK != Tccl_GeetIntt(intterp,argvv9,&dExxcepttedRe
25、et) intterp-ressult = ppara99 errror;retturn TCL_OK;/第三三步:调用用被测函数数Mytesst.MaainSttatFuun();aRett = gg_iBllankLLineNNum;bRett = gg_iCoommLiineNuum;cRett = gg_iCoodeLiineNuum;dRett = gg_iTootalLLineNNum;/第四四步:测试结果果比较if (aReet != aExxcepttedReet) | (bbRet != bbExceepteddRet) | (cReet != cExxcepttedReet) | (ddRet != ddExceepteddRet) intterp-ressult = TTest Failled!;elsee interrp-rresullt = Tesst Suuccedded!;retuurn TTCL_OOK;