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.

uoFilesTestUTF.cpp 3.7KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <fs/Files.h>
  2. #include <boost/filesystem.hpp>
  3. #include <boost/version.hpp>
  4. #include <gtest/gtest.h>
  5. #include <m_ConverterUtf8.h>
  6. #define TEMP_OUTPUT_DIR TMP_DIR "/オッペンヴィベ"
  7. #define TEMP_OUTPUT_DIR_COPY TMP_DIR "/オッペンヴィベ_Copy"
  8. #define TEMP_OUTPUT_ASCII_FILE_PATH TEMP_OUTPUT_DIR "/file.txt"
  9. #define TEMP_OUTPUT_UTF_FILE_PATH TEMP_OUTPUT_DIR "/日本語.txt"
  10. #define TEMP_OUTPUT_UTF_FILE_PATH_COPY TEMP_OUTPUT_DIR_COPY "/日本語.txt"
  11. #define TEMP_OUTPUT_ASCII_FILE_PATH_COPY TEMP_OUTPUT_DIR_COPY "/file.txt"
  12. #define TEST_ASCII_FILE_PATH DATA_DIR "/オッペンヴィベ/file.txt"
  13. #define TEST_UTF_FILE_PATH DATA_DIR "/オッペンヴィベ/日本語.txt"
  14. #define TEST_ASCII_DIR DATA_DIR "/オッペンヴィベ"
  15. TEST(FS_Files_Test_Directories_UTF, validateFileExists)
  16. {
  17. ASSERT_TRUE(FS::Files::fileExists(TEST_ASCII_FILE_PATH));
  18. ASSERT_TRUE(FS::Files::fileExists(TEST_UTF_FILE_PATH));
  19. ASSERT_FALSE(FS::Files::fileExists(DATA_DIR "/オッペンヴィベ/file"));
  20. ASSERT_FALSE(FS::Files::fileExists(DATA_DIR "/オッペンヴィベ/日本語"));
  21. }
  22. TEST(FS_Files_Test_Directories_UTF, validateDirectoryExists)
  23. {
  24. ASSERT_FALSE(FS::Files::directoryExists(DATA_DIR "/inexistent"));
  25. ASSERT_TRUE(FS::Files::directoryExists(DATA_DIR "/オッペンヴィベ"));
  26. }
  27. TEST(FS_Files_Test_Directories_UTF, validateGetParentPath)
  28. {
  29. char parentPath[1024];
  30. ASSERT_TRUE(FS::Files::getParentPath(TEST_ASCII_FILE_PATH, parentPath));
  31. ASSERT_STREQ(DATA_DIR "/オッペンヴィベ", parentPath);
  32. }
  33. TEST(FS_Files_Test_Directories_UTF, validateGetFileName)
  34. {
  35. char fileName[1024];
  36. FS::Files::getFilename(TEST_ASCII_FILE_PATH, fileName);
  37. ASSERT_STREQ("file.txt", fileName);
  38. FS::Files::getFilename(TEST_UTF_FILE_PATH, fileName);
  39. ASSERT_STREQ("日本語.txt", fileName);
  40. }
  41. TEST(FS_Files_Test_Directories_UTF, validateGetFileNameWithoutExtension)
  42. {
  43. char fileName[1024];
  44. FS::Files::getFilenameWithoutExtension(TEST_ASCII_FILE_PATH, fileName);
  45. ASSERT_STREQ("file", fileName);
  46. FS::Files::getFilenameWithoutExtension(TEST_UTF_FILE_PATH, fileName);
  47. ASSERT_STREQ("日本語", fileName);
  48. }
  49. TEST(FS_Files_Test_Directories_UTF, validateGetFileNameExtension)
  50. {
  51. char extension[1024];
  52. FS::Files::getFilenameExtension(TEST_ASCII_FILE_PATH, extension);
  53. ASSERT_STREQ(".txt", extension);
  54. FS::Files::getFilenameExtension(TEST_UTF_FILE_PATH, extension);
  55. ASSERT_STREQ(".txt", extension);
  56. }
  57. TEST(FS_Files_Test_Directories_UTF, validateCreatePath)
  58. {
  59. FS::Files::removeAll(TEMP_OUTPUT_DIR);
  60. ASSERT_FALSE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
  61. ASSERT_TRUE(FS::Files::createPath(TEMP_OUTPUT_DIR));
  62. ASSERT_TRUE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
  63. }
  64. TEST(FS_Files_Test_Directories_UTF, validateCreateParentPath)
  65. {
  66. FS::Files::removeAll(TEMP_OUTPUT_DIR);
  67. ASSERT_FALSE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
  68. ASSERT_TRUE(FS::Files::createParentPath(TEMP_OUTPUT_DIR "/file.txt"));
  69. ASSERT_TRUE(FS::Files::directoryExists(TEMP_OUTPUT_DIR));
  70. }
  71. #if BOOST_VERSION / 100 % 1000 >= 55
  72. TEST(FS_Files_Test_Directories_UTF, validateCopyFile)
  73. {
  74. FS::Files::removeAll(TEMP_OUTPUT_ASCII_FILE_PATH);
  75. FS::Files::createParentPath(TEMP_OUTPUT_ASCII_FILE_PATH);
  76. ASSERT_TRUE(FS::Files::copyFile(TEST_ASCII_FILE_PATH, TEMP_OUTPUT_ASCII_FILE_PATH));
  77. ASSERT_TRUE(FS::Files::fileExists(TEMP_OUTPUT_ASCII_FILE_PATH));
  78. }
  79. TEST(FS_Files_Test_Directories_UTF, validateCopyDirectory)
  80. {
  81. ASSERT_TRUE(FS::Files::copyDirectory(TEST_ASCII_DIR, TEMP_OUTPUT_DIR_COPY));
  82. ASSERT_TRUE(FS::Files::fileExists(TEMP_OUTPUT_UTF_FILE_PATH_COPY));
  83. ASSERT_TRUE(FS::Files::fileExists(TEMP_OUTPUT_ASCII_FILE_PATH_COPY));
  84. }
  85. #endif
  86. int uoFSFilesTestUTF(int argc, char* argv[])
  87. {
  88. testing::InitGoogleTest(&argc, argv);
  89. ::testing::GTEST_FLAG(filter) = "FS_Files_Test_Directories_UTF.*";
  90. return RUN_ALL_TESTS();
  91. }