cleanup headers and especially #includes everywhere
[ntk/apt.git] / test / libapt / sourcelist_test.cc
CommitLineData
453b82a3
DK
1#include <config.h>
2
3#include <apt-pkg/configuration.h>
caeb19b7 4#include <apt-pkg/sourcelist.h>
453b82a3 5#include <apt-pkg/fileutl.h>
caeb19b7 6
453b82a3 7#include <string>
caeb19b7
MV
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11
453b82a3
DK
12#include "assert.h"
13
caeb19b7
MV
14char *tempfile = NULL;
15int tempfile_fd = -1;
16
c3ccac92 17static void remove_tmpfile(void)
caeb19b7
MV
18{
19 if (tempfile_fd > 0)
20 close(tempfile_fd);
21 if (tempfile != NULL) {
22 unlink(tempfile);
23 free(tempfile);
24 }
25}
26
65512241 27int main()
caeb19b7 28{
5d9667d9
MV
29 _config->Set("APT::Sources::Use-Deb822", true);
30
caeb19b7 31 const char contents[] = ""
7f316a3f 32 "Types: deb\n"
75c10df1 33 "URIs: http://ftp.debian.org/debian\n"
6c069a22
MV
34 "Suites: stable\n"
35 "Sections: main\n"
e67b9a23
MV
36 "Description: short\n"
37 " long description that can be very long\n"
caeb19b7 38 "\n"
7f316a3f 39 "Types: deb\n"
75c10df1 40 "URIs: http://ftp.debian.org/debian\n"
7f316a3f
MV
41 "Suites: unstable\n"
42 "Sections: main non-free\n"
caeb19b7
MV
43 ;
44
45 FileFd fd;
9aaa4528 46 atexit(remove_tmpfile);
caeb19b7
MV
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}