]> git.saurik.com Git - apt.git/blob - test/libapt/getlistoffilesindir_test.cc
show the conflicting distribution warning again
[apt.git] / test / libapt / getlistoffilesindir_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/fileutl.h>
4
5 #include <string>
6 #include <vector>
7 #include <iostream>
8
9 #include <gtest/gtest.h>
10
11 #include "file-helpers.h"
12
13 #define P(x) std::string(tempdir).append("/").append(x)
14
15 TEST(FileUtlTest,GetListOfFilesInDir)
16 {
17 std::string tempdir;
18 createTemporaryDirectory("getlistoffiles", tempdir);
19
20 createFile(tempdir, "anormalfile");
21 createFile(tempdir, "01yet-anothernormalfile");
22 createFile(tempdir, "anormalapt.conf");
23 createFile(tempdir, "01yet-anotherapt.conf");
24 createFile(tempdir, "anormalapt.list");
25 createFile(tempdir, "01yet-anotherapt.list");
26 createFile(tempdir, "wrongextension.wron");
27 createFile(tempdir, "wrong-extension.wron");
28 createFile(tempdir, "strangefile.");
29 createFile(tempdir, "s.t.r.a.n.g.e.f.i.l.e");
30 createFile(tempdir, ".hiddenfile");
31 createFile(tempdir, ".hiddenfile.conf");
32 createFile(tempdir, ".hiddenfile.list");
33 createFile(tempdir, "multi..dot");
34 createFile(tempdir, "multi.dot.conf");
35 createFile(tempdir, "multi.dot.list");
36 createFile(tempdir, "disabledfile.disabled");
37 createFile(tempdir, "disabledfile.conf.disabled");
38 createFile(tempdir, "disabledfile.list.disabled");
39 createFile(tempdir, "invälid.conf");
40 createFile(tempdir, "invalíd");
41 createFile(tempdir, "01invalíd");
42 createDirectory(tempdir, "invaliddir");
43 createDirectory(tempdir, "directory.conf");
44 createDirectory(tempdir, "directory.list");
45 createDirectory(tempdir, "directory.wron");
46 createDirectory(tempdir, "directory.list.disabled");
47 createLink(tempdir, "anormalfile", "linkedfile.list");
48 createLink(tempdir, "invaliddir", "linkeddir.list");
49 createLink(tempdir, "non-existing-file", "brokenlink.list");
50
51 // Files with no extension
52 std::vector<std::string> files = GetListOfFilesInDir(tempdir, "", true);
53 ASSERT_EQ(2, files.size());
54 EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
55 EXPECT_EQ(P("anormalfile"), files[1]);
56
57 // Files with no extension - should be the same as above
58 files = GetListOfFilesInDir(tempdir, "", true, true);
59 ASSERT_EQ(2, files.size());
60 EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
61 EXPECT_EQ(P("anormalfile"), files[1]);
62
63 // Files with impossible extension
64 files = GetListOfFilesInDir(tempdir, "impossible", true);
65 EXPECT_TRUE(files.empty());
66
67 // Files with impossible or no extension
68 files = GetListOfFilesInDir(tempdir, "impossible", true, true);
69 ASSERT_EQ(2, files.size());
70 EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
71 EXPECT_EQ(P("anormalfile"), files[1]);
72
73 // Files with list extension - nothing more
74 files = GetListOfFilesInDir(tempdir, "list", true);
75 ASSERT_EQ(4, files.size());
76 EXPECT_EQ(P("01yet-anotherapt.list"), files[0]);
77 EXPECT_EQ(P("anormalapt.list"), files[1]);
78 EXPECT_EQ(P("linkedfile.list"), files[2]);
79 EXPECT_EQ(P("multi.dot.list"), files[3]);
80
81 // Files with conf or no extension
82 files = GetListOfFilesInDir(tempdir, "conf", true, true);
83 ASSERT_EQ(5, files.size());
84 EXPECT_EQ(P("01yet-anotherapt.conf"), files[0]);
85 EXPECT_EQ(P("01yet-anothernormalfile"), files[1]);
86 EXPECT_EQ(P("anormalapt.conf"), files[2]);
87 EXPECT_EQ(P("anormalfile"), files[3]);
88 EXPECT_EQ(P("multi.dot.conf"), files[4]);
89
90 // Files with disabled extension - nothing more
91 files = GetListOfFilesInDir(tempdir, "disabled", true);
92 ASSERT_EQ(3, files.size());
93 EXPECT_EQ(P("disabledfile.conf.disabled"), files[0]);
94 EXPECT_EQ(P("disabledfile.disabled"), files[1]);
95 EXPECT_EQ(P("disabledfile.list.disabled"), files[2]);
96
97 // Files with disabled or no extension
98 files = GetListOfFilesInDir(tempdir, "disabled", true, true);
99 ASSERT_EQ(5, files.size());
100 EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
101 EXPECT_EQ(P("anormalfile"), files[1]);
102 EXPECT_EQ(P("disabledfile.conf.disabled"), files[2]);
103 EXPECT_EQ(P("disabledfile.disabled"), files[3]);
104 EXPECT_EQ(P("disabledfile.list.disabled"), files[4]);
105
106 removeDirectory(tempdir);
107 }