r21482 - gnucash/trunk/src/optional/gtkmm - Gtkmm wrappers: Get first test case up and running.
Christian Stimming
cstim at code.gnucash.org
Sat Oct 22 17:30:51 EDT 2011
Author: cstim
Date: 2011-10-22 17:30:51 -0400 (Sat, 22 Oct 2011)
New Revision: 21482
Trac: http://svn.gnucash.org/trac/changeset/21482
Modified:
gnucash/trunk/src/optional/gtkmm/Makefile.am
gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp
gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp
gnucash/trunk/src/optional/gtkmm/test/test-book.cpp
gnucash/trunk/src/optional/gtkmm/test/test-gtkmm.cpp
Log:
Gtkmm wrappers: Get first test case up and running.
The second argument to Glib::wrap was the important one. While at it,
I added a few more wrappers to gnc::Book and implemented their unittests.
Modified: gnucash/trunk/src/optional/gtkmm/Makefile.am
===================================================================
--- gnucash/trunk/src/optional/gtkmm/Makefile.am 2011-10-22 20:10:08 UTC (rev 21481)
+++ gnucash/trunk/src/optional/gtkmm/Makefile.am 2011-10-22 21:30:51 UTC (rev 21482)
@@ -1,4 +1,4 @@
-SUBDIRS = test
+SUBDIRS = . test
pkglib_LTLIBRARIES = libgncmod-gtkmm.la
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp 2011-10-22 20:10:08 UTC (rev 21481)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Book.cpp 2011-10-22 21:30:51 UTC (rev 21482)
@@ -115,7 +115,20 @@
}
+void Book::set_string_option (const Glib::ustring& opt_name, const Glib::ustring& opt_val)
+{
+ qof_book_set_string_option(gobj(), opt_name.c_str(), opt_val.c_str());
+}
+Glib::ustring Book::get_string_option (const Glib::ustring& opt_name) const
+{
+ const char* r = qof_book_get_string_option(gobj(), opt_name.c_str());
+ if (r)
+ return r;
+ else
+ return "";
+}
+
// Account Book::get_root_account()
// {
// return Account(gnc_book_get_root_account (get()));
Modified: gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp 2011-10-22 20:10:08 UTC (rev 21481)
+++ gnucash/trunk/src/optional/gtkmm/gncmm/Book.hpp 2011-10-22 21:30:51 UTC (rev 21482)
@@ -98,6 +98,10 @@
Glib::RefPtr<Account> get_root_account();
+ bool is_readonly() const { return qof_book_is_readonly(gobj()); }
+ void mark_readonly() { qof_book_mark_readonly(gobj()); }
+ void set_string_option (const Glib::ustring& opt_name, const Glib::ustring& opt_val);
+ Glib::ustring get_string_option (const Glib::ustring& opt_name) const;
};
} // END namespace gnc
Modified: gnucash/trunk/src/optional/gtkmm/test/test-book.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/test/test-book.cpp 2011-10-22 20:10:08 UTC (rev 21481)
+++ gnucash/trunk/src/optional/gtkmm/test/test-book.cpp 2011-10-22 21:30:51 UTC (rev 21482)
@@ -61,15 +61,11 @@
setup( Fixture *fixture, gconstpointer pData )
{
fixture->book = qof_book_new();
- g_test_message("Book ref counter: is floating=%d",
- g_object_is_floating(G_OBJECT(fixture->book)));
}
static void
teardown( Fixture *fixture, gconstpointer pData )
{
- g_test_message("Book ref counter: is floating=%d",
- g_object_is_floating(G_OBJECT(fixture->book)));
qof_book_destroy( fixture->book );
}
@@ -132,25 +128,47 @@
{
g_assert( fixture->book != NULL );
{
- Glib::RefPtr<gnc::Book> book = Glib::wrap(fixture->book);
+ // WATCH OUT: The second "true" argument is very important, as it says
+ // the Glib::RefPtr must not take ownership of the original object.
+ Glib::RefPtr<gnc::Book> book = Glib::wrap(fixture->book, true);
g_assert( book->gobj() == fixture->book );
g_assert(G_IS_OBJECT(fixture->book));
}
- g_assert(G_IS_OBJECT(fixture->book)); // uh oh.
- // Due to the missing ref counting in setup() and teardown(), the
- // Glib::wrap pointer is the first reference. Once it gets out of
- // scope, the underlying object will be deleted as nobody owns a
- // ref() anymore. Oops.
+ g_assert(G_IS_OBJECT(fixture->book)); // All is fine due to the "true" above.
+ // The setup() and teardown() indeed uses the GObject ref counting correctly.
-// g_test_message("Book ref counter: is floating=%d",
-// g_object_is_floating(G_OBJECT(fixture->book)));
-
- qof_book_mark_readonly( fixture->book ); // this will crash due to the deleted book
+ qof_book_mark_readonly( fixture->book );
g_assert( qof_book_is_readonly( fixture->book ) );
}
+static void
+test_book_wrap_readonly( Fixture *fixture, gconstpointer pData )
+{
+ Glib::RefPtr<gnc::Book> book = Glib::wrap(fixture->book, true); // "true" is important!
+ g_assert( book );
+ g_assert( book->gobj() == fixture-> book); // indeed the identical object
+ g_assert( !book->is_readonly() );
+ g_assert( !qof_book_is_readonly( fixture->book ) );
+ book->mark_readonly();
+ g_assert( book->is_readonly() );
+ g_assert( qof_book_is_readonly( fixture->book ) ); // indeed the identical object
+}
+static void
+test_book_get_string_option( Fixture *fixture, gconstpointer pData )
+{
+ Glib::ustring opt_name("Option Name");
+ Glib::ustring opt_value("Option Value");
+ Glib::ustring opt_name_notset("Not Set");
+ Glib::RefPtr<gnc::Book> book = Glib::wrap(fixture->book, true); // "true" is important!
+ g_assert( book );
+ book->set_string_option( opt_name, opt_value);
+ g_assert_cmpstr( book->get_string_option( opt_name ).c_str(), == , opt_value.c_str());
+ g_assert( book->get_string_option( opt_name_notset ).empty());
+}
void test_suite_gtkmm_book()
{
GNC_TEST_ADD( suitename, "readonly", Fixture, NULL, setup, test_book_readonly, teardown );
GNC_TEST_ADD( suitename, "wrap", Fixture, NULL, setup, test_book_wrap, teardown );
+ GNC_TEST_ADD( suitename, "wrapped-readonly", Fixture, NULL, setup, test_book_wrap_readonly, teardown );
+ GNC_TEST_ADD( suitename, "wrapped-get_string_option", Fixture, NULL, setup, test_book_get_string_option, teardown );
}
Modified: gnucash/trunk/src/optional/gtkmm/test/test-gtkmm.cpp
===================================================================
--- gnucash/trunk/src/optional/gtkmm/test/test-gtkmm.cpp 2011-10-22 20:10:08 UTC (rev 21481)
+++ gnucash/trunk/src/optional/gtkmm/test/test-gtkmm.cpp 2011-10-22 21:30:51 UTC (rev 21482)
@@ -28,7 +28,7 @@
extern "C" {
#include "qof.h"
- gint libgncmod_gtkmm_gnc_module_init(gint refcount);
+// gint libgncmod_gtkmm_gnc_module_init(gint refcount);
}
// c++ includes
#include <gtkmm.h>
More information about the gnucash-changes
mailing list