]>
git.saurik.com Git - apt.git/blob - test/libapt/tagfile_test.cc
2e2144f995f3090d0009de0db13958722e5fbe5c
1 #include <apt-pkg/fileutl.h>
2 #include <apt-pkg/tagfile.h>
11 void remove_tmpfile(void)
15 if (tempfile
!= NULL
) {
21 int main(int argc
, char *argv
[])
24 const char contents
[] = "FieldA-12345678: the value of the field";
25 atexit(remove_tmpfile
);
26 tempfile
= strdup("apt-test.XXXXXXXX");
27 tempfile_fd
= mkstemp(tempfile
);
29 /* (Re-)Open (as FileFd), write and seek to start of the temp file */
30 equals(fd
.OpenDescriptor(tempfile_fd
, FileFd::ReadWrite
), true);
31 equals(fd
.Write(contents
, strlen(contents
)), true);
32 equals(fd
.Seek(0), true);
34 pkgTagFile
tfile(&fd
);
35 pkgTagSection section
;
36 equals(tfile
.Step(section
), true);
38 /* It has one field */
39 equals(section
.Count(), 1);
41 /* ... and it is called FieldA-12345678 */
42 equals(section
.Exists("FieldA-12345678"), true);
44 /* its value is correct */
45 equals(section
.FindS("FieldA-12345678"), std::string("the value of the field"));
46 /* A non-existent field has an empty string as value */
47 equals(section
.FindS("FieldB-12345678"), std::string());
49 /* ... and Exists does not lie about missing fields... */
50 equalsNot(section
.Exists("FieldB-12345678"), true);
52 /* There is only one section in this tag file */
53 equals(tfile
.Step(section
), false);
55 /* clean up handled by atexit handler, so just return here */