55
66#include " ffpython.h"
77
8- #define TestGuard (X, Y ) printf(" -------%s begin-----------\n " , X);try {Y;}catch (exception& e_){printf (" exception<%s>\n " , e_.what ());}\
9- printf (" -------%s end-----------\n " , X);
8+ #define TestGuard (X, Y ) \
9+ printf (" -------%s begin---------\n " , X); \
10+ try { \
11+ Y; \
12+ } \
13+ catch (exception& e_) \
14+ { \
15+ printf (" exception<%s>\n " , e_.what ()); \
16+ } \
17+ printf (" -------%s end-----------\n " , X); \
18+ printf (" \n " );
1019
1120void test_base (ffpython_t & ffpython)
1221{
@@ -33,9 +42,9 @@ void test_return_stl(ffpython_t& ffpython)
3342 ret_t val = ffpython.call <ret_t >(" fftest" , " test_return_stl" );
3443}
3544
36- static int print_val (int a1, int a2, const string& a3, const vector<double >& a4)
45+ static int print_val (int a1, double a2, const string& a3, const vector<double >& a4)
3746{
38- // printf("%s[%d,%f,%s,%d]\n", __FUNCTION__, a1, a2, a3.c_str(), a4.size());
47+ printf (" %s[%d,%f,%s,%d]\n " , __FUNCTION__, a1, a2, a3.c_str (), a4.size ());
3948 return 0 ;
4049}
4150struct ops_t
@@ -48,12 +57,8 @@ struct ops_t
4857 }
4958};
5059
51- void test_reg_function ()
60+ void test_reg_function ( ffpython_t & ffpython )
5261{
53- ffpython_t ffpython;// ("ext1");
54- ffpython.reg (&print_val, " print_val" )
55- .reg (&ops_t ::return_stl, " return_stl" );
56- ffpython.init (" ext1" );
5762 ffpython.call <void >(" fftest" , " test_reg_function" );
5863}
5964
@@ -66,7 +71,7 @@ class foo_t
6671 }
6772 virtual ~foo_t ()
6873 {
69- printf (" %s\n " , __FUNCTION__);
74+ printf (" %s<%d> \n " , __FUNCTION__, m_value );
7075 }
7176 int get_value () const { return m_value; }
7277 void set_value (int v_) { m_value = v_; }
@@ -112,15 +117,24 @@ void test_register_base_class(ffpython_t& ffpython)
112117 ffpython.reg_class <dumy_t , PYCTOR (int )>(" dumy_t" , " dumy_t class inherit foo_t ctor <int>" , " foo_t" )
113118 .reg (&dumy_t ::dump, " dump" );
114119
115- ffpython.reg (obj_test, " obj_test" );
120+ ffpython.reg (&obj_test, " obj_test" )
121+ .reg (&print_val, " print_val" )
122+ .reg (&ops_t ::return_stl, " return_stl" );
116123
117124 ffpython.init (" ext2" );
118125 ffpython.call <void >(" fftest" , " test_register_base_class" );
119126};
120127
121128void test_register_inherit_class (ffpython_t & ffpython)
122129{
123- ffpython.call <void >(" fftest" , " test_register_inherit_class" );
130+ foo_t * p = ffpython.call <foo_t *>(" fftest" , " test_register_inherit_class" );
131+
132+ if ( p )
133+ {
134+ printf ( " p's value is %d\n " , p->m_value );
135+ p->set_value ( 3333 );
136+ printf ( " p's value is %d\n " , p->m_value );
137+ }
124138};
125139
126140void test_cpp_obj_to_py (ffpython_t & ffpython)
@@ -137,8 +151,12 @@ void test_cpp_obj_py_obj(ffpython_t& ffpython)
137151{
138152 dumy_t tmp_foo (2013 );
139153
140- // foo_t* p = ffpython.call<foo_t*>("fftest", "test_cpp_obj_py_obj", &tmp_foo);
141- // p = NULL;
154+ foo_t * p = ffpython.call <foo_t *>(" fftest" , " test_cpp_obj_py_obj" , &tmp_foo);
155+
156+ if ( p )
157+ printf ( " p's value is %d\n " , p->m_value );
158+
159+ // p = NULL;
142160}
143161
144162void test_py_class_lambda (ffpython_t & ffpython)
@@ -160,10 +178,10 @@ int main(int argc, char* argv[])
160178 ffpython_t::add_path (" ./" );
161179 ffpython_t ffpython;// ("ext2");
162180
181+ TestGuard (" test_register_base_class" , test_register_base_class (ffpython));
163182 TestGuard (" test_base" , test_base (ffpython));
164183 TestGuard (" test_stl" , test_stl (ffpython));
165- TestGuard (" test_reg_function" , test_reg_function ());
166- TestGuard (" test_register_base_class" , test_register_base_class (ffpython));
184+ TestGuard (" test_reg_function" , test_reg_function (ffpython));
167185
168186 TestGuard (" test_register_inherit_class" , test_register_inherit_class (ffpython));
169187 TestGuard (" test_cpp_obj_to_py" , test_cpp_obj_to_py (ffpython));
0 commit comments