annotate ui/tests/commontest.cpp @ 1387:c64b6c56ce96 0.9.8

(issue95) Change keys for release build. Fix release build usage.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 15 Jan 2015 16:46:36 +0100
parents 17e1c8f37d72
children
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 239
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 239
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 239
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 239
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 239
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 239
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 239
diff changeset
7 */
182
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #include <QString>
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 #include <QByteArray>
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 #include <QTest>
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 #include "commontest.h"
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 #include "strhelp.h"
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
237
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
15 void CommonTest::testInvalidInput() {
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
16 const char * foo = "Zm9vA"; /* Invalid input with a bit valid input */
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
17 char *data = NULL;
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
18 size_t data_size = 0;
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
19 int ret = -1;
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
20 ret = str_base64_decode(&data, &data_size, (char *)foo, 5);
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
21
239
6b4ad6ccc48e Change the specification of str_b64_decode so that it matches the
Andre Heinecke <aheinecke@intevation.de>
parents: 237
diff changeset
22 QVERIFY(ret == 0);
6b4ad6ccc48e Change the specification of str_b64_decode so that it matches the
Andre Heinecke <aheinecke@intevation.de>
parents: 237
diff changeset
23 QVERIFY(data == QString::fromLatin1("foo"));
237
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
24 free(data);
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
25 }
6435e28ae753 Properly test for invalid input
Andre Heinecke <aheinecke@intevation.de>
parents: 233
diff changeset
26
182
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 void CommonTest::testStrBase64Decode() {
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 char garbage[1000];
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 char *data = NULL;
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 size_t data_size = 0;
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 int ret;
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 for (int i = 0; i < 1000; i++) {
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 garbage[i] = (char) qrand() % 255;
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 }
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 QByteArray ba(garbage, 1000);
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 QByteArray baB64 = ba.toBase64();
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 ret = str_base64_decode(&data, &data_size, (char *)baB64.constData(), baB64.size());
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 QVERIFY(ret == 0);
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 QVERIFY(data_size == 1000);
184
1f44aae4528e Add C linkage for strhelp. Check for data in commontest.
Andre Heinecke <aheinecke@intevation.de>
parents: 182
diff changeset
44 QVERIFY(data);
182
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 for (size_t i = 0; i < data_size; i++) {
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 QVERIFY(garbage[i] == data[i]);
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48 }
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 free (data);
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 }
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51
6c3a089d3265 Add test for str_base64_decode as i suspect it to have a bug
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 QTEST_GUILESS_MAIN (CommonTest);

http://wald.intevation.org/projects/trustbridge/