[complement-svn] SF.net SVN: complement: [1855] trunk/complement/explore/app/SMTP-tools/ smtp_serve
Status: Pre-Alpha
Brought to you by:
complement
From: <oke...@us...> - 2008-04-24 11:58:28
|
Revision: 1855 http://complement.svn.sourceforge.net/complement/?rev=1855&view=rev Author: okechina Date: 2008-04-24 04:58:15 -0700 (Thu, 24 Apr 2008) Log Message: ----------- Modified Paths: -------------- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-23 19:22:40 UTC (rev 1854) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.cc 2008-04-24 11:58:15 UTC (rev 1855) @@ -1,6 +1,8 @@ // -*- C++ -*- Time-stamp: <08/03/26 01:53:46 ptr> #include "my_test.h" + + #include "SMTP_Server.h" #include <mt/thread> @@ -10,6 +12,7 @@ #include <typeinfo> #include <iostream> +#include <fstream> #include <semaphore.h> #include <sys/wait.h> @@ -20,72 +23,156 @@ using namespace std; -static int fd1[2], fd2[2]; +//possible states +// disconnect +// connect +// hello +// sender +// recipient +// letter +const string set_state [6] = { + "quit\n", + "", + "helo mail.ru\n", + "helo mail.ru\nmail from:se...@ma...\n", + "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\n", + "helo mail.ru\nmail from:se...@ma...\nrcpt to:cl...@ma...\ndata\n" + }; + +//possible commands +// helo +// ehlo +// mail +// rcpt +// data +// rset +// vrfy +// expn +// help +// noop +// quit +// none + + +const string set_command [12] = { + "helo mail.ru", + "ehlo mail.ru", + "mail from:se...@ma...", + "rcpt to:rec...@ma...", + "data", + "rset", + "vrfy se...@ma...", + "expn se...@ma...", + "help", + "noop", + "quit", + "none" + }; + +const int set_result [6][12] = { + {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999}, +// {221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221}, + {250, 250, 503, 503, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 250, 503, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 503, 250, 503, 250, 502, 502, 214, 250, 221, 500}, + {503, 503, 503, 250, 354, 250, 502, 502, 214, 250, 221, 500}, + {999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999} + }; + const int buf_size = 1024; const int com_length = 4; +const int test_num = 0; +static int fd1[2], fd2[2]; + +bool active; + void server_thread() { char buffer[buf_size]; state st = connect; command com; string param, message, stout; - while (st != disconnect) { if (st != letter) { - if (read (fd2[0], buffer, sizeof(buffer)) < 1) fprintf(stderr,"Reading error\n"); - else fprintf (stderr,"%s\n",buffer); - - string str(buffer); - param.assign (str, com_length, str.size()); - str.erase (com_length, str.size() - com_length + 1); - com = setCom (str); - change (st, com, param, stout); + else { + cerr << ">> "<< buffer << endl; + string str (buffer); + param.assign (str, com_length, str.size()); + str.erase (com_length, str.size() - com_length + 1); + com = setCom (str); + change (st, com, param, stout); - strcpy (buffer, stout.c_str()); - write (fd1[1], buffer, sizeof(buffer)); + strcpy (buffer, stout.c_str()); + write (fd1[1], buffer, sizeof(buffer)); + } } - else { + else { read (fd2[0], buffer, sizeof(buffer)); param.assign (buffer, 0, sizeof(buffer)); if (param != ".") message = message + param + "\n"; else { st = hello; // cout << message; - message = ""; - } + message = ""; + } }; }; - cerr << "Server's loop may be here" << endl; + active = false; +// cerr << "Server's loop may be here" << endl; } int EXAM_IMPL(my_test::thread_call) { - char r_buffer[buf_size], w_buffer[buf_size]; pipe (fd1); pipe (fd2); - std::tr2::basic_thread<0,0> t( server_thread ); + active = false; + for (int i = 0; i <= test_num; i++) { + char r_buffer[buf_size], w_buffer[buf_size]; + std::tr2::basic_thread<0,0> t( server_thread ); + active = true; - strcpy (w_buffer, "ehlo"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; + ostringstream st; + st << "test_" << i; + ifstream in (st.str().c_str()); + + string expected; + getline(in, expected); + + while (!in.eof()){ + string s; + getline(in, s); + if (s != "") { + strcpy (w_buffer, s.c_str()); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << "<< " << r_buffer; + } + } + in.close(); + t.join(); - strcpy (w_buffer, "help"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; + string result (r_buffer); + if (expected.compare (0, 3, result, 0, 3) != 0) + cerr << expected << "!=" << result << " at " << i << endl; + + EXAM_CHECK ((expected.compare (0, 3, result, 0, 3) == 0)); + +/* strcpy (w_buffer, "help"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; - strcpy (w_buffer, "quit"); - write (fd2[1], w_buffer, sizeof(w_buffer)); - read (fd1[0], r_buffer, sizeof(r_buffer)); - cerr << r_buffer; + strcpy (w_buffer, "quit"); + write (fd2[1], w_buffer, sizeof(w_buffer)); + read (fd1[0], r_buffer, sizeof(r_buffer)); + cerr << r_buffer; - cerr << "Client's text may be here" << endl; - t.join(); - + cerr << "Client's text may be here" << endl; +*/ + } // EXAM_CHECK( val == 1 ); // std::tr2::basic_thread<0,0> t2( thread_func_int, 2 ); // t2.join(); @@ -95,3 +182,23 @@ return EXAM_RESULT; } + +int EXAM_IMPL(my_test::test_gen) +{ + int num = 1; + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 12; j++) { + ostringstream st; + st << "test_" << num; +// st << "test_" << i << "_" << j; + ofstream os (st.str().c_str()); + os << set_result [i][j] << endl; + os << set_state [i] << set_command [j]; + os.close(); + num++; + } + } + return EXAM_RESULT; +} + + Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h 2008-04-23 19:22:40 UTC (rev 1854) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test.h 2008-04-24 11:58:15 UTC (rev 1855) @@ -13,6 +13,7 @@ { public: int EXAM_DECL(thread_call); + int EXAM_DECL(test_gen); }; #endif // __MY_TEST_H Modified: trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc =================================================================== --- trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-23 19:22:40 UTC (rev 1854) +++ trunk/complement/explore/app/SMTP-tools/smtp_server_ut/my_test_suite.cc 2008-04-24 11:58:15 UTC (rev 1855) @@ -10,6 +10,7 @@ exam::test_suite t( "my test" ); my_test test; + t.add( &my_test::test_gen, test, "my_test::test_gen" ); t.add( &my_test::thread_call, test, "my_test::thread_call" ); return t.girdle(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |