API
 
Loading...
Searching...
No Matches
ocam_temps_generated_tests.cpp
Go to the documentation of this file.
1#include <assert.h>
2#include "../../../../tests/catch2/catch.hpp"
3#include "../generated/logCodes.hpp"
4#include "../types/ocam_temps.hpp"
5#include "../types/generated/ocam_temps_generated.h"
6#include "../types/flatbuffer_log.hpp"
7
8/*
9 * GENERATED TEST FILE for types/ocam_temps.hpp
10 * generated by generateTemplateCatch2Tests.py
11 */
12
13const float ocamTempsCcd_0 = 0.69765; // dummy ccd
14const float ocamTempsCpu_0 = 0.729808; // dummy cpu
15const float ocamTempsPower_0 = 0.763519; // dummy power
16const float ocamTempsBias_0 = 0.996292; // dummy bias
17const float ocamTempsWater_0 = 0.420266; // dummy water
18const float ocamTempsLeft_0 = 0.033949; // dummy left
19const float ocamTempsRight_0 = 0.404133; // dummy right
20const float ocamTempsCooling_0 = 0.131155; // dummy cooling
21
22
23/** Class to encapsulate ocam_temps flatbuffer data using
24 ** => types/ocam_temps.hpp
25 ** => types/generated/ocam_temps_generated.h
26 **/
28{
29public:
30 // Saved input parameter value; unused
39
40 // Parameters retrieved from flatbuffer
41 float m_ccd;
42 float m_cpu;
43 float m_power;
44 float m_bias;
45 float m_water;
46 float m_left;
47 float m_right;
48 float m_cooling;
49
50 // Flatbuffers verifier success/failure
51 bool m_verify{false};
52
53 // flatbuffer data length; used in ::verify
54 int L;
55
56 // Constructor
57 COcamTemps_0(float ccd_, float cpu_, float power_, float bias_, float water_, float left_, float right_, float cooling_) {
58 // Save input parameters
59 m_saveOtCcd = ccd_;
60 m_saveOtCpu = cpu_;
61 m_saveOtPower = power_;
62 m_saveOtBias = bias_;
63 m_saveOtWater = water_;
64 m_saveOtLeft = left_;
65 m_saveOtRight = right_;
66 m_saveOtCooling = cooling_;
67
68 // Create the flatbuffer messageT using the input parameters
69 auto ot = MagAOX::logger::ocam_temps::messageT(ccd_, cpu_, power_, bias_, water_, left_, right_, cooling_);
70
71 // Retrieve flatbuffer pointer (if not an empty_log type) and length
72 void* buffPtr = ot.builder.GetBufferPointer();
74
75 // Retrieve the flatbuffer parameters for Catch2 comparison below
78 m_power = MagAOX::logger::GetOcam_temps_fb(buffPtr)->power();
80 m_water = MagAOX::logger::GetOcam_temps_fb(buffPtr)->water();
82 m_right = MagAOX::logger::GetOcam_temps_fb(buffPtr)->right();
83 m_cooling = MagAOX::logger::GetOcam_temps_fb(buffPtr)->cooling();
84
85 // Run the ocam_temps verifier
86 m_verify = verify(ot);
87 }
88
89 // Run the flatbuffer Verifier for this log type
90 // - requires bufferPtrT (shared_ptr<char*>) to full log entry
91 // comprising log header plus flatbuffer log message
92 bool verify(const typename MagAOX::logger::ocam_temps::messageT& msg) {
93
94 // Timestamp, prioriy (use nominal value here)
95 flatlogs::timespecX tsx{0,0};
97
98 // Create full log: log header(*); log message (+)
99 // * Log level (priority)
100 // * Event code (implicit in <MagAOX::logger::type>)
101 // * Timestamp
102 // * Message size (variable length; 1, 2, or 8 bytes)
103 // + Message (variable length)
104
105 // N.G. allocates space and writes pointer value to logBuffer
106 flatlogs::bufferPtrT logBuffer;
107 flatlogs::logHeader::createLog<MagAOX::logger::ocam_temps>(logBuffer
108 , tsx, msg
109 , prio);
110 // Run full log through flatbuffer Verifier
111 return MagAOX::logger::ocam_temps::verify(logBuffer,L);
112 }
113};
114
115SCENARIO( "Create ocam_temps 0", "[a log item]")
116{
117 GIVEN("a ocam_temps log code")
118 {
119 WHEN("random values for fields")
120 {
121 // Create flatbuffer
123 // Compare flatbuffer parameters
124 REQUIRE(ot.m_ccd == ocamTempsCcd_0);
125 REQUIRE(ot.m_cpu == ocamTempsCpu_0);
126 REQUIRE(ot.m_power == ocamTempsPower_0);
127 REQUIRE(ot.m_bias == ocamTempsBias_0);
128 REQUIRE(ot.m_water == ocamTempsWater_0);
129 REQUIRE(ot.m_left == ocamTempsLeft_0);
130 REQUIRE(ot.m_right == ocamTempsRight_0);
131 REQUIRE(ot.m_cooling == ocamTempsCooling_0);
132 REQUIRE(ot.m_verify);
133 }
134 }
135}
136
137
COcamTemps_0(float ccd_, float cpu_, float power_, float bias_, float water_, float left_, float right_, float cooling_)
bool verify(const typename MagAOX::logger::ocam_temps::messageT &msg)
int8_t logPrioT
The type of the log priority code.
Definition logDefs.hpp:21
std::shared_ptr< char > bufferPtrT
The log entry buffer smart pointer.
Definition logHeader.hpp:58
const MagAOX::logger::Ocam_temps_fb * GetOcam_temps_fb(const void *buf)
static constexpr logPrioT LOG_DEFAULT
Used to denote "use the default level for this log type".
const float ocamTempsWater_0
const float ocamTempsRight_0
SCENARIO("Create ocam_temps 0", "[a log item]")
const float ocamTempsCcd_0
const float ocamTempsCooling_0
const float ocamTempsPower_0
const float ocamTempsLeft_0
const float ocamTempsBias_0
const float ocamTempsCpu_0
static flatlogs::msgLenT length(const fbMessage &msg)
Get the length of the message.
The type of the input message.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
A fixed-width timespec structure.
Definition timespecX.hpp:35