1 /*
2 * steghide 0.5.1 - a steganogrchy 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 "WKSConstructionHeuristic.h"
22 #include "BitString.h"
23 #include "Edge.h"
24 #include "Graph.h"
25 #include "Matching.h"
26 #include "Selector.h"
27
28 #include "DummyFile.h"
29 #include "WKSConstructionHeuristicTest.h"
30
31 #define CREATEEDGE(G,V1,V2) (new Edge ((G)->getVertex(V1), 0, (G)->getVertex(V2), 1))
32
WKSConstructionHeuristicTest(TestSuite * s)33 WKSConstructionHeuristicTest::WKSConstructionHeuristicTest (TestSuite* s)
34 : UnitTest ("WKSConstructionHeuristic", s)
35 {
36 ADDTESTCATEGORY (WKSConstructionHeuristicTest, testAlgorithm) ;
37 }
38
setup()39 void WKSConstructionHeuristicTest::setup ()
40 {
41 UnitTest::setup() ;
42
43 // a trivial case to start with
44 {
45 Globs.reset() ;
46 std::vector<std::list<UWORD16> > adjlist (2) ;
47 adjlist[0].push_back(1) ;
48 DummyFile::createGraph (adjlist, &bs1, &f1, &s1) ;
49 g1 = new Graph (f1, *bs1, *s1) ;
50 m1 = new Matching (g1) ;
51 ch1 = new WKSConstructionHeuristic (g1, m1, 100.0) ;
52 gl1 = Globs ;
53 }
54
55 // first counterexample - will not find maximum matching
56 {
57 Globs.reset() ;
58 std::vector<std::list<UWORD16> > adjlist (4) ;
59 adjlist[0].push_back(1) ; adjlist[0].push_back(2) ; adjlist[0].push_back(3) ;
60 adjlist[1].push_back(2) ; adjlist[1].push_back(3) ;
61 DummyFile::createGraph (adjlist, &bs2, &f2, &s2) ;
62 g2 = new Graph (f2, *bs2, *s2) ;
63 m2 = new Matching (g2) ;
64 ch2 = new WKSConstructionHeuristic (g2, m2, 100.0) ;
65 gl2 = Globs ;
66 }
67
68 // will find maximum matching here because of Deg1-rule
69 {
70 Globs.reset() ;
71 std::vector<std::list<UWORD16> > adjlist (4) ;
72 adjlist[0].push_back(1) ; adjlist[0].push_back(2) ;
73 adjlist[1].push_back(3) ;
74 DummyFile::createGraph (adjlist, &bs3, &f3, &s3) ;
75 g3 = new Graph (f3, *bs3, *s3) ;
76 m3 = new Matching (g3) ;
77 ch3 = new WKSConstructionHeuristic (g3, m3, 100.0) ;
78 gl3 = Globs ;
79 }
80 }
81
cleanup()82 void WKSConstructionHeuristicTest::cleanup ()
83 {
84 UnitTest::cleanup() ;
85
86 Globs = gl1 ; delete ch1 ; delete m1 ; delete g1 ; delete s1 ; delete bs1 ; delete f1 ;
87 Globs = gl2 ; delete ch2 ; delete m2 ; delete g2 ; delete s2 ; delete bs2 ; delete f2 ;
88 Globs = gl3 ; delete ch3 ; delete m3 ; delete g3 ; delete s3 ; delete bs3 ; delete f3 ;
89 }
90
testAlgorithm()91 void WKSConstructionHeuristicTest::testAlgorithm ()
92 {
93 {
94 Globs = gl1 ;
95 ch1->run() ;
96 addTestResult ( m1->isMatched((VertexLabel) 0) &&
97 m1->isMatched((VertexLabel) 1)) ;
98 }
99
100 {
101 Globs = gl2 ;
102 ch2->run() ;
103 addTestResult ( m2->isMatched((VertexLabel) 0) &&
104 m2->isMatched((VertexLabel) 1) &&
105 m2->isExposed((VertexLabel) 2) &&
106 m2->isExposed((VertexLabel) 3)) ;
107 }
108
109 {
110 Globs = gl3 ;
111 ch3->run() ;
112 addTestResult ( m3->isMatched((VertexLabel) 0) &&
113 m3->isMatched((VertexLabel) 1) &&
114 m3->isMatched((VertexLabel) 2) &&
115 m3->isMatched((VertexLabel) 3)) ;
116 }
117 }
118