#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

void SameFingerMatch()
{
	int result;
	unsigned char tz_buf[345]={0}, mb_buf[345]={0};
	FILE   *fp;
	fp=fopen("mb1.txt","r");
	fscanf(fp,"%s",mb_buf);
	fclose(fp);
	/*printf("\n指纹1模板数据：%s\n",mb_buf);*/

	fp=fopen("tz1.txt","r");
	fscanf(fp,"%s",tz_buf);
	fclose(fp);
	/*printf("\n指纹1特征数据：%s\n",tz_buf);*/

	result = mxFingerMatchBase64(mb_buf, tz_buf, 3);
	if(result!=0)
		printf("\n     指纹比对失败！！\n");
	else
		printf("\n     指纹比对成功！！\n"); 
}

void DiffFingerMatch()
{
	int result;
	unsigned char tz_buf[345]={0}, mb_buf[345]={0};
	FILE   *fp;
	fp=fopen("mb1.txt","r");
		fscanf(fp,"%s",mb_buf);
	fclose(fp);
	/*printf("\n指纹1模板数据：%s\n",mb_buf);*/

	fp=fopen("tz2.txt","r");
		fscanf(fp,"%s",tz_buf);
	fclose(fp);
	/*printf("\n指纹2特征数据：%s\n",tz_buf);*/

	result = mxFingerMatchBase64(mb_buf, tz_buf, 3);
	if(result!=0)
		printf("\n     指纹比对失败！！\n");
	else
		printf("\n     指纹比对成功！！\n"); 
}

void InvalidDataMatch()
{
	int result;
	unsigned char tz_buf[345]={0}, mb_buf[345]={0};
	FILE   *fp;
	fp=fopen("mb1.txt","r");
		fscanf(fp,"%s",mb_buf);
	fclose(fp);
	/*printf("\n指纹1模板数据：%s\n",mb_buf);*/

	fp=fopen("tz1.txt","r");
	fscanf(fp,"%s",tz_buf);
	fclose(fp);
	tz_buf[50] = 0;      /*数据被篡改*/
	/*printf("\n指纹1特征数据：%s\n",tz_buf);*/

	result = mxFingerMatchBase64(mb_buf, tz_buf, 3);
	if(result!=0)
		printf("\n     指纹比对失败！！\n");
	else
		printf("\n     指纹比对成功！！\n"); 
}

void GetVersion()
{
	char version[100]={0};
	MXGetVersion(version);
	printf("\n     %s\n",version);	
}

int main(int argc, char** argv)
{
	int flag = 1;
	char szAct[100];

	while(flag)
	{
    		printf("\n****************************");
    		printf("\n* 杭州中正比对算法测试程序 *");
    		printf("\n*    1.相同手指比对        *");	
    		printf("\n*    2.不同手指比对        *");
    		printf("\n*    3.非法数据比对        *");
    		printf("\n*    4.算法版本            *");
    		printf("\n*    0.退出                *"); 
   			printf("\n****************************");   
    		printf("\n     请选择(0-4):");
    
    		gets(szAct);
    		switch(szAct[0])
    		{
    		case '1':
        		SameFingerMatch();
        		break;
      	case '2':
        		DiffFingerMatch();
       			break;
      	case '3':
						InvalidDataMatch();
						break;
				case '4':
						GetVersion();
						break;
      	case '0':
        		flag = 0;
        		break;
    		}
  	}
  	return 0;
}
