sourcelist_test.cc 1.3 KB

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