File: MatchingTest.cc

package info (click to toggle)
steghide 0.5.1-15
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,440 kB
  • sloc: cpp: 13,302; ansic: 6,184; sh: 3,960; makefile: 384; yacc: 316; perl: 228; sed: 16
file content (229 lines) | stat: -rw-r--r-- 6,603 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * steghide 0.5.1 - a steganography program
 * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include "BitString.h"
#include "Edge.h"
#include "Graph.h"
#include "Selector.h"

#include "DummyFile.h"
#include "MatchingTest.h"

#define CREATEEDGEPTR(G,V1,V2) (new Edge ((G)->getVertex(V1), 0, (G)->getVertex(V2), 1))
#define CREATEEDGEOBJ(G,V1,V2) (Edge ((G)->getVertex(V1), 0, (G)->getVertex(V2), 1))

MatchingTest::MatchingTest (TestSuite* s)
	: UnitTest ("Matching", s)
{
	ADDTESTCATEGORY (MatchingTest, testAddRemoveEdge) ;
	ADDTESTCATEGORY (MatchingTest, testAugmentingPath) ;
}

void MatchingTest::setup ()
{
	UnitTest::setup() ;

	Globs.reset() ;
	std::vector<std::list<UWORD16> > adjlist1 (4) ;
	adjlist1[0].push_back(1) ; adjlist1[0].push_back(2) ;
	adjlist1[1].push_back(2) ; adjlist1[1].push_back(3) ;
	DummyFile::createGraph (adjlist1, &bs1, &f1, &s1) ;
	g1 = new Graph (f1, *bs1, *s1) ;
	m1 = new Matching (g1) ;
	gl1 = Globs ;

	Globs.reset() ;
	std::vector<std::list<UWORD16> > adjlist2 (10) ;
	adjlist2[0].push_back(1) ; adjlist2[0].push_back(4) ;
	adjlist2[1].push_back(2) ; adjlist2[1].push_back(3) ; adjlist2[1].push_back(7) ;
	adjlist2[2].push_back(3) ; adjlist2[2].push_back(4) ; adjlist2[2].push_back(5) ; adjlist2[2].push_back(6) ;
	adjlist2[3].push_back(6) ;
	adjlist2[4].push_back(6) ; adjlist2[4].push_back(7) ; adjlist2[4].push_back(8) ; adjlist2[4].push_back(9) ;
	adjlist2[5].push_back(6) ;
	adjlist2[7].push_back(8) ;
	DummyFile::createGraph (adjlist2, &bs2, &f2, &s2) ;
	g2 = new Graph (f2, *bs2, *s2) ;
	m2 = new Matching (g2) ;
	gl2 = Globs ;
}

void MatchingTest::cleanup ()
{
	UnitTest::cleanup() ;

	delete m1 ;
	delete g1 ;
	delete s1 ;
	delete bs1 ;
	delete f1 ;

	delete m2 ;
	delete g2 ;
	delete s2 ;
	delete bs2 ;
	delete f2 ;
}

void MatchingTest::testAddRemoveEdge ()
{
	{ // test Matching m1
		Globs = gl1 ;

		Edge e1 = CREATEEDGEOBJ (g1, 0, 2) ;
		m1->addEdge (e1) ;
		addTestResult (	m1->isMatched((VertexLabel) 0) &&
						m1->isExposed((VertexLabel) 1) &&
						m1->isMatched((VertexLabel) 2) &&
						m1->isExposed((VertexLabel) 3)) ;

		Edge e2 = CREATEEDGEOBJ (g1, 1, 3) ;
		m1->addEdge (e2) ;
		addTestResult (	m1->isMatched((VertexLabel) 0) &&
						m1->isMatched((VertexLabel) 1) &&
						m1->isMatched((VertexLabel) 2) &&
						m1->isMatched((VertexLabel) 3)) ;

		m1->removeEdge (e1) ;
		addTestResult (	m1->isExposed((VertexLabel) 0) &&
						m1->isMatched((VertexLabel) 1) &&
						m1->isExposed((VertexLabel) 2) &&
						m1->isMatched((VertexLabel) 3)) ;

		m1->removeEdge (e2) ;
		addTestResult (	m1->isExposed((VertexLabel) 0) &&
						m1->isExposed((VertexLabel) 1) &&
						m1->isExposed((VertexLabel) 2) &&
						m1->isExposed((VertexLabel) 3)) ;

	}

	{ // test Matching m2
		Globs = gl2 ;

		Edge e1 = CREATEEDGEOBJ (g2, 1, 7) ;
		m2->addEdge (e1) ;
		addTestResult (	m2->getCardinality() == 1 &&
						m2->includesEdge(e1)) ;

		Edge e2 = CREATEEDGEOBJ (g2, 4, 8) ;
		m2->addEdge (e2) ;
		addTestResult (	m2->getCardinality() == 2 &&
						m2->includesEdge(e1) &&
						m2->includesEdge(e2)) ;

		Edge e3 = CREATEEDGEOBJ (g2, 2, 6) ;
		m2->addEdge (e3) ;
		addTestResult (	m2->getCardinality() == 3 &&
						m2->includesEdge(e1) &&
						m2->includesEdge(e2) &&
						m2->includesEdge(e3)) ;

		m2->removeEdge (e2) ;
		addTestResult (	m2->getCardinality() == 2 &&
						m2->includesEdge(e1) &&
						m2->includesEdge(e3)) ;

		m2->removeEdge (e1) ;
		addTestResult (	m2->getCardinality() == 1 &&
						m2->includesEdge(e3)) ;

		m2->removeEdge (e3) ;
		addTestResult ( m2->getCardinality() == 0) ;
	}
}

