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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
// test_dense_setset.cc
//
// Copyright (C) 2005, 2009 Daniel Burrows
//
// 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; see the file COPYING. If not, write to
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
#include <generic/problemresolver/promotion_set.h>
#include <generic/problemresolver/dummy_universe.h>
#include <cppunit/extensions/HelperMacros.h>
#include <iostream>
namespace
{
const char *dummy_universe_1 = "\
UNIVERSE [ \
PACKAGE a < v1 v2 v3 > v1 \
PACKAGE b < v1 v2 v3 > v1 \
PACKAGE c < v1 v2 v3 > v1 \
\
DEP a v1 -> < b v2 > \
DEP b v2 -> < c v2 > \
\
DEP a v2 -> < > \
DEP a v3 -> < > \
]";
}
class Promotion_SetTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(Promotion_SetTest);
CPPUNIT_TEST(testFindHighestPromotion);
CPPUNIT_TEST(testRemoveTier);
CPPUNIT_TEST(testRemoveBelowTier);
CPPUNIT_TEST_SUITE_END();
static dummy_universe_ref parseUniverse(const std::string &s)
{
std::istringstream in(s);
return parse_universe(in);
}
typedef dummy_universe_ref::package package;
typedef dummy_universe_ref::version version;
typedef dummy_universe_ref::dep dep;
typedef generic_choice<dummy_universe_ref> choice;
typedef generic_choice_set<dummy_universe_ref> choice_set;
typedef generic_promotion_set<dummy_universe_ref> dummy_promotion_set;
typedef dummy_promotion_set::promotion promotion;
static imm::set<promotion> get_promotions(const dummy_promotion_set &promotions)
{
imm::set<promotion> rval;
for(dummy_promotion_set::const_iterator it = promotions.begin();
it != promotions.end(); ++it)
rval.insert(*it);
return rval;
}
static unsigned int empirical_promotions_size(const dummy_promotion_set &promotions)
{
unsigned int rval = 0;
for(dummy_promotion_set::const_iterator it = promotions.begin();
it != promotions.end(); ++it)
++rval;
return rval;
}
static void make_test_promotions(const dummy_universe_ref &u,
dummy_promotion_set &promotions)
{
// Otherwise the tests below will fail.
CPPUNIT_ASSERT_EQUAL((unsigned int)0, promotions.size());
package a(u.find_package("a"));
package b(u.find_package("b"));
package c(u.find_package("c"));
version av1(a.version_from_name("v1"));
version av2(a.version_from_name("v2"));
version av3(a.version_from_name("v3"));
version bv1(b.version_from_name("v1"));
version bv2(b.version_from_name("v2"));
version bv3(b.version_from_name("v3"));
version cv1(c.version_from_name("v1"));
version cv2(c.version_from_name("v2"));
version cv3(c.version_from_name("v3"));
dep av1d1(*av1.deps_begin());
dep bv2d1(*bv2.deps_begin());
dep av2d1(*av2.deps_begin());
dep av3d1(*av3.deps_begin());
// Insert promotions:
// (Install(a v1 [a v2 -> <>])): 100
// (Install(a v1, b v2, c v3)): 50
// (Install(a v1, b v2)): 75
// (Install(a v1, b v2, c v1)): 10
// (Install(b v2)): 30
// (Break(b v2 -> <c v2>)): 125
// (Install(c v3), Break (b v2 -> <c v2>)): 500
// (Install(bv3 [b v2 -> <c v2>], cv2)): 50
//
// Note that the third entry should override the second one. The
// fourth entry shouldn't be stored at all.
// Verify that the promotion set has the expected
// entries at each point in its construction.
imm::set<promotion> expected_promotions;
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p1_choices;
p1_choices.insert_or_narrow(make_install_version_from_dep_source(av1, av2d1));
promotion p1(p1_choices, 100);
expected_promotions.insert(p1);
promotions.insert(p1);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p2_choices;
p2_choices.insert_or_narrow(make_install_version(av1));
p2_choices.insert_or_narrow(make_install_version(bv2));
p2_choices.insert_or_narrow(make_install_version(cv3));
promotion p2(p2_choices, 50);
expected_promotions.insert(p2);
promotions.insert(p2);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p3_choices;
p3_choices.insert_or_narrow(make_install_version(av1));
p3_choices.insert_or_narrow(make_install_version(bv2));
promotion p3(p3_choices, 75);
expected_promotions.insert(p3);
expected_promotions.erase(p2);
promotions.insert(p3);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p4_choices;
p4_choices.insert_or_narrow(make_install_version(av1));
p4_choices.insert_or_narrow(make_install_version(bv2));
p4_choices.insert_or_narrow(make_install_version(cv1));
promotion p4(p4_choices, 10);
promotions.insert(p4);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p5_choices;
p5_choices.insert_or_narrow(make_install_version(bv2));
promotion p5(p5_choices, 30);
expected_promotions.insert(p5);
promotions.insert(p5);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p6_choices;
p6_choices.insert_or_narrow(make_break_soft_dep(bv2d1));
promotion p6(p6_choices, 125);
expected_promotions.insert(p6);
promotions.insert(p6);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p7_choices;
p7_choices.insert_or_narrow(make_install_version(cv3));
p7_choices.insert_or_narrow(make_break_soft_dep(bv2d1));
promotion p7(p7_choices, 500);
expected_promotions.insert(p7);
promotions.insert(p7);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
choice_set p8_choices;
p8_choices.insert_or_narrow(make_install_version_from_dep_source(bv3, bv2d1));
p8_choices.insert_or_narrow(make_install_version(cv2));
promotion p8(p8_choices, 50);
expected_promotions.insert(p8);
promotions.insert(p8);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), promotions.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(promotions));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(promotions));
}
// We don't care about id in these tests, so these are convenience
// routines that use a dummy value.
static choice make_install_version(const version &v)
{
return choice::make_install_version(v, dep(), -1);
}
static choice make_install_version_from_dep_source(const version &v, const dep &d)
{
return choice::make_install_version_from_dep_source(v, d, -1);
}
static choice make_break_soft_dep(const dep &d)
{
return choice::make_break_soft_dep(d, -1);
}
public:
// Test searching for the highest promotion contained in a
void testFindHighestPromotion()
{
dummy_universe_ref u(parseUniverse(dummy_universe_1));
dummy_promotion_set p(u);
package a(u.find_package("a"));
package b(u.find_package("b"));
package c(u.find_package("c"));
version av1(a.version_from_name("v1"));
version av2(a.version_from_name("v2"));
version av3(a.version_from_name("v3"));
version bv1(b.version_from_name("v1"));
version bv2(b.version_from_name("v2"));
version bv3(b.version_from_name("v3"));
version cv1(c.version_from_name("v1"));
version cv2(c.version_from_name("v2"));
version cv3(c.version_from_name("v3"));
dep av1d1(*av1.deps_begin());
dep bv2d1(*bv2.deps_begin());
dep av2d1(*av2.deps_begin());
dep av3d1(*av3.deps_begin());
make_test_promotions(u, p);
// First search: (Install(a v1), Install(b v3),
// Install(c v3), Break(b v2 -> <c v2>))
//
// Should turn up only (T500: Install(c v3), Break(b v2 -> <c v2>))
//
// Checks that a search for a set with several hits returns the
// highest-valued one.
choice_set search1;
search1.insert_or_narrow(make_install_version(av1));
search1.insert_or_narrow(make_install_version(bv3));
search1.insert_or_narrow(make_install_version(cv3));
search1.insert_or_narrow(make_break_soft_dep(bv2d1));
choice_set expected1_choices;
expected1_choices.insert_or_narrow(make_install_version(cv3));
expected1_choices.insert_or_narrow(make_break_soft_dep(bv2d1));
promotion expected1(expected1_choices, 500);
dummy_promotion_set::const_iterator found = p.find_highest_promotion_for(search1);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected1, *found);
dummy_promotion_set::const_iterator found2 =
p.find_highest_promotion_containing(search1, make_install_version(av1));
CPPUNIT_ASSERT(found2 == p.end());
found2 = p.find_highest_promotion_containing(search1, make_install_version(bv3));
CPPUNIT_ASSERT(found2 == p.end());
found2 = p.find_highest_promotion_containing(search1, make_install_version(cv3));
CPPUNIT_ASSERT(found2 != p.end());
CPPUNIT_ASSERT_EQUAL(expected1, *found2);
found2 = p.find_highest_promotion_containing(search1, make_break_soft_dep(bv2d1));
CPPUNIT_ASSERT(found2 != p.end());
CPPUNIT_ASSERT_EQUAL(expected1, *found2);
// Second search: (a v1, b v1)
//
// Should turn up nothing.
//
// Checks that a search for a set with no hits returns nothing.
choice_set search2;
search2.insert_or_narrow(make_install_version(av1));
search2.insert_or_narrow(make_install_version(bv1));
CPPUNIT_ASSERT(p.find_highest_promotion_for(search2) == p.end());
CPPUNIT_ASSERT(p.find_highest_promotion_containing(search2, make_install_version(av1)) == p.end());
CPPUNIT_ASSERT(p.find_highest_promotion_containing(search2, make_install_version(bv1)) == p.end());
// Third search: (Break(b v2 -> <c v2>))
//
// Should turn up only (T125: Break(b v2 -> <c v2>))
//
// Checks that a higher-valued superset is correctly ignored.
choice_set search3;
search3.insert_or_narrow(make_break_soft_dep(bv2d1));
choice_set expected_choices3 = search3;
promotion expected3(expected_choices3, 125);
found = p.find_highest_promotion_for(search3);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected3, *found);
found = p.find_highest_promotion_containing(search3, make_break_soft_dep(bv2d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected3, *found);
// Fourth search: (Install(a v1 [a v3 -> <>]), Install(b v2))
//
// Should turn up only (T75: Install(a v1), Install(b v2))
//
// Tests that choices made due to a dependency are matched by
// choices made not due to a dependency, but not by choices made
// due to a different dependency.
choice_set search4;
search4.insert_or_narrow(make_install_version_from_dep_source(av1, av3d1));
search4.insert_or_narrow(make_install_version(bv2));
choice_set expected_choices4;
expected_choices4.insert_or_narrow(make_install_version(av1));
expected_choices4.insert_or_narrow(make_install_version(bv2));
promotion expected4(expected_choices4, 75);
found = p.find_highest_promotion_for(search4);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected4, *found);
found = p.find_highest_promotion_containing(search4, make_install_version_from_dep_source(av1, av3d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected4, *found);
found = p.find_highest_promotion_containing(search4, make_install_version(bv2));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected4, *found);
// Fifth search: (Install(a v1 [a v2 -> <>]), Install(b v2))
//
// Should turn up only (T100: Install(a v1 [a v2 -> <>]))
//
// Tests that choices made due to a dependency are matched by
// choices made due to the same dependency.
choice_set search5;
search5.insert_or_narrow(make_install_version_from_dep_source(av1, av2d1));
search5.insert_or_narrow(make_install_version(bv2));
choice_set expected_choices5;
expected_choices5.insert_or_narrow(make_install_version_from_dep_source(av1, av2d1));
promotion expected5(expected_choices5, 100);
found = p.find_highest_promotion_for(search5);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected5, *found);
found = p.find_highest_promotion_containing(search5, make_install_version_from_dep_source(av1, av2d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected5, *found);
// In this case there is a different expectation: we should find
// (T75: Install(a v1, b v2)), since the otherwise expected
// solution doesn't contain the "key" element.
choice_set expected_choices5_2;
expected_choices5_2.insert_or_narrow(make_install_version(av1));
expected_choices5_2.insert_or_narrow(make_install_version(bv2));
promotion expected5_2(expected_choices5_2, 75);
found = p.find_highest_promotion_containing(search5, make_install_version(bv2));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected5_2, *found);
// Check that nothing matches (Install(bv3, cv2)), because it
// doesn't have the right from-dep-source information. Tests that
// find_highest_promotion_containing correctly checks the
// from-dep-source information.
choice_set search6;
search6.insert_or_narrow(make_install_version(bv3));
search6.insert_or_narrow(make_install_version(cv2));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_for(search6));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(search6, make_install_version(bv3)));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(search6, make_install_version(cv2)));
// Check that we can match (Install(bv3 [bv2 -> <c v2>], cv2))
// instead.
choice_set search7;
search7.insert_or_narrow(make_install_version_from_dep_source(bv3, bv2d1));
search7.insert_or_narrow(make_install_version(cv2));
promotion expected7(search7, 50);
found = p.find_highest_promotion_for(search7);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected7, *found);
found = p.find_highest_promotion_containing(search7, make_install_version_from_dep_source(bv3, bv2d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected7, *found);
found = p.find_highest_promotion_containing(search7, make_install_version(cv2));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected7, *found);
}
void testRemoveTier()
{
dummy_universe_ref u(parseUniverse(dummy_universe_1));
dummy_promotion_set p(u);
package a(u.find_package("a"));
package b(u.find_package("b"));
package c(u.find_package("c"));
version av1(a.version_from_name("v1"));
version av2(a.version_from_name("v2"));
version av3(a.version_from_name("v3"));
version bv1(b.version_from_name("v1"));
version bv2(b.version_from_name("v2"));
version bv3(b.version_from_name("v3"));
version cv1(c.version_from_name("v1"));
version cv2(c.version_from_name("v2"));
version cv3(c.version_from_name("v3"));
dep av1d1(*av1.deps_begin());
dep bv2d1(*bv2.deps_begin());
dep av2d1(*av2.deps_begin());
dep av3d1(*av3.deps_begin());
make_test_promotions(u, p);
// Remove tiers 500 and 50, and make sure they doesn't show up in
// the results.
p.remove_tier(500);
p.remove_tier(50);
// Check that the size and contents (when iterating) of the
// promotion set are maintained correctly.
{
imm::set<promotion> expected_promotions;
choice_set p1_choices;
p1_choices.insert_or_narrow(make_install_version_from_dep_source(av1, av2d1));
promotion p1(p1_choices, 100);
expected_promotions.insert(p1);
p.insert(p1);
choice_set p2_choices;
p2_choices.insert_or_narrow(make_install_version(av1));
p2_choices.insert_or_narrow(make_install_version(bv2));
promotion p2(p2_choices, 75);
expected_promotions.insert(p2);
p.insert(p2);
choice_set p3_choices;
p3_choices.insert_or_narrow(make_install_version(bv2));
promotion p3(p3_choices, 30);
expected_promotions.insert(p3);
p.insert(p3);
choice_set p4_choices;
p4_choices.insert_or_narrow(make_break_soft_dep(bv2d1));
promotion p4(p4_choices, 125);
expected_promotions.insert(p4);
p.insert(p4);
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), p.size());
CPPUNIT_ASSERT_EQUAL(expected_promotions.size(), empirical_promotions_size(p));
CPPUNIT_ASSERT_EQUAL(expected_promotions, get_promotions(p));
}
// First search: (Install(a v1), Install(b v3),
// Install(c v3), Break(b v2 -> <c v2>))
//
// Should turn up (T125: Break(b v2 -> <c v2>))
choice_set search1;
search1.insert_or_narrow(make_install_version(av1));
search1.insert_or_narrow(make_install_version(bv3));
search1.insert_or_narrow(make_install_version(cv3));
search1.insert_or_narrow(make_break_soft_dep(bv2d1));
choice_set expected_choices1;
expected_choices1.insert_or_narrow(make_break_soft_dep(bv2d1));
promotion expected1(expected_choices1, 125);
dummy_promotion_set::const_iterator found = p.find_highest_promotion_for(search1);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected1, *found);
found = p.find_highest_promotion_containing(search1, make_install_version(av1));
CPPUNIT_ASSERT(found == p.end());
found = p.find_highest_promotion_containing(search1, make_install_version(bv3));
CPPUNIT_ASSERT(found == p.end());
found = p.find_highest_promotion_containing(search1, make_install_version(cv3));
CPPUNIT_ASSERT(found == p.end());
found = p.find_highest_promotion_containing(search1, make_break_soft_dep(bv2d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(expected1, *found);
// Nothing should match the tier-50 promotion.
choice_set search2;
search2.insert_or_narrow(make_install_version_from_dep_source(bv3, bv2d1));
search2.insert_or_narrow(make_install_version(cv2));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_for(search2));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(search2, make_install_version_from_dep_source(bv3, bv2d1)));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(search2, make_install_version(cv2)));
}
void testRemoveBelowTier()
{
dummy_universe_ref u(parseUniverse(dummy_universe_1));
dummy_promotion_set p(u);
package a(u.find_package("a"));
package b(u.find_package("b"));
package c(u.find_package("c"));
version av1(a.version_from_name("v1"));
version av2(a.version_from_name("v2"));
version av3(a.version_from_name("v3"));
version bv1(b.version_from_name("v1"));
version bv2(b.version_from_name("v2"));
version bv3(b.version_from_name("v3"));
version cv1(c.version_from_name("v1"));
version cv2(c.version_from_name("v2"));
version cv3(c.version_from_name("v3"));
dep av1d1(*av1.deps_begin());
dep bv2d1(*bv2.deps_begin());
dep av2d1(*av2.deps_begin());
dep av3d1(*av3.deps_begin());
make_test_promotions(u, p);
// Remove everything below (and including) tier 75.
p.remove_below_tier(76);
// We expect {(T100: Install(a v1 [a v2 -> <>])),
// (T125: Break(b v2 -> <c v2>)),
// (T500: Install(c v3), Break(b v2 -> c v2))}
//
// The previously available promotions
// (T75: Install(a v1, b v2)),
// (T50: Install(b v3 [b v2 -> <c v2>], cv2)), and
// (T30: Install(b v2))
// should be gone.
imm::set<promotion> expected;
choice_set p1_choices;
p1_choices.insert_or_narrow(make_install_version_from_dep_source(av1, av2d1));
promotion p1(p1_choices, 100);
expected.insert(p1);
choice_set p2_choices;
p2_choices.insert_or_narrow(make_break_soft_dep(bv2d1));
promotion p2(p2_choices, 125);
expected.insert(p2);
choice_set p3_choices;
p3_choices.insert_or_narrow(make_install_version(cv3));
p3_choices.insert_or_narrow(make_break_soft_dep(bv2d1));
promotion p3(p3_choices, 500);
expected.insert(p3);
// Unexpected promotions. These should match nothing.
choice_set up1_choices;
up1_choices.insert_or_narrow(make_install_version(av1));
up1_choices.insert_or_narrow(make_install_version(bv2));
choice_set up2_choices;
up2_choices.insert_or_narrow(make_install_version(bv2));
choice_set up3_choices;
up3_choices.insert_or_narrow(make_install_version_from_dep_source(bv3, bv2d1));
up3_choices.insert_or_narrow(make_install_version(cv2));
// Check that the new size of the set is correct.
CPPUNIT_ASSERT_EQUAL(expected.size(), p.size());
CPPUNIT_ASSERT_EQUAL(expected.size(), empirical_promotions_size(p));
CPPUNIT_ASSERT_EQUAL(expected, get_promotions(p));
// Check that each remaining promotion is reachable via the find_*
// methods.
dummy_promotion_set::const_iterator found;
found = p.find_highest_promotion_for(p1_choices);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(p1, *found);
found = p.find_highest_promotion_containing(p1_choices, make_install_version_from_dep_source(av1, av2d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(p1, *found);
found = p.find_highest_promotion_for(p2_choices);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(p2, *found);
found = p.find_highest_promotion_containing(p2_choices, make_break_soft_dep(bv2d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(p2, *found);
found = p.find_highest_promotion_for(p3_choices);
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(p3, *found);
found = p.find_highest_promotion_containing(p3_choices, make_install_version(cv3));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(p3, *found);
found = p.find_highest_promotion_containing(p3_choices, make_break_soft_dep(bv2d1));
CPPUNIT_ASSERT(found != p.end());
CPPUNIT_ASSERT_EQUAL(p3, *found);
// Check that the unexpected promotions are unreachable.
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_for(up1_choices));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(up1_choices, make_install_version(av1)));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(up1_choices, make_install_version(bv2)));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_for(up2_choices));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(up2_choices, make_install_version(bv2)));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_for(up3_choices));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(up3_choices, make_install_version_from_dep_source(bv3, bv2d1)));
CPPUNIT_ASSERT(p.end() == p.find_highest_promotion_containing(up3_choices, make_install_version(cv2)));
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(Promotion_SetTest);
|