Commit b727916b authored by Bob Ham's avatar Bob Ham
Browse files

tests: Add tests for Origin and Calls

parent 58c3820f
......@@ -30,35 +30,35 @@ calls_deps = [ dependency('gobject-2.0'),
dependency('mm-glib'),
]
calls_sources = ['calls-message-source.c', 'calls-message-source.h',
'calls-call.c',
'calls-origin.c', 'calls-origin.h',
'calls-provider.c', 'calls-provider.h',
'calls-ofono-call.c', 'calls-ofono-call.h',
'calls-ofono-origin.c', 'calls-ofono-origin.h',
'calls-ofono-provider.c', 'calls-ofono-provider.h',
'calls-mm-call.c', 'calls-mm-call.h',
'calls-mm-origin.c', 'calls-mm-origin.h',
'calls-mm-provider.c', 'calls-mm-provider.h',
'calls-party.c', 'calls-party.h',
'calls-call-data.c', 'calls-call-data.h',
'calls-call-holder.c', 'calls-call-holder.h',
'calls-call-display.c', 'calls-call-display.h',
'calls-call-selector-item.c', 'calls-call-selector-item.h',
'calls-call-window.c', 'calls-call-window.h',
'calls-encryption-indicator.c', 'calls-encryption-indicator.h',
'calls-history-box.c', 'calls-history-box.h',
'calls-history-header-bar.c', 'calls-history-header-bar.h',
'calls-new-call-box.c', 'calls-new-call-box.h',
'calls-new-call-header-bar.c', 'calls-new-call-header-bar.h',
'calls-main-window.c', 'calls-main-window.h',
'util.c', 'util.h',
]
calls_sources = files(['calls-message-source.c', 'calls-message-source.h',
'calls-call.c',
'calls-origin.c', 'calls-origin.h',
'calls-provider.c', 'calls-provider.h',
'calls-ofono-call.c', 'calls-ofono-call.h',
'calls-ofono-origin.c', 'calls-ofono-origin.h',
'calls-ofono-provider.c', 'calls-ofono-provider.h',
'calls-mm-call.c', 'calls-mm-call.h',
'calls-mm-origin.c', 'calls-mm-origin.h',
'calls-mm-provider.c', 'calls-mm-provider.h',
'calls-party.c', 'calls-party.h',
'calls-call-data.c', 'calls-call-data.h',
'calls-call-holder.c', 'calls-call-holder.h',
'calls-call-display.c', 'calls-call-display.h',
'calls-call-selector-item.c', 'calls-call-selector-item.h',
'calls-call-window.c', 'calls-call-window.h',
'calls-encryption-indicator.c', 'calls-encryption-indicator.h',
'calls-history-box.c', 'calls-history-box.h',
'calls-history-header-bar.c', 'calls-history-header-bar.h',
'calls-new-call-box.c', 'calls-new-call-box.h',
'calls-new-call-header-bar.c', 'calls-new-call-header-bar.h',
'calls-main-window.c', 'calls-main-window.h',
'util.c', 'util.h',
])
calls_dummy_sources = ['calls-dummy-call.c', 'calls-dummy-call.h',
'calls-dummy-origin.c', 'calls-dummy-origin.h',
'calls-dummy-provider.c', 'calls-dummy-provider.h',
]
calls_dummy_sources = files(['calls-dummy-call.c', 'calls-dummy-call.h',
'calls-dummy-origin.c', 'calls-dummy-origin.h',
'calls-dummy-provider.c', 'calls-dummy-provider.h',
])
prefix = get_option('prefix')
config_data = configuration_data()
......@@ -80,7 +80,7 @@ config_h = vcs_tag(
output: 'config.h',
)
calls_enum_headers = ['calls-call.h']
calls_enum_headers = files(['calls-call.h'])
calls_enum_sources = gnome.mkenums_simple('enum-types',
sources : calls_enum_headers)
......
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#define add_calls_test(Object,object,name) \
g_test_add ("/Calls/" #Object "/" #name, Object##Fixture, NULL, \
test_dummy_##object##_set_up, \
test_dummy_##object##_##name, \
test_dummy_##object##_tear_down)
......@@ -17,30 +17,36 @@ test_link_args = [
'-fPIC',
]
test_names = [
'test-provider',
tests = [
[ 'provider', [] ],
[ 'origin', [ 'provider' ] ],
[ 'call', [ 'provider', 'origin' ] ],
]
test_calls_source_arrays = [ calls_sources, calls_dummy_sources ]
foreach test : tests
name = test[0]
test_calls_sources = []
foreach source_array : test_calls_source_arrays
foreach source : source_array
test_calls_sources += join_paths('..', 'src', source)
setup_bases = test[1]
setup_bases += name
test_sources = []
foreach base : setup_bases
test_sources += [ 'setup-' + base + '.c',
'setup-' + base + '.h' ]
endforeach
endforeach
test_sources += [ 'test-' + name + '.c',
'common.h' ]
foreach test_name : test_names
t = executable(test_name, test_name + '.c',
test_calls_sources, calls_enum_sources, calls_resources,
c_args : test_cflags,
link_args: test_link_args,
t = executable(name, test_sources,
calls_sources, calls_dummy_sources, calls_enum_sources, calls_resources,
c_args : test_cflags,
link_args: test_link_args,
link_with : gdbofono_lib,
dependencies: calls_deps,
dependencies: calls_deps,
include_directories : include_directories('..',
join_paths('..', 'src')),
)
test(test_name, t, env: test_env)
)
test(name, t, env: test_env)
endforeach
endif
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "setup-call.h"
#include "calls-origin.h"
void
test_dummy_call_set_up (CallFixture *fixture,
gconstpointer user_data)
{
CallsOrigin *origin;
GList *calls;
test_dummy_origin_set_up (&fixture->parent, user_data);
origin = CALLS_ORIGIN (fixture->parent.dummy_origin);
calls_origin_dial (origin, TEST_CALL_NUMBER);
calls = calls_origin_get_calls (origin);
fixture->dummy_call = CALLS_DUMMY_CALL (calls->data);
g_list_free (calls);
}
void
test_dummy_call_tear_down (CallFixture *fixture,
gconstpointer user_data)
{
fixture->dummy_call = NULL;
test_dummy_origin_tear_down (&fixture->parent, user_data);
}
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "setup-origin.h"
#include "calls-dummy-call.h"
typedef struct {
OriginFixture parent;
CallsDummyCall *dummy_call;
} CallFixture;
void test_dummy_call_set_up (CallFixture *fixture, gconstpointer user_data);
void test_dummy_call_tear_down (CallFixture *fixture, gconstpointer user_data);
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "setup-origin.h"
#include "calls-provider.h"
void
test_dummy_origin_set_up (OriginFixture *fixture,
gconstpointer user_data)
{
GList *origins;
test_dummy_provider_set_up (&fixture->parent, user_data);
calls_dummy_provider_add_origin (fixture->parent.dummy_provider,
TEST_ORIGIN_NAME);
origins = calls_provider_get_origins
(CALLS_PROVIDER (fixture->parent.dummy_provider));
fixture->dummy_origin = CALLS_DUMMY_ORIGIN (origins->data);
g_list_free (origins);
}
void
test_dummy_origin_tear_down (OriginFixture *fixture,
gconstpointer user_data)
{
fixture->dummy_origin = NULL;
test_dummy_provider_tear_down (&fixture->parent, user_data);
}
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "setup-provider.h"
#include "calls-dummy-origin.h"
#define TEST_ORIGIN_NAME "Test origin"
#define TEST_CALL_NUMBER "0123456789"
typedef struct {
ProviderFixture parent;
CallsDummyOrigin *dummy_origin;
} OriginFixture;
void test_dummy_origin_set_up (OriginFixture *fixture, gconstpointer user_data);
void test_dummy_origin_tear_down (OriginFixture *fixture, gconstpointer user_data);
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "setup-provider.h"
void
test_dummy_provider_set_up (ProviderFixture *fixture,
gconstpointer user_data)
{
fixture->dummy_provider = calls_dummy_provider_new ();
}
void
test_dummy_provider_tear_down (ProviderFixture *fixture,
gconstpointer user_data)
{
g_clear_object (&fixture->dummy_provider);
}
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "calls-dummy-provider.h"
typedef struct {
CallsDummyProvider *dummy_provider;
} ProviderFixture;
void test_dummy_provider_set_up (ProviderFixture *fixture, gconstpointer user_data);
void test_dummy_provider_tear_down (ProviderFixture *fixture, gconstpointer user_data);
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "setup-call.h"
#include "calls-message-source.h"
#include "calls-call.h"
#include "calls-origin.h"
#include "common.h"
#include <gtk/gtk.h>
#include <string.h>
static void
test_dummy_call_object (CallFixture *fixture,
gconstpointer user_data)
{
g_assert_true (G_IS_OBJECT (fixture->dummy_call));
g_assert_true (CALLS_IS_MESSAGE_SOURCE (fixture->dummy_call));
g_assert_true (CALLS_IS_CALL (fixture->dummy_call));
}
static void
test_dummy_call_get_number (CallFixture *fixture,
gconstpointer user_data)
{
const gchar *number;
number = calls_call_get_number (CALLS_CALL (fixture->dummy_call));
g_assert_nonnull (number);
g_assert_cmpstr (number, ==, TEST_CALL_NUMBER);
}
static void
test_dummy_call_get_state (CallFixture *fixture,
gconstpointer user_data)
{
CallsCallState state;
state = calls_call_get_state (CALLS_CALL (fixture->dummy_call));
g_assert_true (state == CALLS_CALL_STATE_ACTIVE);
}
static void
test_dummy_call_hang_up (CallFixture *fixture,
gconstpointer user_data)
{
calls_call_hang_up (CALLS_CALL (fixture->dummy_call));
g_assert_null (calls_origin_get_calls
(CALLS_ORIGIN (fixture->parent.dummy_origin)));
}
gint
main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
#define add_test(name) add_calls_test(Call, call, name)
add_test(object);
add_test(get_number);
add_test(get_state);
add_test(hang_up);
#undef add_test
return g_test_run();
}
/*
* Copyright (C) 2018 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0+
*/
#include "setup-origin.h"
#include "calls-message-source.h"
#include "calls-origin.h"
#include "common.h"
#include <gtk/gtk.h>
#include <string.h>
static void
test_dummy_origin_object (OriginFixture *fixture,
gconstpointer user_data)
{
g_assert_true (G_IS_OBJECT (fixture->dummy_origin));
g_assert_true (CALLS_IS_MESSAGE_SOURCE (fixture->dummy_origin));
g_assert_true (CALLS_IS_ORIGIN (fixture->dummy_origin));
}
static void
test_dummy_origin_get_name (OriginFixture *fixture,
gconstpointer user_data)
{
CallsOrigin *origin;
const gchar *name;
origin = CALLS_ORIGIN (fixture->dummy_origin);
name = calls_origin_get_name (origin);
g_assert_nonnull (name);
g_assert_cmpstr (name, ==, TEST_ORIGIN_NAME);
}
static void
add_call (guint *add_count)
{
++(*add_count);
}
static void
test_dummy_origin_calls (OriginFixture *fixture,
gconstpointer user_data)
{
static const guint ADDS = 2;
CallsOrigin *origin = CALLS_ORIGIN (fixture->dummy_origin);
guint i, add_count = 0;
gulong handler;
GList *calls;
handler = g_signal_connect_swapped (origin, "call-added",
G_CALLBACK (add_call), &add_count);
g_assert_cmpuint (handler, >, 0);
for (i = 1; i <= ADDS; ++i)
{
char number[8];
snprintf (number, 2, "%u", i);
calls_origin_dial (origin, number);
}
g_signal_handler_disconnect (origin, handler);
g_assert_cmpuint (add_count, ==, ADDS);
calls = calls_origin_get_calls (origin);
g_assert_cmpuint (g_list_length (calls), ==, add_count);
g_list_free (calls);
}
gint
main (gint argc,
gchar *argv[])
{
gtk_test_init (&argc, &argv, NULL);
#define add_test(name) add_calls_test(Origin, origin, name)
add_test(object);
add_test(get_name);
add_test(calls);
#undef add_test
return g_test_run();
}
......@@ -4,41 +4,17 @@
* SPDX-License-Identifier: GPL-3.0+
*/
#include "calls-dummy-provider.h"
#include "setup-provider.h"
#include "calls-provider.h"
#include "calls-origin.h"
#include "calls-message-source.h"
#include "common.h"
#include <gtk/gtk.h>
#include <string.h>
typedef struct {
CallsDummyProvider *dummy_provider;
} Fixture;
static void
test_dummy_provider_set_up (Fixture *fixture,
gconstpointer user_data)
{
fixture->dummy_provider = calls_dummy_provider_new ();
calls_dummy_provider_add_origin (fixture->dummy_provider,
"Test origin 1");
calls_dummy_provider_add_origin (fixture->dummy_provider,
"Test origin 2");
}
static void
test_dummy_provider_tear_down (Fixture *fixture,
gconstpointer user_data)
{
g_clear_object (&fixture->dummy_provider);
}
static void
test_dummy_provider_object (Fixture *fixture,
test_dummy_provider_object (ProviderFixture *fixture,
gconstpointer user_data)
{
g_assert_true (G_IS_OBJECT (fixture->dummy_provider));
......@@ -48,7 +24,7 @@ test_dummy_provider_object (Fixture *fixture,
static void
test_dummy_provider_get_name (Fixture *fixture,
test_dummy_provider_get_name (ProviderFixture *fixture,
gconstpointer user_data)
{
CallsProvider *provider;
......@@ -61,24 +37,20 @@ test_dummy_provider_get_name (Fixture *fixture,
g_assert_cmpuint (strlen (name), >, 0U);
}
static void
test_dummy_provider_get_origins (Fixture *fixture,
gconstpointer user_data)
test_dummy_provider_origins (ProviderFixture *fixture,
gconstpointer user_data)
{
GList *origins, *node;
GList *origins;
calls_dummy_provider_add_origin (fixture->dummy_provider,
"Test origin 1");
calls_dummy_provider_add_origin (fixture->dummy_provider,
"Test origin 2");
origins = calls_provider_get_origins
(CALLS_PROVIDER (fixture->dummy_provider));
g_assert_cmpuint (g_list_length (origins), ==, 2);
for (node = origins; node; node = node->next)
{
g_assert_true (G_IS_OBJECT (node->data));
g_assert_true (CALLS_IS_ORIGIN (node->data));
}
g_list_free (origins);
}
......@@ -90,17 +62,14 @@ main (gint argc,
gtk_test_init (&argc, &argv, NULL);
#define add_test(name) \
g_test_add ("/Calls/Provider/" #name, Fixture, NULL, \
test_dummy_provider_set_up, \
test_dummy_provider_##name, \
test_dummy_provider_tear_down); \
#define add_test(name) add_calls_test(Provider, provider, name)
add_test(object);
add_test(get_name);
add_test(get_origins);
add_test(origins);
#undef add_test
return g_test_run();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment