1 /*
2  * steghide 0.5.1 - a steganography program
3  * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  */
20 
21 #include "WavPCMSampleValueTest.h"
22 #include "utcommon.h"
23 
24 #include "WavPCMSampleValue.h"
25 #include "CvrStgFile.h"
26 
WavPCMSampleValueTest(TestSuite * s)27 WavPCMSampleValueTest::WavPCMSampleValueTest (TestSuite* s)
28 	: SampleValueTest ("WavPCMSampleValue", s)
29 {
30 	ADDTESTCATEGORY (WavPCMSampleValueTest, testDistance) ;
31 	ADDTESTCATEGORY (WavPCMSampleValueTest, testIsNeighbour) ;
32 }
33 
setup()34 void WavPCMSampleValueTest::setup ()
35 {
36 	UnitTest::setup() ;
37 
38 	Globs.reset() ;
39 	f_WavPCM8 = CvrStgFile::readFile (std::string(DATADIR) + "pcm8_std.wav") ;
40 	sv_WavPCM8_0 = new WavPCMSampleValue (0) ;
41 	sv_WavPCM8_1 = new WavPCMSampleValue (1) ;
42 	sv_WavPCM8_45 = new WavPCMSampleValue (45) ;
43 	gl_WavPCM8 = Globs ;
44 
45 	Globs.reset() ;
46 	f_WavPCM16 = CvrStgFile::readFile (std::string(DATADIR) + "pcm16_std.wav") ;
47 	sv_WavPCM16_m32768 = new WavPCMSampleValue (-32768) ;
48 	sv_WavPCM16_32767 = new WavPCMSampleValue (32767) ;
49 	sv_WavPCM16_0 = new WavPCMSampleValue (0) ;
50 	sv_WavPCM16_15 = new WavPCMSampleValue (15) ;
51 	gl_WavPCM16 = Globs ;
52 }
53 
cleanup()54 void WavPCMSampleValueTest::cleanup ()
55 {
56 	UnitTest::cleanup() ;
57 
58 	delete f_WavPCM8 ; delete f_WavPCM16 ;
59 	delete sv_WavPCM8_0 ; delete sv_WavPCM8_1 ; delete sv_WavPCM8_45 ;
60 	delete sv_WavPCM16_m32768 ; delete sv_WavPCM16_32767 ; delete sv_WavPCM16_0 ; delete sv_WavPCM16_15 ;
61 }
62 
testDistance()63 void WavPCMSampleValueTest::testDistance ()
64 {
65 	Globs = gl_WavPCM8 ;
66 	addTestResult (genericTestDistance (sv_WavPCM8_0, sv_WavPCM8_1, 1)) ;
67 	addTestResult (genericTestDistance (sv_WavPCM8_1, sv_WavPCM8_45, 44)) ;
68 
69 	Globs = gl_WavPCM16 ;
70 	addTestResult (genericTestDistance (sv_WavPCM16_0, sv_WavPCM16_15, 15)) ;
71 	addTestResult (genericTestDistance (sv_WavPCM16_15, sv_WavPCM16_32767, 32752)) ;
72 	addTestResult (genericTestDistance (sv_WavPCM16_m32768, sv_WavPCM16_32767, 65535)) ;
73 }
74 
testIsNeighbour()75 void WavPCMSampleValueTest::testIsNeighbour ()
76 {
77 	Globs = gl_WavPCM8 ;
78 	addTestResult (genericTestIsNeighbour (sv_WavPCM8_0, sv_WavPCM8_1, true)) ;
79 	addTestResult (genericTestIsNeighbour (sv_WavPCM8_0, sv_WavPCM8_45, false)) ;
80 
81 	Globs = gl_WavPCM16 ;
82 	addTestResult (genericTestIsNeighbour (sv_WavPCM16_0, sv_WavPCM16_15, true)) ;
83 	addTestResult (genericTestIsNeighbour (sv_WavPCM16_m32768, sv_WavPCM16_0, false)) ;
84 	addTestResult (genericTestIsNeighbour (sv_WavPCM16_m32768, sv_WavPCM16_32767, false)) ;
85 }
86