vfs_get_encoding.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. lib/vfs - test vfs_get_encoding() functionality
  3. Copyright (C) 2013-2024
  4. Free Software Foundation, Inc.
  5. Written by:
  6. Andrew Borodin <aborodin@vmail.ru>, 2013
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define TEST_SUITE_NAME "/lib/vfs"
  20. #include "tests/mctest.h"
  21. #include "lib/vfs/path.h"
  22. /* --------------------------------------------------------------------------------------------- */
  23. /* @Before */
  24. static void
  25. setup (void)
  26. {
  27. }
  28. /* --------------------------------------------------------------------------------------------- */
  29. /* @After */
  30. static void
  31. teardown (void)
  32. {
  33. }
  34. /* --------------------------------------------------------------------------------------------- */
  35. /* @DataSource("test_vfs_get_encoding_ds") */
  36. /* *INDENT-OFF* */
  37. static const struct test_vfs_get_encoding_ds
  38. {
  39. const char *path;
  40. const char *expected_encoding;
  41. } test_vfs_get_encoding_ds[] =
  42. {
  43. { /* 0 */
  44. "",
  45. NULL
  46. },
  47. { /* 1 */
  48. "aaaa",
  49. NULL
  50. },
  51. { /* 2 */
  52. "/aaaa",
  53. NULL
  54. },
  55. { /* 3 */
  56. "aaaa/bbbb",
  57. NULL
  58. },
  59. { /* 4 */
  60. "/aaaa/bbbb",
  61. NULL
  62. },
  63. { /* 5 */
  64. "#enc:UTF-8/aaaa",
  65. "UTF-8"
  66. },
  67. { /* 6 */
  68. "/#enc:UTF-8/aaaa",
  69. "UTF-8"
  70. },
  71. { /* 7 */
  72. "/aaaa/#enc:UTF-8/bbbb",
  73. "UTF-8"
  74. },
  75. { /* 8 */
  76. "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R",
  77. "KOI8-R"
  78. },
  79. { /* 9 */
  80. "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R/cccc",
  81. "KOI8-R"
  82. },
  83. { /* 10 */
  84. "/aaaa/#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
  85. "UTF-8"
  86. },
  87. { /* 11 */
  88. "/#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
  89. "UTF-8"
  90. },
  91. { /* 12 */
  92. "#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
  93. "UTF-8"
  94. },
  95. { /* 13 */
  96. "aaaa#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
  97. NULL
  98. },
  99. { /* 14 */
  100. "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R#enc:CP866/cccc",
  101. "KOI8-R#enc:CP866"
  102. }
  103. };
  104. /* *INDENT-ON* */
  105. /* @Test(dataSource = "test_vfs_get_encoding_ds") */
  106. /* *INDENT-OFF* */
  107. START_PARAMETRIZED_TEST (test_vfs_get_encoding, test_vfs_get_encoding_ds)
  108. /* *INDENT-ON* */
  109. {
  110. /* given */
  111. char *actual_encoding;
  112. /* when */
  113. actual_encoding = vfs_get_encoding (data->path, -1);
  114. /* then */
  115. mctest_assert_str_eq (actual_encoding, data->expected_encoding);
  116. g_free (actual_encoding);
  117. }
  118. /* *INDENT-OFF* */
  119. END_PARAMETRIZED_TEST
  120. /* *INDENT-ON* */
  121. /* --------------------------------------------------------------------------------------------- */
  122. int
  123. main (void)
  124. {
  125. TCase *tc_core;
  126. tc_core = tcase_create ("Core");
  127. tcase_add_checked_fixture (tc_core, setup, teardown);
  128. /* Add new tests here: *************** */
  129. mctest_add_parameterized_test (tc_core, test_vfs_get_encoding, test_vfs_get_encoding_ds);
  130. /* *********************************** */
  131. return mctest_run_all (tc_core);
  132. }
  133. /* --------------------------------------------------------------------------------------------- */