You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.2 KiB

  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. "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. "Type: deb\n"
  29. "URIs: 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. }