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-2025
   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 <https://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.h"
  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 static const struct test_vfs_get_encoding_ds
  52 {
  53     const char *path;
  54     const char *expected_encoding;
  55 } test_vfs_get_encoding_ds[] = {
  56     {
  57         // 0
  58         "",
  59         NULL,
  60     },
  61     {
  62         // 1
  63         "aaaa",
  64         NULL,
  65     },
  66     {
  67         // 2
  68         "/aaaa",
  69         NULL,
  70     },
  71     {
  72         // 3
  73         "aaaa/bbbb",
  74         NULL,
  75     },
  76     {
  77         // 4
  78         "/aaaa/bbbb",
  79         NULL,
  80     },
  81     {
  82         // 5
  83         "#enc:UTF-8/aaaa",
  84         "UTF-8",
  85     },
  86     {
  87         // 6
  88         "/#enc:UTF-8/aaaa",
  89         "UTF-8",
  90     },
  91     {
  92         // 7
  93         "/aaaa/#enc:UTF-8/bbbb",
  94         "UTF-8",
  95     },
  96     {
  97         // 8
  98         "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R",
  99         "KOI8-R",
 100     },
 101     {
 102         // 9
 103         "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R/cccc",
 104         "KOI8-R",
 105     },
 106     {
 107         // 10
 108         "/aaaa/#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
 109         "UTF-8",
 110     },
 111     {
 112         // 11
 113         "/#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
 114         "UTF-8",
 115     },
 116     {
 117         // 12
 118         "#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
 119         "UTF-8",
 120     },
 121     {
 122         // 13
 123         "aaaa#enc:UTF-8/bbbb/cccc#enc:KOI8-R/dddd",
 124         NULL,
 125     },
 126     {
 127         // 14
 128         "/aaaa/#enc:UTF-8/bbbb/#enc:KOI8-R#enc:CP866/cccc",
 129         "KOI8-R#enc:CP866",
 130     },
 131 };
 132 
 133 /* @Test(dataSource = "test_vfs_get_encoding_ds") */
 134 START_PARAMETRIZED_TEST (test_vfs_get_encoding, test_vfs_get_encoding_ds)
     /* [previous][next][first][last][top][bottom][index][help]  */
 135 {
 136     // given
 137     char *actual_encoding;
 138 
 139     // when
 140     actual_encoding = vfs_get_encoding (data->path, -1);
 141 
 142     // then
 143     mctest_assert_str_eq (actual_encoding, data->expected_encoding);
 144 
 145     g_free (actual_encoding);
 146 }
 147 END_PARAMETRIZED_TEST
 148 
 149 /* --------------------------------------------------------------------------------------------- */
 150 
 151 int
 152 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 153 {
 154     TCase *tc_core;
 155 
 156     tc_core = tcase_create ("Core");
 157 
 158     tcase_add_checked_fixture (tc_core, setup, teardown);
 159 
 160     // Add new tests here: ***************
 161     mctest_add_parameterized_test (tc_core, test_vfs_get_encoding, test_vfs_get_encoding_ds);
 162     // ***********************************
 163 
 164     return mctest_run_all (tc_core);
 165 }
 166 
 167 /* --------------------------------------------------------------------------------------------- */

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