tcl集成测试环境搭建指南
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
tcl集成测试环境搭建指南修订记录
第一步:
猎取tcl8.3的安装包,安装到c:\名目下(安装时一定要选取lib库安装)。
第二步:
利用Visual C++建立一个Win32 Console Application 工程,工程的名字为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定义TC L讲明器全局变量。在文件CounterTest.cpp中定义tcl讲明器,即全局变量:Tcl_Interp* MyInterp;
例如:(红色部分为添加的代码)
//定义讲明器
Tcl_Interp* MyInterp;
2)创建讲明器:通过使用TCL函数Tcl_CreateInterp()创建讲明器。
在文件CounterTest.cpp中创建tcl讲明器,例如:(红色部分代码)
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLi ne(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
//创建tcl讲明器
MyInterp = Tcl_CreateInterp();
//初始化Tcl讲明器
Tcl_Init(MyInterp);
//创建外部命令COUNTER,该外部命令能够被tcl讲明器识不,同时执行COUNTER命令的时候,直//接调用外部命令函数TclEx_Counter。
Tcl_CreateCommand(MyInterp,"COUNTER",TclEx_Counter,NUL L,NULL);
int rCode;
char sScript[255];
//CString sScript;
while(1)
{
//通过嵌入集成测试框架的Tcl讲明器MyInterp,运行外部传入的tcl脚本
printf("请输入要执行的TCL脚本文件名:\n");
scanf("%s",&sScript);
rCode = Tcl_EvalFile(MyInterp,(char *)sScript );
if (TCL_OK != rCode )
{
printf("There are errors in your Tcl File\n");
}
else
{
printf("Testing Succeed!\n");
}
// CString strHello;
// strHello.LoadString(IDS_HELLO);
// cout << (LPCTSTR)strHello << endl;
}
}
return nRetCode;
}
3)初始化讲明器:通过使用TCL函数Tcl_Init()初始化讲明器。
在文件CounterTest.cpp中初始化tcl讲明器,例如:(红色部分代码)int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLi ne(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
//创建tcl讲明器
MyInterp = Tcl_CreateInterp();
//初始化Tcl讲明器
Tcl_Init(MyInterp);
//创建外部命令COUNTER,该外部命令能够被tcl讲明器识不,同时执行COUNTER命令的时候,直//接调用外部命令函数TclEx_Counter。
Tcl_CreateCommand(MyInterp,"COUNTER",TclEx_Counter,NUL L,NULL);
int rCode;
char sScript[255];
//CString sScript;
while(1)
{
//通过嵌入集成测试框架的Tcl讲明器MyInterp,运行外部传入的tcl脚本
printf("请输入要执行的TCL脚本文件名:\n");
scanf("%s",&sScript);
rCode = Tcl_EvalFile(MyInterp,(char *)sScript );
if (TCL_OK != rCode )
{
printf("There are errors in your Tcl File\n");
}
else
{
printf("Testing Succeed!\n");
}