Release 1.25.0 -- Buddy Idle Time, RTF
[siplcs.git] / src / core / sipe-generic-tests.c
blob8ff457f6448a005583a2e1df89db15e4f102b631
1 /**
2 * @file sipe-generic-tests.c
4 * pidgin-sipe
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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdint.h>
31 #include <glib.h>
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"
40 * Stubs
42 gboolean sipe_backend_debug_enabled(void)
44 return(TRUE);
47 void sipe_backend_debug_literal(sipe_debug_level level,
48 const gchar *msg)
50 printf("DEBUG(%d): %s\n", level, msg);
53 void sipe_backend_debug(sipe_debug_level level,
54 const gchar *format,
55 ...)
57 va_list ap;
58 gchar *newformat = g_strdup_printf("DEBUG(%d): %s\n", level, format);
60 va_start(ap, format);
61 vprintf(newformat, ap);
62 va_end(ap);
64 g_free(newformat);
67 const gchar *sip_transport_epid(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private)
69 return(NULL);
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)
81 * Tester code
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)) {
89 succeeded++;
90 } else {
91 printf("FAILED: %s\n %s\n", got, expected);
92 failed++;
96 static void assert_equal_uint(gsize expected, gsize got)
98 if (expected == got) {
99 succeeded++;
100 } else {
101 printf("FAILED: %" G_GSIZE_FORMAT "\n %" G_GSIZE_FORMAT "\n",
102 got, expected);
103 failed++;
107 static void tests_sipe_utils_time(void) {
108 gchar *result_str;
109 time_t result_time;
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);
115 g_free(result_str);
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");
143 /* 365 - 31 days */
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);
159 generic_tests();
161 printf("Result: %d PASSED %d FAILED\n", succeeded, failed);
162 return(failed);
166 Local Variables:
167 mode: c
168 c-file-style: "bsd"
169 indent-tabs-mode: t
170 tab-width: 8
171 End: