Commit 55c1e997 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Did get api tests

parent 84e695ae
Pipeline #6781 failed with stages
in 3 minutes and 45 seconds
#include "connectors/http.h"
#include <malloc.h>
#include <string.h>
static const char* set_token;
const char* get_set_token(void)
{
return set_token;
}
const char* set_token;
int door_http_initialize(const char* token)
{
set_token = token;
return 0;
}
void door_http_destroy(void)
......@@ -17,22 +15,27 @@ void door_http_destroy(void)
// nothing
}
static const char* get_path;
static door_http_callback_t* get_callback;
char* get_path;
door_http_callback_t* get_callback;
int http_get_return;
int door_http_get(const char* path, door_http_callback_t* callbacks)
void reset_module(void)
{
get_callback = callbacks;
get_path = path;
free((void*)get_path);
get_path = NULL;
}
static bool update_succeed;
void set_update_succeed(bool succeed)
int door_http_get(const char* path, door_http_callback_t* callbacks)
{
update_succeed = succeed;
get_callback = callbacks;
get_path = malloc(strlen(path));
// Plus 1 to include the null terminator
memcpy(get_path, path, strlen(path) + 1);
return http_get_return;
}
bool update_succeed;
bool door_http_ota_update(const char* api_token)
{
set_token = api_token;
......
#pragma ide diagnostic ignored "bugprone-infinite-loop"
#include <catch2/catch.hpp>
#include <cstring>
#include <string>
extern "C" {
#include "app/api.h"
#include "config.h"
extern int http_get_return;
extern const char* get_path;
void reset_module(void);
}
TEST_CASE("api makes request to correct end point with correct parameters", "[api]")
{
SECTION("testing succeed on http 200 response")
{
http_get_return = 200;
REQUIRE(door_api_verify_code("code"));
}
SECTION("testing fail on other http response")
{
http_get_return = -1;
REQUIRE_FALSE(door_api_verify_code("code"));
}
SECTION("testing url gets built correctly")
{
http_get_return = 1;
door_api_verify_code("code");
REQUIRE(strcmp(API_BASE_PATH "/access/code" , get_path) == 0);
}
SECTION("Testing up to max length codes")
{
http_get_return = 200;
std::string code(500, '1');
REQUIRE(door_api_verify_code(code.c_str()));
}
SECTION("testing codes that are too long")
{
http_get_return = 200;
std::string code(501, '1');
REQUIRE_FALSE(door_api_verify_code(code.c_str()));
}
reset_module();
}
#pragma ide diagnostic ignored "bugprone-infinite-loop"
#include <catch2/catch.hpp>
extern "C" {
#include "app/random.h"
void set_random_number(uint32_t number);
#include "app/random.h"
void set_random_number(uint32_t number);
}
TEST_CASE("random rescales ot min and max", "[application]") {
TEST_CASE("random rescales ot min and max", "[application]")
{
// Setup
set_random_number(500);
SECTION("testing min larger than given") {
SECTION("testing min larger than given")
{
int rand = door_random_get_random_between(1000, 2000);
REQUIRE(rand >= 1000);
REQUIRE(rand <= 2000);
}
SECTION("testing max smaller than given") {
SECTION("testing max smaller than given")
{
int rand = door_random_get_random_between(100, 200);
REQUIRE(rand >= 100);
REQUIRE(rand <= 200);
}
SECTION("testing when random number is in the range")
{
int rand = door_random_get_random_between(100, 1000);
REQUIRE(rand >= 100);
REQUIRE(rand <= 1000);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment