monotone

monotone Mtn Source Tree

Root/restrictions.cc

1// Copyright (C) 2005 Derek Scherger <derek@echologic.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#include "base.hh"
11#include "safe_map.hh"
12#include "vector.hh"
13#include "restrictions.hh"
14#include "file_io.hh"
15#include "roster.hh"
16#include "database.hh" // for parent_roster
17
18#ifdef BUILD_UNIT_TESTS
19# include "unit_tests.hh"
20# include "constants.hh"
21#else
22# include "work.hh"
23#endif
24
25using std::make_pair;
26using std::map;
27using std::set;
28using std::vector;
29
30// TODO: add check for relevant rosters to be used by log
31//
32// i.e. as log goes back through older and older rosters it may hit one
33// that pre-dates any of the nodes in the restriction. the nodes that the
34// restriction includes or excludes may not have been born in a sufficiently
35// old roster. at this point log should stop because no earlier roster will
36// include these nodes.
37
38static void
39map_nodes(map<node_id, restricted_path::status> & node_map,
40 roster_t const & roster,
41 set<file_path> const & paths,
42 set<file_path> & known_paths,
43 restricted_path::status const status)
44{
45 for (set<file_path>::const_iterator i = paths.begin(); i != paths.end(); ++i)
46 {
47 if (roster.has_node(*i))
48 {
49 known_paths.insert(*i);
50 node_id nid = roster.get_node(*i)->self;
51
52 map<node_id, restricted_path::status>::iterator n
53 = node_map.find(nid);
54 if (n != node_map.end())
55 N(n->second == status,
56 F("conflicting include/exclude on path '%s'") % *i);
57 else
58 node_map.insert(make_pair(nid, status));
59 }
60 }
61}
62
63static void
64map_nodes(map<node_id, restricted_path::status> & node_map,
65 roster_t const & roster,
66 set<file_path> const & included_paths,
67 set<file_path> const & excluded_paths,
68 set<file_path> & known_paths)
69{
70 map_nodes(node_map, roster, included_paths, known_paths,
71 restricted_path::included);
72 map_nodes(node_map, roster, excluded_paths, known_paths,
73 restricted_path::excluded);
74}
75
76static void
77map_paths(map<file_path, restricted_path::status> & path_map,
78 set<file_path> const & paths,
79 restricted_path::status const status)
80{
81 for (set<file_path>::const_iterator i = paths.begin(); i != paths.end(); ++i)
82 {
83 map<file_path, restricted_path::status>::iterator p = path_map.find(*i);
84 if (p != path_map.end())
85 N(p->second == status,
86 F("conflicting include/exclude on path '%s'") % *i);
87 else
88 path_map.insert(make_pair(*i, status));
89 }
90}
91
92namespace
93{
94 struct unknown_p
95 {
96 virtual bool operator()(file_path const &) const = 0;
97 protected:
98 unknown_p() {}
99 virtual ~unknown_p() {}
100 };
101
102 struct unknown_node : public unknown_p
103 {
104 explicit unknown_node(set<file_path> const & known_paths)
105 : known_paths(known_paths)
106 {}
107 virtual bool operator()(file_path const & p) const
108 {
109 return known_paths.find(p) == known_paths.end();
110 }
111
112 private:
113 set<file_path> const & known_paths;
114 };
115
116 struct unknown_path : public unknown_p
117 {
118 virtual bool operator()(file_path const & p) const
119 {
120 return !path_exists(p);
121 }
122 };
123
124#ifndef BUILD_UNIT_TESTS
125 // ignored paths are allowed into the restriction but are not considered
126 // invalid if they are found in none of the restriction's rosters
127 // this is only relevant to the main program, not the unit tests
128 struct unknown_unignored_node : public unknown_p
129 {
130 explicit unknown_unignored_node(set<file_path> const & known_paths,
131 workspace & work)
132 : known_paths(known_paths), work(work)
133 {}
134 virtual bool operator()(file_path const & p) const
135 {
136 return (known_paths.find(p) == known_paths.end()
137 && !work.ignore_file(p));
138 }
139
140 private:
141 set<file_path> const & known_paths;
142 workspace & work;
143 };
144
145 struct unknown_unignored_path : public unknown_p
146 {
147 explicit unknown_unignored_path(workspace & work)
148 : work(work)
149 {}
150 virtual bool operator()(file_path const & p) const
151 {
152 return !path_exists(p) && !work.ignore_file(p);
153 }
154 private:
155 workspace & work;
156 };
157#endif
158}
159
160static void
161validate_paths(set<file_path> const & included_paths,
162 set<file_path> const & excluded_paths,
163 unknown_p const & is_unknown)
164{
165 int bad = 0;
166
167 for (set<file_path>::const_iterator i = included_paths.begin();
168 i != included_paths.end(); ++i)
169 if (is_unknown(*i))
170 {
171 bad++;
172 W(F("restriction includes unknown path '%s'") % *i);
173 }
174
175 for (set<file_path>::const_iterator i = excluded_paths.begin();
176 i != excluded_paths.end(); ++i)
177 if (is_unknown(*i))
178 {
179 bad++;
180 W(F("restriction excludes unknown path '%s'") % *i);
181 }
182
183 N(bad == 0, FP("%d unknown path", "%d unknown paths", bad) % bad);
184}
185
186restriction::restriction(std::vector<file_path> const & includes,
187 std::vector<file_path> const & excludes,
188 long depth)
189 : included_paths(includes.begin(), includes.end()),
190 excluded_paths(excludes.begin(), excludes.end()),
191 depth(depth)
192{}
193
194node_restriction::node_restriction(std::vector<file_path> const & includes,
195 std::vector<file_path> const & excludes,
196 long depth,
197 roster_t const & roster) :
198 restriction(includes, excludes, depth)
199{
200 map_nodes(node_map, roster, included_paths, excluded_paths, known_paths);
201 validate_paths(included_paths, excluded_paths, unknown_node(known_paths));
202}
203
204node_restriction::node_restriction(std::vector<file_path> const & includes,
205 std::vector<file_path> const & excludes,
206 long depth,
207 roster_t const & roster1,
208 roster_t const & roster2) :
209 restriction(includes, excludes, depth)
210{
211 map_nodes(node_map, roster1, included_paths, excluded_paths, known_paths);
212 map_nodes(node_map, roster2, included_paths, excluded_paths, known_paths);
213 validate_paths(included_paths, excluded_paths, unknown_node(known_paths));
214}
215
216node_restriction::node_restriction(std::vector<file_path> const & includes,
217 std::vector<file_path> const & excludes,
218 long depth,
219 parent_map const & rosters1,
220 roster_t const & roster2) :
221 restriction(includes, excludes, depth)
222{
223 for (parent_map::const_iterator i = rosters1.begin();
224 i != rosters1.end(); i++)
225 map_nodes(node_map, parent_roster(i),
226 included_paths, excluded_paths, known_paths);
227 map_nodes(node_map, roster2, included_paths, excluded_paths, known_paths);
228 validate_paths(included_paths, excluded_paths, unknown_node(known_paths));
229}
230
231
232path_restriction::path_restriction(std::vector<file_path> const & includes,
233 std::vector<file_path> const & excludes,
234 long depth,
235 validity_check vc) :
236 restriction(includes, excludes, depth)
237{
238 map_paths(path_map, included_paths, restricted_path::included);
239 map_paths(path_map, excluded_paths, restricted_path::excluded);
240
241 if (vc == check_paths)
242 validate_paths(included_paths, excluded_paths, unknown_path());
243}
244
245// The constructor variants that take a workspace argument are only used in
246// the main program, not the unit tests. Conditional compilation lets us
247// leave work.o out of the unit_tester binary.
248#ifndef BUILD_UNIT_TESTS
249node_restriction::node_restriction(workspace & work,
250 std::vector<file_path> const & includes,
251 std::vector<file_path> const & excludes,
252 long depth,
253 roster_t const & roster) :
254 restriction(includes, excludes, depth)
255{
256 map_nodes(node_map, roster, included_paths, excluded_paths, known_paths);
257 validate_paths(included_paths, excluded_paths,
258 unknown_unignored_node(known_paths, work));
259}
260
261node_restriction::node_restriction(workspace & work,
262 std::vector<file_path> const & includes,
263 std::vector<file_path> const & excludes,
264 long depth,
265 roster_t const & roster1,
266 roster_t const & roster2) :
267 restriction(includes, excludes, depth)
268{
269 map_nodes(node_map, roster1, included_paths, excluded_paths, known_paths);
270 map_nodes(node_map, roster2, included_paths, excluded_paths, known_paths);
271
272 validate_paths(included_paths, excluded_paths,
273 unknown_unignored_node(known_paths, work));
274}
275
276node_restriction::node_restriction(workspace & work,
277 std::vector<file_path> const & includes,
278 std::vector<file_path> const & excludes,
279 long depth,
280 parent_map const & rosters1,
281 roster_t const & roster2) :
282 restriction(includes, excludes, depth)
283{
284 for (parent_map::const_iterator i = rosters1.begin();
285 i != rosters1.end(); i++)
286 map_nodes(node_map, parent_roster(i),
287 included_paths, excluded_paths, known_paths);
288 map_nodes(node_map, roster2, included_paths, excluded_paths, known_paths);
289 validate_paths(included_paths, excluded_paths,
290 unknown_unignored_node(known_paths, work));
291}
292
293
294path_restriction::path_restriction(workspace & work,
295 std::vector<file_path> const & includes,
296 std::vector<file_path> const & excludes,
297 long depth,
298 validity_check vc) :
299 restriction(includes, excludes, depth)
300{
301 map_paths(path_map, included_paths, restricted_path::included);
302 map_paths(path_map, excluded_paths, restricted_path::excluded);
303
304 if (vc == check_paths)
305 validate_paths(included_paths, excluded_paths,
306 unknown_unignored_path(work));
307}
308#endif
309
310
311bool
312node_restriction::includes(roster_t const & roster, node_id nid) const
313{
314 MM(roster);
315 I(roster.has_node(nid));
316
317 file_path fp;
318 roster.get_name(nid, fp);
319
320 if (empty())
321 {
322 if (depth != -1)
323 {
324 int path_depth = fp.depth();
325 if (path_depth <= depth)
326 {
327 L(FL("depth includes nid %d path '%s'") % nid % fp);
328 return true;
329 }
330 else
331 {
332 L(FL("depth excludes nid %d path '%s'") % nid % fp);
333 return false;
334 }
335 }
336 else
337 {
338 // don't log this, we end up using rather a bit of cpu time just
339 // in the logging code, for totally unrestricted operations.
340 return true;
341 }
342 }
343
344 node_id current = nid;
345 int path_depth = 0;
346
347 while (!null_node(current) && (depth == -1 || path_depth <= depth))
348 {
349 map<node_id, restricted_path::status>::const_iterator
350 r = node_map.find(current);
351
352 if (r != node_map.end())
353 {
354 switch (r->second)
355 {
356 case restricted_path::included:
357 L(FL("explicit include of nid %d path '%s'")
358 % current % fp);
359 return true;
360
361 case restricted_path::excluded:
362 L(FL("explicit exclude of nid %d path '%s'")
363 % current % fp);
364 return false;
365 }
366 }
367
368 node_t node = roster.get_node(current);
369 current = node->parent;
370 path_depth++;
371 }
372
373 if (included_paths.empty())
374 {
375 L(FL("default include of nid %d path '%s'")
376 % nid % fp);
377 return true;
378 }
379 else
380 {
381 L(FL("(debug) default exclude of nid %d path '%s'")
382 % nid % fp);
383 return false;
384 }
385}
386
387bool
388path_restriction::includes(file_path const & pth) const
389{
390 if (empty())
391 {
392 if (depth != -1)
393 {
394 int path_depth = pth.depth();
395 if (path_depth <= depth)
396 {
397 L(FL("depth includes path '%s'") % pth);
398 return true;
399 }
400 else
401 {
402 L(FL("depth excludes path '%s'") % pth);
403 return false;
404 }
405 }
406 else
407 {
408 L(FL("empty include of path '%s'") % pth);
409 return true;
410 }
411 }
412
413 int path_depth = 0;
414 file_path fp = pth;
415 while (depth == -1 || path_depth <= depth)
416 {
417 map<file_path, restricted_path::status>::const_iterator
418 r = path_map.find(fp);
419
420 if (r != path_map.end())
421 {
422 switch (r->second)
423 {
424 case restricted_path::included:
425 L(FL("explicit include of path '%s'") % pth);
426 return true;
427
428 case restricted_path::excluded:
429 L(FL("explicit exclude of path '%s'") % pth);
430 return false;
431 }
432 }
433
434 if (fp.empty())
435 break;
436 fp = fp.dirname();
437 path_depth++;
438 }
439
440 if (included_paths.empty())
441 {
442 L(FL("default include of path '%s'") % pth);
443 return true;
444 }
445 else
446 {
447 L(FL("default exclude of path '%s'") % pth);
448 return false;
449 }
450}
451
452///////////////////////////////////////////////////////////////////////
453// tests
454///////////////////////////////////////////////////////////////////////
455
456#ifdef BUILD_UNIT_TESTS
457
458using std::string;
459
460// f's and g's are files
461// x's and y's are directories
462// and this is rather painful
463
464#define fp_root file_path_internal("")
465#define fp_f file_path_internal("f")
466#define fp_g file_path_internal("g")
467
468#define fp_x file_path_internal("x")
469#define fp_xf file_path_internal("x/f")
470#define fp_xg file_path_internal("x/g")
471#define fp_xx file_path_internal("x/x")
472#define fp_xxf file_path_internal("x/x/f")
473#define fp_xxg file_path_internal("x/x/g")
474#define fp_xy file_path_internal("x/y")
475#define fp_xyf file_path_internal("x/y/f")
476#define fp_xyg file_path_internal("x/y/g")
477
478#define fp_y file_path_internal("y")
479#define fp_yf file_path_internal("y/f")
480#define fp_yg file_path_internal("y/g")
481#define fp_yx file_path_internal("y/x")
482#define fp_yxf file_path_internal("y/x/f")
483#define fp_yxg file_path_internal("y/x/g")
484#define fp_yy file_path_internal("y/y")
485#define fp_yyf file_path_internal("y/y/f")
486#define fp_yyg file_path_internal("y/y/g")
487
488namespace
489{
490 node_id nid_root;
491 node_id nid_f;
492 node_id nid_g;
493
494 node_id nid_x;
495 node_id nid_xf;
496 node_id nid_xg;
497 node_id nid_xx;
498 node_id nid_xxf;
499 node_id nid_xxg;
500 node_id nid_xy;
501 node_id nid_xyf;
502 node_id nid_xyg;
503
504 node_id nid_y;
505 node_id nid_yf;
506 node_id nid_yg;
507 node_id nid_yx;
508 node_id nid_yxf;
509 node_id nid_yxg;
510 node_id nid_yy;
511 node_id nid_yyf;
512 node_id nid_yyg;
513
514 file_id fid_f (string(constants::idlen_bytes, '\x11'));
515 file_id fid_g (string(constants::idlen_bytes, '\x22'));
516
517 file_id fid_xf (string(constants::idlen_bytes, '\x33'));
518 file_id fid_xg (string(constants::idlen_bytes, '\x44'));
519 file_id fid_xxf(string(constants::idlen_bytes, '\x55'));
520 file_id fid_xxg(string(constants::idlen_bytes, '\x66'));
521 file_id fid_xyf(string(constants::idlen_bytes, '\x77'));
522 file_id fid_xyg(string(constants::idlen_bytes, '\x88'));
523
524 file_id fid_yf (string(constants::idlen_bytes, '\x99'));
525 file_id fid_yg (string(constants::idlen_bytes, '\xaa'));
526 file_id fid_yxf(string(constants::idlen_bytes, '\xbb'));
527 file_id fid_yxg(string(constants::idlen_bytes, '\xcc'));
528 file_id fid_yyf(string(constants::idlen_bytes, '\xdd'));
529 file_id fid_yyg(string(constants::idlen_bytes, '\xee'));
530}
531
532static void setup(roster_t & roster)
533{
534 temp_node_id_source nis;
535
536 // these directories must exist for the path_restrictions to be valid. it
537 // is a bit lame to be creating directories arbitrarily like this. perhaps
538 // unit_tests should run in a unit_tests.dir or something.
539
540 mkdir_p(file_path_internal("x/x"));
541 mkdir_p(file_path_internal("x/y"));
542 mkdir_p(file_path_internal("y/x"));
543 mkdir_p(file_path_internal("y/y"));
544
545 nid_root = roster.create_dir_node(nis);
546 nid_f = roster.create_file_node(fid_f, nis);
547 nid_g = roster.create_file_node(fid_g, nis);
548
549 nid_x = roster.create_dir_node(nis);
550 nid_xf = roster.create_file_node(fid_xf, nis);
551 nid_xg = roster.create_file_node(fid_xg, nis);
552 nid_xx = roster.create_dir_node(nis);
553 nid_xxf = roster.create_file_node(fid_xxf, nis);
554 nid_xxg = roster.create_file_node(fid_xxg, nis);
555 nid_xy = roster.create_dir_node(nis);
556 nid_xyf = roster.create_file_node(fid_xxf, nis);
557 nid_xyg = roster.create_file_node(fid_xxg, nis);
558
559 nid_y = roster.create_dir_node(nis);
560 nid_yf = roster.create_file_node(fid_yf, nis);
561 nid_yg = roster.create_file_node(fid_yg, nis);
562 nid_yx = roster.create_dir_node(nis);
563 nid_yxf = roster.create_file_node(fid_yxf, nis);
564 nid_yxg = roster.create_file_node(fid_yxg, nis);
565 nid_yy = roster.create_dir_node(nis);
566 nid_yyf = roster.create_file_node(fid_yxf, nis);
567 nid_yyg = roster.create_file_node(fid_yxg, nis);
568
569 roster.attach_node(nid_root, fp_root);
570 roster.attach_node(nid_f, fp_f);
571 roster.attach_node(nid_g, fp_g);
572
573 roster.attach_node(nid_x, fp_x);
574 roster.attach_node(nid_xf, fp_xf);
575 roster.attach_node(nid_xg, fp_xg);
576 roster.attach_node(nid_xx, fp_xx);
577 roster.attach_node(nid_xxf, fp_xxf);
578 roster.attach_node(nid_xxg, fp_xxg);
579 roster.attach_node(nid_xy, fp_xy);
580 roster.attach_node(nid_xyf, fp_xyf);
581 roster.attach_node(nid_xyg, fp_xyg);
582
583 roster.attach_node(nid_y, fp_y);
584 roster.attach_node(nid_yf, fp_yf);
585 roster.attach_node(nid_yg, fp_yg);
586 roster.attach_node(nid_yx, fp_yx);
587 roster.attach_node(nid_yxf, fp_yxf);
588 roster.attach_node(nid_yxg, fp_yxg);
589 roster.attach_node(nid_yy, fp_yy);
590 roster.attach_node(nid_yyf, fp_yyf);
591 roster.attach_node(nid_yyg, fp_yyg);
592
593}
594
595UNIT_TEST(restrictions, empty_restriction)
596{
597 roster_t roster;
598 setup(roster);
599
600 // check restricted nodes
601
602 node_restriction nmask;
603
604 UNIT_TEST_CHECK(nmask.empty());
605
606 UNIT_TEST_CHECK(nmask.includes(roster, nid_root));
607 UNIT_TEST_CHECK(nmask.includes(roster, nid_f));
608 UNIT_TEST_CHECK(nmask.includes(roster, nid_g));
609
610 UNIT_TEST_CHECK(nmask.includes(roster, nid_x));
611 UNIT_TEST_CHECK(nmask.includes(roster, nid_xf));
612 UNIT_TEST_CHECK(nmask.includes(roster, nid_xg));
613 UNIT_TEST_CHECK(nmask.includes(roster, nid_xx));
614 UNIT_TEST_CHECK(nmask.includes(roster, nid_xxf));
615 UNIT_TEST_CHECK(nmask.includes(roster, nid_xxg));
616 UNIT_TEST_CHECK(nmask.includes(roster, nid_xy));
617 UNIT_TEST_CHECK(nmask.includes(roster, nid_xyf));
618 UNIT_TEST_CHECK(nmask.includes(roster, nid_xyg));
619
620 UNIT_TEST_CHECK(nmask.includes(roster, nid_y));
621 UNIT_TEST_CHECK(nmask.includes(roster, nid_yf));
622 UNIT_TEST_CHECK(nmask.includes(roster, nid_yg));
623 UNIT_TEST_CHECK(nmask.includes(roster, nid_yx));
624 UNIT_TEST_CHECK(nmask.includes(roster, nid_yxf));
625 UNIT_TEST_CHECK(nmask.includes(roster, nid_yxg));
626 UNIT_TEST_CHECK(nmask.includes(roster, nid_yy));
627 UNIT_TEST_CHECK(nmask.includes(roster, nid_yyf));
628 UNIT_TEST_CHECK(nmask.includes(roster, nid_yyg));
629
630 // check restricted paths
631
632 path_restriction pmask;
633
634 UNIT_TEST_CHECK(pmask.empty());
635
636 UNIT_TEST_CHECK(pmask.includes(fp_root));
637 UNIT_TEST_CHECK(pmask.includes(fp_f));
638 UNIT_TEST_CHECK(pmask.includes(fp_g));
639
640 UNIT_TEST_CHECK(pmask.includes(fp_x));
641 UNIT_TEST_CHECK(pmask.includes(fp_xf));
642 UNIT_TEST_CHECK(pmask.includes(fp_xg));
643 UNIT_TEST_CHECK(pmask.includes(fp_xx));
644 UNIT_TEST_CHECK(pmask.includes(fp_xxf));
645 UNIT_TEST_CHECK(pmask.includes(fp_xxg));
646 UNIT_TEST_CHECK(pmask.includes(fp_xy));
647 UNIT_TEST_CHECK(pmask.includes(fp_xyf));
648 UNIT_TEST_CHECK(pmask.includes(fp_xyg));
649
650 UNIT_TEST_CHECK(pmask.includes(fp_y));
651 UNIT_TEST_CHECK(pmask.includes(fp_yf));
652 UNIT_TEST_CHECK(pmask.includes(fp_yg));
653 UNIT_TEST_CHECK(pmask.includes(fp_yx));
654 UNIT_TEST_CHECK(pmask.includes(fp_yxf));
655 UNIT_TEST_CHECK(pmask.includes(fp_yxg));
656 UNIT_TEST_CHECK(pmask.includes(fp_yy));
657 UNIT_TEST_CHECK(pmask.includes(fp_yyf));
658 UNIT_TEST_CHECK(pmask.includes(fp_yyg));
659}
660
661UNIT_TEST(restrictions, simple_include)
662{
663 roster_t roster;
664 setup(roster);
665
666 vector<file_path> includes, excludes;
667 includes.push_back(file_path_internal("x/x"));
668 includes.push_back(file_path_internal("y/y"));
669
670 // check restricted nodes
671
672 node_restriction nmask(includes, excludes, -1, roster);
673
674 UNIT_TEST_CHECK(!nmask.empty());
675
676 UNIT_TEST_CHECK(!nmask.includes(roster, nid_root));
677 UNIT_TEST_CHECK(!nmask.includes(roster, nid_f));
678 UNIT_TEST_CHECK(!nmask.includes(roster, nid_g));
679
680 UNIT_TEST_CHECK(!nmask.includes(roster, nid_x));
681 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xf));
682 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xg));
683 UNIT_TEST_CHECK( nmask.includes(roster, nid_xx));
684 UNIT_TEST_CHECK( nmask.includes(roster, nid_xxf));
685 UNIT_TEST_CHECK( nmask.includes(roster, nid_xxg));
686 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xy));
687 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyf));
688 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyg));
689
690 UNIT_TEST_CHECK(!nmask.includes(roster, nid_y));
691 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yf));
692 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yg));
693 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yx));
694 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxf));
695 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxg));
696 UNIT_TEST_CHECK( nmask.includes(roster, nid_yy));
697 UNIT_TEST_CHECK( nmask.includes(roster, nid_yyf));
698 UNIT_TEST_CHECK( nmask.includes(roster, nid_yyg));
699
700 // check restricted paths
701
702 path_restriction pmask(includes, excludes, -1);
703
704 UNIT_TEST_CHECK(!pmask.empty());
705
706 UNIT_TEST_CHECK(!pmask.includes(fp_root));
707 UNIT_TEST_CHECK(!pmask.includes(fp_f));
708 UNIT_TEST_CHECK(!pmask.includes(fp_g));
709
710 UNIT_TEST_CHECK(!pmask.includes(fp_x));
711 UNIT_TEST_CHECK(!pmask.includes(fp_xf));
712 UNIT_TEST_CHECK(!pmask.includes(fp_xg));
713 UNIT_TEST_CHECK( pmask.includes(fp_xx));
714 UNIT_TEST_CHECK( pmask.includes(fp_xxf));
715 UNIT_TEST_CHECK( pmask.includes(fp_xxg));
716 UNIT_TEST_CHECK(!pmask.includes(fp_xy));
717 UNIT_TEST_CHECK(!pmask.includes(fp_xyf));
718 UNIT_TEST_CHECK(!pmask.includes(fp_xyg));
719
720 UNIT_TEST_CHECK(!pmask.includes(fp_y));
721 UNIT_TEST_CHECK(!pmask.includes(fp_yf));
722 UNIT_TEST_CHECK(!pmask.includes(fp_yg));
723 UNIT_TEST_CHECK(!pmask.includes(fp_yx));
724 UNIT_TEST_CHECK(!pmask.includes(fp_yxf));
725 UNIT_TEST_CHECK(!pmask.includes(fp_yxg));
726 UNIT_TEST_CHECK( pmask.includes(fp_yy));
727 UNIT_TEST_CHECK( pmask.includes(fp_yyf));
728 UNIT_TEST_CHECK( pmask.includes(fp_yyg));
729}
730
731UNIT_TEST(restrictions, simple_exclude)
732{
733 roster_t roster;
734 setup(roster);
735
736 vector<file_path> includes, excludes;
737 excludes.push_back(file_path_internal("x/x"));
738 excludes.push_back(file_path_internal("y/y"));
739
740 // check restricted nodes
741
742 node_restriction nmask(includes, excludes, -1, roster);
743
744 UNIT_TEST_CHECK(!nmask.empty());
745
746 UNIT_TEST_CHECK( nmask.includes(roster, nid_root));
747 UNIT_TEST_CHECK( nmask.includes(roster, nid_f));
748 UNIT_TEST_CHECK( nmask.includes(roster, nid_g));
749
750 UNIT_TEST_CHECK( nmask.includes(roster, nid_x));
751 UNIT_TEST_CHECK( nmask.includes(roster, nid_xf));
752 UNIT_TEST_CHECK( nmask.includes(roster, nid_xg));
753 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xx));
754 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxf));
755 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxg));
756 UNIT_TEST_CHECK( nmask.includes(roster, nid_xy));
757 UNIT_TEST_CHECK( nmask.includes(roster, nid_xyf));
758 UNIT_TEST_CHECK( nmask.includes(roster, nid_xyg));
759
760 UNIT_TEST_CHECK( nmask.includes(roster, nid_y));
761 UNIT_TEST_CHECK( nmask.includes(roster, nid_yf));
762 UNIT_TEST_CHECK( nmask.includes(roster, nid_yg));
763 UNIT_TEST_CHECK( nmask.includes(roster, nid_yx));
764 UNIT_TEST_CHECK( nmask.includes(roster, nid_yxf));
765 UNIT_TEST_CHECK( nmask.includes(roster, nid_yxg));
766 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yy));
767 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyf));
768 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyg));
769
770 // check restricted paths
771
772 path_restriction pmask(includes, excludes, -1);
773
774 UNIT_TEST_CHECK(!pmask.empty());
775
776 UNIT_TEST_CHECK( pmask.includes(fp_root));
777 UNIT_TEST_CHECK( pmask.includes(fp_f));
778 UNIT_TEST_CHECK( pmask.includes(fp_g));
779
780 UNIT_TEST_CHECK( pmask.includes(fp_x));
781 UNIT_TEST_CHECK( pmask.includes(fp_xf));
782 UNIT_TEST_CHECK( pmask.includes(fp_xg));
783 UNIT_TEST_CHECK(!pmask.includes(fp_xx));
784 UNIT_TEST_CHECK(!pmask.includes(fp_xxf));
785 UNIT_TEST_CHECK(!pmask.includes(fp_xxg));
786 UNIT_TEST_CHECK( pmask.includes(fp_xy));
787 UNIT_TEST_CHECK( pmask.includes(fp_xyf));
788 UNIT_TEST_CHECK( pmask.includes(fp_xyg));
789
790 UNIT_TEST_CHECK( pmask.includes(fp_y));
791 UNIT_TEST_CHECK( pmask.includes(fp_yf));
792 UNIT_TEST_CHECK( pmask.includes(fp_yg));
793 UNIT_TEST_CHECK( pmask.includes(fp_yx));
794 UNIT_TEST_CHECK( pmask.includes(fp_yxf));
795 UNIT_TEST_CHECK( pmask.includes(fp_yxg));
796 UNIT_TEST_CHECK(!pmask.includes(fp_yy));
797 UNIT_TEST_CHECK(!pmask.includes(fp_yyf));
798 UNIT_TEST_CHECK(!pmask.includes(fp_yyg));
799}
800
801UNIT_TEST(restrictions, include_exclude)
802{
803 roster_t roster;
804 setup(roster);
805
806 vector<file_path> includes, excludes;
807 includes.push_back(file_path_internal("x"));
808 includes.push_back(file_path_internal("y"));
809 excludes.push_back(file_path_internal("x/x"));
810 excludes.push_back(file_path_internal("y/y"));
811
812 // check restricted nodes
813
814 node_restriction nmask(includes, excludes, -1, roster);
815
816 UNIT_TEST_CHECK(!nmask.empty());
817
818 UNIT_TEST_CHECK(!nmask.includes(roster, nid_root));
819 UNIT_TEST_CHECK(!nmask.includes(roster, nid_f));
820 UNIT_TEST_CHECK(!nmask.includes(roster, nid_g));
821
822 UNIT_TEST_CHECK( nmask.includes(roster, nid_x));
823 UNIT_TEST_CHECK( nmask.includes(roster, nid_xf));
824 UNIT_TEST_CHECK( nmask.includes(roster, nid_xg));
825 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xx));
826 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxf));
827 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxg));
828 UNIT_TEST_CHECK( nmask.includes(roster, nid_xy));
829 UNIT_TEST_CHECK( nmask.includes(roster, nid_xyf));
830 UNIT_TEST_CHECK( nmask.includes(roster, nid_xyg));
831
832 UNIT_TEST_CHECK( nmask.includes(roster, nid_y));
833 UNIT_TEST_CHECK( nmask.includes(roster, nid_yf));
834 UNIT_TEST_CHECK( nmask.includes(roster, nid_yg));
835 UNIT_TEST_CHECK( nmask.includes(roster, nid_yx));
836 UNIT_TEST_CHECK( nmask.includes(roster, nid_yxf));
837 UNIT_TEST_CHECK( nmask.includes(roster, nid_yxg));
838 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yy));
839 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyf));
840 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyg));
841
842 // check restricted paths
843
844 path_restriction pmask(includes, excludes, -1);
845
846 UNIT_TEST_CHECK(!pmask.empty());
847
848 UNIT_TEST_CHECK(!pmask.includes(fp_root));
849 UNIT_TEST_CHECK(!pmask.includes(fp_f));
850 UNIT_TEST_CHECK(!pmask.includes(fp_g));
851
852 UNIT_TEST_CHECK( pmask.includes(fp_x));
853 UNIT_TEST_CHECK( pmask.includes(fp_xf));
854 UNIT_TEST_CHECK( pmask.includes(fp_xg));
855 UNIT_TEST_CHECK(!pmask.includes(fp_xx));
856 UNIT_TEST_CHECK(!pmask.includes(fp_xxf));
857 UNIT_TEST_CHECK(!pmask.includes(fp_xxg));
858 UNIT_TEST_CHECK( pmask.includes(fp_xy));
859 UNIT_TEST_CHECK( pmask.includes(fp_xyf));
860 UNIT_TEST_CHECK( pmask.includes(fp_xyg));
861
862 UNIT_TEST_CHECK( pmask.includes(fp_y));
863 UNIT_TEST_CHECK( pmask.includes(fp_yf));
864 UNIT_TEST_CHECK( pmask.includes(fp_yg));
865 UNIT_TEST_CHECK( pmask.includes(fp_yx));
866 UNIT_TEST_CHECK( pmask.includes(fp_yxf));
867 UNIT_TEST_CHECK( pmask.includes(fp_yxg));
868 UNIT_TEST_CHECK(!pmask.includes(fp_yy));
869 UNIT_TEST_CHECK(!pmask.includes(fp_yyf));
870 UNIT_TEST_CHECK(!pmask.includes(fp_yyg));
871}
872
873UNIT_TEST(restrictions, exclude_include)
874{
875 roster_t roster;
876 setup(roster);
877
878 vector<file_path> includes, excludes;
879 // note that excludes higher up the tree than the top
880 // include are rather pointless -- nothing above the
881 // top include is included anyway
882 excludes.push_back(file_path_internal("x"));
883 excludes.push_back(file_path_internal("y"));
884 includes.push_back(file_path_internal("x/x"));
885 includes.push_back(file_path_internal("y/y"));
886
887 // check restricted nodes
888
889 node_restriction nmask(includes, excludes, -1, roster);
890
891 UNIT_TEST_CHECK(!nmask.empty());
892
893 UNIT_TEST_CHECK(!nmask.includes(roster, nid_root));
894 UNIT_TEST_CHECK(!nmask.includes(roster, nid_f));
895 UNIT_TEST_CHECK(!nmask.includes(roster, nid_g));
896
897 UNIT_TEST_CHECK(!nmask.includes(roster, nid_x));
898 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xf));
899 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xg));
900 UNIT_TEST_CHECK( nmask.includes(roster, nid_xx));
901 UNIT_TEST_CHECK( nmask.includes(roster, nid_xxf));
902 UNIT_TEST_CHECK( nmask.includes(roster, nid_xxg));
903 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xy));
904 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyf));
905 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyg));
906
907 UNIT_TEST_CHECK(!nmask.includes(roster, nid_y));
908 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yf));
909 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yg));
910 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yx));
911 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxf));
912 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxg));
913 UNIT_TEST_CHECK( nmask.includes(roster, nid_yy));
914 UNIT_TEST_CHECK( nmask.includes(roster, nid_yyf));
915 UNIT_TEST_CHECK( nmask.includes(roster, nid_yyg));
916
917 // check restricted paths
918
919 path_restriction pmask(includes, excludes, -1);
920
921 UNIT_TEST_CHECK(!pmask.empty());
922
923 UNIT_TEST_CHECK(!pmask.includes(fp_root));
924 UNIT_TEST_CHECK(!pmask.includes(fp_f));
925 UNIT_TEST_CHECK(!pmask.includes(fp_g));
926
927 UNIT_TEST_CHECK(!pmask.includes(fp_x));
928 UNIT_TEST_CHECK(!pmask.includes(fp_xf));
929 UNIT_TEST_CHECK(!pmask.includes(fp_xg));
930 UNIT_TEST_CHECK( pmask.includes(fp_xx));
931 UNIT_TEST_CHECK( pmask.includes(fp_xxf));
932 UNIT_TEST_CHECK( pmask.includes(fp_xxg));
933 UNIT_TEST_CHECK(!pmask.includes(fp_xy));
934 UNIT_TEST_CHECK(!pmask.includes(fp_xyf));
935 UNIT_TEST_CHECK(!pmask.includes(fp_xyg));
936
937 UNIT_TEST_CHECK(!pmask.includes(fp_y));
938 UNIT_TEST_CHECK(!pmask.includes(fp_yf));
939 UNIT_TEST_CHECK(!pmask.includes(fp_yg));
940 UNIT_TEST_CHECK(!pmask.includes(fp_yx));
941 UNIT_TEST_CHECK(!pmask.includes(fp_yxf));
942 UNIT_TEST_CHECK(!pmask.includes(fp_yxg));
943 UNIT_TEST_CHECK( pmask.includes(fp_yy));
944 UNIT_TEST_CHECK( pmask.includes(fp_yyf));
945 UNIT_TEST_CHECK( pmask.includes(fp_yyg));
946}
947
948UNIT_TEST(restrictions, invalid_roster_paths)
949{
950 roster_t roster;
951 setup(roster);
952
953 vector<file_path> includes, excludes;
954 includes.push_back(file_path_internal("foo"));
955 excludes.push_back(file_path_internal("bar"));
956
957 UNIT_TEST_CHECK_THROW(node_restriction(includes, excludes, -1, roster),
958 informative_failure);
959}
960
961UNIT_TEST(restrictions, invalid_workspace_paths)
962{
963 roster_t roster;
964 setup(roster);
965
966 vector<file_path> includes, excludes;
967 includes.push_back(file_path_internal("foo"));
968 excludes.push_back(file_path_internal("bar"));
969
970 UNIT_TEST_CHECK_THROW(path_restriction(includes, excludes, -1),
971 informative_failure);
972}
973
974UNIT_TEST(restrictions, ignored_invalid_workspace_paths)
975{
976 roster_t roster;
977 setup(roster);
978
979 vector<file_path> includes, excludes;
980 includes.push_back(file_path_internal("foo"));
981 excludes.push_back(file_path_internal("bar"));
982
983 path_restriction pmask(includes, excludes, -1,
984 path_restriction::skip_check);
985
986 UNIT_TEST_CHECK( pmask.includes(file_path_internal("foo")));
987 UNIT_TEST_CHECK(!pmask.includes(file_path_internal("bar")));
988}
989
990UNIT_TEST(restrictions, include_depth_0)
991{
992 roster_t roster;
993 setup(roster);
994
995 vector<file_path> includes, excludes;
996 includes.push_back(file_path_internal("x"));
997 includes.push_back(file_path_internal("y"));
998
999 long depth = 0;
1000
1001 // check restricted nodes
1002
1003 node_restriction nmask(includes, excludes, depth, roster);
1004
1005 UNIT_TEST_CHECK(!nmask.empty());
1006
1007 UNIT_TEST_CHECK(!nmask.includes(roster, nid_root));
1008 UNIT_TEST_CHECK(!nmask.includes(roster, nid_f));
1009 UNIT_TEST_CHECK(!nmask.includes(roster, nid_g));
1010
1011 UNIT_TEST_CHECK( nmask.includes(roster, nid_x));
1012 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xf));
1013 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xg));
1014 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xx));
1015 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxf));
1016 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxg));
1017 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xy));
1018 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyf));
1019 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyg));
1020
1021 UNIT_TEST_CHECK( nmask.includes(roster, nid_y));
1022 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yf));
1023 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yg));
1024 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yx));
1025 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxf));
1026 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxg));
1027 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yy));
1028 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyf));
1029 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyg));
1030
1031 // check restricted paths
1032
1033 path_restriction pmask(includes, excludes, depth);
1034
1035 UNIT_TEST_CHECK(!pmask.empty());
1036
1037 UNIT_TEST_CHECK(!pmask.includes(fp_root));
1038 UNIT_TEST_CHECK(!pmask.includes(fp_f));
1039 UNIT_TEST_CHECK(!pmask.includes(fp_g));
1040
1041 UNIT_TEST_CHECK( pmask.includes(fp_x));
1042 UNIT_TEST_CHECK(!pmask.includes(fp_xf));
1043 UNIT_TEST_CHECK(!pmask.includes(fp_xg));
1044 UNIT_TEST_CHECK(!pmask.includes(fp_xx));
1045 UNIT_TEST_CHECK(!pmask.includes(fp_xxf));
1046 UNIT_TEST_CHECK(!pmask.includes(fp_xxg));
1047 UNIT_TEST_CHECK(!pmask.includes(fp_xy));
1048 UNIT_TEST_CHECK(!pmask.includes(fp_xyf));
1049 UNIT_TEST_CHECK(!pmask.includes(fp_xyg));
1050
1051 UNIT_TEST_CHECK( pmask.includes(fp_y));
1052 UNIT_TEST_CHECK(!pmask.includes(fp_yf));
1053 UNIT_TEST_CHECK(!pmask.includes(fp_yg));
1054 UNIT_TEST_CHECK(!pmask.includes(fp_yx));
1055 UNIT_TEST_CHECK(!pmask.includes(fp_yxf));
1056 UNIT_TEST_CHECK(!pmask.includes(fp_yxg));
1057 UNIT_TEST_CHECK(!pmask.includes(fp_yy));
1058 UNIT_TEST_CHECK(!pmask.includes(fp_yyf));
1059 UNIT_TEST_CHECK(!pmask.includes(fp_yyg));
1060}
1061
1062UNIT_TEST(restrictions, include_depth_1)
1063{
1064 roster_t roster;
1065 setup(roster);
1066
1067 vector<file_path> includes, excludes;
1068 includes.push_back(file_path_internal("x"));
1069 includes.push_back(file_path_internal("y"));
1070
1071 long depth = 1;
1072
1073 // check restricted nodes
1074
1075 node_restriction nmask(includes, excludes, depth, roster);
1076
1077 UNIT_TEST_CHECK(!nmask.empty());
1078
1079 UNIT_TEST_CHECK(!nmask.includes(roster, nid_root));
1080 UNIT_TEST_CHECK(!nmask.includes(roster, nid_f));
1081 UNIT_TEST_CHECK(!nmask.includes(roster, nid_g));
1082
1083 UNIT_TEST_CHECK( nmask.includes(roster, nid_x));
1084 UNIT_TEST_CHECK( nmask.includes(roster, nid_xf));
1085 UNIT_TEST_CHECK( nmask.includes(roster, nid_xg));
1086 UNIT_TEST_CHECK( nmask.includes(roster, nid_xx));
1087 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxf));
1088 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxg));
1089 UNIT_TEST_CHECK( nmask.includes(roster, nid_xy));
1090 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyf));
1091 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyg));
1092
1093 UNIT_TEST_CHECK( nmask.includes(roster, nid_y));
1094 UNIT_TEST_CHECK( nmask.includes(roster, nid_yf));
1095 UNIT_TEST_CHECK( nmask.includes(roster, nid_yg));
1096 UNIT_TEST_CHECK( nmask.includes(roster, nid_yx));
1097 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxf));
1098 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxg));
1099 UNIT_TEST_CHECK( nmask.includes(roster, nid_yy));
1100 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyf));
1101 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyg));
1102
1103 // check restricted paths
1104
1105 path_restriction pmask(includes, excludes, depth);
1106
1107 UNIT_TEST_CHECK(!pmask.empty());
1108
1109 UNIT_TEST_CHECK(!pmask.includes(fp_root));
1110 UNIT_TEST_CHECK(!pmask.includes(fp_f));
1111 UNIT_TEST_CHECK(!pmask.includes(fp_g));
1112
1113 UNIT_TEST_CHECK( pmask.includes(fp_x));
1114 UNIT_TEST_CHECK( pmask.includes(fp_xf));
1115 UNIT_TEST_CHECK( pmask.includes(fp_xg));
1116 UNIT_TEST_CHECK( pmask.includes(fp_xx));
1117 UNIT_TEST_CHECK(!pmask.includes(fp_xxf));
1118 UNIT_TEST_CHECK(!pmask.includes(fp_xxg));
1119 UNIT_TEST_CHECK( pmask.includes(fp_xy));
1120 UNIT_TEST_CHECK(!pmask.includes(fp_xyf));
1121 UNIT_TEST_CHECK(!pmask.includes(fp_xyg));
1122
1123 UNIT_TEST_CHECK( pmask.includes(fp_y));
1124 UNIT_TEST_CHECK( pmask.includes(fp_yf));
1125 UNIT_TEST_CHECK( pmask.includes(fp_yg));
1126 UNIT_TEST_CHECK( pmask.includes(fp_yx));
1127 UNIT_TEST_CHECK(!pmask.includes(fp_yxf));
1128 UNIT_TEST_CHECK(!pmask.includes(fp_yxg));
1129 UNIT_TEST_CHECK( pmask.includes(fp_yy));
1130 UNIT_TEST_CHECK(!pmask.includes(fp_yyf));
1131 UNIT_TEST_CHECK(!pmask.includes(fp_yyg));
1132}
1133
1134UNIT_TEST(restrictions, include_depth_1_empty_restriction)
1135{
1136 roster_t roster;
1137 setup(roster);
1138
1139 vector<file_path> includes, excludes;
1140
1141 long depth = 1;
1142
1143 // check restricted nodes
1144
1145 node_restriction nmask(includes, excludes, depth, roster);
1146
1147 UNIT_TEST_CHECK( nmask.empty());
1148
1149 UNIT_TEST_CHECK( nmask.includes(roster, nid_root));
1150 UNIT_TEST_CHECK( nmask.includes(roster, nid_f));
1151 UNIT_TEST_CHECK( nmask.includes(roster, nid_g));
1152
1153 UNIT_TEST_CHECK( nmask.includes(roster, nid_x));
1154 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xf));
1155 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xg));
1156 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xx));
1157 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxf));
1158 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xxg));
1159 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xy));
1160 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyf));
1161 UNIT_TEST_CHECK(!nmask.includes(roster, nid_xyg));
1162
1163 UNIT_TEST_CHECK( nmask.includes(roster, nid_y));
1164 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yf));
1165 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yg));
1166 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yx));
1167 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxf));
1168 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yxg));
1169 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yy));
1170 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyf));
1171 UNIT_TEST_CHECK(!nmask.includes(roster, nid_yyg));
1172
1173 // check restricted paths
1174
1175 path_restriction pmask(includes, excludes, depth);
1176
1177 UNIT_TEST_CHECK( pmask.empty());
1178
1179 UNIT_TEST_CHECK( pmask.includes(fp_root));
1180 UNIT_TEST_CHECK( pmask.includes(fp_f));
1181 UNIT_TEST_CHECK( pmask.includes(fp_g));
1182
1183 UNIT_TEST_CHECK( pmask.includes(fp_x));
1184 UNIT_TEST_CHECK(!pmask.includes(fp_xf));
1185 UNIT_TEST_CHECK(!pmask.includes(fp_xg));
1186 UNIT_TEST_CHECK(!pmask.includes(fp_xx));
1187 UNIT_TEST_CHECK(!pmask.includes(fp_xxf));
1188 UNIT_TEST_CHECK(!pmask.includes(fp_xxg));
1189 UNIT_TEST_CHECK(!pmask.includes(fp_xy));
1190 UNIT_TEST_CHECK(!pmask.includes(fp_xyf));
1191 UNIT_TEST_CHECK(!pmask.includes(fp_xyg));
1192
1193 UNIT_TEST_CHECK( pmask.includes(fp_y));
1194 UNIT_TEST_CHECK(!pmask.includes(fp_yf));
1195 UNIT_TEST_CHECK(!pmask.includes(fp_yg));
1196 UNIT_TEST_CHECK(!pmask.includes(fp_yx));
1197 UNIT_TEST_CHECK(!pmask.includes(fp_yxf));
1198 UNIT_TEST_CHECK(!pmask.includes(fp_yxg));
1199 UNIT_TEST_CHECK(!pmask.includes(fp_yy));
1200 UNIT_TEST_CHECK(!pmask.includes(fp_yyf));
1201 UNIT_TEST_CHECK(!pmask.includes(fp_yyg));
1202}
1203
1204UNIT_TEST(restrictions, include_depth_2)
1205{
1206 roster_t roster;
1207 setup(roster);
1208
1209 vector<file_path> includes, excludes;
1210 includes.push_back(file_path_internal("x"));
1211 includes.push_back(file_path_internal("y"));
1212
1213 long depth = 2;
1214
1215 // check restricted nodes
1216
1217 node_restriction nmask(includes, excludes, depth, roster);
1218
1219 UNIT_TEST_CHECK(!nmask.empty());
1220
1221 UNIT_TEST_CHECK(!nmask.includes(roster, nid_root));
1222 UNIT_TEST_CHECK(!nmask.includes(roster, nid_f));
1223 UNIT_TEST_CHECK(!nmask.includes(roster, nid_g));
1224
1225 UNIT_TEST_CHECK( nmask.includes(roster, nid_x));
1226 UNIT_TEST_CHECK( nmask.includes(roster, nid_xf));
1227 UNIT_TEST_CHECK( nmask.includes(roster, nid_xg));
1228 UNIT_TEST_CHECK( nmask.includes(roster, nid_xx));
1229 UNIT_TEST_CHECK( nmask.includes(roster, nid_xxf));
1230 UNIT_TEST_CHECK( nmask.includes(roster, nid_xxg));
1231 UNIT_TEST_CHECK( nmask.includes(roster, nid_xy));
1232 UNIT_TEST_CHECK( nmask.includes(roster, nid_xyf));
1233 UNIT_TEST_CHECK( nmask.includes(roster, nid_xyg));
1234
1235 UNIT_TEST_CHECK( nmask.includes(roster, nid_y));
1236 UNIT_TEST_CHECK( nmask.includes(roster, nid_yf));
1237 UNIT_TEST_CHECK( nmask.includes(roster, nid_yg));
1238 UNIT_TEST_CHECK( nmask.includes(roster, nid_yx));
1239 UNIT_TEST_CHECK( nmask.includes(roster, nid_yxf));
1240 UNIT_TEST_CHECK( nmask.includes(roster, nid_yxg));
1241 UNIT_TEST_CHECK( nmask.includes(roster, nid_yy));
1242 UNIT_TEST_CHECK( nmask.includes(roster, nid_yyf));
1243 UNIT_TEST_CHECK( nmask.includes(roster, nid_yyg));
1244
1245 // check restricted paths
1246
1247 path_restriction pmask(includes, excludes, depth);
1248
1249 UNIT_TEST_CHECK(!pmask.empty());
1250
1251 UNIT_TEST_CHECK(!pmask.includes(fp_root));
1252 UNIT_TEST_CHECK(!pmask.includes(fp_f));
1253 UNIT_TEST_CHECK(!pmask.includes(fp_g));
1254
1255 UNIT_TEST_CHECK( pmask.includes(fp_x));
1256 UNIT_TEST_CHECK( pmask.includes(fp_xf));
1257 UNIT_TEST_CHECK( pmask.includes(fp_xg));
1258 UNIT_TEST_CHECK( pmask.includes(fp_xx));
1259 UNIT_TEST_CHECK( pmask.includes(fp_xxf));
1260 UNIT_TEST_CHECK( pmask.includes(fp_xxg));
1261 UNIT_TEST_CHECK( pmask.includes(fp_xy));
1262 UNIT_TEST_CHECK( pmask.includes(fp_xyf));
1263 UNIT_TEST_CHECK( pmask.includes(fp_xyg));
1264
1265 UNIT_TEST_CHECK( pmask.includes(fp_y));
1266 UNIT_TEST_CHECK( pmask.includes(fp_yf));
1267 UNIT_TEST_CHECK( pmask.includes(fp_yg));
1268 UNIT_TEST_CHECK( pmask.includes(fp_yx));
1269 UNIT_TEST_CHECK( pmask.includes(fp_yxf));
1270 UNIT_TEST_CHECK( pmask.includes(fp_yxg));
1271 UNIT_TEST_CHECK( pmask.includes(fp_yy));
1272 UNIT_TEST_CHECK( pmask.includes(fp_yyf));
1273 UNIT_TEST_CHECK( pmask.includes(fp_yyg));
1274}
1275
1276#endif // BUILD_UNIT_TESTS
1277
1278// Local Variables:
1279// mode: C++
1280// fill-column: 76
1281// c-file-style: "gnu"
1282// indent-tabs-mode: nil
1283// End:
1284// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status