summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2019-01-25 16:57:19 +0100
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2019-01-25 16:57:19 +0100
commitee64cd329725218231e5b1bade01c998482f5da7 (patch)
treed610cbbdcc864a1f3fa427b1cba98b2a1279c71d /tests
parent96a997b1f4cf902a7690de8a27e1173f1d217042 (diff)
downloadglibmm-ee64cd329725218231e5b1bade01c998482f5da7.tar.gz
Gio::AsyncResult: Explain why wrap() is not used in get_source_object_base()
* gio/src/asyncresult.ccg: Replace a TODO comment with an explanation. * tests/giomm_asyncresult_sourceobject/main.cc: Add code that demonstrates why Glib::wrap(GObject* object, bool take_copy) returns an empty RefPtr.
Diffstat (limited to 'tests')
-rw-r--r--tests/giomm_asyncresult_sourceobject/main.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/giomm_asyncresult_sourceobject/main.cc b/tests/giomm_asyncresult_sourceobject/main.cc
index cf2b01be..6e71a755 100644
--- a/tests/giomm_asyncresult_sourceobject/main.cc
+++ b/tests/giomm_asyncresult_sourceobject/main.cc
@@ -1,5 +1,6 @@
#include <giomm.h>
#include <iostream>
+#include <typeinfo>
void
on_read_async(const Glib::RefPtr<Gio::AsyncResult>& result)
@@ -10,12 +11,26 @@ on_read_async(const Glib::RefPtr<Gio::AsyncResult>& result)
exit(EXIT_FAILURE);
}
- if (!g_async_result_get_source_object(result->gobj()))
+ auto cobj = g_async_result_get_source_object(result->gobj());
+ if (!cobj)
{
std::cerr << G_STRFUNC << ": g_async_result_get_source_object() failed." << std::endl;
exit(EXIT_FAILURE);
}
+ // Show why Glib::wrap(cobj) can't be used in Gio::AsyncResult::get_source_object_base().
+ // cppobjbase is not a Glib::Object*, it's a Gio::File* which is a Glib::Interface*.
+ std::cout << "GType name: " << G_OBJECT_TYPE_NAME(cobj) << std::endl;
+ auto cppobjbase = Glib::wrap_auto(cobj); // Glib::ObjectBase::_get_current_wrapper(cobj);
+ if (cppobjbase)
+ {
+ std::cout << "C++ type name: " << typeid(*cppobjbase).name() << std::endl;
+ auto cppobj = dynamic_cast<Glib::Object*>(cppobjbase); // Part of Glib::wrap(GObject*, bool)
+ auto cppiface = dynamic_cast<Glib::Interface*>(cppobjbase);
+ std::cout << "dynamic_cast<Glib::Object*>: " << cppobj << std::endl;
+ std::cout << "dynamic_cast<Glib::Interface*>: " << cppiface << std::endl;
+ }
+
if (!result->get_source_object_base())
{
std::cerr << G_STRFUNC << ": result->get_source_object_base() failed." << std::endl;