root/tests/lib/vfs/vfs_get_encoding.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_PARAMETRIZED_TEST
  4. main

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

/* [previous][next][first][last][top][bottom][index][help]  */