tagfile_test.cc 1000 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <config.h>
  2. #include <apt-pkg/fileutl.h>
  3. #include <apt-pkg/tagfile.h>
  4. #include <string>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <gtest/gtest.h>
  9. #include "file-helpers.h"
  10. TEST(TagFileTest,SingleField)
  11. {
  12. FileFd fd;
  13. createTemporaryFile("singlefield", fd, NULL, "FieldA-12345678: the value of the field");
  14. pkgTagFile tfile(&fd);
  15. pkgTagSection section;
  16. ASSERT_TRUE(tfile.Step(section));
  17. // It has one field
  18. EXPECT_EQ(1, section.Count());
  19. // ... and it is called FieldA-12345678
  20. EXPECT_TRUE(section.Exists("FieldA-12345678"));
  21. // its value is correct
  22. EXPECT_EQ("the value of the field", section.FindS("FieldA-12345678"));
  23. // A non-existent field has an empty string as value
  24. EXPECT_EQ("", section.FindS("FieldB-12345678"));
  25. // ... and Exists does not lie about missing fields...
  26. EXPECT_FALSE(section.Exists("FieldB-12345678"));
  27. // There is only one section in this tag file
  28. EXPECT_FALSE(tfile.Step(section));
  29. }