~ubuntu-branches/ubuntu/precise/glom/precise

« back to all changes in this revision

Viewing changes to tests/python/test_python_execute_func_change_result_type.cc

  • Committer: Package Import Robot
  • Author(s): Daniel Holbach
  • Date: 2011-09-13 11:04:29 UTC
  • mfrom: (1.1.46 upstream)
  • Revision ID: package-import@ubuntu.com-20110913110429-39c9eh8ez2qg0aq4
Tags: 1.18.3-0ubuntu1
* New upstream release, fixes FTBFS (LP: #749267).
* debian/watch: updated.
* Updated to 1.18 ABI.
* debian/control: 
  - update build depends,
  - added libxml++2.6-dev depends to libglom-1.18-dev (LP: #736913).
* Use dh_python2.
* Don't ship internal libjs-underscore, use system version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <glom/libglom/init.h>
 
2
#include <glom/python_embed/glom_python.h>
 
3
#include <libglom/data_structure/glomconversions.h>
 
4
#include <boost/python.hpp>
 
5
#include <iostream>
 
6
 
 
7
int main()
 
8
{
 
9
  Glom::libglom_init(); //Also initializes python.
 
10
 
 
11
  const char* calculation = "count = 0\nfor i in range(0, 100): count += i\nreturn count";
 
12
  Glom::type_map_fields field_values;
 
13
  Glib::RefPtr<Gnome::Gda::Connection> connection;
 
14
 
 
15
  //Execute a python function:
 
16
  Gnome::Gda::Value value;
 
17
  Glib::ustring error_message;
 
18
  const Glom::Field::glom_field_type result_type = Glom::Field::TYPE_TEXT;
 
19
  try
 
20
  {
 
21
    //We ask for a text result though the python function actually returns a number.
 
22
    value = Glom::glom_evaluate_python_function_implementation(
 
23
      result_type, calculation, field_values,
 
24
      0 /* document */, "" /* table name */,
 
25
      Glom::sharedptr<Glom::Field>(), Gnome::Gda::Value(), // primary key details. Not used in this test.
 
26
      connection,
 
27
      error_message);
 
28
  }
 
29
  catch(const std::exception& ex)
 
30
  {
 
31
    std::cerr << "Exception: " << ex.what() << std::endl;
 
32
    return EXIT_FAILURE;
 
33
  }
 
34
  catch(const boost::python::error_already_set& ex)
 
35
  {
 
36
    std::cerr << "Exception: boost::python::error_already_set" << std::endl;
 
37
    return EXIT_FAILURE;
 
38
  }
 
39
 
 
40
  //std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
 
41
 
 
42
  //Check that there was no python error:
 
43
  g_assert(error_message.empty());
 
44
 
 
45
  //Check that the return value is of the expected type:
 
46
  g_assert(Glom::Field::get_glom_type_for_gda_type(value.get_value_type()) == result_type);
 
47
 
 
48
  //Check that the return value is of the expected value:
 
49
  const Glib::ustring text = value.get_string();
 
50
  //std::cout << "text=" << text << std::endl;
 
51
  g_assert(text == "4950"); //This should always be as per ISO, not according to the user's locale, because it's generally passed to the database. Presentation is separate to calculation or storage.
 
52
 
 
53
  //std::cout << "value=" << value.to_string() << std::endl;
 
54
 
 
55
  return EXIT_SUCCESS;
 
56
}