summaryrefslogtreecommitdiffstats
path: root/kioslave/smtp/test_responseparser.cc
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kioslave/smtp/test_responseparser.cc
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kioslave/smtp/test_responseparser.cc')
-rw-r--r--kioslave/smtp/test_responseparser.cc107
1 files changed, 107 insertions, 0 deletions
diff --git a/kioslave/smtp/test_responseparser.cc b/kioslave/smtp/test_responseparser.cc
new file mode 100644
index 000000000..5daa2fb3b
--- /dev/null
+++ b/kioslave/smtp/test_responseparser.cc
@@ -0,0 +1,107 @@
+#include "response.h"
+#include <assert.h>
+
+static const QCString singleLineResponseCRLF = "250 OK\r\n";
+static const QCString singleLineResponse = "250 OK";
+
+static const QCString 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.cc"