ifw-daq  1.0.0
IFW Data Acquisition modules
testState.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libdaq_test
4  * @copyright 2021 ESO - European Southern Observatory
5  *
6  * @brief Test State functions.
7  */
8 #include <gtest/gtest.h>
9 #include <daq/state.hpp>
10 
11 #include <fmt/format.h>
12 #include <fmt/ostream.h>
13 
14 using daq::State;
15 
16 
17 TEST(State, TestFormatString) {
18  EXPECT_EQ("NotStarted", fmt::format("{}", State::NotStarted));
19  EXPECT_EQ("Starting", fmt::format("{}", State::Starting));
20  EXPECT_EQ("Acquiring", fmt::format("{}", State::Acquiring));
21  EXPECT_EQ("Stopping", fmt::format("{}", State::Stopping));
22  EXPECT_EQ("Stopped", fmt::format("{}", State::Stopped));
23  EXPECT_EQ("Aborting", fmt::format("{}", State::Aborting));
24  EXPECT_EQ("Aborted", fmt::format("{}", State::Aborted));
25 }
26 
27 
29  // Setup
30  auto standard_without_final = {
31  State::NotStarted, State::Starting, State::Acquiring, State::Stopping};
32 
33  // Test
34  EXPECT_FALSE(daq::IsSubsequentState(State::Aborting, State::Aborted));
35  EXPECT_TRUE(daq::IsSubsequentState(State::Aborted, State::Aborting));
36 
37  EXPECT_TRUE(daq::IsSubsequentState(State::Starting, State::NotStarted));
38  EXPECT_TRUE(daq::IsSubsequentState(State::Acquiring, State::Starting));
39  EXPECT_TRUE(daq::IsSubsequentState(State::Stopping, State::Acquiring));
40 
41 
42  // Standard life-cycle states (excluding the final state)
43  for (auto state : standard_without_final) {
44  // Final states always comes after any other
45  EXPECT_TRUE(daq::IsSubsequentState(State::Stopped, state));
46  EXPECT_TRUE(daq::IsSubsequentState(State::Aborted, state));
47 
48  EXPECT_FALSE(daq::IsSubsequentState(state, State::Stopped));
49  EXPECT_FALSE(daq::IsSubsequentState(state, State::Aborted));
50  EXPECT_FALSE(daq::IsSubsequentState(state, state));
51  }
52 }
daq::State
State
Observable states of the data acquisition process.
Definition: state.hpp:41
TEST
TEST(State, TestFormatString)
Definition: testState.cpp:17
daq::IsSubsequentState
bool IsSubsequentState(State state, State after) noexcept
Compares states and returns whether state occurs after after.
Definition: state.cpp:25
state.hpp
Declares daq::State and related functions.