strings.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 extension
  32. path::extension("/home/project/texture.tga", path_output, 128);
  33. assert(string::strcmp("tga", path_output) == 0);
  34. path::extension("/home/project/texture", path_output, 128);
  35. assert(string::strcmp("", path_output) == 0);
  36. path::extension("/home/project.x/texture.tga", path_output, 128);
  37. assert(string::strcmp("tga", path_output) == 0);
  38. }