]>
Commit | Line | Data |
---|---|---|
caeb19b7 MV |
1 | #include <apt-pkg/sourcelist.h> |
2 | #include <apt-pkg/tagfile.h> | |
3 | ||
4 | #include "assert.h" | |
5 | #include <stdlib.h> | |
6 | #include <string.h> | |
7 | #include <unistd.h> | |
8 | ||
9 | char *tempfile = NULL; | |
10 | int tempfile_fd = -1; | |
11 | ||
12 | void remove_tmpfile(void) | |
13 | { | |
14 | if (tempfile_fd > 0) | |
15 | close(tempfile_fd); | |
16 | if (tempfile != NULL) { | |
17 | unlink(tempfile); | |
18 | free(tempfile); | |
19 | } | |
20 | } | |
21 | ||
22 | int main(int argc, char *argv[]) | |
23 | { | |
5d9667d9 MV |
24 | _config->Set("APT::Sources::Use-Deb822", true); |
25 | ||
caeb19b7 | 26 | const char contents[] = "" |
7f316a3f | 27 | "Types: deb\n" |
75c10df1 | 28 | "URIs: http://ftp.debian.org/debian\n" |
6c069a22 MV |
29 | "Suites: stable\n" |
30 | "Sections: main\n" | |
e67b9a23 MV |
31 | "Description: short\n" |
32 | " long description that can be very long\n" | |
caeb19b7 | 33 | "\n" |
7f316a3f | 34 | "Types: deb\n" |
75c10df1 | 35 | "URIs: http://ftp.debian.org/debian\n" |
7f316a3f MV |
36 | "Suites: unstable\n" |
37 | "Sections: main non-free\n" | |
caeb19b7 MV |
38 | ; |
39 | ||
40 | FileFd fd; | |
9aaa4528 | 41 | atexit(remove_tmpfile); |
caeb19b7 MV |
42 | tempfile = strdup("apt-test.XXXXXXXX"); |
43 | tempfile_fd = mkstemp(tempfile); | |
44 | ||
45 | /* (Re-)Open (as FileFd), write and seek to start of the temp file */ | |
46 | equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true); | |
47 | equals(fd.Write(contents, strlen(contents)), true); | |
48 | equals(fd.Seek(0), true); | |
49 | ||
50 | pkgSourceList sources(tempfile); | |
51 | equals(sources.size(), 2); | |
52 | ||
53 | /* clean up handled by atexit handler, so just return here */ | |
54 | return 0; | |
55 | } |