sourcelist_test.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. "Type: deb\n"
  22. "URI: http://ftp.debian.org/debian\n"
  23. "Suites: stable\n"
  24. "Sections: main\n"
  25. "Comment: Some random string\n"
  26. " that can be very long\n"
  27. "\n"
  28. "Type: deb\n"
  29. "URI: http://ftp.debian.org/debian\n"
  30. "Suite: unstable\n"
  31. "Section: main non-free\n"
  32. ;
  33. FileFd fd;
  34. tempfile = strdup("apt-test.XXXXXXXX");
  35. tempfile_fd = mkstemp(tempfile);
  36. /* (Re-)Open (as FileFd), write and seek to start of the temp file */
  37. equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
  38. equals(fd.Write(contents, strlen(contents)), true);
  39. equals(fd.Seek(0), true);
  40. pkgSourceList sources(tempfile);
  41. equals(sources.size(), 2);
  42. /* clean up handled by atexit handler, so just return here */
  43. return 0;
  44. }