summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2008-07-06 15:19:28 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2008-07-06 15:19:28 +0000
commit7dd0248a21ecc9bd0b333d3c251b52faee532549 (patch)
tree579cc869b076897970e99596a242471b9cbd1d1e /xdelta3
parente82b0cd004eadfefb9465713acbe6b62a3f99f6f (diff)
Add mutator test working.
Diffstat (limited to 'xdelta3')
-rw-r--r--xdelta3/testing/modify.h44
-rw-r--r--xdelta3/testing/regtest.cc33
2 files changed, 71 insertions, 6 deletions
diff --git a/xdelta3/testing/modify.h b/xdelta3/testing/modify.h
index 8da03a2..2080904 100644
--- a/xdelta3/testing/modify.h
+++ b/xdelta3/testing/modify.h
@@ -111,7 +111,7 @@ void ChangeListMutator::Mutate(const Change &ch,
111 MTRandom *rand) { 111 MTRandom *rand) {
112 switch (ch.kind) { 112 switch (ch.kind) {
113 case Change::ADD: 113 case Change::ADD:
114 //AddChange(ch, table, source_table, rand); 114 AddChange(ch, table, source_table, rand);
115 break; 115 break;
116 case Change::MODIFY: 116 case Change::MODIFY:
117 ModifyChange(ch, table, source_table, rand); 117 ModifyChange(ch, table, source_table, rand);
@@ -164,6 +164,45 @@ void ChangeListMutator::ModifyChange(const Change &ch,
164 } 164 }
165} 165}
166 166
167void ChangeListMutator::AddChange(const Change &ch,
168 SegmentMap *table,
169 const SegmentMap *source_table,
170 MTRandom *rand) {
171 xoff_t m_start = ch.addr1;
172
173 for (SegmentMap::const_iterator iter(source_table->begin());
174 iter != source_table->end();
175 ++iter) {
176 const Segment &seg = iter->second;
177 xoff_t i_start = iter->first;
178 xoff_t i_end = i_start + seg.length;
179
180 if (i_end <= m_start) {
181 table->insert(table->end(), make_pair(i_start, seg));
182 continue;
183 }
184
185 if (i_start > m_start) {
186 table->insert(table->end(), make_pair(i_start + ch.size, seg));
187 continue;
188 }
189
190 if (i_start < m_start) {
191 Segment before(seg.seed, m_start - i_start, seg.seed_offset);
192 table->insert(table->end(), make_pair(i_start, before));
193 }
194
195 Segment addseg(rand->Rand32(), ch.size);
196 table->insert(table->end(), make_pair(m_start, addseg));
197
198 if (m_start < i_end) {
199 Segment after(seg.seed, i_end - m_start,
200 seg.seed_offset + (m_start - i_start));
201 table->insert(table->end(), make_pair(m_start + ch.size, after));
202 }
203 }
204}
205
167class Modify1stByte : public Mutator { 206class Modify1stByte : public Mutator {
168public: 207public:
169 void Mutate(SegmentMap *table, 208 void Mutate(SegmentMap *table,
@@ -172,9 +211,6 @@ public:
172 ChangeListMutator::Mutate(Change(Change::MODIFY, 1, 0), 211 ChangeListMutator::Mutate(Change(Change::MODIFY, 1, 0),
173 table, source_table, rand); 212 table, source_table, rand);
174 } 213 }
175
176private:
177 ChangeListMutator clm_;
178}; 214};
179 215
180} // namespace regtest 216} // namespace regtest
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc
index 12499ba..487a407 100644
--- a/xdelta3/testing/regtest.cc
+++ b/xdelta3/testing/regtest.cc
@@ -268,9 +268,7 @@ void TestModifyMutator() {
268 for (size_t i = 0; i < SIZEOF_ARRAY(test_cases); i++) { 268 for (size_t i = 0; i < SIZEOF_ARRAY(test_cases); i++) {
269 ChangeList cl1; 269 ChangeList cl1;
270 cl1.push_back(Change(Change::MODIFY, test_cases[i].size, test_cases[i].addr)); 270 cl1.push_back(Change(Change::MODIFY, test_cases[i].size, test_cases[i].addr));
271 spec0.Print();
272 spec0.ModifyTo(ChangeListMutator(cl1), &spec1); 271 spec0.ModifyTo(ChangeListMutator(cl1), &spec1);
273 spec1.Print();
274 272
275 size_t diff = CmpDifferentBytes(spec0, spec1); 273 size_t diff = CmpDifferentBytes(spec0, spec1);
276 CHECK_LE(diff, test_cases[i].size); 274 CHECK_LE(diff, test_cases[i].size);
@@ -280,12 +278,43 @@ void TestModifyMutator() {
280 } 278 }
281} 279}
282 280
281void TestAddMutator() {
282 MTRandom rand;
283 FileSpec spec0(&rand);
284 FileSpec spec1(&rand);
285
286 spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 2);
287
288 struct {
289 size_t size;
290 size_t addr;
291 } test_cases[] = {
292 { 1, 0 },
293 { 1, 1 },
294 { 1, Constants::BLOCK_SIZE - 1 },
295 { 1, Constants::BLOCK_SIZE },
296 { 1, Constants::BLOCK_SIZE + 1},
297 { 1, 2 * Constants::BLOCK_SIZE },
298 };
299
300 for (size_t i = 0; i < SIZEOF_ARRAY(test_cases); i++) {
301 ChangeList cl1;
302 cl1.push_back(Change(Change::ADD, test_cases[i].size, test_cases[i].addr));
303 spec0.Print();
304 spec0.ModifyTo(ChangeListMutator(cl1), &spec1);
305 spec1.Print();
306
307 InMemoryEncodeDecode(spec0, spec1);
308 }
309}
310
283int main(int argc, char **argv) { 311int main(int argc, char **argv) {
284#define TEST(x) cerr << #x << "..." << endl; x() 312#define TEST(x) cerr << #x << "..." << endl; x()
285 TEST(TestRandomNumbers); 313 TEST(TestRandomNumbers);
286 TEST(TestRandomFile); 314 TEST(TestRandomFile);
287 TEST(TestFirstByte); 315 TEST(TestFirstByte);
288 TEST(TestModifyMutator); 316 TEST(TestModifyMutator);
317 TEST(TestAddMutator);
289 return 0; 318 return 0;
290} 319}
291 320