Add a basic library example with a test hooked in
This commit is contained in:
parent
83bbdf2122
commit
5ad70691ca
|
@ -0,0 +1,30 @@
|
|||
project(
|
||||
'efl-example-lib', 'c',
|
||||
version : '0.0.1',
|
||||
default_options: [ 'c_std=gnu99', 'warning_level=2' ],
|
||||
meson_version : '>= 0.40.0')
|
||||
|
||||
add_global_arguments('-DHAVE_CONFIG_H=1', '-DHAVE_CONFIG=1', language: 'c')
|
||||
|
||||
config_h = configuration_data()
|
||||
config_h.set_quoted('PACKAGE', meson.project_name())
|
||||
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
|
||||
config_h.set_quoted('PACKAGE_STRING', meson.project_name() + ' ' + meson.project_version())
|
||||
config_h.set_quoted('PACKAGE_NAME', meson.project_name())
|
||||
config_h.set_quoted('PACKAGE_BUILD_DIR', meson.build_root())
|
||||
|
||||
config_h.set_quoted('EFL_EO_API_SUPPORT', '1')
|
||||
config_h.set_quoted('EFL_BETA_API_SUPPORT', '1')
|
||||
|
||||
eina = dependency('eina', version : '>=1.20.99')
|
||||
efl = dependency('efl', version : '>=1.20.99')
|
||||
elm = dependency('elementary', version : '>=1.20.99')
|
||||
|
||||
inc = include_directories('.')
|
||||
subdir('src')
|
||||
|
||||
configure_file(
|
||||
output : 'config.h',
|
||||
install : false,
|
||||
configuration: config_h
|
||||
)
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef EXAMPLE_H_
|
||||
# define EXAMPLE_H_
|
||||
|
||||
#include <Eina.h>
|
||||
|
||||
#ifdef EAPI
|
||||
# undef EAPI
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef EFL_EDI_BUILD
|
||||
# ifdef DLL_EXPORT
|
||||
# define EAPI __declspec(dllexport)
|
||||
# else
|
||||
# define EAPI
|
||||
# endif /* ! DLL_EXPORT */
|
||||
# else
|
||||
# define EAPI __declspec(dllimport)
|
||||
# endif /* ! EFL_EDI_BUILD */
|
||||
#else
|
||||
# ifdef __GNUC__
|
||||
# if __GNUC__ >= 4
|
||||
# define EAPI __attribute__ ((visibility("default")))
|
||||
# else
|
||||
# define EAPI
|
||||
# endif
|
||||
# else
|
||||
# define EAPI
|
||||
# endif
|
||||
#endif /* ! _WIN32 */
|
||||
|
||||
/**
|
||||
* A dummy method that should return true.
|
||||
*
|
||||
* @return EINA_TRUE
|
||||
*/
|
||||
EAPI Eina_Bool example_method();
|
||||
|
||||
#endif /* EXAMPLE_H_ */
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "Example.h"
|
||||
|
||||
EAPI Eina_Bool example_method()
|
||||
{
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
src = files([
|
||||
'Example.h',
|
||||
'example.c',
|
||||
])
|
||||
|
||||
lib = library('example', src,
|
||||
dependencies : [eina, efl, elm],
|
||||
include_directories : inc,
|
||||
install : true
|
||||
)
|
||||
|
||||
example_lib = declare_dependency(
|
||||
link_with : lib,
|
||||
include_directories : [include_directories('./'), inc]
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
subdir('lib')
|
||||
subdir('test')
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
src = files([
|
||||
'suite.h',
|
||||
'runner.c',
|
||||
'test_lib.c',
|
||||
])
|
||||
|
||||
check = dependency('check')
|
||||
|
||||
exe = executable('example-test', src,
|
||||
dependencies : [eina, efl, elm, check, example_lib],
|
||||
include_directories : inc,
|
||||
install : true
|
||||
)
|
||||
test('lib test', exe)
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <check.h>
|
||||
#include <Elementary.h>
|
||||
|
||||
#include <Example.h>
|
||||
#include "suite.h"
|
||||
|
||||
EAPI_MAIN void
|
||||
efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
|
||||
{
|
||||
Efl_Loop_Arguments *args = ev->info;
|
||||
Suite *s;
|
||||
SRunner *sr;
|
||||
TCase *tc = NULL;
|
||||
char *test = NULL;
|
||||
unsigned int i;
|
||||
int failed_count = -1;
|
||||
|
||||
if (eina_array_count(args->argv) > 0)
|
||||
{
|
||||
test = eina_array_data_get(args->argv, 0);
|
||||
|
||||
if (!strcmp(test, "--list"))
|
||||
{
|
||||
fprintf(stdout, "Available tests :\n");
|
||||
for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
|
||||
fprintf(stdout, "\t%s\n", tests[i].name);
|
||||
|
||||
efl_exit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
s = suite_create("Example");
|
||||
for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
|
||||
{
|
||||
if (test && strcmp(tests[i].name, test))
|
||||
continue ;
|
||||
|
||||
tc = tcase_create(tests[i].name);
|
||||
tcase_set_timeout(tc, 0);
|
||||
|
||||
tests[i].build(tc);
|
||||
suite_add_tcase(s, tc);
|
||||
}
|
||||
|
||||
sr = srunner_create(s);
|
||||
srunner_set_xml(sr, PACKAGE_BUILD_DIR "/check-results.xml");
|
||||
|
||||
srunner_run_all(sr, CK_ENV);
|
||||
failed_count = srunner_ntests_failed(sr);
|
||||
srunner_free(sr);
|
||||
|
||||
// TODO set the return code somehow
|
||||
// return (failed_count == 0) ? 0 : 255;
|
||||
efl_exit();
|
||||
}
|
||||
EFL_MAIN();
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef _SUITE_H
|
||||
#define _SUITE_H
|
||||
|
||||
#include <check.h>
|
||||
|
||||
#include <Example.h>
|
||||
|
||||
void lib_test_basic(TCase *tc);
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
void (*build)(TCase *tc);
|
||||
} tests[] = {
|
||||
{ "basic", lib_test_basic },
|
||||
};
|
||||
|
||||
#endif /* _SUITE_H */
|
|
@ -0,0 +1,17 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "suite.h"
|
||||
|
||||
START_TEST (lib_test_basic_call)
|
||||
{
|
||||
ck_assert(example_method());
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void lib_test_basic(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, lib_test_basic_call);
|
||||
}
|
||||
|
Loading…
Reference in New Issue