1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-27 15:31:17 +01:00

tests/pkg_yxml: add basic Yxml package test

This commit is contained in:
Kaspar Schleiser 2020-03-11 22:47:49 +01:00
parent fd0fd1cb3c
commit f9e80f8b71
4 changed files with 115 additions and 0 deletions

6
tests/pkg_yxml/Makefile Normal file
View File

@ -0,0 +1,6 @@
include ../Makefile.tests_common
USEPKG += yxml
USEMODULE += embunit
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,5 @@
BOARD_INSUFFICIENT_MEMORY := \
nucleo-f042k6 \
nucleo-f031k6 \
stm32f030f4-demo \
#

86
tests/pkg_yxml/main.c Normal file
View File

@ -0,0 +1,86 @@
/*
* Copyright (C) 2020 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 the yxml XML parser library package
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @}
*/
#include <string.h>
#include <stdio.h>
#include "embUnit.h"
#include "yxml.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
static char _yxml_buf[1024];
static const char *_doc = "<foo>bar</foo>";
static void test_yxml(void)
{
yxml_t yxml;
char content[64];
/* initialize yxml instance */
yxml_init(&yxml, _yxml_buf, sizeof(_yxml_buf));
/* parse XML document bytewise */
for (const char *doc = _doc; *doc; doc++) {
yxml_ret_t r = yxml_parse(&yxml, *doc);
TEST_ASSERT(r >= 0);
/* handle tokens */
switch (r) {
case YXML_OK:
break;
case YXML_ELEMSTART:
DEBUG("YXML_ELEMSTART \"%s\"\n", yxml.elem);
TEST_ASSERT_EQUAL_STRING("foo", yxml.elem);
memset(content, 0, sizeof(content));
break;
case YXML_CONTENT:
DEBUG_PUTS("YXML_CONTENT");
strcat(content, yxml.data);
break;
case YXML_ELEMEND:
DEBUG("YXML_ELEMEND content=\"%s\"\n", content);
TEST_ASSERT_EQUAL_STRING("bar", content);
break;
default:
DEBUG("unhandled token %i\n", r);
}
}
/* let yxml know the document has ended */
TEST_ASSERT_EQUAL_INT(0, yxml_eof(&yxml));
}
TestRef tests_yxml(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_yxml),
};
EMB_UNIT_TESTCALLER(YxmlTest, 0, 0, fixtures);
return (TestRef) & YxmlTest;
}
int main(void)
{
TESTS_START();
TESTS_RUN(tests_yxml());
TESTS_END();
return 0;
}

18
tests/pkg_yxml/tests/01-run.py Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# Copyright (C) 2017 Freie Universität Berlin
#
# 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(r'OK \(\d+ tests\)')
if __name__ == "__main__":
sys.exit(run(testfunc))