added tests for get_vfs_class() function
[midnight-commander.git] / lib / tests / vfs / get_vfs_class.c
blob0aef4877e221da28766da2bd5f510f2fe42032cc
1 /* lib/vfs - get vfs class from string
3 Copyright (C) 2011 Free Software Foundation, Inc.
5 Written by:
6 Slava Zanko <slavazanko@gmail.com>, 2011
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #define TEST_SUITE_NAME "/lib/vfs"
25 #include <check.h>
28 #include "lib/global.h"
29 #include "lib/strutil.h"
30 #include "lib/vfs/xdirentry.h"
31 #include "lib/vfs/vfs.c" /* for testing static methods */
33 #include "src/vfs/local/local.c"
35 static void
36 setup (void)
38 str_init_strings (NULL);
40 vfs_init ();
41 init_localfs ();
42 vfs_setup_work_dir ();
45 static void
46 teardown (void)
48 vfs_shut ();
51 /* --------------------------------------------------------------------------------------------- */
53 START_TEST (test_register_vfs_class)
55 static struct vfs_s_subclass test_subclass;
56 static struct vfs_class vfs_test_ops;
58 test_subclass.flags = VFS_S_REMOTE;
59 vfs_s_init_class (&vfs_test_ops, &test_subclass);
61 vfs_test_ops.name = "testfs";
62 vfs_test_ops.flags = VFSF_NOLINKS;
63 vfs_test_ops.prefix = "test:";
64 vfs_register_class (&vfs_test_ops);
66 fail_if (vfs_list->len != 2, "Failed to register test VFS module");;
69 struct vfs_class *result;
70 result = vfs_get_class("/#test://bla-bla/some/path");
71 fail_if(result == NULL, "VFS module not found!");
72 fail_unless(result == &vfs_test_ops, "Result(%p) don't match to vfs_test_ops(%p)!", result, &vfs_test_ops);
77 struct vfs_class *result;
78 result = vfs_get_class("/#test://bla-bla/some/path/#test_not_exists://bla-bla/some/path");
79 fail_if(result == NULL, "VFS module not found!");
80 fail_unless(result == &vfs_test_ops, "Result(%p) don't match to vfs_test_ops(%p)!", result, &vfs_test_ops);
84 END_TEST
86 /* --------------------------------------------------------------------------------------------- */
88 int
89 main (void)
91 int number_failed;
93 Suite *s = suite_create (TEST_SUITE_NAME);
94 TCase *tc_core = tcase_create ("Core");
95 SRunner *sr;
97 tcase_add_checked_fixture (tc_core, setup, teardown);
99 /* Add new tests here: *************** */
100 tcase_add_test (tc_core, test_register_vfs_class);
101 /* *********************************** */
103 suite_add_tcase (s, tc_core);
104 sr = srunner_create (s);
105 srunner_set_log (sr, "get_vfs_class.log");
106 srunner_run_all (sr, CK_NORMAL);
107 number_failed = srunner_ntests_failed (sr);
108 srunner_free (sr);
109 return (number_failed == 0) ? 0 : 1;
112 /* --------------------------------------------------------------------------------------------- */