void MatchingTest::testAugmentingPath ()
{
	{ // test Matching m1
		Globs = gl1 ;

		std::vector<Edge*> augpath1 ;
		augpath1.push_back (CREATEEDGEPTR (g1, 0, 1)) ;
		m1->augment (augpath1) ;
		addTestResult (	m1->isMatched((VertexLabel) 0) &&
						m1->isMatched((VertexLabel) 1) &&
						m1->isExposed((VertexLabel) 2) &&
						m1->isExposed((VertexLabel) 3)) ;

		std::vector<Edge*> augpath2 ;
		augpath2.push_back (CREATEEDGEPTR (g1, 1, 3)) ;
		augpath2.push_back (CREATEEDGEPTR (g1, 0, 1)) ;
		augpath2.push_back (CREATEEDGEPTR (g1, 0, 2)) ;
		m1->augment (augpath2) ;
		addTestResult (	m1->isMatched((VertexLabel) 0) &&
						m1->isMatched((VertexLabel) 1) &&
						m1->isMatched((VertexLabel) 2) &&
						m1->isMatched((VertexLabel) 3)) ;
	}

	{ // test Matching m2
		Globs = gl2 ;

		Edge* e12 = CREATEEDGEPTR (g2, 1, 2) ;
		Edge* e17 = CREATEEDGEPTR (g2, 1, 7) ;
		Edge* e23 = CREATEEDGEPTR (g2, 2, 3) ;
		Edge* e36 = CREATEEDGEPTR (g2, 3, 6) ;
		Edge* e47 = CREATEEDGEPTR (g2, 4, 7) ;
		Edge* e49 = CREATEEDGEPTR (g2, 4, 9) ;
		Edge* e56 = CREATEEDGEPTR (g2, 5, 6) ;

		std::vector<Edge*> augpath1 ;
		augpath1.push_back (e12) ;
		m2->augment (augpath1) ;
		addTestResult (	m2->getCardinality() == 1 &&
						m2->includesEdge(*e12)) ;

		std::vector<Edge*> augpath2 ;
		augpath2.push_back (e17) ;
		augpath2.push_back (e12) ;
		augpath2.push_back (e23) ;
		m2->augment (augpath2) ;
		addTestResult (	m2->getCardinality() == 2 &&
						m2->includesEdge(*e17) &&
						m2->includesEdge(*e23)) ;

		std::vector<Edge*> augpath3 ;
		augpath3.push_back (e47) ;
		augpath3.push_back (e17) ;
		augpath3.push_back (e12) ;
		augpath3.push_back (e23) ;
		augpath3.push_back (e36) ;
		m2->augment (augpath3) ;
		addTestResult (	m2->getCardinality() == 3 &&
						m2->includesEdge(*e47) &&
						m2->includesEdge(*e12) &&
						m2->includesEdge(*e36)) ;

		std::vector<Edge*> augpath4 ;
		augpath4.push_back (e49) ;
		augpath4.push_back (e47) ;
		augpath4.push_back (e17) ;
		augpath4.push_back (e12) ;
		augpath4.push_back (e23) ;
		augpath4.push_back (e36) ;
		augpath4.push_back (e56) ;
		m2->augment (augpath4) ;
		addTestResult (	m2->getCardinality() == 4 &&
						m2->includesEdge(*e49) &&
						m2->includesEdge(*e17) &&
						m2->includesEdge(*e23) &&
						m2->includesEdge(*e56)) ;
	}
}