Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[unit] Added plugins_dbus_service_adapter test
  • Loading branch information
monich committed Jul 29, 2019
1 parent 5b0ae27 commit d3de246
Show file tree
Hide file tree
Showing 12 changed files with 1,179 additions and 119 deletions.
1 change: 1 addition & 0 deletions unit/Makefile
Expand Up @@ -21,6 +21,7 @@ all:
@$(MAKE) -C plugins_dbus_handlers_type_mediatype $*
@$(MAKE) -C plugins_dbus_handlers_type_text $*
@$(MAKE) -C plugins_dbus_handlers_type_uri $*
@$(MAKE) -C plugins_dbus_service_adapter $*

clean: unitclean
rm -f *~
Expand Down
17 changes: 14 additions & 3 deletions unit/common/Makefile
Expand Up @@ -43,6 +43,16 @@ ifneq ($(GEN_SRC),)
# Additional requirements for generated stubs
PKGS += gio-unix-2.0
INCLUDES += -I. -I$(GEN_DIR)

# Make sure stubs get generated before compilation starts
$(GEN_SRC:%=$(GEN_DIR)/%): | $(GEN_DIR)
$(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o): | $(GEN_SRC:%=$(GEN_DIR)/%)
$(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o): | $(GEN_SRC:%=$(GEN_DIR)/%)
$(SRC:%.c=$(COVERAGE_BUILD_DIR)/%.o): | $(GEN_SRC:%=$(GEN_DIR)/%)
endif

ifeq ($(SPEC_DIR),)
SPEC_DIR = .
endif

#
Expand Down Expand Up @@ -118,8 +128,6 @@ $(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
$(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR)

$(GEN_SRC:%=$(GEN_DIR)/%): | $(GEN_DIR)

DEBUG_DEPS += $(DEBUG_CORE_LIB)
RELEASE_DEPS += $(RELEASE_CORE_LIB)
COVERAGE_DEPS += $(COVERAGE_CORE_LIB)
Expand Down Expand Up @@ -156,6 +164,9 @@ test: test_banner debug
valgrind: test_banner debug
@G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no $(DEBUG_EXE)

$(GEN_DIR):
mkdir -p $@

$(DEBUG_BUILD_DIR):
mkdir -p $@

Expand All @@ -165,7 +176,7 @@ $(RELEASE_BUILD_DIR):
$(COVERAGE_BUILD_DIR):
mkdir -p $@

$(GEN_DIR)/%.c: %.xml
$(GEN_DIR)/%.c: $(SPEC_DIR)/%.xml
gdbus-codegen --generate-c-code $(@:%.c=%) $<

$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
Expand Down
8 changes: 4 additions & 4 deletions unit/common/test_common.h
@@ -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 Down
78 changes: 78 additions & 0 deletions unit/common/test_target.c
@@ -0,0 +1,78 @@
/*
* 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 "test_target.h"
#include "nfc_target_impl.h"

typedef NfcTargetClass TestTargetClass;
typedef NfcTarget TestTarget;

G_DEFINE_TYPE(TestTarget, test_target, NFC_TYPE_TARGET)
#define TEST_TYPE_TARGET (test_target_get_type())

NfcTarget*
test_target_new(
void)
{
return g_object_new(TEST_TYPE_TARGET, NULL);
}

static
void
test_target_deactivate(
NfcTarget* target)
{
nfc_target_gone(target);
}

static
void
test_target_init(
TestTarget* self)
{
}

static
void
test_target_class_init(
NfcTargetClass* klass)
{
klass->deactivate = test_target_deactivate;
}

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
50 changes: 50 additions & 0 deletions unit/common/test_target.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_TARGET_H
#define TEST_TARGET_H

#include <nfc_types.h>

NfcTarget*
test_target_new(
void);

#endif /* TEST_TARGET_H */

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
2 changes: 2 additions & 0 deletions unit/core_adapter/Makefile
Expand Up @@ -2,4 +2,6 @@

EXE = test_core_adapter

COMMON_SRC = test_main.c test_target.c

include ../common/Makefile
59 changes: 5 additions & 54 deletions unit/core_adapter/test_core_adapter.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 Down Expand Up @@ -31,6 +31,7 @@
*/

#include "test_common.h"
#include "test_target.h"

#include "nfc_adapter_p.h"
#include "nfc_target_impl.h"
Expand All @@ -40,8 +41,6 @@

static TestOpt test_opt;

#define TEST_TIMEOUT (10) /* seconds */

static
void
test_adapter_inc(
Expand All @@ -61,52 +60,6 @@ test_adapter_tag_inc(
(*(int*)user_data)++;
}

/*==========================================================================*
* Test target
*==========================================================================*/

typedef NfcTargetClass TestTargetClass;
typedef struct test_target {
NfcTarget target;
gboolean deactivated;
} TestTarget;

G_DEFINE_TYPE(TestTarget, test_target, NFC_TYPE_TARGET)
#define TEST_TYPE_TARGET (test_target_get_type())
#define TEST_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
TEST_TYPE_TARGET, TestTarget))

TestTarget*
test_target_new(
void)
{
return g_object_new(TEST_TYPE_TARGET, NULL);
}

static
void
test_target_deactivate(
NfcTarget* target)
{
TEST_TARGET(target)->deactivated = TRUE;
NFC_TARGET_CLASS(test_target_parent_class)->deactivate(target);
}

static
void
test_target_init(
TestTarget* self)
{
}

static
void
test_target_class_init(
NfcTargetClass* klass)
{
klass->deactivate = test_target_deactivate;
}

/*==========================================================================*
* Test adapter
*==========================================================================*/
Expand Down Expand Up @@ -620,11 +573,9 @@ test_tags(
void)
{
TestAdapter* test = test_adapter_new();
TestTarget* test_target0 = test_target_new();
TestTarget* test_target1 = test_target_new();
NfcTarget* target0 = test_target_new();
NfcTarget* target1 = test_target_new();
NfcAdapter* adapter = &test->adapter;
NfcTarget* target0 = &test_target0->target;
NfcTarget* target1 = &test_target1->target;
NfcTag* tag0;
NfcTag* tag1;
gulong id[3];
Expand Down
2 changes: 2 additions & 0 deletions unit/core_tag/Makefile
Expand Up @@ -2,4 +2,6 @@

EXE = test_core_tag

COMMON_SRC = test_main.c test_target.c

include ../common/Makefile

0 comments on commit d3de246

Please sign in to comment.