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