Commit | Line | Data |
---|---|---|
208db683 JT |
1 | /* |
2 | Copyright (C) 2006 | |
3 | intra2net.com | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | */ | |
19 | #include <socket_client.hxx> | |
20 | ||
21 | // include generated library headers | |
22 | #include "default_client.hxx" | |
23 | #include "other_client.hxx" | |
24 | ||
25 | template <typename X, typename Y> | |
26 | std::ostream& operator<<(std::ostream &o, const std::pair<X,Y> &p) | |
27 | { | |
28 | o << "<" << p.first << "," << p.second << ">"; | |
29 | return o; | |
30 | } | |
31 | ||
32 | int main(int argc, char** argv) | |
33 | { | |
34 | libt2n::socket_client_connection sc("./socket"); | |
35 | libt2n::socket_client_connection sc_other("./socket_other"); | |
36 | cmd_group_default_client cc(sc); | |
37 | cmd_group_other_client cc_other(sc_other); | |
38 | ||
39 | bool throwok=false; | |
40 | try | |
41 | { | |
42 | cc.testfunc("throw"); | |
43 | }catch(libt2n::t2n_runtime_error &e){ | |
44 | throwok=(std::string(e.what())=="throw me around"); | |
45 | } | |
46 | ||
47 | if (throwok) { | |
48 | throwok=false; | |
49 | try | |
50 | { | |
51 | cc.t6(); | |
52 | }catch(libt2n::t2n_runtime_error &e){ | |
53 | throwok=(std::string(e.what())=="throw me around2"); | |
54 | } | |
55 | } | |
56 | ||
57 | Foo foo={10,10}; | |
58 | ||
59 | std::vector<unsigned> v; | |
60 | std::list<unsigned> l; | |
61 | std::set<unsigned> s; | |
62 | for (unsigned i=1;i<=100;++i) { | |
63 | v.push_back(i); | |
64 | l.push_back(i); | |
65 | s.insert(i); | |
66 | } | |
67 | unsigned expected_sum=(101*100)/2; | |
68 | ||
69 | int exit_status=EXIT_SUCCESS; | |
70 | ||
71 | #define COMPARE(x,y) do{if (x!=y) {std::cerr << #x << "!=" << #y << ": " << x << "!=" << y << std::endl; exit_status=EXIT_FAILURE;}}while(0) | |
72 | ||
73 | COMPARE(throwok, true); | |
74 | COMPARE( cc.testfunc("hello"), "hello, testfunc() was here" ); | |
75 | COMPARE( cc.testfunc_ref("hello"), "hello, testfunc() was here" ); | |
76 | COMPARE( cc.t2(10), 10 ); | |
77 | COMPARE( cc.t3(10), 10 ); | |
78 | COMPARE( cc.t4(static_cast<const int *>(&foo.i)), 10 ); | |
79 | COMPARE( cc.t5(), 10 ); | |
80 | COMPARE( cc.sum(v), expected_sum ); | |
81 | COMPARE( cc.sum(l), expected_sum ); | |
82 | COMPARE( cc.sum(s), expected_sum ); | |
83 | COMPARE( cc.pdup(10), (std::pair<int,int>(10,10))); | |
84 | // todo: boost doesn't provide serialization for boost tuple :-( | |
85 | // COMPARE( cc.quad(10), boost::tuple<int,int,int,int>(10,10,10,10)); | |
86 | COMPARE( cc_other.t3(10, 20, "hello", std::pair<int, float>(10,20)), true ); | |
87 | COMPARE( cc_other.t3(10), 10 ); | |
88 | COMPARE( cc_other.t3(std::vector<int>(1,10)), true ); | |
89 | COMPARE( cc_other.t3(foo), true ); | |
90 | return exit_status; | |
91 | } |