1 /**
2  * @file
3  * Test code for mutt_file_quote_filename()
4  *
5  * @authors
6  * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
7  *
8  * @copyright
9  * This program is free software: you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation, either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #define TEST_NO_MAIN
24 #include "config.h"
25 #include "acutest.h"
26 #include "mutt/lib.h"
27 #include "common.h"
28 
test_mutt_file_quote_filename(void)29 void test_mutt_file_quote_filename(void)
30 {
31   // size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen);
32 
33   // clang-format off
34   static struct TestValue tests[] = {
35     { "plain",  "'plain'",       7 },
36     { "ba`ck",  "'ba'\\`'ck'",  10 },
37     { "qu'ote", "'qu'\\''ote'", 11 },
38   };
39   // clang-format on
40 
41   {
42     char buf[32] = { 0 };
43     TEST_CHECK(mutt_file_quote_filename(NULL, buf, sizeof(buf)) == 0);
44   }
45 
46   {
47     TEST_CHECK(mutt_file_quote_filename("apple", NULL, 10) == 0);
48   }
49 
50   int rc;
51   char buf[256];
52   for (size_t i = 0; i < mutt_array_size(tests); i++)
53   {
54     TEST_CASE(tests[i].first);
55     memset(buf, 0, sizeof(buf));
56     rc = mutt_file_quote_filename(tests[i].first, buf, sizeof(buf));
57     if (!TEST_CHECK(rc == tests[i].retval) ||
58         !TEST_CHECK(mutt_str_equal(buf, tests[i].second)))
59     {
60       TEST_MSG("Expected: %d", tests[i].retval);
61       TEST_MSG("Actual:   %d", rc);
62       TEST_MSG("Original: %s", tests[i].first);
63       TEST_MSG("Expected: %s", tests[i].second);
64       TEST_MSG("Actual:   %s", buf);
65     }
66   }
67 }
68