[glom] Tests: Complete the test_python_execute_func_date test.



commit 6f260a8161022bc836ec3b168a954916abefe3a4
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Dec 9 10:38:26 2009 +0100

    Tests: Complete the test_python_execute_func_date test.
    
    * glom/libglom/python_embed/pygdavalue_conversions.c
    (glom_pygda_value_from_pyobject): Use g_date_new_dmy() so the GDate
    is really completely initialized, avoiding errors about invalid dates.
    * tests/test_python_execute_func_date.cc: Check the return type and
    value, by comparing the python result with the current date.
    Bug is now really fixed #603686. (Andrew Ruthven)

 ChangeLog                                          |   11 +++++++++++
 glom/libglom/python_embed/pygdavalue_conversions.c |   11 ++++++-----
 tests/test_python_execute_func_date.cc             |   12 +++++++-----
 3 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6e0aa02..c599281 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-12-09  Murray Cumming  <murrayc murrayc-desktop>
+
+	Tests: Complete the test_python_execute_func_date test.
+
+	* glom/libglom/python_embed/pygdavalue_conversions.c
+	(glom_pygda_value_from_pyobject): Use g_date_new_dmy() so the GDate 
+	is really completely initialized, avoiding errors about invalid dates.
+	* tests/test_python_execute_func_date.cc: Check the return type and 
+	value, by comparing the python result with the current date. 
+	Bug is now really fixed #603686. (Andrew Ruthven)
+
 2009-12-09  Murray Cumming  <murrayc murrayc com>
 
 	Fix the crash when calling python functions that return dates.
diff --git a/glom/libglom/python_embed/pygdavalue_conversions.c b/glom/libglom/python_embed/pygdavalue_conversions.c
index 521286d..fd49565 100644
--- a/glom/libglom/python_embed/pygdavalue_conversions.c
+++ b/glom/libglom/python_embed/pygdavalue_conversions.c
@@ -61,12 +61,13 @@ glom_pygda_value_from_pyobject(GValue *boxed, PyObject *input)
          gda.timezone = 0;
          gda_value_set_timestamp (boxed, &gda);
      } else if (PyDate_Check (input)) {
-         GDate gda;
-         gda.year = PyDateTime_GET_YEAR(input);
-         gda.month = PyDateTime_GET_MONTH(input);
-         gda.day = PyDateTime_GET_DAY(input);
+         GDate *gda = g_date_new_dmy(
+           PyDateTime_GET_DAY(input),
+           PyDateTime_GET_MONTH(input),
+           PyDateTime_GET_YEAR(input) );
          g_value_init (boxed, G_TYPE_DATE);
-         g_value_set_boxed(boxed, &gda);
+         g_value_set_boxed(boxed, gda);
+         g_date_free(gda);
      } else if (PyTime_Check (input)) {
          GdaTime gda;
          gda.hour = PyDateTime_TIME_GET_HOUR(input);
diff --git a/tests/test_python_execute_func_date.cc b/tests/test_python_execute_func_date.cc
index 60e2318..b7c8fb0 100644
--- a/tests/test_python_execute_func_date.cc
+++ b/tests/test_python_execute_func_date.cc
@@ -25,16 +25,18 @@ int main()
     Glom::Field::TYPE_DATE, calculation, field_values, 
     0 /* document */, "" /* table name */, connection);
 
-  std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
+  //std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
 
   //Check that the return value is of the expected type:
-  //g_assert(value.get_value_type() == GDA_TYPE_NUMERIC);
+  g_assert(value.get_value_type() == G_TYPE_DATE);
 
   //Check that the return value is of the expected value:
-  //const double numeric = Glom::Conversions::get_double_for_gda_value_numeric(value);
-  //g_assert(numeric == 4950.0);
+  Glib::Date date_current;
+  date_current.set_time_current();
+  const Glib::Date date_result= value.get_date();
+  g_assert(date_current == date_result);
 
-  std::cout << "value=" << value.to_string() << std::endl;
+  //std::cout << "value=" << value.to_string() << std::endl;
 
   return EXIT_SUCCESS;
 }



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