tcl集成测试环境搭建指南.docx

上传人:b****0 文档编号:9357241 上传时间:2023-05-18 格式:DOCX 页数:19 大小:235.88KB
下载 相关 举报
tcl集成测试环境搭建指南.docx_第1页
第1页 / 共19页
tcl集成测试环境搭建指南.docx_第2页
第2页 / 共19页
tcl集成测试环境搭建指南.docx_第3页
第3页 / 共19页
tcl集成测试环境搭建指南.docx_第4页
第4页 / 共19页
tcl集成测试环境搭建指南.docx_第5页
第5页 / 共19页
tcl集成测试环境搭建指南.docx_第6页
第6页 / 共19页
tcl集成测试环境搭建指南.docx_第7页
第7页 / 共19页
tcl集成测试环境搭建指南.docx_第8页
第8页 / 共19页
tcl集成测试环境搭建指南.docx_第9页
第9页 / 共19页
tcl集成测试环境搭建指南.docx_第10页
第10页 / 共19页
tcl集成测试环境搭建指南.docx_第11页
第11页 / 共19页
tcl集成测试环境搭建指南.docx_第12页
第12页 / 共19页
tcl集成测试环境搭建指南.docx_第13页
第13页 / 共19页
tcl集成测试环境搭建指南.docx_第14页
第14页 / 共19页
tcl集成测试环境搭建指南.docx_第15页
第15页 / 共19页
tcl集成测试环境搭建指南.docx_第16页
第16页 / 共19页
tcl集成测试环境搭建指南.docx_第17页
第17页 / 共19页
tcl集成测试环境搭建指南.docx_第18页
第18页 / 共19页
tcl集成测试环境搭建指南.docx_第19页
第19页 / 共19页
亲,该文档总共19页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

tcl集成测试环境搭建指南.docx

《tcl集成测试环境搭建指南.docx》由会员分享,可在线阅读,更多相关《tcl集成测试环境搭建指南.docx(19页珍藏版)》请在冰点文库上搜索。

tcl集成测试环境搭建指南.docx

tcl集成测试环境搭建指南

tcl集成测试环境搭建指南

 

修订记录

日期

修订版本

修改章节

修改描述

作者

2006-1-17

1.0

初稿完成

周峰

第一步:

猎取tcl8.3的安装包,安装到c:

\名目下(安装时一定要选取lib库安装)。

第二步:

利用VisualC++建立一个Win32ConsoleApplication工程,工程的名字为CounterTest。

因为被测对象有MFC类,因此该工程应该支持MFC:

第三步:

参照下面两个图,分不创建test.h和test.cpp文件。

这两个文件均为空文件。

 

第四步:

添加被测试模块的代码

1)把下面的代码拷贝到文件test.cpp中:

2)把下面的代码拷贝到文件test.h中

第五步:

添加tcl扩展指令代码

1)把下面的代码拷贝到文件CounterTest.cpp中:

#include"tcl.h"

#include"test.h"

第六步:

1)定义tcl讲明器:

通过使用TCL内部的数据类型Tcl_Interp定义TCL讲明器全局变量。

在文件CounterTest.cpp中定义tcl讲明器,即全局变量:

Tcl_Interp*MyInterp;

例如:

(红色部分为添加的代码)

//定义讲明器

Tcl_Interp*MyInterp;

2)创建讲明器:

通过使用TCL函数Tcl_CreateInterp()创建讲明器。

在文件CounterTest.cpp中创建tcl讲明器,例如:

(红色部分代码)

int_tmain(intargc,TCHAR*argv[],TCHAR*envp[])

