Merge pull request 'feat: Test_IOT' (#40) from feat/Test_IOT into master
Reviewed-on: Epitech-T-DEV-811/T-DEV-811#40 Reviewed-by: nico <nicolas.sansd@gmail.com> Reviewed-by: Clement <clement@jo85.com>
This commit is contained in:
commit
17b344732f
@ -21,3 +21,5 @@ build_flags =
|
||||
|
||||
-D EXAMPLE_NUMBER=69
|
||||
|
||||
-D TRASHCAN_ONE=\"gdnuxl0wlgurtj3\"
|
||||
|
||||
|
@ -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]
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Ultrasonic.h>
|
||||
#include "API.h"
|
||||
|
||||
class Program{
|
||||
public:
|
||||
@ -26,5 +27,11 @@ private:
|
||||
*
|
||||
*/
|
||||
Ultrasonic *ultrasonic;
|
||||
|
||||
/**
|
||||
* @brief Réference de l'API pour les calls
|
||||
*
|
||||
*/
|
||||
API *api;
|
||||
};
|
||||
#endif
|
@ -41,8 +41,6 @@ public:
|
||||
*/
|
||||
bool sendValue(String val, String poubelleID, String unit, bool full);
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief connect l'utilisateur a l'api et met a jour le token
|
||||
*
|
||||
@ -51,6 +49,11 @@ private:
|
||||
*/
|
||||
bool connect();
|
||||
|
||||
//TODO :: Check wifibegin avant
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* @brief ID de l'utilisateur
|
||||
*
|
||||
|
@ -59,7 +59,8 @@ bool API::connect(){
|
||||
this->client->println();
|
||||
|
||||
|
||||
while (!client->available()) {}
|
||||
while (!client->available()) {
|
||||
}
|
||||
|
||||
String responce = "";
|
||||
while (client->available()) {
|
||||
@ -77,7 +78,10 @@ bool API::connect(){
|
||||
this->client->stop();
|
||||
|
||||
sortie = true;
|
||||
|
||||
if (JSONVar::stringify(JSONVar::parse(str)["code"]) == "400") {
|
||||
Serial.println("Failed to authenticate");
|
||||
return false;
|
||||
}
|
||||
return sortie;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
#include "Program.h"
|
||||
|
||||
|
||||
int distance;
|
||||
|
||||
|
||||
Program::Program(){
|
||||
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
|
||||
Serial1.begin(MONITOR_SPEED);
|
||||
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
||||
|
||||
Serial.begin(MONITOR_SPEED);
|
||||
this->ultrasonic = new Ultrasonic(ULTRA_SOUND_TRIGD, ULTRA_SOUND_ECHO);
|
||||
}
|
||||
@ -12,7 +15,8 @@ Program::Program(){
|
||||
void Program::loop(){
|
||||
distance = this->ultrasonic->read();
|
||||
|
||||
this->api->sendValue(JSONVar::stringify(distance), TRASHCAN_ONE, "W", false);
|
||||
Serial.print("Distance in CM: ");
|
||||
Serial.println(distance);
|
||||
delay(1000);
|
||||
delay(10000);
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
#ifndef TESTING
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Program.h"
|
||||
|
||||
@ -10,3 +12,5 @@ void setup() {
|
||||
void loop() {
|
||||
program->loop();
|
||||
}
|
||||
|
||||
#endif
|
23
IOT/test/main.cpp
Normal file
23
IOT/test/main.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <Arduino.h>
|
||||
#include <unity.h>
|
||||
#include "test.h"
|
||||
void setup() {
|
||||
delay(2000);
|
||||
// start unit tests engine
|
||||
UNITY_BEGIN();
|
||||
Serial.begin(115200);
|
||||
RUN_TEST(TestWifiBeginConnected);
|
||||
RUN_TEST(TestWifiBeginNotConnected);
|
||||
RUN_TEST(TestConnectAPI);
|
||||
// RUN_TEST(TestConnectAPIFailed);
|
||||
RUN_TEST(TestSendValue);
|
||||
|
||||
|
||||
UNITY_END();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
10
IOT/test/test.h
Normal file
10
IOT/test/test.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
|
||||
void TestWifiBeginConnected();
|
||||
void TestWifiBeginNotConnected();
|
||||
void TestConnectAPI();
|
||||
void TestConnectAPIFailed();
|
||||
void TestSendValue();
|
||||
|
||||
#endif
|
48
IOT/test/test_api.cpp
Normal file
48
IOT/test/test_api.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "test.h"
|
||||
#include <unity.h>
|
||||
#include "API.h"
|
||||
|
||||
|
||||
//Testing WifiBegin function
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
//Testing Connect function
|
||||
void TestConnectAPI() {
|
||||
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
|
||||
|
||||
Serial1.begin(MONITOR_SPEED);
|
||||
api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(true, api->connect(), "Not Connected");
|
||||
}
|
||||
|
||||
//FIXME: boucle inf when connection failed
|
||||
void TestConnectAPIFailed() {
|
||||
API* api = new API("Carl", "toto", API_HOST);
|
||||
|
||||
Serial1.begin(MONITOR_SPEED);
|
||||
api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(false, api->connect(), "Connected");
|
||||
}
|
||||
|
||||
//Testing SendValue function
|
||||
void TestSendValue() {
|
||||
API* api = new API(USER_NAME, USER_PASSWORD, API_HOST);
|
||||
|
||||
Serial1.begin(MONITOR_SPEED);
|
||||
api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(true, api->sendValue("30", "gdnuxl0wlgurtj3", "W", true), "Not Connected to server");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user