From b682c59d330c563eac720889bbb3a91799b8af35 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 30 Jun 2024 13:16:11 +0200 Subject: [PATCH 1/2] restore list's state after empty --- library.json | 47 ++++++++++++++++++++++------------------------- src/utils.h | 1 + 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/library.json b/library.json index d8e72fd..555653d 100644 --- a/library.json +++ b/library.json @@ -1,27 +1,24 @@ { - "name": "ha-mqtt", - "version": "1.0.0", - "description": "Home Assistant classes for integration with MQTT auto discovery", - "repository": + "$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json", + "name": "ha-mqtt", + "version": "1.0.1", + "description": "Home Assistant classes for integration with MQTT auto discovery", + "repository": { + "type": "git", + "url": "https://git.hodos.ro/arduino/ha-mqtt.git" + }, + "authors": [ { - "type": "git", - "url": "https://git.hodos.ro/arduino/ha-mqtt.git" - }, - "authors": - [ - { - "name": "Nicu Hodos", - "email": "nicu@hodos.ro", - "maintainer": true - } - ], - "dependencies": - { - "bblanchon/ArduinoJson": "6.21.5", - "arkhipenko/TaskScheduler": "^3.7.0", - "marvinroger/AsyncMqttClient": "^0.9.0" - }, - "license": "MIT", - "frameworks": "arduino", - "platforms": "*" - } + "name": "Nicu Hodos", + "email": "nicu@hodos.ro", + "maintainer": true + } + ], + "dependencies": { + "bblanchon/ArduinoJson": "6.21.5", + "marvinroger/AsyncMqttClient": "^0.9.0" + }, + "license": "MIT", + "frameworks": "arduino", + "platforms": "*" +} \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 4f63959..e4c000f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -30,6 +30,7 @@ struct List { delete c; c = n; } + first = last = nullptr; } }; From 48b33d5a587073f5667e72f734fb80f98288563c Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Sun, 30 Jun 2024 13:17:34 +0200 Subject: [PATCH 2/2] add tets for list --- .gitignore | 2 ++ platformio.ini | 16 ++++++++++++++++ test/README | 11 +++++++++++ test/utils.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 .gitignore create mode 100644 platformio.ini create mode 100644 test/README create mode 100644 test/utils.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..968a41b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.pio/ +.vscode/ diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..ad67c12 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +default_envs = native + +[env:native] +platform = native +debug_build_flags = -std=c++11 diff --git a/test/README b/test/README new file mode 100644 index 0000000..b94d089 --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/test/utils.cpp b/test/utils.cpp new file mode 100644 index 0000000..966d90c --- /dev/null +++ b/test/utils.cpp @@ -0,0 +1,42 @@ +#include +#include "utils.h" + +void setUp(void) { + // set stuff up here +} + +void tearDown(void) { + // clean stuff up here +} + +void test_add(void) { + List list; + int value = 10; + list.add(&value); + TEST_ASSERT_EQUAL(value, *list.last->t); + TEST_ASSERT_EQUAL_PTR(list.first, list.last); + + int value2 = 12; + list.add(&value2); + TEST_ASSERT_EQUAL(value2, *list.last->t); + TEST_ASSERT_EQUAL_PTR(list.first->next, list.last); +} + +void test_empty(void) { + List list; + int value = 10; + list.add(&value); + list.add(&value); + list.empty(); + TEST_ASSERT_EQUAL_PTR(nullptr, list.first); + TEST_ASSERT_EQUAL_PTR(list.first, list.last); +} + +int main(int argc, char **argv) { + UNITY_BEGIN(); + RUN_TEST(test_add); + RUN_TEST(test_empty); + UNITY_END(); + + return 0; +}