]>
Commit | Line | Data |
---|---|---|
b39c1859 MV |
1 | #include <apt-pkg/fileutl.h> |
2 | ||
3 | #include "assert.h" | |
4 | #include <string> | |
5 | #include <vector> | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <iostream> | |
9 | ||
10 | // simple helper to quickly output a vector of strings | |
11 | void dumpVector(std::vector<std::string> vec) { | |
12 | for (std::vector<std::string>::const_iterator v = vec.begin(); | |
13 | v != vec.end(); v++) | |
14 | std::cout << *v << std::endl; | |
15 | } | |
16 | ||
17 | #define P(x) string(argv[1]).append("/").append(x) | |
18 | ||
19 | int main(int argc,char *argv[]) | |
20 | { | |
21 | if (argc != 2) { | |
22 | std::cout << "One parameter expected - given " << argc << std::endl; | |
23 | return 100; | |
24 | } | |
25 | ||
26 | // Files with no extension | |
27 | std::vector<std::string> files = GetListOfFilesInDir(argv[1], "", true); | |
28 | equals(files.size(), 2); | |
29 | equals(files[0], P("01yet-anothernormalfile")); | |
30 | equals(files[1], P("anormalfile")); | |
31 | ||
32 | // Files with no extension - should be the same as above | |
33 | files = GetListOfFilesInDir(argv[1], "", true, true); | |
34 | equals(files.size(), 2); | |
35 | equals(files[0], P("01yet-anothernormalfile")); | |
36 | equals(files[1], P("anormalfile")); | |
37 | ||
38 | // Files with impossible extension | |
39 | files = GetListOfFilesInDir(argv[1], "impossible", true); | |
40 | equals(files.size(), 0); | |
41 | ||
42 | // Files with impossible or no extension | |
43 | files = GetListOfFilesInDir(argv[1], "impossible", true, true); | |
44 | equals(files.size(), 2); | |
45 | equals(files[0], P("01yet-anothernormalfile")); | |
46 | equals(files[1], P("anormalfile")); | |
47 | ||
48 | // Files with list extension - nothing more | |
49 | files = GetListOfFilesInDir(argv[1], "list", true); | |
50 | equals(files.size(), 4); | |
51 | equals(files[0], P("01yet-anotherapt.list")); | |
52 | equals(files[1], P("anormalapt.list")); | |
53 | equals(files[2], P("linkedfile.list")); | |
54 | equals(files[3], P("multi.dot.list")); | |
55 | ||
56 | // Files with conf or no extension | |
57 | files = GetListOfFilesInDir(argv[1], "conf", true, true); | |
58 | equals(files.size(), 5); | |
59 | equals(files[0], P("01yet-anotherapt.conf")); | |
60 | equals(files[1], P("01yet-anothernormalfile")); | |
61 | equals(files[2], P("anormalapt.conf")); | |
62 | equals(files[3], P("anormalfile")); | |
63 | equals(files[4], P("multi.dot.conf")); | |
64 | ||
65 | // Files with disabled extension - nothing more | |
66 | files = GetListOfFilesInDir(argv[1], "disabled", true); | |
67 | equals(files.size(), 3); | |
68 | equals(files[0], P("disabledfile.conf.disabled")); | |
69 | equals(files[1], P("disabledfile.disabled")); | |
70 | equals(files[2], P("disabledfile.list.disabled")); | |
71 | ||
72 | // Files with disabled or no extension | |
73 | files = GetListOfFilesInDir(argv[1], "disabled", true, true); | |
74 | equals(files.size(), 5); | |
75 | equals(files[0], P("01yet-anothernormalfile")); | |
76 | equals(files[1], P("anormalfile")); | |
77 | equals(files[2], P("disabledfile.conf.disabled")); | |
78 | equals(files[3], P("disabledfile.disabled")); | |
79 | equals(files[4], P("disabledfile.list.disabled")); | |
80 | ||
81 | return 0; | |
82 | } |