{

intnRetCode=0;

//initializeMFCandprintanderroronfailure

if(!

AfxWinInit(:

:

GetModuleHandle(NULL),NULL,:

:

GetCommandLine(),0))

{

//TODO:

changeerrorcodetosuityourneeds

cerr<<_T("FatalError:

MFCinitializationfailed")<

nRetCode=1;

}

else

{

//TODO:

codeyourapplication'sbehaviorhere.

//创建tcl讲明器

MyInterp=Tcl_CreateInterp();

//初始化Tcl讲明器

Tcl_Init(MyInterp);

//创建外部命令COUNTER,该外部命令能够被tcl讲明器识不,同时执行COUNTER命令的时候,直//接调用外部命令函数TclEx_Counter。

Tcl_CreateCommand(MyInterp,"COUNTER",TclEx_Counter,NULL,NULL);

intrCode;

charsScript[255];

//CStringsScript;

while

(1)

{

//通过嵌入集成测试框架的Tcl讲明器MyInterp,运行外部传入的tcl脚本

printf("请输入要执行的TCL脚本文件名:

\n");

scanf("%s",&sScript);

rCode=Tcl_EvalFile(MyInterp,(char*)sScript);

if(TCL_OK!

=rCode)

{

printf("ThereareerrorsinyourTclFile\n");

}

else

{

printf("TestingSucceed!

\n");

}

//CStringstrHello;

//strHello.LoadString(IDS_HELLO);

//cout<<(LPCTSTR)strHello<

}

}

returnnRetCode;

}

3)初始化讲明器:

通过使用TCL函数Tcl_Init()初始化讲明器。

在文件CounterTest.cpp中初始化tcl讲明器,例如:

(红色部分代码)

int_tmain(intargc,TCHAR*argv[],TCHAR*envp[])

{

intnRetCode=0;

//initializeMFCandprintanderroronfailure

if(!

AfxWinInit(:

:

GetModuleHandle(NULL),NULL,:

:

GetCommandLine(),0))

{

//TODO:

changeerrorcodetosuityourneeds

cerr<<_T("FatalError:

MFCinitializationfailed")<

nRetCode=1;

}

else

{

//TODO:

codeyourapplication'sbehaviorhere.

//创建tcl讲明器

MyInterp=Tcl_CreateInterp();

//初始化Tcl讲明器

Tcl_Init(MyInterp);

//创建外部命令COUNTER,该外部命令能够被tcl讲明器识不,同时执行COUNTER命令的时候,直//接调用外部命令函数TclEx_Counter。

Tcl_CreateCommand(MyInterp,"COUNTER",TclEx_Counter,NULL,NULL);

intrCode;

charsScript[255];

//CStringsScript;

while

(1)

{

//通过嵌入集成测试框架的Tcl讲明器MyInterp,运行外部传入的tcl脚本

printf("请输入要执行的TCL脚本文件名:

\n");

scanf("%s",&sScript);

rCode=Tcl_EvalFile(MyInterp,(char*)sScript);

if(TCL_OK!

=rCode)

{

printf("ThereareerrorsinyourTclFile\n");

}

else

{

printf("TestingSucceed!

\n");

}

//CStringstrHello;

//strHello.LoadString(IDS_HELLO);

//cout<<(LPCTSTR)strHello<

}

}

returnnRetCode;

}

4)向讲明器注册扩展指令:

通过使用TCL函数Tcl_CreateCommand()向讲明器注册自定义扩展指令。

在文件CounterTest.cpp中注册扩展指令,例如:

(红色部分代码)

int_tmain(intargc,TCHAR*argv[],TCHAR*envp[])

{

intnRetCode=0;

//initializeMFCandprintanderroronfailure

if(!

AfxWinInit(:

:

GetModuleHandle(NULL),NULL,:

:

GetCommandLine(),0))

{

//TODO:

changeerrorcodetosuityourneeds

cerr<<_T("FatalError:

MFCinitializationfailed")<

nRetCode=1;

}

else

{

//TODO:

codeyourapplication'sbehaviorhere.

//创建tcl讲明器

MyInterp=Tcl_CreateInterp();

//初始化Tcl讲明器

Tcl_Init(MyInterp);

//注册扩展指令COUNTER,该扩展指令能够被tcl讲明器识不,同时执行COUNTER的时候,直截了当调用扩展指令对应处理函数TclEx_Counter。

Tcl_CreateCommand(MyInterp,"COUNTER",TclEx_Counter,NULL,NULL);

intrCode;

charsScript[255];

//CStringsScript;

while

(1)

{

//通过嵌入集成测试框架的Tcl讲明器MyInterp,运行外部传入的tcl脚本

printf("请输入要执行的TCL脚本文件名:

\n");

scanf("%s",&sScript);

rCode=Tcl_EvalFile(MyInterp,(char*)sScript);

if(TCL_OK!

=rCode)

{

printf("ThereareerrorsinyourTclFile\n");

}

else

{

printf("TestingSucceed!

\n");

}

//CStringstrHello;

//strHello.LoadString(IDS_HELLO);

//cout<<(LPCTSTR)strHello<

}

}

returnnRetCode;

}

5)定义扩展指令COUNTER对应的处理函数TclEx_Counter()

#include"stdafx.h"

#include"CounterTest.h"

#include"tcl.h"

#include"test.h"

intTclEx_Counter(ClientDataclientData,Tcl_Interp*interp,intargc,char*argv[])

{

returnTCL_OK;

}

6)执行外部传入的TCL脚本文件:

通过使用TCL函数Tcl_EvalFile()执行外部传入的TCL脚本文件。

在文件CounterTest.cpp中添加执行外部脚本文件的代码,例如:

(红色部分代码)

int_tmain(intargc,TCHAR*argv[],TCHAR*envp[])

{

intnRetCode=0;

//initializeMFCandprintanderroronfailure

if(!

AfxWinInit(:

:

GetModuleHandle(NULL),NULL,:

:

GetCommandLine(),0))

{

//TODO:

changeerrorcodetosuityourneeds

cerr<<_T("FatalError:

MFCinitializationfailed")<

nRetCode=1;

}

else

{

//TODO:

codeyourapplication'sbehaviorhere.

//创建tcl讲明器

MyInterp=Tcl_CreateInterp();

//初始化Tcl讲明器

Tcl_Init(MyInterp);

//创建外部命令COUNTER,该外部命令能够被tcl讲明器识不,同时执行COUNTER命令的时候,直//接调用外部命令函数TclEx_Counter。

Tcl_CreateCommand(MyInterp,"COUNTER",TclEx_Counter,NULL,NULL);

intrCode;

charsScript[255];

//CStringsScript;

while

(1)

{

//通过嵌入集成测试框架的Tcl讲明器MyInterp,运行外部传入的tcl脚本

printf("请输入要执行的TCL脚本文件名:

\n");

scanf("%s",&sScript);

rCode=Tcl_EvalFile(MyInterp,(char*)sScript);

if(TCL_OK!

=rCode)

{

printf("ThereareerrorsinyourTclFile\n");

}

else

{

printf("TestingSucceed!

\n");

}

//CStringstrHello;

//strHello.LoadString(IDS_HELLO);

//cout<<(LPCTSTR)strHello<

}

}

returnnRetCode;

}

第七步:

添加tcl头文件和库文件,并设置相应的头文件和库文件路径

1)如下图所示,采纳如下方法添加tcl83包中的tcl.h和tcl83.lib

2)在[tool…]->[Option…]->[Directory….]菜单中,设置tcl83包的头文件路径:

3)在[tool…]->[Option…]->[Directory….]菜单中,设置tcl83包的库文件路径:

第九步:

实现扩展指令。

参考代码:

intTclEx_Counter(ClientDataclientData,Tcl_Interp*interp,intargc,char*argv[])

{

//定义实际输出

intaRet;//实际输出空行行数

intbRet;//实际输出注释行行数

intcRet;//实际输出代码行行数

intdRet;//实际输出总行行数

//定义期望输出

intaExceptedRet;//期望输出空行行数

intbExceptedRet;//期望输出注释行行数

intcExceptedRet;//期望输出代码行行数

intdExceptedRet;//期望输出总行行数

//定义被测对象

CTestMytest;

//第一步:

检查参数个数

if(10!

=argc)

{

interp->result="Errorparanumber!

";

returnTCL_OK;

}

//第二步:

取出参数

Mytest.g_szStatFileName=argv[1];//取文件路径

//str=argv[1];

//取统计空行标志位

if(TCL_OK!

=Tcl_GetInt(interp,argv[2],&g_bStatBlankLineFlag))

{

interp->result="para2error";

returnTCL_OK;

}

//取统计注释行标志位

if(TCL_OK!

=Tcl_GetInt(interp,argv[3],&g_bStatCommLineFlag))

{

interp->result="para3error";

returnTCL_OK;

}

//取统计代码行标志位

if(TCL_OK!

=Tcl_GetInt(interp,argv[4],&g_bStatCodeLineFlag))

{

interp->result="para4error";

returnTCL_OK;

}

//取统计总行行标志位

if(TCL_OK!

=Tcl_GetInt(interp,argv[5],&g_bStatTotalLineFlag))

{

interp->result="para5error";

returnTCL_OK;

}

//取期望输出空行行数

if(TCL_OK!

=Tcl_GetInt(interp,argv[6],&aExceptedRet))

{

interp->result="para6error";

returnTCL_OK;

}

//取期望输出注释行行数

if(TCL_OK!

=Tcl_GetInt(interp,argv[7],&bExceptedRet))

{

interp->result="para7error";

returnTCL_OK;

}

//取期望输出代码行行数

if(TCL_OK!

=Tcl_GetInt(interp,argv[8],&cExceptedRet))

{

interp->result="para8error";

returnTCL_OK;

}

//取期望输出总行行数

if(TCL_OK!

=Tcl_GetInt(interp,argv[9],&dExceptedRet))

{

interp->result="para9error";

returnTCL_OK;

}

//第三步:

调用被测函数

Mytest.MainStatFun();

aRet=g_iBlankLineNum;

bRet=g_iCommLineNum;

cRet=g_iCodeLineNum;

dRet=g_iTotalLineNum;

//第四步:

测试结果比较

if((aRet!

=aExceptedRet)||(bRet!

=bExceptedRet)

||(cRet!

=cExceptedRet)||(dRet!

=dExceptedRet))

{

interp->result="TestFailed!

";

}

else

{

interp->result="TestSucceded!

";

}

returnTCL_OK;

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2