summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2014-11-11 13:03:59 -0200
committerVitor Sousa <vitorsousasilva@gmail.com>2015-01-05 15:52:27 -0200
commited8ce801cb56644c12b395797c3f9e22a508811f (patch)
treec45260a52076155c2698b59afe3bb3625d1ffa12 /src
parent1cbbb9a577eb2dbbfebb441702635b2245840d1c (diff)
eolian_cxx: Assertions to ensure C++ wrapper compatibility with Eo*
Added static assertion in the generated header to ensure that the wrapper have the same size of Eo*, thus grating compatibility between these types. Added static assertion in the generated header to ensure that the wrapper have standard layout. This should ensure correct type sizes when dealing with inheritance. Created a test to ensure that eo::base and the eolian wrappers have the same size of a Eo*. Added eolian_cxx_test_wrapper.cc to the list of test source files in Makefile_Eolian_Cxx.am.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_Eolian_Cxx.am1
-rw-r--r--src/lib/eolian_cxx/grammar/eo_class_generator.hh5
-rw-r--r--src/tests/eolian_cxx/eolian_cxx_suite.cc2
-rw-r--r--src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc29
4 files changed, 36 insertions, 1 deletions
diff --git a/src/Makefile_Eolian_Cxx.am b/src/Makefile_Eolian_Cxx.am
index a2d0766a3e..14cf493d73 100644
--- a/src/Makefile_Eolian_Cxx.am
+++ b/src/Makefile_Eolian_Cxx.am
@@ -62,6 +62,7 @@ tests/eolian_cxx/eolian_cxx_suite.cc \
62tests/eolian_cxx/eolian_cxx_test_parse.cc \ 62tests/eolian_cxx/eolian_cxx_test_parse.cc \
63tests/eolian_cxx/callback.c \ 63tests/eolian_cxx/callback.c \
64tests/eolian_cxx/eolian_cxx_test_callback.cc \ 64tests/eolian_cxx/eolian_cxx_test_callback.cc \
65tests/eolian_cxx/eolian_cxx_test_wrapper.cc \
65tests/eolian_cxx/eolian_cxx_test_generate.cc 66tests/eolian_cxx/eolian_cxx_test_generate.cc
66 67
67tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh 68tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh
diff --git a/src/lib/eolian_cxx/grammar/eo_class_generator.hh b/src/lib/eolian_cxx/grammar/eo_class_generator.hh
index 2b2233bdb7..656a791198 100644
--- a/src/lib/eolian_cxx/grammar/eo_class_generator.hh
+++ b/src/lib/eolian_cxx/grammar/eo_class_generator.hh
@@ -46,7 +46,10 @@ eo_class_generator(std::ostream& out, eo_class const& cls)
46 << eo_class_getter(cls) 46 << eo_class_getter(cls)
47 << "private:" << endl 47 << "private:" << endl
48 << eo_class_constructors(cls) 48 << eo_class_constructors(cls)
49 << "};" << endl; 49 << "};" << endl
50 << "static_assert(sizeof(" << cls.name << ") == sizeof(Eo*), \"sizeof(" << cls.name << ") != sizeof(Eo*)\");" << endl
51 << "static_assert(std::is_standard_layout<" << cls.name << ">::value, \"'" << cls.name << "' is not standard layout\");"
52 << endl << endl;
50} 53}
51 54
52} } } // namespace efl { namespace eolian { namespace grammar { 55} } } // namespace efl { namespace eolian { namespace grammar {
diff --git a/src/tests/eolian_cxx/eolian_cxx_suite.cc b/src/tests/eolian_cxx/eolian_cxx_suite.cc
index bd08e9b8aa..20a8c34a15 100644
--- a/src/tests/eolian_cxx/eolian_cxx_suite.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_suite.cc
@@ -4,6 +4,7 @@
4#include <cassert> 4#include <cassert>
5 5
6void eolian_cxx_test_parse(TCase* tc); 6void eolian_cxx_test_parse(TCase* tc);
7void eolian_cxx_test_wrapper(TCase* tc);
7void eolian_cxx_test_generate(TCase* tc); 8void eolian_cxx_test_generate(TCase* tc);
8void eolian_cxx_test_callback(TCase* tc); 9void eolian_cxx_test_callback(TCase* tc);
9 10
@@ -16,6 +17,7 @@ struct _Eolian_Cxx_Test_Case
16 17
17static const Eolian_Cxx_Test_Case etc[] = { 18static const Eolian_Cxx_Test_Case etc[] = {
18 { "Eolian-Cxx Parsing", eolian_cxx_test_parse }, 19 { "Eolian-Cxx Parsing", eolian_cxx_test_parse },
20 { "Eolian-Cxx Wrapper", eolian_cxx_test_wrapper },
19 { "Eolian-Cxx Generation", eolian_cxx_test_generate }, 21 { "Eolian-Cxx Generation", eolian_cxx_test_generate },
20 { "Eolian-Cxx Callback", eolian_cxx_test_callback }, 22 { "Eolian-Cxx Callback", eolian_cxx_test_callback },
21 { NULL, NULL } 23 { NULL, NULL }
diff --git a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
index fb680a59c1..123b508734 100644
--- a/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc
@@ -1,2 +1,31 @@
1 1
2// Test Eolian-Cxx wrappers 2// Test Eolian-Cxx wrappers
3
4#ifdef HAVE_CONFIG_H
5# include <config.h>
6#endif
7
8#include <Eo.h>
9#include <Ecore.h>
10
11#include <callback.eo.hh>
12
13#include <check.h>
14
15START_TEST(eolian_cxx_test_wrapper_size)
16{
17 efl::eo::eo_init init;
18
19 ::efl::eo::base b(nullptr);
20 ::callback c;
21
22 fail_if(sizeof(b) != sizeof(Eo*));
23 fail_if(sizeof(b) != sizeof(c));
24}
25END_TEST
26
27void
28eolian_cxx_test_wrapper(TCase* tc)
29{
30 tcase_add_test(tc, eolian_cxx_test_wrapper_size);
31}