[gtkmm] tests/object_move: Derive from Gtk::Object, test move assignment
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] tests/object_move: Derive from Gtk::Object, test move assignment
- Date: Sat, 31 Oct 2015 11:03:09 +0000 (UTC)
commit c155e8246c785fcc3a12d2b05cf58308abe1c35c
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Sat Oct 31 11:57:09 2015 +0100
tests/object_move: Derive from Gtk::Object, test move assignment
.gitignore: Add output files from tests
tests/Makefile.am: Execute object_move/test on "make check".
tests/object_move/main.cc: Derive the Derived class from Gtk::Object.
Test move assignment. Check that the underlying C object is moved,
and not copied.
.gitignore | 2 ++
tests/Makefile.am | 3 ++-
tests/object_move/main.cc | 34 ++++++++++++++++++++++++++--------
3 files changed, 30 insertions(+), 9 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 270d8ce..09837f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -558,6 +558,8 @@ gtk/stamp-h3
# tests
/tests/*/test
+/tests/*/test.trs
+/tests/*/test.log
/tests/*.log
/tests/*.trs
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0598b3f..53301ea 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -33,7 +33,8 @@ check_PROGRAMS = \
scrolledwindow/test \
wrap_existing/test
-TESTS = test_validate_docs_xhtml.sh
+TESTS = object_move/test \
+ test_validate_docs_xhtml.sh
builder_test_SOURCES = builder/main.cc
child_widget_test_SOURCES = child_widget/main.cc \
diff --git a/tests/object_move/main.cc b/tests/object_move/main.cc
index fd9df0e..ad7e246 100644
--- a/tests/object_move/main.cc
+++ b/tests/object_move/main.cc
@@ -3,13 +3,11 @@
#include <iostream>
#include <stdlib.h>
-class Derived : public Glib::Object
+class Derived : public Gtk::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),
+ : Gtk::Object(gobject),
i_(i)
{
}
@@ -18,13 +16,13 @@ public:
Derived& operator=(const Derived& src) = delete;
Derived(Derived&& src) noexcept
- : Glib::Object(std::move(src)),
+ : Gtk::Object(std::move(src)),
i_(std::move(src.i_))
{}
Derived& operator=(Derived&& src) noexcept
{
- Glib::Object::operator=(std::move(src));
+ Gtk::Object::operator=(std::move(src));
i_ = std::move(src.i_);
return *this;
@@ -36,14 +34,33 @@ public:
static
void test_object_move_constructor()
{
- GObject *button = G_OBJECT(gtk_button_new());
+ 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);
+
+ Derived derived2(std::move(derived));
g_assert_cmpint(derived2.i_, ==, 5);
std::cout << "debug: gobj(): " << derived2.gobj() << std::endl;
g_assert(derived2.gobj() == button);
+ g_assert(derived.gobj() == nullptr);
+}
+
+static
+void test_object_move_assignment_operator()
+{
+ GObject* button = G_OBJECT(gtk_button_new());
+ Derived derived(button, 5);
+ //std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
+ g_assert(derived.gobj() == button);
+
+ GObject* button2 = G_OBJECT(gtk_button_new());
+ Derived derived2(button2, 6);
+ derived2 = std::move(derived);
+ g_assert_cmpint(derived2.i_, ==, 5);
+ //std::cout << "debug: gobj(): " << derived2.gobj() << std::endl;
+ g_assert(derived2.gobj() == button);
+ g_assert(derived.gobj() == nullptr);
}
int main(int argc, char** argv)
@@ -52,6 +69,7 @@ int main(int argc, char** argv)
Gtk::Main::init_gtkmm_internals();
test_object_move_constructor();
+ test_object_move_assignment_operator();
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]