forked from enlightenment/efl
eolian-cxx: Added callback test
Added test for callback generation and uses
This commit is contained in:
parent
907544be7b
commit
9c6c7728c0
|
@ -49,32 +49,39 @@ bin_eolian_cxx_eolian_cxx_LDADD = @CHECK_LIBS@ @USE_EOLIAN_LIBS@
|
|||
|
||||
bin_eolian_cxx_eolian_cxx_DEPENDENCIES = @USE_EOLIAN_INTERNAL_LIBS@
|
||||
|
||||
include Makefile_Eolian_Cxx_Helper.am
|
||||
|
||||
|
||||
### Unit tests
|
||||
|
||||
if EFL_ENABLE_TESTS
|
||||
|
||||
BUILT_SOURCES += \
|
||||
tests/eolian_cxx/callback.eo.c \
|
||||
tests/eolian_cxx/callback.eo.h
|
||||
|
||||
check_PROGRAMS += tests/eolian_cxx/eolian_cxx_suite
|
||||
TESTS += tests/eolian_cxx/eolian_cxx_suite
|
||||
|
||||
tests_eolian_cxx_eolian_cxx_suite_SOURCES = \
|
||||
tests/eolian_cxx/eolian_cxx_suite.cc \
|
||||
tests/eolian_cxx/eolian_cxx_test_parse.cc \
|
||||
tests/eolian_cxx/callback.c \
|
||||
tests/eolian_cxx/eolian_cxx_test_callback.cc \
|
||||
tests/eolian_cxx/eolian_cxx_test_generate.cc
|
||||
|
||||
tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh
|
||||
|
||||
tests_eolian_cxx_eolian_cxx_suite_CXXFLAGS = \
|
||||
-I$(top_builddir)/src/lib/efl \
|
||||
-I$(top_srcdir)/src/bin/eolian_cxx \
|
||||
-I$(top_srcdir)/src/lib/eolian_cxx \
|
||||
-I$(top_builddir)/src/tests/eolian_cxx \
|
||||
-DTESTS_WD=\"`pwd`\" \
|
||||
-DTESTS_SRC_DIR=\"$(top_srcdir)/src/tests/eolian_cxx\" \
|
||||
-DPACKAGE_BUILD_DIR=\"$(abs_top_builddir)/src/tests/eolian_cxx\" \
|
||||
-DPACKAGE_DATA_DIR=\"$(datadir)/eolian_cxx\" \
|
||||
-DTESTS_BUILD_DIR=\"$(top_builddir)/src/tests/eolian_cxx\" \
|
||||
@CHECK_CFLAGS@ @EOLIAN_CXX_CFLAGS@ @EINA_CXX_CFLAGS@ \
|
||||
@EOLIAN_CFLAGS@ @EINA_CFLAGS@ @EO_CFLAGS@
|
||||
@EOLIAN_CFLAGS@ @EINA_CFLAGS@ @EO_CFLAGS@ @ECORE_CFLAGS@ \
|
||||
@EO_CXX_CFLAGS@
|
||||
|
||||
tests_eolian_cxx_eolian_cxx_suite_CFLAGS = ${tests_eolian_cxx_eolian_cxx_suite_CXXFLAGS}
|
||||
tests_eolian_cxx_eolian_cxx_suite_CPPFLAGS = ${tests_eolian_cxx_eolian_cxx_suite_CXXFLAGS}
|
||||
|
@ -84,4 +91,6 @@ tests_eolian_cxx_eolian_cxx_suite_DEPENDENCIES = @USE_EOLIAN_INTERNAL_LIBS@
|
|||
|
||||
endif
|
||||
|
||||
include Makefile_Eolian_Cxx_Helper.am
|
||||
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Eo.h>
|
||||
#include <Ecore.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "callback.eo.h"
|
||||
|
||||
struct _Callback_Data {};
|
||||
typedef struct _Callback_Data Callback_Data;
|
||||
|
||||
#define MY_CLASS CALLBACK_CLASS
|
||||
|
||||
static void _callback_default_constructor(Eo *obj EINA_UNUSED, Callback_Data *pd EINA_UNUSED)
|
||||
{
|
||||
eo_do_super(obj, MY_CLASS, eo_constructor());
|
||||
}
|
||||
|
||||
static void _callback_constructor(Eo *obj EINA_UNUSED, Callback_Data *pd EINA_UNUSED, Ecore_Cb cb, void *data)
|
||||
{
|
||||
eo_do_super(obj, MY_CLASS, eo_constructor());
|
||||
cb(data);
|
||||
}
|
||||
|
||||
static void _callback_constructor2(Eo *obj EINA_UNUSED, Callback_Data *pd EINA_UNUSED, Ecore_Cb cb, void *data
|
||||
, Ecore_Cb cb2 EINA_UNUSED)
|
||||
{
|
||||
eo_do_super(obj, MY_CLASS, eo_constructor());
|
||||
cb(data);
|
||||
}
|
||||
|
||||
static void _callback_onecallback(Eo *obj EINA_UNUSED, Callback_Data *pd EINA_UNUSED, Ecore_Cb cb, void *data)
|
||||
{
|
||||
cb(data);
|
||||
}
|
||||
|
||||
static void _callback_twocallback(Eo *obj EINA_UNUSED, Callback_Data *pd EINA_UNUSED, Ecore_Cb cb, void *data
|
||||
, Ecore_Cb cb2 EINA_UNUSED)
|
||||
{
|
||||
cb(data);
|
||||
}
|
||||
|
||||
#include "callback.eo.c"
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
class Callback (Eo.Base)
|
||||
{
|
||||
legacy_prefix: null;
|
||||
data: Callback_Data;
|
||||
constructors {
|
||||
default_constructor {
|
||||
}
|
||||
constructor {
|
||||
params {
|
||||
@in Ecore_Cb cb;
|
||||
@in void* data;
|
||||
}
|
||||
}
|
||||
constructor2 {
|
||||
params {
|
||||
@in Ecore_Cb cb;
|
||||
@in void* data;
|
||||
@in Ecore_Cb cb2;
|
||||
}
|
||||
}
|
||||
}
|
||||
methods {
|
||||
onecallback {
|
||||
params {
|
||||
@in Ecore_Cb cb;
|
||||
@in void* data;
|
||||
}
|
||||
}
|
||||
twocallback {
|
||||
params {
|
||||
@in Ecore_Cb cb;
|
||||
@in void* data;
|
||||
@in Ecore_Cb cb2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
void eolian_cxx_test_parse(TCase* tc);
|
||||
void eolian_cxx_test_generate(TCase* tc);
|
||||
void eolian_cxx_test_callback(TCase* tc);
|
||||
|
||||
typedef struct _Eolian_Cxx_Test_Case Eolian_Cxx_Test_Case;
|
||||
struct _Eolian_Cxx_Test_Case
|
||||
|
@ -16,6 +17,7 @@ struct _Eolian_Cxx_Test_Case
|
|||
static const Eolian_Cxx_Test_Case etc[] = {
|
||||
{ "Eolian-Cxx Parsing", eolian_cxx_test_parse },
|
||||
{ "Eolian-Cxx Generation", eolian_cxx_test_generate },
|
||||
{ "Eolian-Cxx Callback", eolian_cxx_test_callback },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Eo.h>
|
||||
#include <Ecore.h>
|
||||
|
||||
#include <callback.eo.hh>
|
||||
|
||||
#include <check.h>
|
||||
|
||||
void foo(void*) {}
|
||||
|
||||
START_TEST(eolian_cxx_test_callback_constructor)
|
||||
{
|
||||
efl::eo::eo_init i;
|
||||
|
||||
bool called1 = false, called2 = false;
|
||||
::callback c1 (std::bind([&called1] { called1 = true; }));
|
||||
::callback c2 (std::bind([&called2] { called2 = true; }), &foo);
|
||||
assert(called1 == true);
|
||||
assert(called2 == true);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(eolian_cxx_test_callback_method)
|
||||
{
|
||||
efl::eo::eo_init i;
|
||||
|
||||
callback c;
|
||||
|
||||
bool called1 = false, called2 = false;
|
||||
|
||||
c.onecallback(std::bind([&called1] { called1 = true; }));
|
||||
c.twocallback(std::bind([&called2] { called2 = true; }), &foo);
|
||||
|
||||
assert(called1 == true);
|
||||
assert(called2 == true);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eolian_cxx_test_callback(TCase* tc)
|
||||
{
|
||||
tcase_add_test(tc, eolian_cxx_test_callback_constructor);
|
||||
tcase_add_test(tc, eolian_cxx_test_callback_method);
|
||||
}
|
|
@ -8,8 +8,8 @@
|
|||
START_TEST(eolian_cxx_test_parse_complex_types)
|
||||
{
|
||||
efl::eolian::eolian_init init;
|
||||
fail_if(!::eolian_directory_scan(PACKAGE_DATA_DIR"/data"));
|
||||
fail_if(!::eolian_eo_file_parse(PACKAGE_DATA_DIR"/data/complex_type.eo"));
|
||||
// fail_if(!::eolian_directory_scan(PACKAGE_DATA_DIR"/data"));
|
||||
// fail_if(!::eolian_eo_file_parse(PACKAGE_DATA_DIR"/data/complex_type.eo"));
|
||||
// TODO finish
|
||||
}
|
||||
END_TEST
|
||||
|
@ -27,4 +27,5 @@ void
|
|||
eolian_cxx_test_parse(TCase* tc)
|
||||
{
|
||||
tcase_add_test(tc, eolian_cxx_test_parse_qualifiers);
|
||||
tcase_add_test(tc, eolian_cxx_test_parse_complex_types);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue