From 503e5c21546668169e1d78abca560ac336fb8cb5 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Fri, 30 Apr 2021 16:24:07 +0200 Subject: [PATCH] test: Add util tests Unit test the `get_protocol_from_address()` function family. --- tests/meson.build | 12 ++++++++++++ tests/test-util.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/test-util.c diff --git a/tests/meson.build b/tests/meson.build index f2dbdca..adfe262 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -111,4 +111,16 @@ t = executable('account', test_sources, ) test('account', t, env: test_env) +test_sources = [ 'test-util.c' ] +t = executable('util', test_sources, + c_args : test_cflags, + link_args: test_link_args, + link_with : [calls_vala, libcalls], + dependencies: calls_deps, + include_directories : [ + calls_includes, + ] + ) +test('util', t, env: test_env) + endif diff --git a/tests/test-util.c b/tests/test-util.c new file mode 100644 index 0000000..d2fbab7 --- /dev/null +++ b/tests/test-util.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2021 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0+ + * + * Author: Evangelos Ribeiro Tzaras + */ + +#include "util.h" + +#include + +static void +test_protocol_prefix () +{ + g_assert_cmpstr (get_protocol_from_address ("sip:alice@example.org"), ==, "sip"); + g_assert_cmpstr (get_protocol_from_address ("SIP:alice@example.org"), ==, "sip"); + g_assert_cmpstr (get_protocol_from_address ("sips:bob@example.org"), ==, "sips"); + g_assert_cmpstr (get_protocol_from_address ("sIpS:bob@example.org"), ==, "sips"); + g_assert_cmpstr (get_protocol_from_address ("tel:+49123456789"), ==, "tel"); + g_assert_cmpstr (get_protocol_from_address ("+49123456789"), ==, NULL); + g_assert_cmpstr (get_protocol_from_address_with_fallback ("+49123456789"), ==, "tel"); + g_assert_cmpstr (get_protocol_from_address ("mailto:charley@spam.com"), ==, NULL); +} + + +int +main (int argc, + char *argv[]) +{ + gtk_test_init (&argc, &argv, NULL); + + g_test_add_func ("/Calls/util/protocol_prefix", (GTestFunc) test_protocol_prefix); + + g_test_run (); +}