]> git.saurik.com Git - apt.git/blame - test/libapt/sourcelist_test.cc
set APT::Sources::Use-Deb822 to default false for now
[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[] = ""
7f316a3f 25 "Types: deb\n"
75c10df1 26 "URIs: http://ftp.debian.org/debian\n"
6c069a22
MV
27 "Suites: stable\n"
28 "Sections: main\n"
e67b9a23
MV
29 "Description: short\n"
30 " long description that can be very long\n"
caeb19b7 31 "\n"
7f316a3f 32 "Types: deb\n"
75c10df1 33 "URIs: http://ftp.debian.org/debian\n"
7f316a3f
MV
34 "Suites: unstable\n"
35 "Sections: main non-free\n"
caeb19b7
MV
36 ;
37
38 FileFd fd;
9aaa4528 39 atexit(remove_tmpfile);
caeb19b7
MV
40 tempfile = strdup("apt-test.XXXXXXXX");
41 tempfile_fd = mkstemp(tempfile);
42
43 /* (Re-)Open (as FileFd), write and seek to start of the temp file */
44 equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
45 equals(fd.Write(contents, strlen(contents)), true);
46 equals(fd.Seek(0), true);
47
48 pkgSourceList sources(tempfile);
49 equals(sources.size(), 2);
50
51 /* clean up handled by atexit handler, so just return here */
52 return 0;
53}