[glibmm] Improve tests/glibmm_interface_implementation



commit ffc7d974949c8ceb0273a11c649c6af947afcf18
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Tue Mar 17 14:27:14 2015 +0100

    Improve tests/glibmm_interface_implementation
    
    * tests/glibmm_interface_implementation/main.cc: Return EXIT_FAILURE if some
    test fails. Add more tests of virtual functions. Bug #705124.

 tests/glibmm_interface_implementation/main.cc |   48 ++++++++++++++++++++++--
 1 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/tests/glibmm_interface_implementation/main.cc b/tests/glibmm_interface_implementation/main.cc
index bc8253b..ec0ea93 100644
--- a/tests/glibmm_interface_implementation/main.cc
+++ b/tests/glibmm_interface_implementation/main.cc
@@ -1,6 +1,12 @@
+// This program does not only test the implementation of an interface
+// in a custom class. It also tests virtual functions that have leaked memory
+// or printed unjustified critical messages in glibmm before version 2.44.
+// See https://bugzilla.gnome.org/show_bug.cgi?id=705124.
+
 #include <glibmm.h>
 #include <giomm.h> //There are no Interfaces in glibmm, but there are in giomm.
 #include <iostream>
+#include <cstring>
 
 class CustomAction :
   public Gio::Action,
@@ -13,8 +19,10 @@ public:
   Glib::Property<Glib::ustring> property;
 
 protected:
-  //Implement a vfunc:
+  //Implement vfuncs:
   virtual Glib::ustring get_name_vfunc() const;
+  virtual Glib::VariantType get_state_type_vfunc() const;
+  virtual Glib::VariantBase get_state_hint_vfunc() const;
 };
 
 CustomAction::CustomAction()
@@ -32,33 +40,65 @@ Glib::ustring CustomAction::get_name_vfunc() const
   return "custom-name";
 }
 
+Glib::VariantType CustomAction::get_state_type_vfunc() const
+{
+  return Glib::VariantType(G_VARIANT_TYPE_INT16);
+}
+
+Glib::VariantBase CustomAction::get_state_hint_vfunc() const
+{
+  return Glib::Variant<gint16>::create(42);
+}
 
 int main(int, char**)
 {
   Glib::init();
 
   CustomAction action;
+  bool success = true;
+
   Glib::ustring name = action.get_name();
   std::cout << "The name is '" << name << "'." << std::endl;
+  success &= name == "custom-name";
+
   std::cout << "The name property of the implemented interface is '"
             << action.property_name().get_value() << "'." << std::endl;
+  success &= action.property_name().get_value() == "";
+
   std::cout << "The custom string property is '"
             << action.property.get_value() << "'." << std::endl;
+  success &= action.property.get_value() == "Initial value.";
 
   action.property = "A new value.";
   std::cout << "The custom string property (after changing it) is '"
             << action.property.get_value() << "'." << std::endl;
+  success &= action.property.get_value() == "A new value.";
 
   gchar* prop_value = 0;
   g_object_set(action.gobj(), "custom_property", "Another value", NULL);
   g_object_get(action.gobj(), "custom_property", &prop_value, NULL);
-  std::cout << "The custom property after g_object_get/set() is '"
+  std::cout << "The custom property after g_object_set/get() is '"
             << prop_value << "'." << std::endl;
+  success &= std::strcmp(prop_value, "Another value") == 0;
+  g_free(prop_value);
+  prop_value = 0;
+
   std::cout << "The custom property through the Glib::Property<> is '"
             << action.property.get_value() << "'." << std::endl;
+  success &= action.property.get_value() == "Another value";
+
   std::cout << "The name property of the implemented interface is '"
             << action.property_name().get_value() << "'." << std::endl;
-  g_assert(get_name_called);
+  success &= action.property_name().get_value() == "";
+  success &= get_name_called;
+
+  // Check if other vfuncs leak memory. Use valgrind!
+  action.get_parameter_type();
+  action.get_state_type();
+  action.get_state_type();
+  action.get_state_hint_variant();
+  action.get_state_variant();
+  action.get_enabled();
 
-  return EXIT_SUCCESS;
+  return success ? EXIT_SUCCESS : EXIT_FAILURE;
 }


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