sourcelist_test.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. static 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()
  19. {
  20. _config->Set("APT::Sources::Use-Deb822", true);
  21. const char contents[] = ""
  22. "Types: deb\n"
  23. "URIs: http://ftp.debian.org/debian\n"
  24. "Suites: stable\n"
  25. "Sections: main\n"
  26. "Description: short\n"
  27. " long description that can be very long\n"
  28. "\n"
  29. "Types: deb\n"
  30. "URIs: http://ftp.debian.org/debian\n"
  31. "Suites: unstable\n"
  32. "Sections: main non-free\n"
  33. ;
  34. FileFd fd;
  35. atexit(remove_tmpfile);
  36. tempfile = strdup("apt-test.XXXXXXXX");
  37. tempfile_fd = mkstemp(tempfile);
  38. /* (Re-)Open (as FileFd), write and seek to start of the temp file */
  39. equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
  40. equals(fd.Write(contents, strlen(contents)), true);
  41. equals(fd.Seek(0), true);
  42. pkgSourceList sources(tempfile);
  43. equals(sources.size(), 2);
  44. /* clean up handled by atexit handler, so just return here */
  45. return 0;
  46. }