summaryrefslogtreecommitdiffstats
path: root/tdeioslave/smtp/test_responseparser.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2020-12-07 22:58:44 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2020-12-07 22:58:44 +0900
commit145abc15d57fb29701a12e8a14dcb9c1fd72e9be (patch)
treefbb4f2f737ec6f4e8a85bea5f2ca2257d20d7e22 /tdeioslave/smtp/test_responseparser.cpp
parentd95494d97233919fa0b2eebf60759537b793e05b (diff)
downloadtdebase-145abc15d57fb29701a12e8a14dcb9c1fd72e9be.tar.gz
tdebase-145abc15d57fb29701a12e8a14dcb9c1fd72e9be.zip
Renaming of files in preparation for code style tools.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdeioslave/smtp/test_responseparser.cpp')
-rw-r--r--tdeioslave/smtp/test_responseparser.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/tdeioslave/smtp/test_responseparser.cpp b/tdeioslave/smtp/test_responseparser.cpp
new file mode 100644
index 000000000..4786bc717
--- /dev/null
+++ b/tdeioslave/smtp/test_responseparser.cpp
@@ -0,0 +1,107 @@
+#include "response.h"
+#include <assert.h>
+
+static const TQCString singleLineResponseCRLF = "250 OK\r\n";
+static const TQCString singleLineResponse = "250 OK";
+
+static const TQCString multiLineResponse[] = {
+ "250-ktown.kde.org\r\n",
+ "250-STARTTLS\r\n",
+ "250-AUTH PLAIN DIGEST-MD5\r\n",
+ "250 PIPELINING\r\n"
+};
+static const unsigned int numMultiLineLines = sizeof multiLineResponse / sizeof *multiLineResponse ;
+
+int main ( int, char** ) {
+
+ KioSMTP::Response r;
+ assert( r.isValid() );
+ assert( r.lines().empty() );
+ assert( r.isWellFormed() );
+ assert( r.code() == 0 );
+ assert( r.isUnknown() );
+ assert( !r.isComplete() );
+ assert( !r.isOk() );
+ r.parseLine( singleLineResponseCRLF.data(),
+ singleLineResponseCRLF.length() );
+ assert( r.isWellFormed() );
+ assert( r.isComplete() );
+ assert( r.isValid() );
+ assert( r.isPositive() );
+ assert( r.isOk() );
+ assert( r.code() == 250 );
+ assert( r.errorCode() == 0 );
+ assert( r.first() == 2 );
+ assert( r.second() == 5 );
+ assert( r.third() == 0 );
+ assert( r.lines().count() == 1 );
+ assert( r.lines().front() == "OK" );
+ r.parseLine( singleLineResponse.data(),
+ singleLineResponse.length() );
+ assert( !r.isValid() );
+ r.clear();
+ assert( r.isValid() );
+ assert( r.lines().empty() );
+
+ r.parseLine( singleLineResponse.data(),
+ singleLineResponse.length() );
+ assert( r.isWellFormed() );
+ assert( r.isComplete() );
+ assert( r.isValid() );
+ assert( r.isPositive() );
+ assert( r.isOk() );
+ assert( r.code() == 250 );
+ assert( r.first() == 2 );
+ assert( r.second() == 5 );
+ assert( r.third() == 0 );
+ assert( r.lines().count() == 1 );
+ assert( r.lines().front() == "OK" );
+ r.parseLine( singleLineResponse.data(),
+ singleLineResponse.length() );
+ assert( !r.isValid() );
+ r.clear();
+ assert( r.isValid() );
+
+ for ( unsigned int i = 0 ; i < numMultiLineLines ; ++i ) {
+ r.parseLine( multiLineResponse[i].data(),
+ multiLineResponse[i].length() );
+ assert( r.isWellFormed() );
+ if ( i < numMultiLineLines-1 )
+ assert( !r.isComplete() );
+ else
+ assert( r.isComplete() );
+ assert( r.isValid() );
+ assert( r.isPositive() );
+ assert( r.code() == 250 );
+ assert( r.first() == 2 );
+ assert( r.second() == 5 );
+ assert( r.third() == 0 );
+ assert( r.lines().count() == i + 1 );
+ }
+ assert( r.lines().back() == "PIPELINING" );
+
+ r.clear();
+ r.parseLine( "230", 3 );
+ assert( r.isValid() );
+ assert( r.isWellFormed() ); // even though it isn't ;-)
+ assert( r.code() == 230 );
+ assert( r.lines().count() == 1 );
+ assert( r.lines().front().isNull() );
+
+ r.clear();
+ r.parseLine( "230\r\n", 5 );
+ assert( r.isValid() );
+ assert( r.isWellFormed() ); // even though it isn't ;-)
+ assert( r.code() == 230 );
+ assert( r.lines().count() == 1 );
+ assert( r.lines().front().isNull() );
+
+ r.clear();
+ r.parseLine( " 23 ok", 6 );
+ assert( !r.isValid() );
+ assert( !r.isWellFormed() );
+
+ return 0;
+}
+
+#include "response.cpp"