sourcelist_test.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <apt-pkg/sourcelist.h>
  2. #include <apt-pkg/tagfile.h>
  3. #include "assert.h"
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. char *tempfile = NULL;
  8. int tempfile_fd = -1;
  9. void remove_tmpfile(void)
  10. {
  11. if (tempfile_fd > 0)
  12. close(tempfile_fd);
  13. if (tempfile != NULL) {
  14. unlink(tempfile);
  15. free(tempfile);
  16. }
  17. }
  18. int main(int argc, char *argv[])
  19. {
  20. const char contents[] = ""
  21. "Types: deb\n"
  22. "URIs: http://ftp.debian.org/debian\n"
  23. "Suites: stable\n"
  24. "Sections: main\n"
  25. "Description: short\n"
  26. " long description that can be very long\n"
  27. "\n"
  28. "Types: deb\n"
  29. "URIs: http://ftp.debian.org/debian\n"
  30. "Suites: unstable\n"
  31. "Sections: main non-free\n"
  32. ;
  33. FileFd fd;
  34. atexit(remove_tmpfile);
  35. tempfile = strdup("apt-test.XXXXXXXX");
  36. tempfile_fd = mkstemp(tempfile);
  37. /* (Re-)Open (as FileFd), write and seek to start of the temp file */
  38. equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
  39. equals(fd.Write(contents, strlen(contents)), true);
  40. equals(fd.Seek(0), true);
  41. pkgSourceList sources(tempfile);
  42. equals(sources.size(), 2);
  43. /* clean up handled by atexit handler, so just return here */
  44. return 0;
  45. }