2 * @file sipe-generic-tests.c
6 * Copyright (C) 2019 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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 General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "sipe-common.h"
34 #include "sipe-backend.h"
35 #include "sipe-crypt.h"
36 #include "sipe-utils.h"
37 #include "sip-transport.h"
42 gboolean
sipe_backend_debug_enabled(void)
47 void sipe_backend_debug_literal(sipe_debug_level level
,
50 printf("DEBUG(%d): %s\n", level
, msg
);
53 void sipe_backend_debug(sipe_debug_level level
,
58 gchar
*newformat
= g_strdup_printf("DEBUG(%d): %s\n", level
, format
);
61 vprintf(newformat
, ap
);
67 const gchar
*sip_transport_epid(SIPE_UNUSED_PARAMETER
struct sipe_core_private
*sipe_private
)
72 /* needed when linking against NSS */
73 void md4sum(const uint8_t *data
, uint32_t length
, uint8_t *digest
);
74 void md4sum(SIPE_UNUSED_PARAMETER
const uint8_t *data
,
75 SIPE_UNUSED_PARAMETER
uint32_t length
,
76 SIPE_UNUSED_PARAMETER
uint8_t *digest
)
83 static guint succeeded
= 0;
84 static guint failed
= 0;
86 static void assert_equal_str(const char *expected
, const gchar
*got
)
88 if (sipe_strequal(expected
, got
)) {
91 printf("FAILED: %s\n %s\n", got
, expected
);
96 static void assert_equal_uint(gsize expected
, gsize got
)
98 if (expected
== got
) {
101 printf("FAILED: %" G_GSIZE_FORMAT
"\n %" G_GSIZE_FORMAT
"\n",
107 static void tests_sipe_utils_time(void) {
111 #define UNIX_EPOCH_IN_ISO8601_UTC "1970-01-01T00:00:00Z"
113 result_str
= sipe_utils_time_to_str(0);
114 assert_equal_str(result_str
, UNIX_EPOCH_IN_ISO8601_UTC
);
117 result_time
= sipe_utils_str_to_time(NULL
);
118 assert_equal_uint(result_time
, 0);
119 result_time
= sipe_utils_str_to_time(UNIX_EPOCH_IN_ISO8601_UTC
);
120 assert_equal_uint(result_time
, 0);
121 /* handle missing "Z" */
122 result_time
= sipe_utils_str_to_time("1970-01-01T00:00:01");
123 assert_equal_uint(result_time
, 1);
124 result_time
= sipe_utils_str_to_time("1970-01-01T00:00:20Z");
125 assert_equal_uint(result_time
, 20);
126 result_time
= sipe_utils_str_to_time("1970-01-01T00:03:00");
127 assert_equal_uint(result_time
, 3 * 60);
128 result_time
= sipe_utils_str_to_time("1970-01-01T00:40:00Z");
129 assert_equal_uint(result_time
, 40 * 60);
130 result_time
= sipe_utils_str_to_time("1970-01-01T05:00:00");
131 assert_equal_uint(result_time
, 5 * 60 * 60);
132 result_time
= sipe_utils_str_to_time("1970-01-01T23:00:00Z");
133 assert_equal_uint(result_time
, 23 * 60 * 60);
134 /* 6th day after epoch */
135 result_time
= sipe_utils_str_to_time("1970-01-07T00:00:00");
136 assert_equal_uint(result_time
, 6 * 24 * 60 * 60);
137 /* 17th day after epoch */
138 result_time
= sipe_utils_str_to_time("1970-01-18T00:00:00Z");
139 assert_equal_uint(result_time
, 17 * 24 * 60 * 60);
140 result_time
= sipe_utils_str_to_time("1970-02-01T00:00:00");
141 assert_equal_uint(result_time
, 31 * 24 * 60 * 60);
142 result_time
= sipe_utils_str_to_time("1970-12-01T00:00:00Z");
144 assert_equal_uint(result_time
, 334 * 24 * 60 * 60);
145 result_time
= sipe_utils_str_to_time("1971-01-01T00:00:00");
146 assert_equal_uint(result_time
, 365 * 24 * 60 * 60);
149 static void generic_tests(void) {
150 tests_sipe_utils_time();
153 int main(SIPE_UNUSED_PARAMETER
int argc
,
154 SIPE_UNUSED_PARAMETER
char *argv
[])
156 /* Initialization for crypto backend (test mode) */
157 sipe_crypto_init(FALSE
);
161 printf("Result: %d PASSED %d FAILED\n", succeeded
, failed
);