reenable unlimited pdiff files download
[ntk/apt.git] / test / libapt / sourcelist_test.cc
CommitLineData
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
9char *tempfile = NULL;
10int tempfile_fd = -1;
11
12void 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
22int main(int argc, char *argv[])
23{
24 const char contents[] = ""
25 "Type: deb\n"
26 "URL: http://ftp.debian.org/debian\n"
27 "Dist: stable\n"
28 "Section: main\n"
29 "Comment: Some random string\n"
30 " that can be very long\n"
31 "\n"
32 "Type: deb\n"
33 "URL: http://ftp.debian.org/debian\n"
34 "Dist: unstable\n"
35 "Section: main non-free\n"
36 ;
37
38 FileFd fd;
39 tempfile = strdup("apt-test.XXXXXXXX");
40 tempfile_fd = mkstemp(tempfile);
41
42 /* (Re-)Open (as FileFd), write and seek to start of the temp file */
43 equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
44 equals(fd.Write(contents, strlen(contents)), true);
45 equals(fd.Seek(0), true);
46
47 pkgSourceList sources(tempfile);
48 equals(sources.size(), 2);
49
50 /* clean up handled by atexit handler, so just return here */
51 return 0;
52}