Skip to content

Commit

Permalink
[unit] Added plugins_dbus_service_tag test
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Jul 30, 2019
1 parent e47baf1 commit 1c5ca67
Show file tree
Hide file tree
Showing 9 changed files with 1,832 additions and 77 deletions.
1 change: 1 addition & 0 deletions unit/Makefile
Expand Up @@ -22,6 +22,7 @@ all:
@$(MAKE) -C plugins_dbus_handlers_type_text $*
@$(MAKE) -C plugins_dbus_handlers_type_uri $*
@$(MAKE) -C plugins_dbus_service_adapter $*
@$(MAKE) -C plugins_dbus_service_tag $*

clean: unitclean
rm -f *~
Expand Down
95 changes: 95 additions & 0 deletions unit/common/test_adapter.c
@@ -0,0 +1,95 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "nfc_adapter_impl.h"
#include "test_adapter.h"

/*==========================================================================*
* Test adapter
*==========================================================================*/

typedef NfcAdapterClass TestAdapterClass;
typedef NfcAdapter TestAdapter;

G_DEFINE_TYPE(TestAdapter, test_adapter, NFC_TYPE_ADAPTER)
#define TEST_TYPE_ADAPTER (test_adapter_get_type())

NfcAdapter*
test_adapter_new(
void)
{
return g_object_new(TEST_TYPE_ADAPTER, NULL);
}

static
gboolean
test_adapter_submit_power_request(
NfcAdapter* adapter,
gboolean on)
{
nfc_adapter_power_notify(adapter, on, TRUE);
return TRUE;
}

static
gboolean
test_adapter_submit_mode_request(
NfcAdapter* adapter,
NFC_MODE mode)
{
nfc_adapter_mode_notify(adapter, mode, TRUE);
return TRUE;
}

static
void
test_adapter_init(
TestAdapter* self)
{
}

static
void
test_adapter_class_init(
NfcAdapterClass* klass)
{
klass->submit_power_request = test_adapter_submit_power_request;
klass->submit_mode_request = test_adapter_submit_mode_request;
}

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
50 changes: 50 additions & 0 deletions unit/common/test_adapter.h
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef TEST_ADAPTER_H
#define TEST_ADAPTER_H

#include <nfc_types.h>

NfcAdapter*
test_adapter_new(
void);

#endif /* TEST_ADAPTER_H */

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
10 changes: 5 additions & 5 deletions unit/common/test_main.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018-2019 Jolla Ltd.
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -14,8 +14,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand All @@ -39,7 +39,7 @@ gboolean
test_timeout_expired(
gpointer data)
{
g_assert(!"TIMEOUT");
g_assert_not_reached();
return G_SOURCE_REMOVE;
}

Expand Down
3 changes: 2 additions & 1 deletion unit/coverage/run
Expand Up @@ -23,7 +23,8 @@ plugins_dbus_handlers_type_generic \
plugins_dbus_handlers_type_mediatype \
plugins_dbus_handlers_type_text \
plugins_dbus_handlers_type_uri \
plugins_dbus_service_adapter"
plugins_dbus_service_adapter \
plugins_dbus_service_tag"

function err() {
echo "*** ERROR!" $1
Expand Down
2 changes: 1 addition & 1 deletion unit/plugins_dbus_service_adapter/Makefile
Expand Up @@ -2,6 +2,6 @@

EXE = test_plugins_dbus_service_adapter

COMMON_SRC = test_target.c test_dbus.c test_main.c
COMMON_SRC = test_dbus.c test_main.c test_adapter.c test_target.c

include ../common/Makefile.plugins
Expand Up @@ -31,6 +31,7 @@
*/

#include "test_common.h"
#include "test_adapter.h"
#include "test_target.h"
#include "test_dbus.h"

Expand All @@ -47,64 +48,6 @@

static TestOpt test_opt;

/*==========================================================================*
* Test adapter
*==========================================================================*/

typedef NfcAdapterClass TestAdapterClass;
typedef NfcAdapter TestAdapter;

G_DEFINE_TYPE(TestAdapter, test_adapter, NFC_TYPE_ADAPTER)
#define TEST_TYPE_ADAPTER (test_adapter_get_type())

static
NfcAdapter*
test_adapter_new(
void)
{
return g_object_new(TEST_TYPE_ADAPTER, NULL);
}

static
gboolean
test_adapter_submit_power_request(
NfcAdapter* adapter,
gboolean on)
{
nfc_adapter_power_notify(adapter, on, TRUE);
return TRUE;
}

static
gboolean
test_adapter_submit_mode_request(
NfcAdapter* adapter,
NFC_MODE mode)
{
nfc_adapter_mode_notify(adapter, mode, TRUE);
return TRUE;
}

static
void
test_adapter_init(
TestAdapter* self)
{
}

static
void
test_adapter_class_init(
NfcAdapterClass* klass)
{
klass->submit_power_request = test_adapter_submit_power_request;
klass->submit_mode_request = test_adapter_submit_mode_request;
}

/*==========================================================================*
* TestData
*==========================================================================*/

typedef struct test_data {
GMainLoop* loop;
NfcManager* manager;
Expand Down Expand Up @@ -248,14 +191,8 @@ test_get_all_start(
GDBusConnection* server,
void* user_data)
{
TestData* test = user_data;

test->service = dbus_service_adapter_new(test->adapter, server);
g_assert_nonnull(test->service);
g_dbus_connection_call(client, NULL,
dbus_service_adapter_path(test->service), NFC_ADAPTER_INTERFACE,
"GetAll", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL,
test_get_all_done, test);
test_start_and_get((TestData*)user_data, client, server,
"GetAll", test_get_all_done);
}

static
Expand Down Expand Up @@ -613,7 +550,7 @@ test_get_tags_start(

/* Add second tag after creating DBusServiceAdapter */
target = test_target_new();
g_assert(nfc_adapter_add_other_tag(test->adapter, target));
g_assert_nonnull(nfc_adapter_add_other_tag(test->adapter, target));
nfc_target_unref(target);

g_dbus_connection_call(client, NULL,
Expand All @@ -635,7 +572,7 @@ test_get_tags(

/* Add one tag before creating DBusServiceAdapter */
target = test_target_new();
g_assert(nfc_adapter_add_other_tag(test.adapter, target));
g_assert_nonnull(nfc_adapter_add_other_tag(test.adapter, target));
nfc_target_unref(target);

dbus = test_dbus_new(test_get_tags_start, &test);
Expand Down Expand Up @@ -876,7 +813,7 @@ test_tag_added_start(

/* Add a tag */
target = test_target_new();
g_assert(nfc_adapter_add_other_tag(test->adapter, target));
g_assert_nonnull(nfc_adapter_add_other_tag(test->adapter, target));
nfc_target_unref(target);
}

Expand Down Expand Up @@ -959,7 +896,7 @@ test_tag_removed(
test_data_init(&test);

target = test_target_new();
g_assert(nfc_adapter_add_other_tag(test.adapter, target));
g_assert_nonnull(nfc_adapter_add_other_tag(test.adapter, target));
nfc_target_unref(target);

dbus = test_dbus_new(test_tag_removed_start, &test);
Expand Down
7 changes: 7 additions & 0 deletions unit/plugins_dbus_service_tag/Makefile
@@ -0,0 +1,7 @@
# -*- Mode: makefile-gmake -*-

EXE = test_plugins_dbus_service_tag

COMMON_SRC = test_dbus.c test_main.c test_adapter.c test_target.c

include ../common/Makefile.plugins

0 comments on commit 1c5ca67

Please sign in to comment.