[glom] Added unit test for the new button script ui python API.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Added unit test for the new button script ui python API.
- Date: Sun, 28 Feb 2010 12:37:08 +0000 (UTC)
commit 3bb14dfba075fa320b0ddd021f5fde50a174f001
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Feb 28 13:36:55 2010 +0100
Added unit test for the new button script ui python API.
* Makefile_tests.am:
* tests/test_python_execute_script.cc: Added unit test for the new button
script ui python API.
ChangeLog | 8 ++++
Makefile_tests.am | 9 +++-
tests/test_python_execute_script.cc | 72 +++++++++++++++++++++++++++++++++++
3 files changed, 87 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e610c72..ebdf663 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2010-02-28 Murray Cumming <murrayc murrayc com>
+ Added unit test for the new button script ui python API.
+
+ * Makefile_tests.am:
+ * tests/test_python_execute_script.cc: Added unit test for the new button
+ script ui python API.
+
+2010-02-28 Murray Cumming <murrayc murrayc com>
+
PyGlomUI: Simplify the callbacks object.
* glom/libglom/python_embed/py_glom_ui.[h|cc]: Use public sigc::slots instead
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 5c86ddd..8c04660 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -27,7 +27,8 @@ check_PROGRAMS = \
tests/test_python_module \
tests/test_python_execute_func \
tests/test_python_execute_func_date \
- tests/import/test_parsing\
+ tests/test_python_execute_script \
+ tests/import/test_parsing \
tests/import/test_signals
TESTS = tests/test_parsing_time \
@@ -36,7 +37,8 @@ TESTS = tests/test_parsing_time \
tests/test_load_python_library \
tests/test_python_module \
tests/test_python_execute_func \
- tests/test_python_execute_func_date
+ tests/test_python_execute_func_date \
+ tests/test_python_execute_script
# These hang most of the time, but not always:
# tests/import/test_parsing \
# tests/import/test_signals
@@ -62,6 +64,8 @@ tests_test_python_execute_func_SOURCES = tests/test_python_execute_func.cc \
glom/python_embed/glom_python.cc
tests_test_python_execute_func_date_SOURCES = tests/test_python_execute_func_date.cc \
glom/python_embed/glom_python.cc
+tests_test_python_execute_script_SOURCES = tests/test_python_execute_script.cc \
+ glom/python_embed/glom_python.cc
tests_import_test_parsing_SOURCES = \
glom/import_csv/csv_parser.cc \
glom/import_csv/csv_parser.h \
@@ -111,5 +115,6 @@ tests_test_load_python_library_LDADD = $(LIBGLOM_LIBS)
tests_test_python_module_LDADD = $(tests_ldadd) $(PYTHON_LIBS)
tests_test_python_execute_func_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
tests_test_python_execute_func_date_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
+tests_test_python_execute_script_LDADD = $(tests_ldadd) $(GLOM_LIBS) $(PYTHON_LIBS)
tests_import_test_parsing_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
tests_import_test_signals_LDADD = $(LIBGLOM_LIBS) $(GLOM_LIBS)
diff --git a/tests/test_python_execute_script.cc b/tests/test_python_execute_script.cc
new file mode 100644
index 0000000..b495349
--- /dev/null
+++ b/tests/test_python_execute_script.cc
@@ -0,0 +1,72 @@
+#include <glom/libglom/init.h>
+#include <glom/python_embed/glom_python.h>
+
+//Store results from the callbacks and check them later:
+Glib::ustring result_table_name_list;
+Glib::ustring result_table_name_details;
+Gnome::Gda::Value result_primary_key_value_details;
+
+static void on_script_ui_show_table_list(const Glib::ustring& table_name)
+{
+ //std::cout << "debug: on_script_ui_show_table_list(): table_name=" << table_name << std::endl;
+ result_table_name_list = table_name;
+}
+
+static void on_script_ui_show_table_details(const Glib::ustring& table_name, const Gnome::Gda::Value& primary_key_value)
+{
+ //std::cout << "debug: on_script_ui_show_table_details(): table_name=" << table_name
+ // << ", primary_key_value=" << primary_key_value.to_string() << std::endl;
+ result_table_name_details = table_name;
+ result_primary_key_value_details = primary_key_value;
+}
+
+int main()
+{
+ Glom::libglom_init(); //Also initializes python.
+
+ const Glib::ustring table_name_input = "sometable";
+ const Glib::ustring table_name_details_input = "artists";
+ const Gnome::Gda::Value primary_key_value_input(123);
+
+ //Just some code to make sure that the python API exists:
+ const Glib::ustring script =
+ "table_name = record.table_name;\n"
+ "ui.show_table_list(table_name);\n"
+ "ui.show_table_details(\"" + table_name_details_input + "\", " + primary_key_value_input.to_string() + ")\n";
+ Glom::type_map_fields field_values;
+ Glib::RefPtr<Gnome::Gda::Connection> connection;
+
+ Glom::PythonUICallbacks callbacks;
+ callbacks.m_slot_show_table_list =
+ sigc::ptr_fun(&on_script_ui_show_table_list);
+ callbacks.m_slot_show_table_details =
+ sigc::ptr_fun(&on_script_ui_show_table_details);
+
+ //Execute a python script:
+ try
+ {
+ Glom::glom_execute_python_function_implementation(
+ script, field_values,
+ 0 /* document */, table_name_input,
+ Glom::sharedptr<Glom::Field>(), Gnome::Gda::Value(), // primary key details. Not used in this test.
+ connection,
+ callbacks);
+ }
+ catch(const std::exception& ex)
+ {
+ std::cerr << "Exception: " << ex.what() << std::endl;
+ return EXIT_FAILURE;
+ }
+ catch(const boost::python::error_already_set& ex)
+ {
+ std::cerr << "Exception: boost::python::error_already_set" << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ //Check that the callbacks received the expected values:
+ g_assert(result_table_name_list == table_name_input);
+ g_assert(result_table_name_details == table_name_details_input);
+ g_assert(result_primary_key_value_details == primary_key_value_input);
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]