mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
tests: add test application for qrcode package
This commit is contained in:
parent
4b6a5abc47
commit
08ae97257c
9
tests/pkg_qr-code-generator/Makefile
Normal file
9
tests/pkg_qr-code-generator/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEPKG += qr-code-generator
|
||||
|
||||
MESSAGE_TO_ENCODE ?= "https://riot-os.org"
|
||||
|
||||
CFLAGS += -DMESSAGE_TO_ENCODE=\"$(MESSAGE_TO_ENCODE)\"
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
1
tests/pkg_qr-code-generator/app.config.test
Normal file
1
tests/pkg_qr-code-generator/app.config.test
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_PACKAGE_QR-CODE-GENERATOR=y
|
53
tests/pkg_qr-code-generator/main.c
Normal file
53
tests/pkg_qr-code-generator/main.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Inria
|
||||
*
|
||||
* 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 Test application for the qr-code-generator package
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "qrcodegen.h"
|
||||
|
||||
#ifndef MESSAGE_TO_ENCODE
|
||||
#define MESSAGE_TO_ENCODE "unknown"
|
||||
#endif
|
||||
|
||||
static uint8_t qr0[qrcodegen_BUFFER_LEN_FOR_VERSION(2)];
|
||||
static uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(2)];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (!qrcodegen_encodeText(MESSAGE_TO_ENCODE,
|
||||
buffer, qr0, qrcodegen_Ecc_MEDIUM,
|
||||
qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX,
|
||||
qrcodegen_Mask_AUTO, true)) {
|
||||
puts("Encoding error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int size = qrcodegen_getSize(qr0);
|
||||
for (int y = 0; y < size; y++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
printf("%s", qrcodegen_getModule(qr0, x, y) ? "██" : " ");
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
49
tests/pkg_qr-code-generator/tests/01-run.py
Executable file
49
tests/pkg_qr-code-generator/tests/01-run.py
Executable file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2021 Inria
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
QR_CODE = (
|
||||
"██████████████ ██████████ ██ ██████████████\n"
|
||||
"██ ██ ██ ██ ████ ██ ██\n"
|
||||
"██ ██████ ██ ████ ██ ████ ██ ██████ ██\n"
|
||||
"██ ██████ ██ ████ ██ ██ ██████ ██\n"
|
||||
"██ ██████ ██ ██████████ ████ ██ ██████ ██\n"
|
||||
"██ ██ ██ ██ ████ ██ ██\n"
|
||||
"██████████████ ██ ██ ██ ██ ██ ██████████████\n"
|
||||
" ██ ██████ ██ \n"
|
||||
" ████ ██ ████ ██████ ██████ ██ ██████████\n"
|
||||
" ████ ██ ████████ ██ ████ ██\n"
|
||||
" ██ ████████ ██ ██ ████ ██████\n"
|
||||
"██████ ██ ██ ██ ██ ██ ██ \n"
|
||||
" ████████ ██ ██ ██████ ██ ████\n"
|
||||
" ██ ████ ██ ██ ██████ ██ ██\n"
|
||||
"██ ██ ██ ████████ ██ ██ ██████\n"
|
||||
" ██ ████ ████ ██ ██ ██ ██ ██ \n"
|
||||
"██ ██ ██████ ████████████████ \n"
|
||||
" ██████ ██ ████ ████ ████\n"
|
||||
"██████████████ ████████ ████████ ██ ████ ████\n"
|
||||
"██ ██ ██ ██████ ██ ████ ██\n"
|
||||
"██ ██████ ██ ██████████ ████████████ ██\n"
|
||||
"██ ██████ ██ ████ ██ ██ ████████ \n"
|
||||
"██ ██████ ██ ██ ████ ██ ██ ██ ██\n"
|
||||
"██ ██ ████ ██████████ ████ ██ \n"
|
||||
"██████████████ ██ ██ ████ ████\n"
|
||||
)
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
for line in QR_CODE.split("\n"):
|
||||
child.expect_exact(line)
|
||||
print("\nSUCCESS")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc))
|
Loading…
Reference in New Issue
Block a user