eolian_cxx: Assertions to ensure C++ wrapper compatibility with Eo*
authorVitor Sousa <vitorsousasilva@gmail.com>
Tue, 11 Nov 2014 15:03:59 +0000 (13:03 -0200)
committerVitor Sousa <vitorsousasilva@gmail.com>
Mon, 5 Jan 2015 17:52:27 +0000 (15:52 -0200)
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.

src/Makefile_Eolian_Cxx.am
src/lib/eolian_cxx/grammar/eo_class_generator.hh
src/tests/eolian_cxx/eolian_cxx_suite.cc
src/tests/eolian_cxx/eolian_cxx_test_wrapper.cc

index a2d0766..14cf493 100644 (file)
@@ -62,6 +62,7 @@ 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_wrapper.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
index 2b2233b..656a791 100644 (file)
@@ -46,7 +46,10 @@ eo_class_generator(std::ostream& out, eo_class const& cls)
        << eo_class_getter(cls)
         << "private:" << endl
        << eo_class_constructors(cls)
-       << "};" << endl;
+       << "};" << endl
+       << "static_assert(sizeof(" << cls.name << ") == sizeof(Eo*), \"sizeof(" << cls.name << ") != sizeof(Eo*)\");" << endl
+       << "static_assert(std::is_standard_layout<" << cls.name << ">::value, \"'" << cls.name << "' is not standard layout\");"
+       << endl << endl;
 }
 
 } } } // namespace efl { namespace eolian { namespace grammar {
index bd08e9b..20a8c34 100644 (file)
@@ -4,6 +4,7 @@
 #include <cassert>
 
 void eolian_cxx_test_parse(TCase* tc);
+void eolian_cxx_test_wrapper(TCase* tc);
 void eolian_cxx_test_generate(TCase* tc);
 void eolian_cxx_test_callback(TCase* tc);
 
@@ -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 Wrapper", eolian_cxx_test_wrapper },
   { "Eolian-Cxx Generation", eolian_cxx_test_generate },
   { "Eolian-Cxx Callback", eolian_cxx_test_callback },
   { NULL, NULL }
index fb680a5..123b508 100644 (file)
@@ -1,2 +1,31 @@
 
 // Test Eolian-Cxx wrappers
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <Eo.h>
+#include <Ecore.h>
+
+#include <callback.eo.hh>
+
+#include <check.h>
+
+START_TEST(eolian_cxx_test_wrapper_size)
+{
+  efl::eo::eo_init init;
+
+  ::efl::eo::base b(nullptr);
+  ::callback c;
+
+  fail_if(sizeof(b) != sizeof(Eo*));
+  fail_if(sizeof(b) != sizeof(c));
+}
+END_TEST
+
+void
+eolian_cxx_test_wrapper(TCase* tc)
+{
+  tcase_add_test(tc, eolian_cxx_test_wrapper_size);
+}