Skip to content

Commit

Permalink
[#289] Add unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSomeMan committed Apr 17, 2024
1 parent d08a094 commit 4cb63ce
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions tests/test_http_server_resp/test_http_server_resp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TestHttpServerResp : public ::testing::Test
SetUp() override
{
this->m_idx_random_value = 0;
std::fill(arr_of_random_values.begin(), arr_of_random_values.end(), 0);
}

void
Expand All @@ -31,9 +32,10 @@ class TestHttpServerResp : public ::testing::Test
}

public:
const uint32_t* m_p_random_values;
size_t m_num_random_values;
size_t m_idx_random_value;
const uint32_t* m_p_random_values;
size_t m_num_random_values;
size_t m_idx_random_value;
std::array<uint32_t, 50> arr_of_random_values;

TestHttpServerResp();

Expand Down Expand Up @@ -346,3 +348,32 @@ TEST_F(TestHttpServerResp, resp_data_from_file_octet_stream) // NOLINT
ASSERT_EQ(HTTP_CONTENT_ENCODING_NONE, resp.content_encoding);
ASSERT_EQ(sock, resp.select_location.fatfs.fd);
}

TEST_F(TestHttpServerResp, test_http_server_resp_200_auth_allow_with_new_session_id) // NOLINT
{
const bool flag_no_cache = true;
const sta_ip_string_t remote_ip = { "192.168.1.110" };
const wifiman_hostinfo_t hostinfo = { .hostname = { "hostname" },
.fw_ver = { "v1.15.0" },
.nrf52_fw_ver = { "v1.0.0" } };
http_header_extra_fields_t extra_header_fields = { '\0' };

std::fill(arr_of_random_values.begin(), arr_of_random_values.end(), 0);
set_random_values(this->arr_of_random_values.data(), this->arr_of_random_values.size());

const http_server_resp_t resp = http_server_resp_200_auth_allow_with_new_session_id(
&remote_ip,
&hostinfo,
&extra_header_fields);
ASSERT_EQ(HTTP_RESP_CODE_200, resp.http_resp_code);
ASSERT_EQ(HTTP_CONTENT_LOCATION_STATIC_MEM, resp.content_location);
ASSERT_EQ(flag_no_cache, resp.flag_no_cache);
ASSERT_EQ(HTTP_CONTENT_TYPE_APPLICATION_JSON, resp.content_type);
ASSERT_EQ(nullptr, resp.p_content_type_param);
ASSERT_EQ(123, resp.content_len);
ASSERT_EQ(HTTP_CONTENT_ENCODING_NONE, resp.content_encoding);
ASSERT_EQ(
"{\"gateway_name\": \"hostname\", \"fw_ver\": \"v1.15.0\", \"nrf52_fw_ver\": \"v1.0.0\", \"lan_auth_type\": "
"\"lan_auth_allow\", \"lan\": true}",
string(reinterpret_cast<const char*>(resp.select_location.memory.p_buf)));
}

0 comments on commit 4cb63ce

Please sign in to comment.