strings.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. printf("%s\n", path_output);
  34. assert(string::strcmp("texture", path_output) == 0);
  35. path::basename("/home/project/textureabc", path_output, 128);
  36. assert(string::strcmp("textureabc", path_output) == 0);
  37. path::basename("/hom.e/proj./e.ct/textu.reabc", path_output, 128);
  38. assert(string::strcmp("textu", path_output) == 0);
  39. path::basename("/home", path_output, 128);
  40. assert(string::strcmp("home", path_output) == 0);
  41. path::basename("/", path_output, 128);
  42. assert(string::strcmp("", path_output) == 0);
  43. path::basename("", path_output, 128);
  44. assert(string::strcmp("", path_output) == 0);
  45. // Test extension
  46. path::extension("/home/project/texture.tga", path_output, 128);
  47. assert(string::strcmp("tga", path_output) == 0);
  48. path::extension("/home/project/texture", path_output, 128);
  49. assert(string::strcmp("", path_output) == 0);
  50. path::extension("/home/project.x/texture.tga", path_output, 128);
  51. assert(string::strcmp("tga", path_output) == 0);
  52. }