X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fsimplecmd.cpp;h=b2b5bbdca2f8f1c0883d469150aa508a42c62eb7;hp=462a03ffe6e7cdf9de0bfafa16e4d5e43e0d200c;hb=e453407db5951aa7f504282ea82d1ca1f19d22fb;hpb=d535333ffe637c9e547e68b792f334c229641520 diff --git a/test/simplecmd.cpp b/test/simplecmd.cpp index 462a03f..b2b5bbd 100644 --- a/test/simplecmd.cpp +++ b/test/simplecmd.cpp @@ -36,6 +36,8 @@ using namespace CppUnit; string testfunc(const string& str) { + if (str=="throw") + throw libt2n::t2n_runtime_error("throw me around"); string ret(str); ret+=", testfunc() was here"; return ret; @@ -110,6 +112,7 @@ class test_simplecmd : public TestFixture CPPUNIT_TEST_SUITE(test_simplecmd); CPPUNIT_TEST(SimpleCmd); + CPPUNIT_TEST(SimpleException); CPPUNIT_TEST_SUITE_END(); @@ -166,6 +169,58 @@ class test_simplecmd : public TestFixture } } + void SimpleException() + { + pid_t pid; + + switch(pid=fork()) + { + case -1: + { + CPPUNIT_FAIL("fork error"); + break; + } + case 0: + // child + { + socket_server ss("./socket"); + command_server cs(ss); + + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + + // don't call atexit and stuff + _exit(0); + } + + default: + // parent + { + // wait till server is up + sleep(1); + socket_client_connection sc("./socket"); + sc.set_logging(&cerr,debug); + command_client cc(sc); + + result_container rc; + cc.send_command(new testfunc_cmd("throw"),rc); + + string ret; + + try + { + ret=dynamic_cast(rc.get_result())->get_data(); + } + catch(t2n_runtime_error &e) + { ret=e.what(); } + catch(...) + { throw; } + + CPPUNIT_ASSERT_EQUAL(string("throw me around"),ret); + } + } + } };