Skip to content
Snippets Groups Projects
Commit 8844c266 authored by Matt Clarke_1's avatar Matt Clarke_1
Browse files

Merge branch 'backfill_tests' into 'main'

Backfill tests for json to data generators

See merge request !878
parents dc2ef8a5 fa6d0a9d
No related branches found
No related tags found
1 merge request!878Backfill tests for json to data generators
Pipeline #208058 passed
......@@ -65,7 +65,7 @@
"connection_status": "ConnectionInfo::CONNECTED",
"timestamp": 10111
},
{
{
"schema": "al00",
"topic": "local_choppers",
"kafka_timestamp": 10112,
......
......@@ -8,7 +8,10 @@
// Screaming Udder! https://esss.se
#include <FlatBufferGenerators.h>
#include <ad00_area_detector_array_generated.h>
#include <al00_alarm_generated.h>
#include <da00_dataarray_generated.h>
#include <ep01_epics_connection_generated.h>
#include <ev44_events_generated.h>
#include <f144_logdata_generated.h>
#include <gtest/gtest.h>
......@@ -41,6 +44,31 @@ std::string const example_json = R"(
"name": "signal",
"axis_name": "x",
"data": [4, 3, 2, 1, 2, 3, 4]
},
{
"schema": "ad00",
"topic": "local_detector",
"kafka_timestamp": 10310,
"source_name": "image_data",
"timestamp": 10310,
"data": [[13, 12], [11, 10]]
},
{
"schema": "ep01",
"topic": "local_choppers",
"kafka_timestamp": 10111,
"source_name": "local:choppers:rotation_speed",
"connection_status": "ConnectionInfo::CONNECTED",
"timestamp": 10111
},
{
"schema": "al00",
"topic": "local_choppers",
"kafka_timestamp": 10112,
"source_name": "local:choppers:rotation_speed",
"timestamp": 10112,
"severity": "Severity::OK",
"message": "Chopper speed is perfect"
}
]
)";
......@@ -96,4 +124,43 @@ TEST(json_to_fb, can_create_da00_buffer) {
ASSERT_EQ(4, data_array[6]);
}
// TODO: ep00, al00 and ad00 tests needed
TEST(json_to_fb, can_create_ad00_buffer) {
json data = json::parse(example_json);
json item = data[3];
std::pair<std::unique_ptr<uint8_t[]>, size_t> raw_flatbuffer =
FlatBuffers::convert_to_raw_flatbuffer(item);
uint8_t *buffer = raw_flatbuffer.first.get();
auto fb = Getad00_ADArray(buffer);
ASSERT_EQ("image_data", fb->source_name()->str());
ASSERT_EQ(10310000000, fb->timestamp());
auto data_array = reinterpret_cast<const uint16_t *>(fb->data()->data());
ASSERT_EQ(13, data_array[0]);
ASSERT_EQ(12, data_array[1]);
ASSERT_EQ(11, data_array[2]);
ASSERT_EQ(10, data_array[3]);
}
TEST(json_to_fb, can_create_ep01_buffer) {
json data = json::parse(example_json);
json item = data[4];
std::pair<std::unique_ptr<uint8_t[]>, size_t> raw_flatbuffer =
FlatBuffers::convert_to_raw_flatbuffer(item);
uint8_t *buffer = raw_flatbuffer.first.get();
auto fb = GetEpicsPVConnectionInfo(buffer);
ASSERT_EQ("local:choppers:rotation_speed", fb->source_name()->str());
ASSERT_EQ(10111000000, fb->timestamp());
ASSERT_EQ(ConnectionInfo::CONNECTED, fb->status());
}
TEST(json_to_fb, can_create_al00_buffer) {
json data = json::parse(example_json);
json item = data[5];
std::pair<std::unique_ptr<uint8_t[]>, size_t> raw_flatbuffer =
FlatBuffers::convert_to_raw_flatbuffer(item);
uint8_t *buffer = raw_flatbuffer.first.get();
auto fb = GetAlarm(buffer);
ASSERT_EQ("local:choppers:rotation_speed", fb->source_name()->str());
ASSERT_EQ(10112000000, fb->timestamp());
ASSERT_EQ(Severity::OK, fb->severity());
ASSERT_EQ("Chopper speed is perfect", fb->message()->str());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment