diff --git a/tests/pkg_libbase58/Makefile b/tests/pkg_libbase58/Makefile new file mode 100644 index 0000000000..d997e19c84 --- /dev/null +++ b/tests/pkg_libbase58/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.tests_common + +USEMODULE += embunit +USEPKG += libbase58 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/pkg_libbase58/main.c b/tests/pkg_libbase58/main.c new file mode 100644 index 0000000000..8388e0a641 --- /dev/null +++ b/tests/pkg_libbase58/main.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2019 Kaspar Schleiser + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Tests for pkg libbase58 + * + * @author Kaspar Schleiser + */ + +#include +#include +#include +#include + +#include "libbase58.h" +#include "embUnit.h" + +static void test_libbase58_01(void) +{ + const char source[] = "base 58 test string"; + const char encoded[] = "2NVj5VV1YMqTHot6N2xPBQnbqnUF"; + char decoded[sizeof(source)] = {0}; + char target[64] = {0}; + size_t target_len = sizeof(target); + size_t decoded_len = sizeof(decoded); + + /* testing encoding */ + b58enc(target, &target_len, source, sizeof(source)); + + TEST_ASSERT_EQUAL_INT(target_len, sizeof(encoded)); + TEST_ASSERT(strcmp(target, encoded) == 0); + + /* testing decoding */ + b58tobin(decoded, &decoded_len, target, target_len - 1); + + TEST_ASSERT(memcmp(source, decoded, sizeof(source)) == 0); +} + +Test *tests_libbase58(void) +{ + EMB_UNIT_TESTFIXTURES(fixtures) { + new_TestFixture(test_libbase58_01), + }; + + EMB_UNIT_TESTCALLER(libbase58_tests, NULL, NULL, fixtures); + return (Test *)&libbase58_tests; +} + +int main(void) +{ + TESTS_START(); + TESTS_RUN(tests_libbase58()); + TESTS_END(); + return 0; +} diff --git a/tests/pkg_libbase58/tests/01-run.py b/tests/pkg_libbase58/tests/01-run.py new file mode 100755 index 0000000000..5ba9b468a2 --- /dev/null +++ b/tests/pkg_libbase58/tests/01-run.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2016 Kaspar Schleiser +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +from testrunner import run + + +def testfunc(child): + child.expect(u"OK \\([0-9]+ tests\\)") + + +if __name__ == "__main__": + sys.exit(run(testfunc, timeout=120))