Mercurial > trustbridge
changeset 237:6435e28ae753
Properly test for invalid input
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 28 Mar 2014 14:00:21 +0000 |
parents | bd83b038829d |
children | dd417a2ff9cd |
files | ui/tests/commontest.cpp ui/tests/commontest.h |
diffstat | 2 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ui/tests/commontest.cpp Fri Mar 28 13:05:21 2014 +0100 +++ b/ui/tests/commontest.cpp Fri Mar 28 14:00:21 2014 +0000 @@ -5,6 +5,19 @@ #include "commontest.h" #include "strhelp.h" +void CommonTest::testInvalidInput() { + const char * foo = "Zm9vA"; /* Invalid input with a bit valid input */ + char *data = NULL; + size_t data_size = 0; + int ret = -1; + ret = str_base64_decode(&data, &data_size, (char *)foo, 5); + + QVERIFY(ret != 0); + QVERIFY(data == NULL); + QVERIFY(data_size == 0); + free(data); +} + void CommonTest::testStrBase64Decode() { char garbage[1000]; char *data = NULL; @@ -24,13 +37,6 @@ QVERIFY(data_size == 1000); QVERIFY(data); - ret = str_base64_decode(&data, &data_size, (char *)ba.constData(), ba.size()); - QVERIFY(ret != 0); - - const char * foo = "bla"; - ret = str_base64_decode(&data, &data_size, (char *)foo, 3); - QVERIFY(ret != 0); - for (size_t i = 0; i < data_size; i++) { QVERIFY(garbage[i] == data[i]); }