fix test
[ntk/apt.git] / test / libapt / sourcelist_test.cc
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 {
24 _config->Set("APT::Sources::Use-Deb822", true);
25
26 const char contents[] = ""
27 "Types: deb\n"
28 "URIs: http://ftp.debian.org/debian\n"
29 "Suites: stable\n"
30 "Sections: main\n"
31 "Description: short\n"
32 " long description that can be very long\n"
33 "\n"
34 "Types: deb\n"
35 "URIs: http://ftp.debian.org/debian\n"
36 "Suites: unstable\n"
37 "Sections: main non-free\n"
38 ;
39
40 FileFd fd;
41 atexit(remove_tmpfile);
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 }