comparison ui/tests/commontest.cpp @ 237:6435e28ae753

Properly test for invalid input
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 28 Mar 2014 14:00:21 +0000
parents d773e540dec3
children 6b4ad6ccc48e
comparison
equal deleted inserted replaced
236:bd83b038829d 237:6435e28ae753
2 #include <QByteArray> 2 #include <QByteArray>
3 #include <QTest> 3 #include <QTest>
4 4
5 #include "commontest.h" 5 #include "commontest.h"
6 #include "strhelp.h" 6 #include "strhelp.h"
7
8 void CommonTest::testInvalidInput() {
9 const char * foo = "Zm9vA"; /* Invalid input with a bit valid input */
10 char *data = NULL;
11 size_t data_size = 0;
12 int ret = -1;
13 ret = str_base64_decode(&data, &data_size, (char *)foo, 5);
14
15 QVERIFY(ret != 0);
16 QVERIFY(data == NULL);
17 QVERIFY(data_size == 0);
18 free(data);
19 }
7 20
8 void CommonTest::testStrBase64Decode() { 21 void CommonTest::testStrBase64Decode() {
9 char garbage[1000]; 22 char garbage[1000];
10 char *data = NULL; 23 char *data = NULL;
11 size_t data_size = 0; 24 size_t data_size = 0;
22 35
23 QVERIFY(ret == 0); 36 QVERIFY(ret == 0);
24 QVERIFY(data_size == 1000); 37 QVERIFY(data_size == 1000);
25 QVERIFY(data); 38 QVERIFY(data);
26 39
27 ret = str_base64_decode(&data, &data_size, (char *)ba.constData(), ba.size());
28 QVERIFY(ret != 0);
29
30 const char * foo = "bla";
31 ret = str_base64_decode(&data, &data_size, (char *)foo, 3);
32 QVERIFY(ret != 0);
33
34 for (size_t i = 0; i < data_size; i++) { 40 for (size_t i = 0; i < data_size; i++) {
35 QVERIFY(garbage[i] == data[i]); 41 QVERIFY(garbage[i] == data[i]);
36 } 42 }
37 free (data); 43 free (data);
38 } 44 }

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