7
#include <mimetic/codec/codec.h>
12
class TEST_CLASS( test_qp )
14
static const char* test[][3];
15
static const char* test_decode_malformed[][2];
17
// calls qp.encode(char,out)
18
void TEST_FUNCTION( testEncode )
21
while(test[i][0] != 0)
23
std::string src = test[i][0];
24
std::string exp = test[i][1];
28
encode(src.begin(), src.end(), qp,std::back_inserter<std::string>(got));
29
TEST_ASSERT_EQUALS_P( exp, got );
33
// calls qp.encode(InIt, InIt, ,out)
34
void TEST_FUNCTION( testEncodeBlock )
37
while(test[i][0] != 0)
39
std::string src = test[i][0];
40
std::string exp = test[i][1];
44
qp.process(src.begin(), src.end(), std::back_inserter<std::string>(got));
45
TEST_ASSERT_EQUALS_P( exp, got);
49
void TEST_FUNCTION( testBinaryEncode )
52
while(test[i][0] != 0)
54
std::string src = test[i][0];
55
std::string exp = (0 == test[i][2] ?test[i][1] : test[i][2]);
59
encode(src.begin(), src.end(),qp,std::back_inserter<std::string>(got));
60
TEST_ASSERT_EQUALS_P( exp, got);
64
void TEST_FUNCTION( testBinaryEncodeBlock )
67
while(test[i][0] != 0)
69
std::string src = test[i][0];
70
std::string exp = (0 == test[i][2] ?test[i][1] : test[i][2]);
74
qp.process(src.begin(), src.end(),std::back_inserter<std::string>(got));
75
TEST_ASSERT_EQUALS_P( exp, got);
79
void TEST_FUNCTION( testDecode )
82
while(test[i][0] != 0)
84
std::string src = test[i][1];
85
std::string exp = test[i][0];
88
decode(src.begin(), src.end(),qp,std::back_inserter<std::string>(got));
89
TEST_ASSERT_EQUALS_P( exp, got);
93
void TEST_FUNCTION( testDecodeBlock )
96
while(test[i][0] != 0)
98
std::string src = test[i][1];
99
std::string exp = test[i][0];
102
qp.process(src.begin(), src.end(),std::back_inserter<std::string>(got));
103
TEST_ASSERT_EQUALS_P( exp, got);
107
void TEST_FUNCTION( testBinaryInputDecode )
110
while(test[i][2] != 0)
112
std::string src = test[i][2];
113
std::string exp = test[i][0];
116
decode(src.begin(), src.end(),qp,std::back_inserter<std::string>(got));
117
TEST_ASSERT_EQUALS_P( exp, got);
121
void TEST_FUNCTION( testBinaryInputDecodeBlock )
124
while(test[i][2] != 0)
126
std::string src = test[i][2];
127
std::string exp = test[i][0];
130
qp.process(src.begin(), src.end(),std::back_inserter<std::string>(got));
131
TEST_ASSERT_EQUALS_P( exp, got);
135
void TEST_FUNCTION( testMalformedInputDecode )
138
while(test_decode_malformed[i][0] != 0)
140
std::string src = test_decode_malformed[i][1];
141
std::string exp = test_decode_malformed[i][0];
144
decode(src.begin(), src.end(),qp,std::back_inserter<std::string>(got));
145
TEST_ASSERT_EQUALS_P( exp, got);
149
void TEST_FUNCTION( testMalformedInputDecodeBlock )
152
while(test_decode_malformed[i][0] != 0)
154
std::string src = test_decode_malformed[i][1];
155
std::string exp = test_decode_malformed[i][0];
158
qp.process(src.begin(), src.end(),std::back_inserter<std::string>(got));
159
TEST_ASSERT_EQUALS_P( exp, got);
163
// check correctness of static array QP::tb[]
164
void TEST_FUNCTION( testTbValues )
167
for(int c = 0; c < 256; c++)
169
if (c != '=' && c > 32 && c < 127)
170
tb[c] = QP::printable;
176
tb['='] = QP::unsafe;
177
tb[QP::CR] = tb[QP::LF] = QP::newline;
178
const char* unsafe = "!\"#$@[]\\^`{}|~";
180
tb[*unsafe++] = QP::unsafe;
181
for(int i = 0; i < 256; i++)
183
TEST_ASSERT(tb[i] == QP::sTb[i]);
184
//TEST_ASSERT("Correct struct: \n"+tbInitCode(tb), tb[i] == QP::sTb[i]);
188
std::string tbInitCode(short* tb)
190
std::ostringstream out;
191
std::string comment, values;
193
for(int i =0 ; i < 256; i++)
195
if(tb[i] == QP::printable)
203
std::ostringstream oss;
204
oss << tb[i] << ", ";
209
out << std::endl<< "// " << comment << std::endl;
211
out << " " << values << std::endl;
217
out << std::endl<< "// " << comment << std::endl;
218
out << " " << values << std::endl;