[glom] Added test_imageglom_widget.



commit 18d59c949a3ca3803945e0f83a77d8326c455b55
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Feb 25 13:34:19 2016 +0100

    Added test_imageglom_widget.

 Makefile_tests.am                 |   13 +++++
 tests/test_image.pdf              |  Bin 0 -> 76665 bytes
 tests/test_image2.jpg             |  Bin 0 -> 11856 bytes
 tests/test_image2.pdf             |  Bin 0 -> 71756 bytes
 tests/test_utils.cc               |   14 ++++--
 tests/test_utils.h                |    1 +
 tests/ui/test_imageglom_widget.cc |  107 +++++++++++++++++++++++++++++++++++++
 7 files changed, 131 insertions(+), 4 deletions(-)
---
diff --git a/Makefile_tests.am b/Makefile_tests.am
index c65f733..2ad29a1 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -216,6 +216,9 @@ dist_noinst_DATA = \
        tests/import/data/albums.csv \
        tests/translations_po/data/test.po \
        tests/test_image.jpg \
+       tests/test_image2.jpg \
+       tests/test_image.pdf \
+       tests/test_image2.pdf \
        tests/test_example_music_collection_text_pk_fields.glom
 
 # Let the .cc source code know about this path:
@@ -358,6 +361,7 @@ check_PROGRAMS += \
        glom/utility_widgets/eggspreadtablemm/test_spreadtablednd \
        glom/test_pyembed \
        tests/ui/test_glade_derived_instantiation \
+       tests/ui/test_imageglom_widget \
        tests/ui/glade_toplevels_instantiation \
        tests/python/test_python_execute_func \
        tests/python/test_python_execute_func_bad_syntax \
@@ -394,6 +398,7 @@ if GLOM_ENABLE_UI_TESTS
 TESTS += \
        tests/ui/test_glade_toplevels_instantiation.sh \
        tests/ui/test_glade_derived_instantiation \
+       tests/ui/test_imageglom_widget \
        tests/test_glom_date_in_locales.sh \
        tests/test_glom_date_in_locales_lc_time.sh
 endif #GLOM_ENABLE_UI_TESTS
@@ -491,6 +496,14 @@ tests_ui_test_glade_derived_instantiation_SOURCES = tests/ui/test_glade_derived_
 tests_ui_test_glade_derived_instantiation_LDADD = $(glom_all_libs)
 tests_ui_test_glade_derived_instantiation_CPPFLAGS = $(tests_cppflags_ui)
 
+# TODO: Find a subset of glom_source_files that is enough:
+tests_ui_test_imageglom_widget_SOURCES = tests/ui/test_imageglom_widget.cc \
+  $(glom_source_files) \
+  $(sources_test_utils) \
+  $(sources_test_utils_images)
+tests_ui_test_imageglom_widget_LDADD = $(glom_all_libs)
+tests_ui_test_imageglom_widget_CPPFLAGS = $(tests_cppflags_ui) $(glom_test_image_defines)
+
 tests_ui_glade_toplevels_instantiation_SOURCES = tests/ui/glade_toplevels_instantiation.cc
 tests_ui_glade_toplevels_instantiation_LDADD = $(tests_ldadd) $(GLOM_LIBS)
 tests_ui_glade_toplevels_instantiation_CPPFLAGS = $(tests_cppflags_ui)
diff --git a/tests/test_image.pdf b/tests/test_image.pdf
new file mode 100644
index 0000000..4bad803
Binary files /dev/null and b/tests/test_image.pdf differ
diff --git a/tests/test_image2.jpg b/tests/test_image2.jpg
new file mode 100644
index 0000000..aa3ae7b
Binary files /dev/null and b/tests/test_image2.jpg differ
diff --git a/tests/test_image2.pdf b/tests/test_image2.pdf
new file mode 100644
index 0000000..69b6e47
Binary files /dev/null and b/tests/test_image2.pdf differ
diff --git a/tests/test_utils.cc b/tests/test_utils.cc
index 869e878..abf139e 100644
--- a/tests/test_utils.cc
+++ b/tests/test_utils.cc
@@ -48,11 +48,9 @@ std::shared_ptr<const Glom::LayoutItem_Field> get_field_on_layout(const std::sha
   return std::shared_ptr<const Glom::LayoutItem_Field>();
 }
 
