]> git.saurik.com Git - apt.git/blob - test/libapt/getlistoffilesindir_test.cc
warning: no previous declaration for foobar() [-Wmissing-declarations]
[apt.git] / test / libapt / getlistoffilesindir_test.cc
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 #define P(x) std::string(argv[1]).append("/").append(x)
11
12 int main(int argc,char *argv[])
13 {
14 if (argc != 2) {
15 std::cout << "One parameter expected - given " << argc << std::endl;
16 return 100;
17 }
18
19 // Files with no extension
20 std::vector<std::string> files = GetListOfFilesInDir(argv[1], "", true);
21 equals(files.size(), 2);
22 equals(files[0], P("01yet-anothernormalfile"));
23 equals(files[1], P("anormalfile"));
24
25 // Files with no extension - should be the same as above
26 files = GetListOfFilesInDir(argv[1], "", true, true);
27 equals(files.size(), 2);
28 equals(files[0], P("01yet-anothernormalfile"));
29 equals(files[1], P("anormalfile"));
30
31 // Files with impossible extension
32 files = GetListOfFilesInDir(argv[1], "impossible", true);
33 equals(files.size(), 0);
34
35 // Files with impossible or no extension
36 files = GetListOfFilesInDir(argv[1], "impossible", true, true);
37 equals(files.size(), 2);
38 equals(files[0], P("01yet-anothernormalfile"));
39 equals(files[1], P("anormalfile"));
40
41 // Files with list extension - nothing more
42 files = GetListOfFilesInDir(argv[1], "list", true);
43 equals(files.size(), 4);
44 equals(files[0], P("01yet-anotherapt.list"));
45 equals(files[1], P("anormalapt.list"));
46 equals(files[2], P("linkedfile.list"));
47 equals(files[3], P("multi.dot.list"));
48
49 // Files with conf or no extension
50 files = GetListOfFilesInDir(argv[1], "conf", true, true);
51 equals(files.size(), 5);
52 equals(files[0], P("01yet-anotherapt.conf"));
53 equals(files[1], P("01yet-anothernormalfile"));
54 equals(files[2], P("anormalapt.conf"));
55 equals(files[3], P("anormalfile"));
56 equals(files[4], P("multi.dot.conf"));
57
58 // Files with disabled extension - nothing more
59 files = GetListOfFilesInDir(argv[1], "disabled", true);
60 equals(files.size(), 3);
61 equals(files[0], P("disabledfile.conf.disabled"));
62 equals(files[1], P("disabledfile.disabled"));
63 equals(files[2], P("disabledfile.list.disabled"));
64
65 // Files with disabled or no extension
66 files = GetListOfFilesInDir(argv[1], "disabled", true, true);
67 equals(files.size(), 5);
68 equals(files[0], P("01yet-anothernormalfile"));
69 equals(files[1], P("anormalfile"));
70 equals(files[2], P("disabledfile.conf.disabled"));
71 equals(files[3], P("disabledfile.disabled"));
72 equals(files[4], P("disabledfile.list.disabled"));
73
74 return 0;
75 }