1#!/bin/bash
2
3export LC_ALL='C'
4
5echoerr() { echo "$@" 1>&2; }
6
7BASEDIR=$(dirname $0)
8pushd $BASEDIR > /dev/null
9
10if test ! -f ../bin/tlsh
11then
12	echoerr "error: (127), you must compile tlsh"
13        popd > /dev/null
14	exit 127
15fi
16
17if test ! -f ../bin/tlsh_pattern
18then
19	echoerr "error: (127), you must compile ../bin/tlsh_pattern"
20        popd > /dev/null
21	exit 127
22fi
23
24mkdir -p tmp
25
26############################
27# Test 1
28#	create a pattern file
29############################
30testnum=1
31echo
32echo "test_pattern $testnum"
33echo
34
35############
36# create pattern file
37#	col 1: pattern number
38#	col 2: nitems in group
39#	col 3: TLSH
40#	col 4: radius
41#	col 5: pattern label
42############
43PATTERN_FILE=tmp/tenfile.pat
44rm -f $PATTERN_FILE
45patn=0
46for f in	021106_yossivassa.txt 0Alice.txt 11-17-06_Academy.txt 1english-only.txt 2005NISSE.txt			\
47		2006-07_Resource_Brochure.txt 2006_2007PhysicalEducationConceptMap.txt 2007ShowcaseFilm_Package.txt	\
48		22-ppa-3rd_e2snewsletter_jun06.txt  42nd_street.txt ; do
49
50	FILE=example_data/$f
51	if test ! -f $FILE
52	then
53		echoerr "error: (1), cannot find file $FILE"
54        	popd > /dev/null
55		exit 1
56	fi
57	echo "../bin/tlsh -f $FILE | cut -f 1"
58	tlsh=`../bin/tlsh -f $FILE | cut -f 1`
59	echo "pat_$patn	1	$tlsh	30	$f"	>> $PATTERN_FILE
60	patn=`expr $patn + 1`
61done
62
63EXPECTED_PATFILE=exp/tenfile.pat_EXP
64if test ! -f $EXPECTED_PATFILE
65then
66	echoerr "error: ($testnum), Expected Pattern file $EXPECTED_PATFILE does not exist"
67	popd > /dev/null
68	exit 1
69fi
70
71diff --ignore-all-space $PATTERN_FILE $EXPECTED_PATFILE > /dev/null 2>/dev/null
72if [ $? -ne 0 ]; then
73	echoerr "error: ($testnum) diff $PATTERN_FILE $EXPECTED_PATFILE"
74	popd > /dev/null
75	exit $testnum
76fi
77echo "passed"
78
79############################
80# END OF test 1
81############################
82
83############################
84# Test 2
85# use tlsh_pattern
86############################
87testnum=2
88echo
89echo "test_pattern $testnum"
90echo
91
92for dir in example_data example_data_variants ; do
93	RESFILE=tmp/$dir.results
94
95	echo   "../bin/tlsh_pattern -force -r $dir -pat $PATTERN_FILE > $RESFILE"
96		../bin/tlsh_pattern -force -r $dir -pat $PATTERN_FILE > $RESFILE
97
98	EXPECTED_RESFILE=exp/$dir.results_EXP
99	if test ! -f $EXPECTED_RESFILE
100	then
101		echoerr "error: ($testnum), Expected results file $EXPECTED_RESFILE does not exist"
102		popd > /dev/null
103		exit 1
104	fi
105
106	diff --ignore-all-space $RESFILE $EXPECTED_RESFILE > /dev/null 2>/dev/null
107	if [ $? -ne 0 ]; then
108		echoerr "error: ($testnum) diff $RESFILE $EXPECTED_RESFILE"
109		popd > /dev/null
110		exit $testnum
111	fi
112	echo "passed"
113done
114
115############################
116# END OF test 2
117############################
118