]> git.saurik.com Git - apt.git/blob - test/libapt/sourcelist_test.cc
Merge remote-tracking branch 'upstream/debian/sid' into feature/apt-manpage
[apt.git] / test / libapt / sourcelist_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/configuration.h>
4 #include <apt-pkg/sourcelist.h>
5 #include <apt-pkg/fileutl.h>
6
7 #include <string>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11
12 #include "assert.h"
13
14 char *tempfile = NULL;
15 int tempfile_fd = -1;
16
17 static void remove_tmpfile(void)
18 {
19 if (tempfile_fd > 0)
20 close(tempfile_fd);
21 if (tempfile != NULL) {
22 unlink(tempfile);
23 free(tempfile);
24 }
25 }
26
27 int main()
28 {
29 _config->Set("APT::Sources::Use-Deb822", true);
30
31 const char contents[] = ""
32 "Types: deb\n"
33 "URIs: http://ftp.debian.org/debian\n"
34 "Suites: stable\n"
35 "Sections: main\n"
36 "Description: short\n"
37 " long description that can be very long\n"
38 "\n"
39 "Types: deb\n"
40 "URIs: http://ftp.debian.org/debian\n"
41 "Suites: unstable\n"
42 "Sections: main non-free\n"
43 ;
44
45 FileFd fd;
46 atexit(remove_tmpfile);
47 tempfile = strdup("apt-test.XXXXXXXX");
48 tempfile_fd = mkstemp(tempfile);
49
50 /* (Re-)Open (as FileFd), write and seek to start of the temp file */
51 equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
52 equals(fd.Write(contents, strlen(contents)), true);
53 equals(fd.Seek(0), true);
54
55 pkgSourceList sources(tempfile);
56 equals(sources.size(), 2);
57
58 /* clean up handled by atexit handler, so just return here */
59 return 0;
60 }