fileutl_test.cc 939 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <config.h>
  2. #include <apt-pkg/error.h>
  3. #include <apt-pkg/fileutl.h>
  4. #include <string>
  5. #include <vector>
  6. #include <stdlib.h>
  7. #include "assert.h"
  8. int main()
  9. {
  10. std::vector<std::string> files;
  11. // normal match
  12. files = Glob("*.lst");
  13. if (files.size() != 1)
  14. {
  15. _error->DumpErrors();
  16. return 1;
  17. }
  18. // not there
  19. files = Glob("xxxyyyzzz");
  20. if (files.size() != 0 || _error->PendingError())
  21. {
  22. _error->DumpErrors();
  23. return 1;
  24. }
  25. // many matches (number is a bit random)
  26. files = Glob("*.cc");
  27. if (files.size() < 10)
  28. {
  29. _error->DumpErrors();
  30. return 1;
  31. }
  32. // GetTempDir()
  33. unsetenv("TMPDIR");
  34. equals(GetTempDir(), "/tmp");
  35. setenv("TMPDIR", "", 1);
  36. equals(GetTempDir(), "/tmp");
  37. setenv("TMPDIR", "/not-there-no-really-not", 1);
  38. equals(GetTempDir(), "/tmp");
  39. setenv("TMPDIR", "/usr", 1);
  40. equals(GetTempDir(), "/usr");
  41. return 0;
  42. }