Browse Source

test: update terminal strings

mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
e6dc5051ba
4 changed files with 20 additions and 13 deletions
  1. +1
    -0
      code/espurna/terminal_commands.cpp
  2. +5
    -0
      code/test/lib/test_arduino_compat.h
  3. +1
    -0
      code/test/platformio.ini
  4. +13
    -13
      code/test/unit/terminal/terminal.cpp

+ 1
- 0
code/espurna/terminal_commands.cpp View File

@ -13,6 +13,7 @@ Heavily inspired by the Embedis design:
#include "terminal_commands.h"
#include <algorithm>
#include <memory>
namespace terminal {


+ 5
- 0
code/test/lib/test_arduino_compat.h View File

@ -0,0 +1,5 @@
// some overrides we need when using UnixHostDuino
#pragma once
#define strncasecmp_P strncasecmp

+ 1
- 0
code/test/platformio.ini View File

@ -36,4 +36,5 @@ build_flags =
-std=gnu++11
-g
-Os
-include lib/test_arduino_compat.h
-I../espurna/

+ 13
- 13
code/test/unit/terminal/terminal.cpp View File

@ -41,7 +41,7 @@ void test_hex_codes() {
static bool abc_done = false;
terminal::Terminal::addCommand("abc", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("abc"), [](const terminal::CommandContext& ctx) {
TEST_ASSERT_EQUAL(2, ctx.argc);
TEST_ASSERT_EQUAL_STRING("abc", ctx.argv[0].c_str());
TEST_ASSERT_EQUAL_STRING("abc", ctx.argv[1].c_str());
@ -68,17 +68,17 @@ void test_multiple_commands() {
// set up counter to be chained between commands
static int command_calls = 0;
terminal::Terminal::addCommand("test1", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test1"), [](const terminal::CommandContext& ctx) {
TEST_ASSERT_EQUAL_MESSAGE(1, ctx.argc, "Command without args should have argc == 1");
TEST_ASSERT_EQUAL(0, command_calls);
command_calls = 1;
});
terminal::Terminal::addCommand("test2", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test2"), [](const terminal::CommandContext& ctx) {
TEST_ASSERT_EQUAL_MESSAGE(1, ctx.argc, "Command without args should have argc == 1");
TEST_ASSERT_EQUAL(1, command_calls);
command_calls = 2;
});
terminal::Terminal::addCommand("test3", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test3"), [](const terminal::CommandContext& ctx) {
TEST_ASSERT_EQUAL_MESSAGE(1, ctx.argc, "Command without args should have argc == 1");
TEST_ASSERT_EQUAL(2, command_calls);
command_calls = 3;
@ -113,7 +113,7 @@ void test_command() {
static int counter = 0;
terminal::Terminal::addCommand("test.command", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test.command"), [](const terminal::CommandContext& ctx) {
TEST_ASSERT_EQUAL_MESSAGE(1, ctx.argc, "Command without args should have argc == 1");
++counter;
});
@ -150,12 +150,12 @@ void test_command_args() {
static bool waiting = false;
terminal::Terminal::addCommand("test.command.arg1", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test.command.arg1"), [](const terminal::CommandContext& ctx) {
TEST_ASSERT_EQUAL(2, ctx.argc);
waiting = false;
});
terminal::Terminal::addCommand("test.command.arg1_empty", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test.command.arg1_empty"), [](const terminal::CommandContext& ctx) {
TEST_ASSERT_EQUAL(2, ctx.argc);
TEST_ASSERT(!ctx.argv[1].length());
waiting = false;
@ -192,7 +192,7 @@ void test_buffer() {
void test_quotes() {
terminal::Terminal::addCommand("test.quotes", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test.quotes"), [](const terminal::CommandContext& ctx) {
for (auto& arg : ctx.argv) {
TEST_MESSAGE(arg.c_str());
}
@ -216,11 +216,11 @@ void test_quotes() {
void test_case_insensitive() {
terminal::Terminal::addCommand("test.lowercase1", [](const terminal::CommandContext& ctx) {
__asm__ volatile ("nop");
terminal::Terminal::addCommand(F("test.lowercase1"), [](const terminal::CommandContext& ctx) {
TEST_FAIL_MESSAGE("`test.lowercase1` was registered first, but there's another function by the same name. This should not be called");
});
terminal::Terminal::addCommand("TEST.LOWERCASE1", [](const terminal::CommandContext& ctx) {
TEST_FAIL_MESSAGE("`test.lowercase1` was already registered, this should not be registered / called");
terminal::Terminal::addCommand(F("TEST.LOWERCASE1"), [](const terminal::CommandContext& ctx) {
__asm__ volatile ("nop");
});
IOStreamString str;
@ -235,7 +235,7 @@ void test_case_insensitive() {
void test_output() {
terminal::Terminal::addCommand("test.output", [](const terminal::CommandContext& ctx) {
terminal::Terminal::addCommand(F("test.output"), [](const terminal::CommandContext& ctx) {
if (ctx.argc != 2) return;
ctx.output.print(ctx.argv[1]);
});


Loading…
Cancel
Save