API
 
Loading...
Searching...
No Matches
observer_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/observer.hpp"
5#include "../types/generated/observer_generated.h"
6#include "../types/flatbuffer_log.hpp"
7
8/*
9 * GENERATED TEST FILE for types/observer.hpp
10 * generated by generateTemplateCatch2Tests.py
11 */
12
13const std::string observerFullName_0 = "95t8z20yef"; // dummy fullName
14const std::string observerPfoa_0 = "4q3nk232em"; // dummy pfoa
15const std::string observerEmail_0 = "fgbp9s9ej8"; // dummy email
16const std::string observerInstitution_0 = "b5dgg3w1d6"; // dummy institution
17
18
19/** Class to encapsulate observer flatbuffer data using
20 ** => types/observer.hpp
21 ** => types/generated/observer_generated.h
22 **/
24{
25public:
26 // Saved input parameter value; unused
27 std::string m_saveOFullName;
28 std::string m_saveOPfoa;
29 std::string m_saveOEmail;
30 std::string m_saveOInstitution;
31
32 // Parameters retrieved from flatbuffer
33 std::string m_fullName;
34 std::string m_pfoa;
35 std::string m_email;
36 std::string m_institution;
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 CObserver_0(std::string fullName_, std::string pfoa_, std::string email_, std::string institution_) {
46 // Save input parameters
47 m_saveOFullName = fullName_;
48 m_saveOPfoa = pfoa_;
49 m_saveOEmail = email_;
50 m_saveOInstitution = institution_;
51
52 // Create the flatbuffer messageT using the input parameters
53 auto o = MagAOX::logger::observer::messageT(fullName_, pfoa_, email_, institution_);
54
55 // Retrieve flatbuffer pointer (if not an empty_log type) and length
56 void* buffPtr = o.builder.GetBufferPointer();
58
59 // Retrieve the flatbuffer parameters for Catch2 comparison below
60 m_fullName = std::string(MagAOX::logger::GetObserver_fb(buffPtr)->fullName()->c_str());
61 m_pfoa = std::string(MagAOX::logger::GetObserver_fb(buffPtr)->pfoa()->c_str());
62 m_email = std::string(MagAOX::logger::GetObserver_fb(buffPtr)->email()->c_str());
63 m_institution = std::string(MagAOX::logger::GetObserver_fb(buffPtr)->institution()->c_str());
64
65 // Run the observer verifier
66 m_verify = verify(o);
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::observer::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::observer>(logBuffer
88 , tsx, msg
89 , prio);
90 // Run full log through flatbuffer Verifier
91 return MagAOX::logger::observer::verify(logBuffer,L);
92 }
93};
94
95SCENARIO( "Create observer 0", "[a log item]")
96{
97 GIVEN("a observer log code")
98 {
99 WHEN("random values for fields")
100 {
101 // Create flatbuffer
103 // Compare flatbuffer parameters
104 REQUIRE(o.m_fullName == observerFullName_0);
105 REQUIRE(o.m_pfoa == observerPfoa_0);
106 REQUIRE(o.m_email == observerEmail_0);
108 REQUIRE(o.m_verify);
109 }
110 }
111}
112
113
CObserver_0(std::string fullName_, std::string pfoa_, std::string email_, std::string institution_)
bool verify(const typename MagAOX::logger::observer::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::Observer_fb * GetObserver_fb(const void *buf)
static constexpr logPrioT LOG_DEFAULT
Used to denote "use the default level for this log type".
const std::string observerPfoa_0
SCENARIO("Create observer 0", "[a log item]")
const std::string observerFullName_0
const std::string observerInstitution_0
const std::string observerEmail_0
static flatlogs::msgLenT length(const fbMessage &msg)
Get the length of the message.
The type of the input message.
Definition observer.hpp:39
static bool verify(flatlogs::bufferPtrT &logBuff, flatlogs::msgLenT len)
Definition observer.hpp:58
A fixed-width timespec structure.
Definition timespecX.hpp:35