68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#include <unity.h>
|
|
#include <ArduinoJson.h>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include "test_bitaxe_parser.hpp"
|
|
|
|
void setUp(void)
|
|
{
|
|
// Setup code
|
|
}
|
|
|
|
void tearDown(void)
|
|
{
|
|
// Cleanup code
|
|
}
|
|
|
|
void test_bitaxe_api(void)
|
|
{
|
|
JsonDocument doc;
|
|
|
|
std::ifstream file("test/test_json/data/bitaxe_2_3_0.json");
|
|
std::string json((std::istreambuf_iterator<char>(file)),
|
|
std::istreambuf_iterator<char>());
|
|
|
|
DeserializationError error = deserializeJson(doc, json);
|
|
std::string bitaxeHashrate = std::to_string(static_cast<int>(std::round(doc["hashRate"].as<float>())));
|
|
std::string bitaxeBestDiff = doc["bestDiff"].as<std::string>();
|
|
String testInput = "{\"test\":\"data\"}";
|
|
|
|
bitaxeParseApiResponse(testInput);
|
|
|
|
TEST_ASSERT_EQUAL_STRING(bitaxeHashrate.c_str(), std::string("690").c_str());
|
|
}
|
|
|
|
void test_braiins_api(void)
|
|
{
|
|
JsonDocument doc;
|
|
|
|
std::ifstream file("test/test_json/data/20241219-test-braiins.json");
|
|
std::string json((std::istreambuf_iterator<char>(file)),
|
|
std::istreambuf_iterator<char>());
|
|
|
|
DeserializationError error = deserializeJson(doc, json);
|
|
|
|
TEST_ASSERT_EQUAL(DeserializationError::Ok, error.code());
|
|
}
|
|
|
|
void test_ocean_api(void)
|
|
{
|
|
JsonDocument doc;
|
|
|
|
std::ifstream file("test/test_json/data/20241219-test-ocean-api.json");
|
|
std::string json((std::istreambuf_iterator<char>(file)),
|
|
std::istreambuf_iterator<char>());
|
|
|
|
DeserializationError error = deserializeJson(doc, json);
|
|
|
|
TEST_ASSERT_EQUAL(DeserializationError::Ok, error.code());
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_bitaxe_api);
|
|
RUN_TEST(test_braiins_api);
|
|
RUN_TEST(test_ocean_api);
|
|
return UNITY_END();
|
|
}
|