Skip to content

Commit

Permalink
Covered wrong inputs by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artemkin committed Dec 23, 2014
1 parent cd5dbef commit c61227f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ project (Z85)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# Compiler-specific C++11 activation.
# Disable assert() to run all unit tests
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")

# Compiler-specific C++11 activation
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
Expand Down
44 changes: 43 additions & 1 deletion test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include <cstring>
#include <cstdlib>
#include <cstddef>

#include "lest.hpp"
#include "z85.h"
Expand Down Expand Up @@ -259,8 +260,49 @@ const lest::test specification[] =
EXPECT(estimate == decoded);
input += i % 256;
}
}
},

"Test Z85_encode()/Z85_decode() wrong input", []
{
char buf[100];
EXPECT(Z85_encode(NULL, NULL, 5) == 0);
EXPECT(Z85_encode("some binary data", NULL, 5) == 0);
EXPECT(Z85_encode("some binary data", buf, 5) == 0);
EXPECT(Z85_encode("some binary data", buf, 16) == 20);

EXPECT(Z85_decode(NULL, NULL, 4) == 0);
EXPECT(Z85_decode("some text.", NULL, 4) == 0);
EXPECT(Z85_decode("some text.", buf, 4) == 0);
EXPECT(Z85_decode("some text.", buf, 10) == 8);
},

"Test Z85_decode_with_padding() wrong tail bytes count", []
{
char buf[100];
EXPECT(Z85_decode_with_padding("0HelloWorld", buf, 11) == 0);
EXPECT(Z85_decode_with_padding("5HelloWorld", buf, 11) == 0);
EXPECT(Z85_decode_with_padding("AHelloWorld", buf, 11) == 0);
EXPECT(Z85_decode_with_padding("4HelloWorld", buf, 11) == 8);
},

"Test wrong input for z85:: functions", []
{
EXPECT(z85::encode_with_padding(NULL, 0) == "");
EXPECT(z85::encode_with_padding("bin", 0) == "");
EXPECT(z85::encode_with_padding(NULL, 4) == "");

EXPECT(z85::decode_with_padding(NULL, 0) == "");
EXPECT(z85::decode_with_padding("txt", 0) == "");
EXPECT(z85::decode_with_padding(NULL, 5) == "");

EXPECT(z85::encode(NULL, 0) == "");
EXPECT(z85::encode("bin", 0) == "");
EXPECT(z85::encode(NULL, 4) == "");

EXPECT(z85::decode(NULL, 0) == "");
EXPECT(z85::decode("txt", 0) == "");
EXPECT(z85::decode(NULL, 5) == "");
}
};

int main()
Expand Down

0 comments on commit c61227f

Please sign in to comment.