ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
test_main.cpp
Go to the documentation of this file.
1
12#include <Arduino.h>
13#include <unity.h>
14
15#include "module_handler.hpp"
16#include "modules/wifi.hpp"
17
18// create handler
19static ModuleHandler::ModuleHandler module_handler;
20
21static ModuleWiFi module_wifi;
22
23void setUp(void) {
24 // zero out buffers
25 memset(module_handler_rx_buffer, 0, module_handler_buffer_size);
26 memset(module_handler_tx_buffer, 0, module_handler_buffer_size);
27}
28
29void tearDown(void) {}
30
32 module_handler.RegisterModule(Esp32Command_wifi_command_tag, &module_wifi);
33
34 bool mod_exist = true;
35
36 // check if module exists in map
37 try {
38 ModuleHandler::Module *mod = module_handler.GetModule(2);
39 } catch (const std::out_of_range &oor) {
40 mod_exist = false;
41 }
42
43 TEST_ASSERT_TRUE_MESSAGE(mod_exist, "Module does not exist after register");
44}
45
46void test_Connect(void) {
47 // send WiFi command with just type = connect
48 // sps encode --c esp32command wifi --ssid ents-testing --passwd
49 // securepassword --url 10.42.0.1 --port 8080 connect
50 uint8_t data[] = {0x1a, 0x2c, 0x12, 0xc, 0x65, 0x6e, 0x74, 0x73, 0x2d, 0x74,
51 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x1a, 0xe, 0x73, 0x65,
52 0x63, 0x75, 0x72, 0x65, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f,
53 0x72, 0x64, 0x22, 0x9, 0x31, 0x30, 0x2e, 0x34, 0x32, 0x2e,
54 0x30, 0x2e, 0x31, 0x40, 0x90, 0x3f};
55 size_t data_len = 46;
56
57 memcpy(module_handler_rx_buffer, cmd, cmd_len);
58
59 module_handler.OnReceive(cmd_len);
60
61 ModuleHandler::Module *mod = module_handler.GetModule(2);
62 TEST_ASSERT_EQUAL(ModuleWiFi::CONNECT, mod->State());
63
64 // TODO(jtmadden) finish tests
65}
66
67void test_Post(void) {}
68
70 module_handler.RegisterModule(Esp32Command_wifi_command_tag);
71
72 bool mod_exist = true;
73
74 // check that module doesn't exist anymore
75 try {
76 // get the module of that message type
77 ModuleHandler::Module *mod = module_handler.GetModule(2);
78 } catch (const std::out_of_range &oor) {
79 mod_exist = false;
80 }
81
82 TEST_ASSERT_TRUE_MESSAGE(mod_exist, "Module exists after deregister");
83}
84
85void setup() {
86 // NOTE!!! Wait for >2 secs
87 // if board doesn't support software reset via Serial.DTR/RTS
88 delay(2000);
89
90 UNITY_BEGIN();
91
92 RUN_TEST(test_true);
93
94 UNITY_END();
95}
96
97void loop() {}
Interface for the module handler.
Module * GetModule(int type)
Get the module associated with a specific message type.
void OnReceive(size_t num_bytes)
Arduino I2C onRecieve.
void RegisterModule(Module *module)
Register a module with a message type.
Class prototype for modules.
int State(void)
Get the current state of the module.
WiFi module for the esp32.
Definition wifi.hpp:37
const size_t data_len
const char data[]
void setup()
void setUp(void)
Definition test_main.cpp:23
void tearDown(void)
Definition test_main.cpp:32
void loop()
void test_DeregisterModule(void)
Definition test_main.cpp:69
void test_RegisterModule(void)
Definition test_main.cpp:31
void test_Connect(void)
Definition test_main.cpp:46
void test_Post(void)
Definition test_main.cpp:67
Interface for controlling the esp32.
void test_true(void)
Definition test_main.cpp:19
Module for WiFi communication.