mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests: add pkg_libbase58 test
This commit is contained in:
parent
d8751f79d4
commit
c526b11195
6
tests/pkg_libbase58/Makefile
Normal file
6
tests/pkg_libbase58/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += embunit
|
||||
USEPKG += libbase58
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
64
tests/pkg_libbase58/main.c
Normal file
64
tests/pkg_libbase58/main.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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 <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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;
|
||||
}
|
18
tests/pkg_libbase58/tests/01-run.py
Executable file
18
tests/pkg_libbase58/tests/01-run.py
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
#
|
||||
# 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))
|
Loading…
Reference in New Issue
Block a user