看不懂程序要实现什么功能
本人是初学者,从网上下了一份文件检索系统白盒测试报告,但不知道他这个检索系统究竟是要实现什么功能啊?请高手指点,感激不尽!源代码如下:
#include <cstdlib>
#include <iostream>
using namespace std;
#define MAXPATTERN 20 //定义最长的模式名
#define MAXFILELEN 128 //定义最长文件名
#define FALSE 0
#define TRUE 1
void printpre(char file,char pattern);
void printaft(int a);
int FindSubString ( const char* source, const char* dest );
bool MatchPattern(char* file, char* pattern);
int main()
{
char file= {0};
char pattern= {0};
char* pfile;
char* ppattern;
int result = 0;
printpre(file,pattern);
pfile = &file;
ppattern = &pattern;
result = MatchPattern(pfile,ppattern);
printaft(result);
system("PAUSE");
return 0;
}
void printpre(char file,char pattern){
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;
char l_Dest;
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 != '\0') && (l_Source != '\0')
&& ((l_Dest == '?') || (l_Dest == l_Source)))
{
j++;
}
if( l_Dest == '\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;
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 = pattern;
}
i++;
}
cout<<"4,";
i = 0;
l_Ptr = file;
//cout<<"pass4"<<endl;
while(l_Pat != '\0')
{
if(i == 0){
cout<<"5,";
}
j = FindSubString(l_Ptr, l_Pat);
/*
cout<<endl;
cout<<"j="<<j<<endl;
*/
if((j == -1) || ((i == 0) && (pattern != '*') && (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')
{
cout<<"7,E";
return FALSE;
}
else
{
if(pattern != '*')
{
cout<<"8,";
while(strlen(l_Ptr) != 0)
{
cout<<"9,";
j = FindSubString(l_Ptr, l_Pat);
if( j == -1 )
{
cout<<"12,E";
return FALSE;
}
cout<<"11,";
l_Ptr = l_Ptr + j + strlen(l_Pat);
}
}
cout<<"10,E";
return TRUE;
}
} 走读代码啊·看程序代码是否符合编写规则,
页:
[1]