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>
9
Glom::libglom_init(); //Also initializes python.
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;
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;
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.
29
catch(const std::exception& ex)
31
std::cerr << "Exception: " << ex.what() << std::endl;
34
catch(const boost::python::error_already_set& ex)
36
std::cerr << "Exception: boost::python::error_already_set" << std::endl;
40
//std::cout << "type=" << g_type_name(value.get_value_type()) << std::endl;
42
//Check that there was no python error:
43
g_assert(error_message.empty());
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);
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.
53
//std::cout << "value=" << value.to_string() << std::endl;