From 5784e38fbbb804a25643a6523fb36090ebff6b81 Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 24 Apr 2023 12:22:52 +0200 Subject: [PATCH] feat: add Test for WifiConnect API --- .vscode/settings.json | 13 +++++++++++++ IOT/envs.ini | 6 ++++++ IOT/secrets.ini.example | 12 ------------ IOT/src/main.cpp | 8 ++++++-- IOT/test/main.cpp | 20 ++++++++++++++++++++ IOT/test/test.h | 7 +++++++ IOT/test/test_api.cpp | 19 +++++++++++++++++++ 7 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 IOT/secrets.ini.example create mode 100644 IOT/test/main.cpp create mode 100644 IOT/test/test.h create mode 100644 IOT/test/test_api.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a341e93 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.associations": { + "__bit_reference": "cpp", + "__hash_table": "cpp", + "__split_buffer": "cpp", + "array": "cpp", + "initializer_list": "cpp", + "string": "cpp", + "string_view": "cpp", + "unordered_map": "cpp", + "vector": "cpp" + } +} \ No newline at end of file diff --git a/IOT/envs.ini b/IOT/envs.ini index b3db1a7..1bbf9b6 100644 --- a/IOT/envs.ini +++ b/IOT/envs.ini @@ -1,4 +1,10 @@ ; Add additionnal environments in this file +; Debug environemnt +[env:test] +test_build_src = true +build_type = debug +build_flags = ${env.build_flags} + -D TESTING ; Default production environment [env:prod] diff --git a/IOT/secrets.ini.example b/IOT/secrets.ini.example deleted file mode 100644 index b517f84..0000000 --- a/IOT/secrets.ini.example +++ /dev/null @@ -1,12 +0,0 @@ -; Add secrets token/logins/etc `secrets.ini` -; Add the sames values as blank in `secrets.ini.example -; To be able to reproduce it - -[secrets] -build_flags = - - -D WIFI_SSID=\"...\" - -D WIFI_PASSWORD=\"...\"4 - - -D USER_NAME=\"...\" - -D USER_PASSWORD=\"...\" \ No newline at end of file diff --git a/IOT/src/main.cpp b/IOT/src/main.cpp index 14f34bd..4f7861c 100644 --- a/IOT/src/main.cpp +++ b/IOT/src/main.cpp @@ -1,12 +1,16 @@ +#ifndef TESTING + #include #include "Program.h" Program* program; void setup() { - program = new Program(); + program = new Program(); } void loop() { - program->loop(); + program->loop(); } + +#endif \ No newline at end of file diff --git a/IOT/test/main.cpp b/IOT/test/main.cpp new file mode 100644 index 0000000..6683380 --- /dev/null +++ b/IOT/test/main.cpp @@ -0,0 +1,20 @@ +#include +#include +#include "test.h" +void setup() { + delay(2000); + // start unit tests engine + UNITY_BEGIN(); + Serial.begin(115200); + RUN_TEST(TestWifiBeginConnected); + RUN_TEST(TestWifiBeginNotConnected); + + + UNITY_END(); +} + + + +void loop() { + +} \ No newline at end of file diff --git a/IOT/test/test.h b/IOT/test/test.h new file mode 100644 index 0000000..6795825 --- /dev/null +++ b/IOT/test/test.h @@ -0,0 +1,7 @@ +#ifndef TEST_H +#define TEST_H + +void TestWifiBeginConnected(); +void TestWifiBeginNotConnected(); + +#endif \ No newline at end of file diff --git a/IOT/test/test_api.cpp b/IOT/test/test_api.cpp new file mode 100644 index 0000000..0f08f49 --- /dev/null +++ b/IOT/test/test_api.cpp @@ -0,0 +1,19 @@ +#include "test.h" +#include +#include "API.h" + +void TestWifiBeginConnected() { + API* api = new API(USER_NAME, USER_PASSWORD, API_HOST); + + Serial1.begin(MONITOR_SPEED); + TEST_ASSERT_EQUAL_MESSAGE(true, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1), "Wifi not connected"); + +} + +void TestWifiBeginNotConnected() { + API* api = new API(USER_NAME, USER_PASSWORD, API_HOST); + + Serial2.begin(MONITOR_SPEED); + TEST_ASSERT_EQUAL_MESSAGE(false, api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial2), "Wifi connected"); + +} \ No newline at end of file