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 "dirtviz.hpp"
16
17void setUp(void) {}
18
19void tearDown(void) {}
20
21void TestHttpClient(void) {
22 std::string resp =
23 "HTTP/2 200\r\n"
24 "content-type: application/json\r\n"
25 "content-length: 59\r\n"
26 "date: Fri, 01 Nov 2024 23:53:02 GMT\r\n"
27 "access-control-allow-origin: *\r\n"
28 "server: gunicorn\r\n"
29 "x-cache: Miss from cloudfront\r\n"
30 "via: 1.1 4a628119373a320de50f1e6bc0e5f87a.cloudfront.net "
31 "(CloudFront)\r\n"
32 "x-amz-cf-pop: SFO5-P2\r\n"
33 "x-amz-cf-id: "
34 "t9EARJ8Hsu4FipZqiiVhsjwEU29sICEwjA7XMJNIOEXgOnJA-TlhdA==\r\n"
35 "\r\n"
36 "{\r\n"
37 " \"hello\": \"I'm alive and healthy! Super healthy :D\"\r\n"
38 "}\r\n";
39
40 std::string resp_data =
41 "{\r\n"
42 " \"hello\": \"I'm alive and healthy! Super healthy :D\"\r\n"
43 "}";
44
45 HttpClient client(resp);
46
47 TEST_ASSERT_EQUAL_STRING("HTTP/2", client.Version().c_str());
48 TEST_ASSERT_EQUAL(200, client.ResponseCode());
49
50 TEST_ASSERT_EQUAL_STRING("application/json",
51 client.Header("content-type").c_str());
52 TEST_ASSERT_EQUAL_STRING("59", client.Header("content-length").c_str());
53 TEST_ASSERT_EQUAL_STRING("Fri, 01 Nov 2024 23:53:02 GMT",
54 client.Header("date").c_str());
55
56 TEST_ASSERT_EQUAL_STRING(resp_data.c_str(), client.Data().c_str());
57}
58
59void setup() {
60 // NOTE!!! Wait for >2 secs
61 // if board doesn't support software reset via Serial.DTR/RTS
62 delay(2000);
63
64 UNITY_BEGIN();
65
66 RUN_TEST(TestHttpClient);
67
68 UNITY_END();
69}
70
71void loop() {}
HTTP request parser library.
Definition http.hpp:28
std::string Version()
Get the Http version.
Definition http.cpp:29
unsigned int ResponseCode()
Get the http response code.
Definition http.cpp:31
std::string Header(std::string header)
Get value of header.
Definition http.cpp:33
std::string Data()
Get data from Http request.
Definition http.cpp:35
void setup()
void setUp(void)
Definition test_main.cpp:23
void tearDown(void)
Definition test_main.cpp:32
void loop()
void TestHttpClient(void)
Definition test_main.cpp:21