[glom] Tests: Add pixbuf-loading tests in more places.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Tests: Add pixbuf-loading tests in more places.
- Date: Sun, 11 Nov 2012 19:41:47 +0000 (UTC)
commit 0f963c3cdedfc198612af42ad7b86c164dcf0410
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Nov 11 20:41:38 2012 +0100
Tests: Add pixbuf-loading tests in more places.
* tests/test_document_load_image.cc:
* Makefile_tests.am:
* tests/test_utils_images.[h|cc]: Move the use of GdkPixbufLoader
into a check_value_is_an_image() utility function.
* tests/test_field_file_format.cc:
* tests/test_selfhosting_new_then_image.cc: Use it here too.
ChangeLog | 11 +++++
Makefile_tests.am | 23 +++++++---
tests/test_document_load_image.cc | 39 +-----------------
tests/test_field_file_format.cc | 6 ++-
tests/test_selfhosting_new_then_image.cc | 2 +
tests/test_utils_images.cc | 64 ++++++++++++++++++++++++++++++
tests/test_utils_images.h | 29 +++++++++++++
7 files changed, 129 insertions(+), 45 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1fb6481..e154413 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2012-11-11 Murray Cumming <murrayc murrayc com>
+ Tests: Add pixbuf-loading tests in more places.
+
+ * tests/test_document_load_image.cc:
+ * Makefile_tests.am:
+ * tests/test_utils_images.[h|cc]: Move the use of GdkPixbufLoader
+ into a check_value_is_an_image() utility function.
+ * tests/test_field_file_format.cc:
+ * tests/test_selfhosting_new_then_image.cc: Use it here too.
+
+2012-11-11 Murray Cumming <murrayc murrayc com>
+
examples: Add a static image item to the Project Manager example.
* examples/example_project_manager.glom: This is just so we
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 5736911..6beb3fa 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -134,7 +134,11 @@ tests_test_document_load_and_save_SOURCES = tests/test_document_load_and_save.cc
tests_test_document_load_and_save_LDADD = $(tests_ldadd)
tests_test_document_load_and_save_CPPFLAGS = $(tests_cppflags)
-tests_test_document_load_image_SOURCES = tests/test_document_load_image.cc
+sources_test_utils_images = tests/test_utils_images.h \
+ tests/test_utils_images.cc
+
+tests_test_document_load_image_SOURCES = tests/test_document_load_image.cc \
+ $(sources_test_utils_images)
tests_test_document_load_image_LDADD = $(tests_ldadd) $(GDKMM_LIBS)
tests_test_document_load_image_CPPFLAGS = $(tests_cppflags) $(GDKMM_CFLAGS)
@@ -150,9 +154,11 @@ tests_test_document_autosave_SOURCES = tests/test_document_autosave.cc
tests_test_document_autosave_LDADD = $(tests_ldadd)
tests_test_document_autosave_CPPFLAGS = $(tests_cppflags)
-tests_test_field_file_format_SOURCES = tests/test_field_file_format.cc $(sources_test_utils)
-tests_test_field_file_format_LDADD = $(tests_ldadd)
-tests_test_field_file_format_CPPFLAGS = $(tests_cppflags) $(glom_test_image_defines)
+tests_test_field_file_format_SOURCES = tests/test_field_file_format.cc \
+ $(sources_test_utils) \
+ $(sources_test_utils_images)
+tests_test_field_file_format_LDADD = $(tests_ldadd) $(GDKMM_LIBS)
+tests_test_field_file_format_CPPFLAGS = $(tests_cppflags) $(GDKMM_CFLAGS) $(glom_test_image_defines)
tests_test_parsing_time_SOURCES = tests/test_parsing_time.cc
tests_test_parsing_time_LDADD = $(tests_ldadd)
@@ -260,9 +266,12 @@ tests_test_selfhosting_new_then_report_summary_SOURCES = tests/test_selfhosting_
tests_test_selfhosting_new_then_report_summary_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_then_report_summary_CPPFLAGS = $(tests_cppflags)
-tests_test_selfhosting_new_then_image_SOURCES = tests/test_selfhosting_new_then_image.cc $(sources_test_selfhosting_utils) $(sources_test_utils)
-tests_test_selfhosting_new_then_image_LDADD = $(tests_ldadd)
-tests_test_selfhosting_new_then_image_CPPFLAGS = $(tests_cppflags) $(glom_test_image_defines)
+tests_test_selfhosting_new_then_image_SOURCES = tests/test_selfhosting_new_then_image.cc \
+ $(sources_test_selfhosting_utils) \
+ $(sources_test_utils) \
+ $(sources_test_utils_images)
+tests_test_selfhosting_new_then_image_LDADD = $(tests_ldadd) $(GDKMM_LIBS)
+tests_test_selfhosting_new_then_image_CPPFLAGS = $(tests_cppflags) $(GDKMM_CFLAGS) $(glom_test_image_defines)
tests_test_selfhosting_new_then_lookup_SOURCES = tests/test_selfhosting_new_then_lookup.cc $(sources_test_selfhosting_utils)
tests_test_selfhosting_new_then_lookup_LDADD = $(tests_ldadd)
diff --git a/tests/test_document_load_image.cc b/tests/test_document_load_image.cc
index d27b16f..7c01ebc 100644
--- a/tests/test_document_load_image.cc
+++ b/tests/test_document_load_image.cc
@@ -18,15 +18,13 @@
* Boston, MA 02110-1301 USA.
*/
-#include "tests/test_utils.h"
+#include "tests/test_utils_images.h"
#include <libglom/document/document.h>
#include <libglom/init.h>
#include <libglom/db_utils.h>
#include <giomm/file.h>
#include <glibmm/convert.h>
#include <glibmm/miscutils.h>
-#include <gdkmm/wrap_init.h> //TODO: Add a Gdk::init() to gtkmm.
-#include <gdkmm/pixbufloader.h>
#include <iostream>
@@ -90,40 +88,7 @@ int main()
g_assert(image_item);
const Gnome::Gda::Value value = image_item->get_image();
- g_assert(!value.is_null());
- g_assert(value.get_value_type() == GDA_TYPE_BINARY);
- long data_length = 0;
- const guchar* data = value.get_binary(data_length);
- g_assert(data);
- g_assert(data_length);
-
- //Check that it can be interpreted as an image:
- //Luckily, the use of GdkPixbufLoader here does not seem to require an X display.
- Gdk::wrap_init();
- Glib::RefPtr<Gdk::PixbufLoader> refPixbufLoader;
- try
- {
- refPixbufLoader = Gdk::PixbufLoader::create();
- }
- catch(const Gdk::PixbufError& ex)
- {
- std::cerr << "PixbufLoader::create failed: " << ex.what() << std::endl;
- return EXIT_FAILURE;
- }
-
- Glib::RefPtr<Gdk::Pixbuf> pixbuf;
- guint8* puiData = (guint8*)data;
- try
- {
- refPixbufLoader->write(puiData, static_cast<gsize>(data_length));
- pixbuf = refPixbufLoader->get_pixbuf();
- refPixbufLoader->close(); //This throws if write() threw, so it must be inside the try block.
- }
- catch(const Glib::Exception& ex)
- {
- std::cerr << "PixbufLoader::write() failed: " << ex.what() << std::endl;
- return EXIT_FAILURE;
- }
+ g_assert(check_value_is_an_image(value));
Glom::libglom_deinit();
diff --git a/tests/test_field_file_format.cc b/tests/test_field_file_format.cc
index 436621e..0104dc0 100644
--- a/tests/test_field_file_format.cc
+++ b/tests/test_field_file_format.cc
@@ -19,6 +19,7 @@
*/
#include "tests/test_utils.h"
+#include "tests/test_utils_images.h"
#include <libglom/init.h>
#include <libglom/data_structure/field.h>
#include <iostream>
@@ -28,7 +29,6 @@ static void test_text_field()
Glom::sharedptr<Glom::Field> field = Glom::sharedptr<Glom::Field>::create();
field->set_glom_type(Glom::Field::TYPE_TEXT);
- //TODO: Test an image too:
const Gnome::Gda::Value value_original("text with \" double quote and ' single quote");
const Glib::ustring str = field->to_file_format(value_original);
g_assert(!str.empty());
@@ -46,6 +46,8 @@ static void test_image_field()
//TODO: Test an image too:
const Gnome::Gda::Value value_original = get_value_for_image();
+ g_assert(check_value_is_an_image(value_original));
+
const Glib::ustring str = field->to_file_format(value_original);
g_assert(!str.empty());
@@ -53,6 +55,8 @@ static void test_image_field()
const Gnome::Gda::Value value = field->from_file_format(str, converted);
g_assert(converted);
g_assert(value == value_original);
+
+ g_assert(check_value_is_an_image(value));
}
int main()
diff --git a/tests/test_selfhosting_new_then_image.cc b/tests/test_selfhosting_new_then_image.cc
index 359d84c..3d8bcfd 100644
--- a/tests/test_selfhosting_new_then_image.cc
+++ b/tests/test_selfhosting_new_then_image.cc
@@ -20,6 +20,7 @@
#include "tests/test_selfhosting_utils.h"
#include "tests/test_utils.h"
+#include "tests/test_utils_images.h"
#include <libglom/init.h>
#include <libglom/utils.h>
#include <libglom/db_utils.h>
@@ -61,6 +62,7 @@ static bool test(Glom::Document::HostingMode hosting_mode)
//Set the value, from an image file:
const Gnome::Gda::Value value_set = get_value_for_image();
+ g_assert(check_value_is_an_image(value_set));
const Glib::RefPtr<const Gnome::Gda::SqlBuilder> builder_set =
Glom::Utils::build_sql_update_with_where_clause(table_name,
field, value_set, where_clause);
diff --git a/tests/test_utils_images.cc b/tests/test_utils_images.cc
new file mode 100644
index 0000000..a77e1e3
--- /dev/null
+++ b/tests/test_utils_images.cc
@@ -0,0 +1,64 @@
+/* Glom
+ *
+ * Copyright (C) 2012 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include "tests/test_utils_images.h"
+#include <gdkmm/wrap_init.h> //TODO: Add a Gdk::init() to gtkmm.
+#include <gdkmm/pixbufloader.h>
+#include <iostream>
+
+bool check_value_is_an_image(const Gnome::Gda::Value& value)
+{
+ g_assert(!value.is_null());
+ g_assert(value.get_value_type() == GDA_TYPE_BINARY);
+ long data_length = 0;
+ const guchar* data = value.get_binary(data_length);
+ g_assert(data);
+ g_assert(data_length);
+ //Check that it can be interpreted as an image:
+ //Luckily, the use of GdkPixbufLoader here does not seem to require an X display.
+ Gdk::wrap_init();
+ Glib::RefPtr<Gdk::PixbufLoader> refPixbufLoader;
+ try
+ {
+ refPixbufLoader = Gdk::PixbufLoader::create();
+ }
+ catch(const Gdk::PixbufError& ex)
+ {
+ std::cerr << "PixbufLoader::create failed: " << ex.what() << std::endl;
+ return false;
+ }
+
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf;
+ guint8* puiData = (guint8*)data;
+ try
+ {
+ refPixbufLoader->write(puiData, static_cast<gsize>(data_length));
+ pixbuf = refPixbufLoader->get_pixbuf();
+ refPixbufLoader->close(); //This throws if write() threw, so it must be inside the try block.
+ }
+ catch(const Glib::Exception& ex)
+ {
+ std::cerr << "PixbufLoader::write() failed: " << ex.what() << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
diff --git a/tests/test_utils_images.h b/tests/test_utils_images.h
new file mode 100644
index 0000000..a07cf16
--- /dev/null
+++ b/tests/test_utils_images.h
@@ -0,0 +1,29 @@
+/* Glom
+ *
+ * Copyright (C) 2011 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GLOM_TEST_UTILS_IMAGES_H
+#define GLOM_TEST_UTILS_IMAGES_H
+
+#include <libgdamm/value.h>
+
+bool check_value_is_an_image(const Gnome::Gda::Value& value);
+
+#endif //GLOM_TEST_UTILS_IMAGES_H
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]