2 * Copyright (C) 2016 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/errno.h>
28 #include <plover/plover.h>
30 static void test_pre_install_prefix(void)
32 gchar *pre_install_prefix;
33 pre_install_prefix=plover_pre_install_prefix();
34 g_assert_cmpstr(pre_install_prefix,!=,NULL);
35 g_assert_cmpstr(pre_install_prefix,!=,"");
36 g_free(pre_install_prefix);
39 static void test_reports_directory(void)
41 gchar *reports_directory;
42 reports_directory=plover_get_reports_directory();
43 g_assert_cmpstr(reports_directory,!=,NULL);
44 g_assert_cmpstr(reports_directory,!=,"");
45 g_free(reports_directory);
48 static void test_program_directory(void)
50 gchar *program_directory;
51 program_directory=plover_get_program_directory("test-util");
52 g_assert_cmpstr(program_directory,!=,NULL);
53 g_assert_cmpstr(program_directory,!=,"");
54 free(program_directory);
55 program_directory=plover_get_program_directory("./test-util");
56 g_assert_cmpstr(program_directory,!=,NULL);
57 g_assert_cmpstr(program_directory,!=,"");
58 free(program_directory);
61 static void verify_error_propagation(int domain,int code)
63 GError *src,*dest=NULL;
64 struct razor_error *tmp=NULL;
65 src=g_error_new_literal(domain,code,"test error");
66 plover_propagate_g_error(&tmp,src);
68 plover_propagate_razor_error(&dest,tmp);
70 g_assert_cmpint(dest->domain,==,domain);
71 g_assert_cmpint(dest->code,==,code);
72 g_assert_cmpstr(dest->message,==,"test error");
76 static void test_propagate_razor_error(void)
78 verify_error_propagation(PLOVER_RAZOR_ERROR,RAZOR_GENERAL_ERROR_FAILED);
81 static void test_propagate_posix_error(void)
83 verify_error_propagation(PLOVER_POSIX_ERROR,ENOENT);
86 static void test_propagate_mswin_error(void)
89 verify_error_propagation(PLOVER_MSWIN_ERROR,ERROR_NOT_SUPPORTED);
91 verify_error_propagation(PLOVER_MSWIN_ERROR,0);
95 static void test_propagate_zlib_error(void)
97 verify_error_propagation(PLOVER_ZLIB_ERROR,Z_VERSION_ERROR);
100 static void test_propagate_cancelled(void)
102 verify_error_propagation(G_IO_ERROR,G_IO_ERROR_CANCELLED);
105 static void test_propagate_other_error(void)
107 GError *src,*dest=NULL;
108 struct razor_error *tmp=NULL;
109 src=g_error_new_literal(G_SHELL_ERROR,G_SHELL_ERROR_FAILED,"test error");
110 plover_propagate_g_error(&tmp,src);
112 plover_propagate_razor_error(&dest,tmp);
113 g_assert(dest!=NULL);
114 g_assert_cmpint(dest->domain,==,PLOVER_RAZOR_ERROR);
115 g_assert_cmpint(dest->code,==,RAZOR_GENERAL_ERROR_FAILED);
116 g_assert_cmpstr(dest->message,==,"test error");
120 int main(int argc,char **argv)
123 g_test_init(&argc,&argv,NULL);
124 g_test_bug_base("mailto:ali@juiblex.co.uk");
125 g_test_add_func("/util/pre-install-prefix",test_pre_install_prefix);
126 g_test_add_func("/util/reports-directory",test_reports_directory);
127 g_test_add_func("/util/program-directory",test_program_directory);
128 g_test_add_func("/util/propagate-razor-error",test_propagate_razor_error);
129 g_test_add_func("/util/propagate-posix-error",test_propagate_posix_error);
130 g_test_add_func("/util/propagate-mswin-error",test_propagate_mswin_error);
131 g_test_add_func("/util/propagate-zlib-error",test_propagate_zlib_error);
132 g_test_add_func("/util/propagate-cancelled",test_propagate_cancelled);
133 g_test_add_func("/util/propagate-other-error",test_propagate_other_error);