[glibmm] tests: Split glibmm_object_move into 2 files.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] tests: Split glibmm_object_move into 2 files.
- Date: Sat, 22 Aug 2015 19:40:48 +0000 (UTC)
commit 28ccc28e940eefb89c3be4ea32a1350021fb69b0
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Aug 22 19:57:08 2015 +0200
tests: Split glibmm_object_move into 2 files.
To test ObjectBase separately.
tests/Makefile.am | 2 +
tests/glibmm_object_move/main.cc | 66 ++++++++++++++++++++---
tests/glibmm_objectbase_move/main.cc | 96 ++++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+), 9 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5c34f0a..94d3d8c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -32,6 +32,7 @@ check_PROGRAMS = \
glibmm_mainloop/test \
glibmm_nodetree/test \
glibmm_object_move/test \
+ glibmm_objectbase_move/test \
glibmm_ustring_compose/test \
glibmm_ustring_format/test \
glibmm_value/test \
@@ -91,6 +92,7 @@ glibmm_interface_implementation_test_LDADD = $(giomm_ldadd)
glibmm_mainloop_test_SOURCES = glibmm_mainloop/main.cc
glibmm_nodetree_test_SOURCES = glibmm_nodetree/main.cc
glibmm_object_move_test_SOURCES = glibmm_object_move/main.cc
+glibmm_objectbase_move_test_SOURCES = glibmm_objectbase_move/main.cc
glibmm_ustring_compose_test_SOURCES = glibmm_ustring_compose/main.cc
glibmm_ustring_format_test_SOURCES = glibmm_ustring_format/main.cc
glibmm_value_test_SOURCES = glibmm_value/glibmm_value.cc glibmm_value/main.cc
diff --git a/tests/glibmm_object_move/main.cc b/tests/glibmm_object_move/main.cc
index 3bf6ab3..a62bcf9 100644
--- a/tests/glibmm_object_move/main.cc
+++ b/tests/glibmm_object_move/main.cc
@@ -2,26 +2,47 @@
#include <iostream>
#include <stdlib.h>
-class Derived : Glib::Object
+//A basic derived GObject, just to test Glib::ObjectBase.
+typedef struct {
+ GObject parent;
+} TestDerived;
+
+typedef struct {
+ GObjectClass parent;
+} TestDerivedClass;
+
+#define TEST_TYPE_DERIVED (test_derived_get_type ())
+#define TEST_DERIVED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_DERIVED, TestDerived))
+#define TEST_DERIVED_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST ((cls), TEST_TYPE_DERIVED, TestDerivedClass))
+#define TEST_DERIVED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_DERIVED, TestDerivedClass))
+
+static void test_derived_class_init (TestDerivedClass *)
+{}
+static void test_derived_init (TestDerived *)
+{}
+
+G_DEFINE_TYPE(TestDerived, test_derived, G_TYPE_OBJECT)
+
+class DerivedObject : 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(int i)
- : Glib::Object(),
+ DerivedObject(GObject* gobject, int i)
+ : Glib::Object(gobject),
i_(i)
{
}
- Derived(const Derived& src) = delete;
- Derived& operator=(const Derived& src) = delete;
+ DerivedObject(const DerivedObject& src) = delete;
+ DerivedObject& operator=(const DerivedObject& src) = delete;
- Derived(Derived&& src)
+ DerivedObject(DerivedObject&& src) noexcept
: Glib::Object(std::move(src)),
i_(std::move(src.i_))
{}
- Derived& operator=(Derived&& src)
+ DerivedObject& operator=(DerivedObject&& src) noexcept
{
Glib::Object::operator=(std::move(src));
i_ = std::move(src.i_);
@@ -35,14 +56,41 @@ public:
static
void test_object_move_constructor()
{
- Derived derived(5);
- Derived derived2 = std::move(derived);
+ GObject *gobject = G_OBJECT(g_object_new(TEST_TYPE_DERIVED, nullptr));
+ g_object_ref(gobject);
+
+ DerivedObject derived(gobject, 5);
+ std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
+ g_assert(derived.gobj() == gobject);
+ DerivedObject derived2(std::move(derived));
g_assert_cmpint(derived2.i_, ==, 5);
+ std::cout << "debug: gobj(): " << derived2.gobj() << std::endl;
+ g_assert(derived2.gobj() == gobject);
}
+
+static
+void test_object_move_assignment_operator()
+{
+ GObject *gobject = G_OBJECT(g_object_new(TEST_TYPE_DERIVED, nullptr));
+ g_object_ref(gobject);
+
+ DerivedObject derived(gobject, 5);
+ //std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
+ g_assert(derived.gobj() == gobject);
+ DerivedObject derived2 = std::move(derived);
+ g_assert_cmpint(derived2.i_, ==, 5);
+ //std::cout << "debug: gobj(): " << derived2.gobj() << std::endl;
+ g_assert(derived2.gobj() == gobject);
+}
+
+
int main(int, char**)
{
+ Glib::init();
+
test_object_move_constructor();
+ test_object_move_assignment_operator();
return EXIT_SUCCESS;
}
diff --git a/tests/glibmm_objectbase_move/main.cc b/tests/glibmm_objectbase_move/main.cc
new file mode 100644
index 0000000..ed71fe1
--- /dev/null
+++ b/tests/glibmm_objectbase_move/main.cc
@@ -0,0 +1,96 @@
+#include <glibmm.h>
+#include <iostream>
+#include <stdlib.h>
+
+//A basic derived GObject, just to test Glib::ObjectBase.
+typedef struct {
+ GObject parent;
+} TestDerived;
+
+typedef struct {
+ GObjectClass parent;
+} TestDerivedClass;
+
+#define TEST_TYPE_DERIVED (test_derived_get_type ())
+#define TEST_DERIVED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_DERIVED, TestDerived))
+#define TEST_DERIVED_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST ((cls), TEST_TYPE_DERIVED, TestDerivedClass))
+#define TEST_DERIVED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_TYPE_DERIVED, TestDerivedClass))
+
+static void test_derived_class_init (TestDerivedClass *)
+{}
+static void test_derived_init (TestDerived *)
+{}
+
+G_DEFINE_TYPE(TestDerived, test_derived, G_TYPE_OBJECT)
+
+
+class DerivedObjectBase : public Glib::ObjectBase
+{
+public:
+ //A real application would never make the constructor public.
+ //It would instead have a protectd constructor and a public create() method.
+ DerivedObjectBase(GObject* gobject, int i)
+ : Glib::ObjectBase(nullptr),
+ i_(i)
+ {
+ Glib::ObjectBase::initialize(gobject);
+ }
+
+ DerivedObjectBase(const DerivedObjectBase& src) = delete;
+ DerivedObjectBase& operator=(const DerivedObjectBase& src) = delete;
+
+ DerivedObjectBase(DerivedObjectBase&& src) noexcept
+ : Glib::ObjectBase(std::move(src)),
+ i_(std::move(src.i_))
+ {}
+
+ DerivedObjectBase& operator=(DerivedObjectBase&& src) noexcept
+ {
+ Glib::ObjectBase::operator=(std::move(src));
+ i_ = std::move(src.i_);
+
+ return *this;
+ }
+
+ int i_;
+};
+
+static
+void test_objectbase_move_constructor()
+{
+ GObject *gobject = G_OBJECT(g_object_new(TEST_TYPE_DERIVED, nullptr));
+ g_object_ref(gobject);
+
+ DerivedObjectBase derived(gobject, 5);
+ //std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
+ g_assert(derived.gobj() == gobject);
+ DerivedObjectBase derived2(std::move(derived));
+ g_assert_cmpint(derived2.i_, ==, 5);
+ //std::cout << "debug: gobj(): " << derived2.gobj() << std::endl;
+ g_assert(derived2.gobj() == gobject);
+}
+
+static
+void test_objectbase_move_assignment_operator()
+{
+ GObject *gobject = G_OBJECT(g_object_new(TEST_TYPE_DERIVED, nullptr));
+ g_object_ref(gobject);
+
+ DerivedObjectBase derived(gobject, 5);
+ //std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
+ g_assert(derived.gobj() == gobject);
+ DerivedObjectBase derived2 = std::move(derived);
+ g_assert_cmpint(derived2.i_, ==, 5);
+ //std::cout << "debug: gobj(): " << derived2.gobj() << std::endl;
+ g_assert(derived2.gobj() == gobject);
+}
+
+int main(int, char**)
+{
+ Glib::init();
+
+ test_objectbase_move_constructor();
+ test_objectbase_move_assignment_operator();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]