-Gnome::Gda::Value get_value_for_image()
+
+Gnome::Gda::Value get_value_for_image_from_file(const std::string& filename)
 {
-  //Fill a value from a file:
-  const std::string filename =
-    Glib::build_filename(GLOM_TESTS_IMAGE_DATA_NOTINSTALLED, "test_image.jpg");
   std::string data;
   try
   {
@@ -73,3 +71,11 @@ Gnome::Gda::Value get_value_for_image()
   //Set the value:
   return Gnome::Gda::Value((const guchar*)data.c_str(), data.size());
 }
+
+Gnome::Gda::Value get_value_for_image()
+{
+  //Fill a value from a file:
+  const std::string filename =
+    Glib::build_filename(GLOM_TESTS_IMAGE_DATA_NOTINSTALLED, "test_image.jpg");
+  return get_value_for_image_from_file(filename);
+}
diff --git a/tests/test_utils.h b/tests/test_utils.h
index 05c72e4..dbf2aaf 100644
--- a/tests/test_utils.h
+++ b/tests/test_utils.h
@@ -27,6 +27,7 @@
 std::shared_ptr<const Glom::LayoutItem_Field> get_field_on_layout(const std::shared_ptr<Glom::Document>& 
document, const Glib::ustring& layout_table_name, const Glib::ustring& table_name, const Glib::ustring& 
field_name);
 
 Gnome::Gda::Value get_value_for_image();
+Gnome::Gda::Value get_value_for_image_from_file(const std::string& filename);
 
 #endif //GLOM_TEST_UTILS_H
 
diff --git a/tests/ui/test_imageglom_widget.cc b/tests/ui/test_imageglom_widget.cc
new file mode 100644
index 0000000..3c05175
--- /dev/null
+++ b/tests/ui/test_imageglom_widget.cc
@@ -0,0 +1,107 @@
+/* Glom
+ *
+ * Copyright (C) 2016 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 <gtkmm/application.h>
+#include <gtkmm/window.h>
+#include <glibmm/miscutils.h>
+#include <glom/utility_widgets/imageglom.h>
+#include "tests/test_utils.h"
+#include "tests/test_utils_images.h"
+
+const std::string IMAGE_FILE_JPG1 = "test_image.jpg";
+const std::string IMAGE_FILE_JPG2 = "test_image2.jpg";
+const std::string IMAGE_FILE_PDF1 = "test_image.pdf";
+const std::string IMAGE_FILE_PDF2 = "test_image2.pdf";
+
+auto get_image(const std::string& name)
+{
+  const std::string filename =
+    Glib::build_filename(GLOM_TESTS_IMAGE_DATA_NOTINSTALLED, name);
+  return get_value_for_image_from_file(filename);
+}
+
+void test_use_jpg()
+{
+  Glom::ImageGlom imageWidget;
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG1));
+}
+
+void test_reset_same_jpg()
+{
+  Glom::ImageGlom imageWidget;
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG1));
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG1));
+}
+
+void test_changing_jpg()
+{
+  Glom::ImageGlom imageWidget;
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG1));
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG2));
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG1));
+}
+
+void test_use_pdf()
+{
+  Glom::ImageGlom imageWidget;
+  imageWidget.set_value(get_image(IMAGE_FILE_PDF1));
+}
+
+void test_reset_same_pdf()
+{
+  Glom::ImageGlom imageWidget;
+  imageWidget.set_value(get_image(IMAGE_FILE_PDF1));
+  imageWidget.set_value(get_image(IMAGE_FILE_PDF1));
+}
+
+void test_changing_pdf()
+{
+  Glom::ImageGlom imageWidget;
+  imageWidget.set_value(get_image(IMAGE_FILE_PDF1));
+  imageWidget.set_value(get_image(IMAGE_FILE_PDF2));
+  imageWidget.set_value(get_image(IMAGE_FILE_PDF1));
+}
+
+void test_changing_from_jpg_to_pdf_to_jpg()
+{
+  Glom::ImageGlom imageWidget;
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG1));
+  imageWidget.set_value(get_image(IMAGE_FILE_PDF1));
+  imageWidget.set_value(get_image(IMAGE_FILE_JPG2));
+}
+
+
+int main(int argc, char *argv[])
+{
+  auto app = 
+    Gtk::Application::create(argc, argv, "org.glom.test_glade_derived_instantiation");
+
+  test_use_jpg();
+  test_reset_same_jpg();
+  test_changing_jpg();
+  
+  test_use_pdf();
+  test_reset_same_pdf();
+  test_changing_pdf();
+  
+  test_changing_from_jpg_to_pdf_to_jpg();
+
+  return EXIT_SUCCESS;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]