API
 
Loading...
Searching...
No Matches
config_log_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/config_log.hpp"
5#include "../types/generated/config_log_generated.h"
6#include "../types/flatbuffer_log.hpp"
7
8/*
9 * GENERATED TEST FILE for types/config_log.hpp
10 * generated by generateTemplateCatch2Tests.py
11 */
12
13const std::string configLogName_0 = "dgfdouaqp1"; // dummy name
14const int configLogCode_0 = -159854815; // dummy code
15const std::string configLogValue_0 = "dvdxleu0n9"; // dummy value
16const std::string configLogSource_0 = "cg8bqrt8li"; // dummy source
17
18
19/** Class to encapsulate config_log flatbuffer data using
20 ** => types/config_log.hpp
21 ** => types/generated/config_log_generated.h
22 **/
24{
25public:
26 // Saved input parameter value; unused
27 std::string m_saveClName;
29 std::string m_saveClValue;
30 std::string m_saveClSource;
31
32 // Parameters retrieved from flatbuffer
33 std::string m_name;
34 int m_code;
35 std::string m_value;
36 std::string m_source;
37
38 // Flatbuffers verifier success/failure
39 bool m_verify{false};
40
41 // flatbuffer data length; used in ::verify
42 int L;
43
44 // Constructor
45 CConfigLog_0(std::string name_, int code_, std::string value_, std::string source_) {
46 // Save input parameters
47 m_saveClName = name_;
48 m_saveClCode = code_;
49 m_saveClValue = value_;
50 m_saveClSource = source_;
51
52 // Create the flatbuffer messageT using the input parameters
53 auto cl = MagAOX::logger::config_log::messageT(name_, code_, value_, source_);
54
55 // Retrieve flatbuffer pointer (if not an empty_log type) and length
56 void* buffPtr = cl.builder.GetBufferPointer();
58
59 // Retrieve the flatbuffer parameters for Catch2 comparison below
60 m_name = std::string(MagAOX::logger::GetConfig_log_fb(buffPtr)->name()->c_str());
62 m_value = std::string(MagAOX::logger::GetConfig_log_fb(buffPtr)->value()->c_str());
63 m_source = std::string(MagAOX::logger::GetConfig_log_fb(buffPtr)->source()->c_str());
64
65 // Run the config_log verifier
66 m_verify = verify(cl);
67 }
68
69 // Run the flatbuffer Verifier for this log type
70 // - requires bufferPtrT (shared_ptr<char*>) to full log entry
71 // comprising log header plus flatbuffer log message
72 bool verify(const typename MagAOX::logger::config_log::messageT& msg) {
73
74 // Timestamp, prioriy (use nominal value here)
75 flatlogs::timespecX tsx{0,0};
77
78 // Create full log: log header(*); log message (+)
79 // * Log level (priority)
80 // * Event code (implicit in <MagAOX::logger::type>)
81 // * Timestamp
82 // * Message size (variable length; 1, 2, or 8 bytes)
83 // + Message (variable length)
84
85 // N.G. allocates space and writes pointer value to logBuffer
86 flatlogs::bufferPtrT logBuffer;
87 flatlogs::logHeader::createLog<MagAOX::logger::config_log>(logBuffer
88 , tsx, msg
89 , prio);
90 // Run full log through flatbuffer Verifier
91 return MagAOX::logger::config_log::verify(logBuffer,L);
92 }
93};
94
95SCENARIO( "Create config_log 0", "[a log item]")
96{
97 GIVEN("a config_log log code")
98 {
99 WHEN("random values for fields")
100 {
101 // Create flatbuffer
103 // Compare flatbuffer parameters
104 REQUIRE(cl.m_name == configLogName_0);
105 REQUIRE(cl.m_code == configLogCode_0);
106 REQUIRE(cl.m_value == configLogValue_0);
107 REQUIRE(cl.m_source == configLogSource_0);
108 REQUIRE(cl.m_verify);
109 }
110 }
111}
112
113
bool verify(const typename MagAOX::logger::config_log::messageT &msg)
CConfigLog_0(std::string name_, int code_, std::string value_, std::string source_)
const std::string configLogSource_0
const int configLogCode_0
const std::string configLogName_0
SCENARIO("Create config_log 0", "[a log item]")
const std::string configLogValue_0
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::Config_log_fb * GetConfig_log_fb(const void *buf)
static constexpr logPrioT LOG_DEFAULT
Used to denote "use the default level for this log type".
The type of the input message.
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
static flatlogs::msgLenT length(const fbMessage &msg)
Get the length of the message.
A fixed-width timespec structure.
Definition timespecX.hpp:35