paths.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "String.h"
  2. #include "Path.h"
  3. #include <cassert>
  4. #include <stdio.h>
  5. using namespace crown;
  6. int main()
  7. {
  8. char path_output[128];
  9. // Test pathname
  10. path::pathname("/home/project/texture.tga", path_output, 128);
  11. assert(string::strcmp("/home/project", path_output) == 0);
  12. path::pathname("/home/project", path_output, 128);
  13. assert(string::strcmp("/home", path_output) == 0);
  14. path::pathname("/home", path_output, 128);
  15. assert(string::strcmp("", path_output) == 0);
  16. path::pathname("/", path_output, 128);
  17. assert(string::strcmp("", path_output) == 0);
  18. path::pathname("", path_output, 128);
  19. assert(string::strcmp("", path_output) == 0);
  20. // Test filename
  21. path::filename("/home/project/texture.tga", path_output, 128);
  22. assert(string::strcmp("texture.tga", path_output) == 0);
  23. path::filename("/home/project/texture", path_output, 128);
  24. assert(string::strcmp("texture", path_output) == 0);
  25. path::filename("/home", path_output, 128);
  26. assert(string::strcmp("home", path_output) == 0);
  27. path::filename("/", path_output, 128);
  28. assert(string::strcmp("", path_output) == 0);
  29. path::filename("", path_output, 128);
  30. assert(string::strcmp("", path_output) == 0);
  31. // Test basename
  32. path::basename("/home/project/texture.tga", path_output, 128);
  33. assert(string::strcmp("texture", path_output) == 0);
  34. path::basename("/home/project/textureabc", path_output, 128);
  35. assert(string::strcmp("textureabc", path_output) == 0);
  36. path::basename("/hom.e/proj./e.ct/textu.reabc", path_output, 128);
  37. assert(string::strcmp("textu", path_output) == 0);
  38. path::basename("texture.tga", path_output, 128);
  39. assert(string::strcmp("texture", path_output) == 0);
  40. path::basename("/home", path_output, 128);
  41. assert(string::strcmp("home", path_output) == 0);
  42. path::basename("/", path_output, 128);
  43. assert(string::strcmp("", path_output) == 0);
  44. path::basename("", path_output, 128);
  45. assert(string::strcmp("", path_output) == 0);
  46. // Test extension
  47. path::extension("/home/project/texture.tga", path_output, 128);
  48. assert(string::strcmp("tga", path_output) == 0);
  49. path::extension("/home/project/texture", path_output, 128);
  50. assert(string::strcmp("", path_output) == 0);
  51. path::extension("/home/project.x/texture.tga", path_output, 128);
  52. assert(string::strcmp("tga", path_output) == 0);
  53. }