1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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"
|