1@echo off
2Setlocal EnableDelayedExpansion
3
4SET TLSH_PROG=tlsh.exe
5SET SIMP_PROG=simple_unittest.exe
6echo Scenario: tlsh	(c++ standard version)...
7
8if EXIST ..\bin\%TLSH_PROG% ( echo found %TLSH_PROG% ) else ( echo error: 128, you must compile %TLSH_PROG% & EXIT /B 127)
9if EXIST ..\bin\%SIMP_PROG% ( echo found %SIMP_PROG% ) else ( echo error: 128, you must compile %SIMP_PROG% & EXIT /B 127)
10if EXIST tmp ( echo found tmp) else ( echo mkdir tmp & mkdir tmp)
11
12SET HASH=128
13SET CHKSUM=1
14SET SLDWIN=5
15SET VERBOSE=0
16
17SET XLEN="len"
18CALL :runit
19if NOT !errorlevel! == 0 ( EXIT /B !errorlevel! )
20
21REM SET XLEN="xlen"
22REM CALL :runit
23REM if NOT !errorlevel! == 0 ( EXIT /B !errorlevel! )
24
25CALL :test7_to_10
26DEL out.res
27if NOT !errorlevel! == 0 ( EXIT /B !errorlevel! )
28
29
30EXIT /B 0
31
32REM ############################
33REM # THE runit FUNCTION
34REM ############################
35REM #
36REM # this function will be run twice, "" and "-xlen"
37REM #
38:runit
39	if "%XLEN%" == "xlen" ( SET XLEN=xlen& echo & echo "Scenario: not considering len, ...") else ( SET XLEN=len& echo "Scenario: considering len, ...")
40
41	REM ########################################################
42	REM # Test 1
43	REM #	get the TLSH values for a directory of files
44	REM ########################################################
45
46	echo "test 1"
47
48	if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -r example_data -o tmp\example_data.out 2> tmp\example_data.err"
49				..\bin\%TLSH_PROG% -r example_data -o tmp\example_data.out 2> tmp\example_data.err
50
51	SET EXPECTED_OUT=exp\example_data.%HASH%.%CHKSUM%.%XLEN%.out_EXP
52	SET EXPECTED_ERR=exp\example_data.%HASH%.%CHKSUM%.%XLEN%.err_EXP
53	if NOT EXIST %EXPECTED_OUT% ( echo "error: 1, Expected Result file %EXPECTED_OUT% does not exist" & EXIT /B 1)
54	if NOT EXIST %EXPECTED_ERR% ( echo "error: 1, Expected Result file %EXPECTED_ERR% does not exist" & EXIT /B 1)
55
56	if %VERBOSE% == 1 echo fc /W tmp\example_data.out %EXPECTED_OUT%
57			       fc /W tmp\example_data.out %EXPECTED_OUT% >NUL && Echo Same>out.res || Echo Different>out.res
58	set /p diffc=<out.res
59	if "%diffc%" == "Different" ( echo "error: (1), fc tmp/example_data.out %EXPECTED_OUT%" & EXIT /B 1)
60
61	if %VERBOSE% == 1 echo fc /W tmp\example_data.out %EXPECTED_ERR%
62			       fc /W tmp\example_data.err %EXPECTED_ERR% >NUL && Echo Same>out.res || Echo Different>out.res
63	set /p diffc=<out.res
64	if "%diffc%" == "Different" ( echo "error: (1), fc tmp\example_data.out %EXPECTED_ERR%" & EXIT /B 1)
65
66	echo "passed"
67
68	if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -r example_data -o tmp\example_data.json_out -ojson 2> tmp\example_data.err"
69				..\bin\%TLSH_PROG% -r example_data -o tmp\example_data.json_out -ojson 2> tmp\example_data.err
70	SET EXPECTED_OUT=exp\example_data.dos_%XLEN%.json_out_EXP
71	if NOT EXIST %EXPECTED_OUT% ( echo "error: 1, Expected Result file %EXPECTED_OUT% does not exist" & EXIT /B 1)
72
73	if %VERBOSE% == 1 echo fc /W tmp\example_data.json_out %EXPECTED_OUT%
74			       fc /W tmp\example_data.json_out %EXPECTED_OUT% >NUL && Echo Same>out.res || Echo Different>out.res
75	set /p diffc=<out.res
76	if "%diffc%" == "Different" ( echo "error: (1), fc tmp\example_data.json_out %EXPECTED_OUT%" & EXIT /B 1)
77
78	echo "passed"
79
80	REM ########################################################
81	REM # Test 2
82	REM #	calculate scores of a file (website_course_descriptors06-07.txt) compared to the directory of files
83	REM ########################################################
84
85	echo "test 2"
86
87	if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -r example_data -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores 2> tmp\example_data.err2"
88				..\bin\%TLSH_PROG% -r example_data -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores 2> tmp\example_data.err2
89
90	SET EXPECTED_SCO=exp\example_data.%HASH%.%CHKSUM%.%SLDWIN%.%XLEN%.dos_scores_EXP
91	SET EXPECTED_ERR=exp\example_data.%HASH%.%CHKSUM%.%XLEN%.err2_EXP
92	if NOT EXIST %EXPECTED_SCO% ( echo "error: 1, Expected Result file %EXPECTED_SCO% does not exist" & EXIT /B 1)
93	if NOT EXIST %EXPECTED_ERR% ( echo "error: 1, Expected Result file %EXPECTED_ERR% does not exist" & EXIT /B 1)
94
95	if %VERBOSE% == 1 echo fc /W tmp\example_data.scores %EXPECTED_SCO%
96			       fc /W tmp\example_data.scores %EXPECTED_SCO% >NUL && Echo Same>out.res || Echo Different>out.res
97	set /p diffc=<out.res
98	if "%diffc%" == "Different" ( echo "error: (2), fc tmp/example_data.scores %EXPECTED_SCO%" & EXIT /B 2)
99
100	if %VERBOSE% == 1 echo fc /W tmp\example_data.err2 %EXPECTED_ERR%
101			       fc /W tmp\example_data.err2 %EXPECTED_ERR% >NUL && Echo Same>out.res || Echo Different>out.res
102	set /p diffc=<out.res
103	if "%diffc%" == "Different" ( echo "error: (2), fc tmp/example_data.err2 %EXPECTED_ERR%" & EXIT /B 2)
104
105	echo "passed"
106
107	REM ########################################################
108	REM # Test 3
109	REM #	calculate scores of a file (website_course_descriptors06-07.txt) compared to hashes listed in a file
110	REM #	far more efficient
111	REM ########################################################
112
113	echo "test 3"
114
115	REM # note that test 3 will output the following error, so write stderr to /dev/null, so it will not be seen.
116	REM #   warning: cannot read TLSH code ../Testing/example_data/BookingBrochure.txt
117	if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -l tmp\example_data.out -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.2"
118				..\bin\%TLSH_PROG% -l tmp\example_data.out -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.2 2>NUL
119
120	SET EXPECTED_SCO=exp\example_data.%HASH%.%CHKSUM%.%SLDWIN%.%XLEN%.dos_scores.2_EXP
121
122	if %VERBOSE% == 1 echo fc /W tmp\example_data.scores.2 %EXPECTED_SCO%
123			       fc /W tmp\example_data.scores.2 %EXPECTED_SCO% >NUL && Echo Same>out.res || Echo Different>out.res
124	set /p diffc=<out.res
125	if "%diffc%" == "Different" ( echo "error: (3), fc tmp/example_data.scores.2 %EXPECTED_SCO%" & EXIT /B 3)
126
127	echo "passed"
128
129
130	REM ########################################################
131	REM # Test 4
132	REM #	Test out the -xref parameter which computes the distance scores for each file in a directory (-r parameter) with
133	REM #   all other files in that directory.
134	REM ########################################################
135	SET testnum=4
136	echo "test %testnum%"
137	if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -xref -r example_data -o tmp\example_data.xref.scores"
138				..\bin\%TLSH_PROG% -xref -r example_data -o tmp\example_data.xref.scores 2>NUL
139
140	SET EXPECTED_SCO=exp/example_data.%HASH%.%CHKSUM%.%XLEN%.xref.scores_EXP
141
142	if %VERBOSE% == 1 echo fc /W tmp\example_data.xref.scores %EXPECTED_SCO%
143			       fc /W tmp\example_data.xref.scores %EXPECTED_SCO% >NUL && Echo Same>out.res || Echo Different>out.res
144	set /p diffc=<out.res
145	if "%diffc%" == "Different" ( echo "error: (4), fc /W tmp\example_data.xref.scores %EXPECTED_SCO%" & EXIT /B 4)
146
147	echo "passed"
148
149	if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -xref -r example_data -o tmp\example_data.xref.json_scores -ojson"
150				..\bin\%TLSH_PROG% -xref -r example_data -o tmp\example_data.xref.json_scores -ojson 2>NUL
151	SET EXPECTED_SCO=exp/example_data.dos_%XLEN%.xref.json_scores_EXP
152	if %VERBOSE% == 1 echo fc /W tmp\example_data.xref.json_scores %EXPECTED_SCO%
153			       fc /W tmp\example_data.xref.json_scores %EXPECTED_SCO% >NUL && Echo Same>out.res || Echo Different>out.res
154	set /p diffc=<out.res
155	if "%diffc%" == "Different" ( echo "error: (4), fc /W tmp\example_data.xref.json_scores %EXPECTED_SCO%" & EXIT /B 4)
156
157	echo "passed"
158
159	REM ########################################################
160	REM # Test 5
161	REM #	Test out the -T (threshold parameter)
162	REM ########################################################
163	SET testnum=5
164	echo "test 5"
165	REM # note that test 5 will output the following error, so write stderr to /dev/null, so it will not be seen.
166	REM #   warning: cannot read TLSH code ../Testing/example_data/BookingBrochure.txt
167
168	if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -T 201 -l tmp\example_data.out -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.2.T-201"
169				..\bin\%TLSH_PROG% -T 201 -l tmp\example_data.out -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.2.T-201 2>NUL
170
171	SET EXPECTED_SCO=exp/example_data.%HASH%.%CHKSUM%.%SLDWIN%.%XLEN%.dos_scores.2.T-201_EXP
172	if NOT EXIST %EXPECTED_SCO% ( echo "error: 1, Expected Result file %EXPECTED_SCO% does not exist" & EXIT /B 5)
173
174	if %VERBOSE% == 1 echo fc /W tmp\example_data.scores.2.T-201 %EXPECTED_SCO%
175			       fc /W tmp\example_data.scores.2.T-201 %EXPECTED_SCO% >NUL && Echo Same>out.res || Echo Different>out.res
176	set /p diffc=<out.res
177	if "%diffc%" == "Different" ( echo "error: (5), fc tmp/example_data.scores.2.T-201 %EXPECTED_SCO%" & EXIT /B 5)
178
179	echo "passed"
180EXIT /B 0
181
182REM ############################
183REM # END OF THE runit FUNCTION
184REM ############################
185
186REM ############################
187REM # Test 6
188REM #	Test out the TLSH digest with a wide range of lengths (testlen.sh)
189REM need to rewrite testlen.sh as testlen.bat
190REM ############################
191REM
192REM # I use the papameter value of 22 for the Fibanacci sequence for generating content
193REM # this generates files up to 6.7 Meg (good enough for automated testing)
194REM
195REM echo "./testlen.sh $TLSH_PROG 22 > tmp/testlen.out"
196REM       ./testlen.sh $TLSH_PROG 22 > tmp/testlen.out
197REM
198REM EXPECTED_TESTLEN=exp/testlen.%HASH%.%CHKSUM%.%SLDWIN%.out_EXP
199REM if test ! -f $EXPECTED_TESTLEN
200REM (
201REM 		echo "error: ($testnum), Expected Result file $EXPECTED_TESTLEN does not exist"
202REM 		EXIT /B 1
203REM )
204REM
205REM diff --ignore-all-space tmp/testlen.out $EXPECTED_TESTLEN > /dev/null 2>/dev/null
206REM if [ $? -ne 0 ]; (
207REM 	echo "error: ($testnum) fc tmp/testlen.out $EXPECTED_TESTLEN"
208REM 	EXIT /B $testnum
209REM )
210REM echo "passed"
211REM
212REM ############################
213REM # END OF test 6
214REM ############################
215REM
216REM ############################
217REM # Test 7
218REM #	Test the -force option
219REM ############################
220
221:test7_to_10
222
223echo "test 7"
224
225if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -force -f example_data\small.txt -o tmp\small.tlsh"
226			..\bin\%TLSH_PROG% -force -f example_data\small.txt -o tmp\small.tlsh
227
228SET EXPECTED_TLSH=exp/small.%HASH%.%CHKSUM%.%SLDWIN%.dos_tlsh_EXP
229if NOT EXIST %EXPECTED_TLSH% ( echo "error: 1, Expected Result file %EXPECTED_TLSH% does not exist" & EXIT /B 7)
230
231if %VERBOSE% == 1 echo fc /W tmp\small.tlsh %EXPECTED_TLSH%
232		       fc /W tmp\small.tlsh %EXPECTED_TLSH% >NUL && Echo Same>out.res || Echo Different>out.res
233set /p diffc=<out.res
234if "%diffc%" == "Different" ( echo "error: (7), fc tmp/small.tlsh %EXPECTED_TLSH%" & EXIT /B 7)
235
236
237
238if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -force -f example_data\small2.txt -o tmp\small2.tlsh"
239			..\bin\%TLSH_PROG% -force -f example_data\small2.txt -o tmp\small2.tlsh
240
241SET EXPECTED_TLSH=exp/small2.%HASH%.%CHKSUM%.%SLDWIN%.dos_tlsh_EXP
242if NOT EXIST %EXPECTED_TLSH% ( echo "error: 1, Expected Result file %EXPECTED_TLSH% does not exist" & EXIT /B 7)
243
244if %VERBOSE% == 1 echo fc /W tmp\small2.tlsh %EXPECTED_TLSH%
245		       fc /W tmp\small2.tlsh %EXPECTED_TLSH% >NUL && Echo Same>out.res || Echo Different>out.res
246set /p diffc=<out.res
247if "%diffc%" == "Different" ( echo "error: (7), fc tmp/small2.tlsh %EXPECTED_TLSH%" & EXIT /B 7)
248
249echo "passed"
250
251REM ############################
252REM # END OF test 7
253REM ############################
254REM
255REM ############################
256REM # Test 8
257REM #	Test the -l2 and -lcsv options
258REM ############################
259
260echo "test 8"
261
262REM #
263REM # Test 8(a): -l2
264REM #
265if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -T 201 -l2 -l example_data_col_swap.tlsh -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.l2.T-201"
266			..\bin\%TLSH_PROG% -T 201 -l2 -l example_data_col_swap.tlsh -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.l2.T-201 2>NUL
267
268REM # same expected output as Test 5
269
270SET EXPECTED_SCO=exp/example_data.%HASH%.%CHKSUM%.%SLDWIN%.len.dos_scores.2.T-201_EXP
271if NOT EXIST %EXPECTED_SCO% ( echo "error: 1, Expected Result file %EXPECTED_SCO% does not exist" & EXIT /B 8)
272
273if %VERBOSE% == 1 echo fc /W tmp\example_data.scores.l2.T-201 %EXPECTED_SCO%
274		       fc /W tmp\example_data.scores.l2.T-201 %EXPECTED_SCO% >NUL && Echo Same>out.res || Echo Different>out.res
275set /p diffc=<out.res
276if "%diffc%" == "Different" ( echo "error: (8), fc tmp\example_data.scores.l2.T-201 %EXPECTED_SCO%" & EXIT /B 8)
277
278REM #
279REM # Test 8(a): -l2 -lcsv
280REM #
281if %VERBOSE% == 1 echo "..\bin\%TLSH_PROG% -T 201 -l2 -lcsv -l example_data_col_swap.csv -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.l2csv.T-201"
282			..\bin\%TLSH_PROG% -T 201 -l2 -lcsv -l example_data_col_swap.csv -c example_data\website_course_descriptors06-07.txt -o tmp\example_data.scores.l2csv.T-201 2>NUL
283
284REM # same expected output as Test 8(a) above
285
286if %VERBOSE% == 1 echo fc /W tmp\example_data.scores.l2csv.T-201 %EXPECTED_SCO%
287		       fc /W tmp\example_data.scores.l2csv.T-201 %EXPECTED_SCO% >NUL && Echo Same>out.res || Echo Different>out.res
288set /p diffc=<out.res
289if "%diffc%" == "Different" ( echo "error: (8), fc tmp\example_data.scores.l2csv.T-201 %EXPECTED_SCO%" & EXIT /B 8)
290
291echo "passed"
292
293
294REM ############################
295REM # END OF test 8
296REM ############################
297
298REM ############################
299REM # Test 9
300REM #	Test the -split option
301REM	-split is not working relaibly on windows - I need to fix this...
302REM ############################
303
304REM echo "test 9"
305
306REM echo "..\bin\%TLSH_PROG% -split 50,100,200 -f example_data\Week3.txt -o tmp\example_data.Week3.split.tlsh"
307REM       ..\bin\%TLSH_PROG% -split 50,100,200 -f example_data\Week3.txt -o tmp\example_data.Week3.split.tlsh   2>NUL
308
309REM SET EXPECTED_RES=exp/example_data.Week3.split.tlsh
310REM if NOT EXIST %EXPECTED_RES% ( echo "error: 1, Expected Result file %EXPECTED_RES% does not exist" & EXIT /B 9)
311
312REM echo fc /W tmp\example_data.Week3.split.tlsh %EXPECTED_RES%
313REM      fc /W tmp\example_data.Week3.split.tlsh %EXPECTED_RES% >NUL && Echo Same>out.res || Echo Different>out.res
314REM set /p diffc=<out.res
315REM if "%diffc%" == "Different" ( echo "error: (8), fc tmp\example_data.Week3.split.tlsh %EXPECTED_RES%" & EXIT /B 9)
316
317REM echo "passed"
318
319REM ############################
320REM # END OF test 9
321REM ############################
322
323REM ############################
324REM # test 10
325REM ############################
326
327echo "Running %SIMP_PROG%"
328..\bin\%SIMP_PROG% > tmp\simple_unittest.out
329
330SET EXPECTED_STEST=exp\simple_unittest.%HASH%.%CHKSUM%.EXP
331if NOT EXIST %EXPECTED_STEST% ( echo "error: 1, Expected Result file %EXPECTED_STEST% does not exist" & EXIT /B 10)
332
333if %VERBOSE% == 1 echo fc /W tmp\simple_unittest.out %EXPECTED_STEST%
334		       fc /W tmp\simple_unittest.out %EXPECTED_STEST% >NUL && Echo Same>out.res || Echo Different>out.res
335set /p diffc=<out.res
336if "%diffc%" == "Different" ( echo "error: (8), fc tmp\simple_unittest.out %EXPECTED_STEST%" & EXIT /B 10)
337
338echo "passed all example data tests"
339
340echo.
341echo "If you have made changes to the Tlsh python module, build and install it, and run python_test.sh"
342echo.
343
344EXIT /B 0
345