Commit 696685ee authored by Murray Cumming's avatar Murray Cumming

tests: Split object_move and objectbase_move tests.

This allows further reuse of the DerivedObject and DerivedObjectBase test classes.
parent bc233c57
......@@ -35,6 +35,7 @@ check_PROGRAMS = \
glibmm_mainloop/test \
glibmm_nodetree/test \
glibmm_object_move/test \
glibmm_objectbase/test \
glibmm_objectbase_move/test \
glibmm_ustring_compose/test \
glibmm_ustring_format/test \
......@@ -102,7 +103,11 @@ glibmm_interface_move_test_CXXFLAGS = $(GLIBMM_INTERFACE_TEST_WXXFLAGS) $(cxxfla
glibmm_mainloop_test_SOURCES = glibmm_mainloop/main.cc
glibmm_nodetree_test_SOURCES = glibmm_nodetree/main.cc
glibmm_object_test_SOURCES = glibmm_object/main.cc \
glibmm/object/test_derived_object.h
glibmm_object_move_test_SOURCES = glibmm_object_move/main.cc
glibmm_objectbase_test_SOURCES = glibmm_objectbase/main.cc \
glibmm/objectbase/test_derived_objectbase.h
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
......
#include "test_derived_object.h"
#include <glibmm.h>
#include <iostream>
#include <stdlib.h>
static void
test_object()
{
GObject* gobject = G_OBJECT(g_object_new(TEST_TYPE_DERIVED, nullptr));
DerivedObject derived(gobject, 5);
// std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
g_assert(derived.gobj() == gobject);
}
int
main(int, char**)
{
Glib::init();
test_objectbase();
test_object();
return EXIT_SUCCESS;
}
#ifndef _GLIBMM_TEST_DERIVED_OBJECT_H
#define _GLIBMM_TEST_DERIVED_OBJECT_H
#include <glibmm.h>
// A basic derived GObject, just to test Glib::Object.
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 protected constructor and a public create() method.
DerivedObject(GObject* gobject, int i) : Glib::Object(gobject), i_(i) {}
DerivedObject(const DerivedObject& src) = delete;
DerivedObject& operator=(const DerivedObject& src) = delete;
DerivedObject(DerivedObject&& src) noexcept : Glib::Object(std::move(src)), i_(std::move(src.i_))
{
}
DerivedObject& operator=(DerivedObject&& src) noexcept
{
Glib::Object::operator=(std::move(src));
i_ = std::move(src.i_);
return *this;
}
int i_;
};
#endif // _GLIBMM_TEST_DERIVED_OBJECT_H
#include "../glibmm_object/test_derived_object.h"
#include <glibmm.h>
#include <iostream>
#include <stdlib.h>
// A basic derived GObject, just to test Glib::Object.
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 protected constructor and a public create() method.
DerivedObject(GObject* gobject, int i) : Glib::Object(gobject), i_(i) {}
DerivedObject(const DerivedObject& src) = delete;
DerivedObject& operator=(const DerivedObject& src) = delete;
DerivedObject(DerivedObject&& src) noexcept : Glib::Object(std::move(src)), i_(std::move(src.i_))
{
}
DerivedObject& operator=(DerivedObject&& src) noexcept
{
Glib::Object::operator=(std::move(src));
i_ = std::move(src.i_);
return *this;
}
int i_;
};
static void
test_object_move_constructor()
{
......
#include "test_derived_objectbase.h"
#include "../glibmm_object/test_derived_object.h"
#include <glibmm.h>
#include <iostream>
#include <stdlib.h>
static void
test_objectbase()
{
GObject* gobject = G_OBJECT(g_object_new(TEST_TYPE_DERIVED, nullptr));
DerivedObjectBase derived(gobject, 5);
// std::cout << "debug: gobj(): " << derived.gobj() << std::endl;
g_assert(derived.gobj() == gobject);
}
int
main(int, char**)
{
Glib::init();
test_objectbase();
return EXIT_SUCCESS;
}
#ifndef _GLIBMM_TEST_DERIVED_OBJECTBASE_H
#define _GLIBMM_TEST_DERIVED_OBJECTBASE_H
#include <glibmm.h>
class DerivedObjectBase : public Glib::ObjectBase
{
public:
// A real application would never make the constructor public.
// It would instead have a protected 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_))
{
ObjectBase::initialize_move(src.gobject_, &src);
}
DerivedObjectBase& operator=(DerivedObjectBase&& src) noexcept
{
Glib::ObjectBase::operator=(std::move(src));
i_ = std::move(src.i_);
return *this;
}
int i_;
};
#endif // _GLIBMM_TEST_DERIVED_OBJECTBASE_H
#include "../glibmm_objectbase/test_derived_objectbase.h"
#include "../glibmm_object/test_derived_object.h"
#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 protected 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_))
{
ObjectBase::initialize_move(src.gobject_, &src);
}
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()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment