[gtkmm] Add simple test for Gtk::Object move operations.



commit 7696f5126342682be6f830f44e23ef5e2cdf5206
Author: Murray Cumming <murrayc murrayc com>
Date:   Sat Aug 22 13:08:13 2015 +0200

    Add simple test for Gtk::Object move operations.

 tests/Makefile.am         |    2 +
 tests/object_move/main.cc |   57 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0a00374..0598b3f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,6 +27,7 @@ check_PROGRAMS =                      \
        dialog_deletethis/test          \
        main_with_options/test          \
        menu_destruction/test           \
+       object_move/test                \
        property_notification/test      \
        refcount_dialog/test            \
        scrolledwindow/test             \
@@ -45,6 +46,7 @@ dialog_test_SOURCES                = dialog/main.cc
 dialog_deletethis_test_SOURCES     = dialog_deletethis/main.cc
 main_with_options_test_SOURCES     = main_with_options/main.cc
 menu_destruction_test_SOURCES      = menu_destruction/main.cc
+object_move_test_SOURCES           = object_move/main.cc
 property_notification_test_SOURCES = property_notification/main.cc
 refcount_dialog_test_SOURCES       = refcount_dialog/main.cc
 scrolledwindow_test_SOURCES        = scrolledwindow/main.cc
diff --git a/tests/object_move/main.cc b/tests/object_move/main.cc
new file mode 100644
index 0000000..fd9df0e
--- /dev/null
+++ b/tests/object_move/main.cc
@@ -0,0 +1,57 @@
+#include <gtkmm.h>
+#include <gtk/gtk.h>
+#include <iostream>
+#include <stdlib.h>
+
+class Derived : public Glib::Object
+{
+public:
+  //A real application would never make the constructor public.
+  //It would instead have a protectd constructor and a public create() method.
+  Derived(GObject* gobject, int i)
+  : Glib::Object(gobject),
+    i_(i)
+  {
+  }
+
+  Derived(const Derived& src) = delete;
+  Derived& operator=(const Derived& src) = delete;
+
+  Derived(Derived&& src) noexcept
+  : Glib::Object(std::move(src)),
+    i_(std::move(src.i_))
+  {}
+
+  Derived& operator=(Derived&& src) noexcept
+  {
+    Glib::Object::operator=(std::move(src));
+    i_ = std::move(src.i_);
+
+    return *this;
+  }
+
+  int i_;
+};
+
+static
+void test_object_move_constructor()
+{
+  GObject *button = G_OBJECT(gtk_button_new());
+  Derived derived(button, 5);
+  std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
+  g_assert(derived.gobj() == button);
+  Derived derived2 = std::move(derived);
+  g_assert_cmpint(derived2.i_, ==, 5);
+  std::cout << "debug: gobj(): " << derived2.gobj() << std::endl;
+  g_assert(derived2.gobj() == button);
+}
+
+int main(int argc, char** argv)
+{
+  gtk_init(&argc, &argv);
+  Gtk::Main::init_gtkmm_internals();
+
+  test_object_move_constructor();
+
+  return EXIT_SUCCESS;
+}


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