[glibmm] Add a test of implementing an interface.



commit 98ace3653edcb7590904f6e7d997deacff08fcd5
Author: Murray Cumming <murrayc murrayc com>
Date:   Sat Apr 6 22:52:27 2013 +0200

    Add a test of implementing an interface.
    
    * tests/Makefile.am:
    * tests/glibmm_interface_implementation/main.cc: Add a very simple
    test that implements an interface, with a vfunc implementation and
    make sure that the vfunc is called when the caller method is called.

 ChangeLog                                     |    9 +++++
 tests/Makefile.am                             |    5 +++
 tests/glibmm_interface_implementation/main.cc |   41 +++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2a595f0..ce0349d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-04-06  Murray Cumming  <murrayc murrayc com>
+
+       Add a test of implementing an interface.
+
+       * tests/Makefile.am:
+       * tests/glibmm_interface_implementation/main.cc: Add a very simple
+       test that implements an interface, with a vfunc implementation and
+       make sure that the vfunc is called when the caller method is called.
+
 2013-04-02  José Alburquerque  <jaalburquerque gmail com>
 
        ByteArray: Add a Glib::Value<> template specialization for it.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f58e18c..bfee2a5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,6 +25,7 @@ check_PROGRAMS =                              \
        glibmm_btree/test                       \
        glibmm_date/test                        \
        glibmm_buildfilename/test               \
+       glibmm_interface_implementation/test    \
        glibmm_nodetree/test                    \
        glibmm_ustring_compose/test             \
        glibmm_ustring_format/test              \
@@ -69,6 +70,10 @@ giomm_asyncresult_sourceobject_test_LDADD    = $(giomm_ldadd)
 glibmm_btree_test_SOURCES                = glibmm_btree/main.cc
 glibmm_buildfilename_test_SOURCES        = glibmm_buildfilename/main.cc
 glibmm_date_test_SOURCES                 = glibmm_date/main.cc
+
+glibmm_interface_implementation_test_SOURCES = glibmm_interface_implementation/main.cc
+glibmm_interface_implementation_test_LDADD = $(giomm_ldadd)
+
 glibmm_nodetree_test_SOURCES             = glibmm_nodetree/main.cc
 glibmm_ustring_compose_test_SOURCES      = glibmm_ustring_compose/main.cc
 glibmm_ustring_format_test_SOURCES       = glibmm_ustring_format/main.cc
diff --git a/tests/glibmm_interface_implementation/main.cc b/tests/glibmm_interface_implementation/main.cc
new file mode 100644
index 0000000..dfbb716
--- /dev/null
+++ b/tests/glibmm_interface_implementation/main.cc
@@ -0,0 +1,41 @@
+#include <glibmm.h>
+#include <giomm.h> //There are no Interfaces in glibmm, but there are in giomm.
+#include <iostream>
+
+//TODO: I also tried Glib::Action, but that needs us to implement interface properties. murrayc
+class CustomConverter :
+  public Glib::Object,
+  public Gio::Converter
+{
+public:
+  CustomConverter();
+
+protected:
+  //Implement a vfunc:
+  virtual void reset_vfunc();
+};
+
+CustomConverter::CustomConverter()
+: Glib::ObjectBase( typeid(CustomConverter) ),
+  Glib::Object()
+{
+}
+
+static bool reset_called = false;
+
+void CustomConverter::reset_vfunc()
+{
+  reset_called = true;
+}
+
+
+int main(int, char**)
+{
+  Glib::init();
+
+  CustomConverter converter;
+  converter.reset();
+  g_assert(reset_called);
+
+  return EXIT_SUCCESS;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]