efl/src/tests/ecore/efl_app_test_cml.c

89 lines
2.3 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#define EFL_CORE_COMMAND_LINE_PROTECTED
#include <stdio.h>
#include <unistd.h>
#define EFL_NOLEGACY_API_SUPPORT
#include <Efl_Core.h>
#include "efl_app_suite.h"
#include "../efl_check.h"
typedef struct {
} Efl_App_Test_CML_Data;
ecore: Rename EAPI macro to ECORE_API in Ecore library Patch from a series of patches to rename EAPI symbols to specific library DSOs. EAPI was designed to be able to pass ```__attribute__ ((visibility ("default")))``` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as ```__atttribute__((visibility("default")))```. However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
2020-09-20 06:23:26 -07:00
#define ECORETEST_API
#define ECORETEST_API_WEAK
#include "efl_app_test_cml.eo.h"
#include "efl_app_test_cml.eo.c"
static Eina_Array*
_construct_array(void)
{
Eina_Array *array = eina_array_new(16);
eina_array_push(array, eina_stringshare_add("/bin/sh"));
eina_array_push(array, eina_stringshare_add("-C"));
eina_array_push(array, eina_stringshare_add("foo"));
eina_array_push(array, eina_stringshare_add("--test"));
eina_array_push(array, eina_stringshare_add("--option=done"));
eina_array_push(array, eina_stringshare_add("--"));
eina_array_push(array, eina_stringshare_add("asdf --test"));
return array;
}
static const char*
_construct_string(void)
{
return "/bin/sh -C foo --test --option=done -- \"asdf --test\"";
}
EFL_START_TEST(efl_core_cml_string)
{
Efl_App_Test_CML *cml = efl_add_ref(EFL_APP_TEST_CML_CLASS, NULL);
Eina_Array *content = _construct_array();
Eina_Stringshare *str;
Eina_Bool b;
int i = 0;
b = efl_core_command_line_command_string_set(cml, _construct_string());
ck_assert_int_ne(b, 0);
EINA_ACCESSOR_FOREACH(efl_core_command_line_command_access(cml), i, str)
{
ck_assert_str_eq(eina_array_data_get(content, i), str);
}
ck_assert_str_eq(efl_core_command_line_command_get(cml), _construct_string());
}
EFL_END_TEST
EFL_START_TEST(efl_core_cml_array)
{
Efl_App_Test_CML *cml = efl_add_ref(EFL_APP_TEST_CML_CLASS, NULL);
Eina_Array *content1 = _construct_array();
Eina_Array *content2 = _construct_array();
Eina_Stringshare *str;
Eina_Bool b;
int i = 0;
b = efl_core_command_line_command_array_set(cml, content1);
ck_assert_int_ne(b, 0);
EINA_ACCESSOR_FOREACH(efl_core_command_line_command_access(cml), i, str)
{
ck_assert_str_eq(eina_array_data_get(content2, i), str);
}
ck_assert_str_eq(efl_core_command_line_command_get(cml), _construct_string());
}
EFL_END_TEST
void efl_test_efl_cml(TCase *tc)
{
tcase_add_test(tc, efl_core_cml_string);
tcase_add_test(tc, efl_core_cml_array);
}