|
本帖最后由 miji2009 于 2012-4-25 10:39 编辑
从网上下了一个文件检索系统白盒测试报告,本人是初学者,不知道他这个系统究竟是要实现什么功能啊?请高手指点,感激不尽!
源代码如下:
#include <cstdlib>
#include <iostream>
using namespace std;
#define MAXPATTERN 20 //定义最长的模式名
#define MAXFILELEN 128 //定义最长文件名
#define FALSE 0
#define TRUE 1
void printpre(char file[MAXFILELEN+1],char pattern[MAXPATTERN+1]);
void printaft(int a);
int FindSubString ( const char* source, const char* dest );
bool MatchPattern(char* file, char* pattern);
int main()
{
char file[MAXFILELEN+1]= {0};
char pattern[MAXPATTERN+1]= {0};
char* pfile;
char* ppattern;
int result = 0;
printpre(file,pattern);
pfile = &file[0];
ppattern = &pattern[0];
result = MatchPattern(pfile,ppattern);
printaft(result);
system("PAUSE");
return 0;
}
void printpre(char file[MAXFILELEN+1],char pattern[MAXPATTERN+1]){
cout<<"Please type in the file name :";
cin>>file;
//cout<<endl;
cout<<"Please type in the pattern :";
cin>>pattern;
cout<<"。。。测试进行中。。。"<<endl;
cout<<endl;
cout<<"----------------------自动测试分析如下----------------------" <<endl;
///*
cout<<"一、测试输入信息:"<<endl;
cout<<"File: "<<file<<" "<<endl;
cout<<"Pattern:"<<pattern<<endl;
cout<<endl;
cout<<"二、测试过程信息:"<<endl;
cout<<"被测试函数共有条17分支,分别是:"<<endl;
cout<<" ⑴S,1,E "<<endl;
cout<<" ⑵S,2,4,6,7,E "<<endl;
cout<<" ⑶S,2,4,6,8,10,E "<<endl;
cout<<" ⑷S,2,4,6,8,9,11,10,E "<<endl;
cout<<" ⑸S,2,4,6,8,9,12,E "<<endl;
cout<<" ⑹S,2,3,4,6,7,E "<<endl;
cout<<" ⑺S,2,3,4,6,8,10,E "<<endl;
cout<<" ⑻S,2,3,4,6,8,9,11,10,E "<<endl;
cout<<" ⑼S,2,3,4,6,8,9,12,E "<<endl;
cout<<" ⑽S,2,4,5,6,7,E "<<endl;
cout<<" ⑾S,2,4,5,6,8,10,E "<<endl;
cout<<" ⑿S,2,4,5,6,8,9,11,10,E "<<endl;
cout<<" ⒀S,2,4,5,6,8,9,12,E "<<endl;
cout<<" ⒁S,2,3,4,5,6,7,E "<<endl;
cout<<" ⒂S,2,3,4,5,6,8,10,E "<<endl;
cout<<" ⒃S,2,3,4,5,6,8,9,11,10,E "<<endl;
cout<<" ⒄S,2,3,4,5,6,8,9,12,E "<<endl;
cout<<endl;
cout<<"本测试数据经过分支: ";
//*/
}
void printaft(int match){
cout<<endl;
cout<<endl;
cout<<"三、测试输出信息:"<<endl;
if(match == 1){
cout<<"Succeed in Pattern-Match !"<<endl;
}
else{
cout<<"Failure in Pattern-Match !"<<endl;
}
}
int FindSubString ( const char* source, const char* dest )
{
char l_Source[MAXFILELEN+1];
char l_Dest[MAXFILELEN+1];
int i=0 , j=0;
if( (source == NULL) || (dest == NULL) )
{
return -1;
}
strcpy(l_Source, source);
_strupr(l_Source);
strcpy(l_Dest, dest);
_strupr(l_Dest);
while( l_Source != '\0')
{
j = 0;
while((l_Dest[j] != '\0') && (l_Source[i + j] != '\0')
&& ((l_Dest[j] == '?') || (l_Dest[j] == l_Source[i + j])))
{
j++;
}
if( l_Dest[j] == '\0' )
{
break ;
}
else
{
i++;
}
}
if( l_Source != '\0' )
{
/*
cout<<endl;
cout<<"i="<<i<<endl;
*/
return i;
}
else
{
return -1;
}
}
bool MatchPattern(char* file, char* pattern)
{
char l_Pat[MAXPATTERN+1][MAXFILELEN+1];
int i,j,k;
char* l_Ptr;
cout<<"S,";
memset(l_Pat, 0, MAXPATTERN*(MAXFILELEN+1));
i = j = k = 0;
l_Ptr = NULL;
//cout<<"pass1"<<endl;
if((file == NULL) || (pattern == NULL))
{
cout<<"1,";
//ASSERT(FALSE);//该段代码不应该被执行到 如果不能编译可以注释掉
return FALSE;
}
//cout<<"pass2"<<endl;
cout<<"2,";
while(pattern != '\0')
{
//cout<<"pass3"<<endl;
if(i == 0){
cout<<"3,";
}
if( pattern == '*' )
{
if( k != 0)
{
k = 0;
if( j >= (MAXPATTERN - 1) )
{
return FALSE;
}
else
{
j++;
}
}
}
else
{
l_Pat[j][k++] = pattern;
}
i++;
}
cout<<"4,";
i = 0;
l_Ptr = file;
//cout<<"pass4"<<endl;
while(l_Pat[0] != '\0')
{
if(i == 0){
cout<<"5,";
}
j = FindSubString(l_Ptr, l_Pat);
/*
cout<<endl;
cout<<"j="<<j<<endl;
*/
if((j == -1) || ((i == 0) && (pattern[0] != '*') && (j != 0)))
{
break;
}
else
{
l_Ptr = l_Ptr + j + strlen(l_Pat);
i++;
/*
cout<<endl;
cout<<"i="<<i<<endl;
*/
}
}
/*
cout<<endl;
cout<<"i="<<i<<endl;
*/
cout<<"6,";
//cout<<"pass5"<<endl;
if(l_Pat[0] != '\0')
{
cout<<"7,E";
return FALSE;
}
else
{
if(pattern[strlen(pattern) - 1] != '*')
{
cout<<"8,";
while(strlen(l_Ptr) != 0)
{
cout<<"9,";
j = FindSubString(l_Ptr, l_Pat[i-1]);
if( j == -1 )
{
cout<<"12,E";
return FALSE;
}
cout<<"11,";
l_Ptr = l_Ptr + j + strlen(l_Pat[i-1]);
}
}
cout<<"10,E";
return TRUE;
}
} |
|