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