8 #include "mock_prefs_common_get_use_shred.h"
9 #include "mock_prefs_common_get_flush_metadata.h"
20 #define ASSERTMSG_NULLINPUT "*CRITICAL* 'str != NULL' failed*"
21 #define ASSERTMSG_FAILED "*could not parse filename*"
25 FALSE
, ASSERTMSG_NULLINPUT
,
28 struct td td_empty
= {
30 FALSE
, ASSERTMSG_FAILED
,
33 struct td td_suffixonly
= {
35 FALSE
, ASSERTMSG_FAILED
,
38 struct td td_hostonly
= {
40 FALSE
, ASSERTMSG_FAILED
,
43 struct td td_short_nofp
= {
46 "shorthost", "10", NULL
48 struct td td_short_fp
= {
49 "shorthost.10.ab:cd:ef:gh.cert",
51 "shorthost", "10", "ab:cd:ef:gh"
53 struct td td_ip_nofp
= {
54 "10.20.30.40.10.cert",
56 "10.20.30.40", "10", NULL
58 struct td td_ip_fp
= {
59 "10.20.30.40.10.ab:cd:ef:gh.cert",
61 "10.20.30.40", "10", "ab:cd:ef:gh"
63 struct td td_long_nofp
= {
64 "longer.host.name.10.cert",
66 "longer.host.name", "10", NULL
68 struct td td_long_fp
= {
69 "longer.host.name.10.ab:cd:ef:gh.cert",
71 "longer.host.name", "10", "ab:cd:ef:gh"
73 struct td td_cert_starts_with_digits
= {
74 "longer.host.name.10.20:cd:ef:gh.cert",
76 "longer.host.name", "10", "20:cd:ef:gh"
80 test_utils_get_serverportfp_from_filename_nulloutput()
82 if (!g_test_undefined())
85 if (g_test_subprocess()) {
86 gboolean ret
= get_serverportfp_from_filename("valid.host.10.ab:cd:ef:gh.cert",
92 g_test_trap_subprocess(NULL
, 0, 0);
93 g_test_trap_assert_failed();
97 test_utils_get_serverportfp_from_filename(gconstpointer user_data
)
99 const struct td
*data
= (const struct td
*)user_data
;
101 if (!g_test_undefined())
104 if (g_test_subprocess()) {
105 gchar
*host
, *port
, *fp
;
106 gboolean ret
= get_serverportfp_from_filename(data
->str
, &host
, &port
, &fp
);
108 g_assert_true(ret
== data
->ret
);
109 g_assert_cmpstr(host
, ==, data
->host
);
110 g_assert_cmpstr(port
, ==, data
->port
);
111 g_assert_cmpstr(fp
, ==, data
->fp
);
115 g_test_trap_subprocess(NULL
, 0, 0);
117 if (!data
->ret
&& data
->assertmsg
!= NULL
) {
118 g_test_trap_assert_stderr(data
->assertmsg
);
119 g_test_trap_assert_failed();
121 g_test_trap_assert_passed();
126 main(int argc
, char *argv
[])
128 g_test_init(&argc
, &argv
, NULL
);
130 g_test_add_func("/common/utils/get_serverportfp_from_filename/nulloutput",
131 test_utils_get_serverportfp_from_filename_nulloutput
);
133 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/null",
134 &td_null
, test_utils_get_serverportfp_from_filename
);
135 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/empty",
136 &td_empty
, test_utils_get_serverportfp_from_filename
);
137 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/suffixonly",
138 &td_suffixonly
, test_utils_get_serverportfp_from_filename
);
139 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/hostonly",
140 &td_hostonly
, test_utils_get_serverportfp_from_filename
);
141 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/short_nofp",
142 &td_short_nofp
, test_utils_get_serverportfp_from_filename
);
143 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/short_fp",
144 &td_short_fp
, test_utils_get_serverportfp_from_filename
);
145 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/ip_nofp",
146 &td_ip_nofp
, test_utils_get_serverportfp_from_filename
);
147 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/ip_fp",
148 &td_ip_fp
, test_utils_get_serverportfp_from_filename
);
149 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/long_nofp",
150 &td_long_nofp
, test_utils_get_serverportfp_from_filename
);
151 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/long_fp",
152 &td_long_fp
, test_utils_get_serverportfp_from_filename
);
153 g_test_add_data_func("/common/utils/get_serverportfp_from_filename/cert_starts_with_digits",
154 &td_cert_starts_with_digits
, test_utils_get_serverportfp_from_filename
);