ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
testState.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libdaq_test
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief Test State functions.
7  */
8 #include <daq/state.hpp>
9 #include <gtest/gtest.h>
10 
11 #include <fmt/format.h>
12 #include <fmt/ostream.h>
13 
14 using daq::State;
15 
16 TEST(State, TestFormatString) {
17  EXPECT_EQ("NotStarted", fmt::format("{}", State::NotStarted));
18  EXPECT_EQ("Starting", fmt::format("{}", State::Starting));
19  EXPECT_EQ("Acquiring", fmt::format("{}", State::Acquiring));
20  EXPECT_EQ("Stopping", fmt::format("{}", State::Stopping));
21  EXPECT_EQ("Stopped", fmt::format("{}", State::Stopped));
22 
23  EXPECT_EQ("NotScheduled", fmt::format("{}", State::NotScheduled));
24  EXPECT_EQ("Scheduled", fmt::format("{}", State::Scheduled));
25  EXPECT_EQ("Transferring", fmt::format("{}", State::Transferring));
26  EXPECT_EQ("Merging", fmt::format("{}", State::Merging));
27  EXPECT_EQ("Releasing", fmt::format("{}", State::Releasing));
28 
29  EXPECT_EQ("AbortingAcquiring", fmt::format("{}", State::AbortingAcquiring));
30  EXPECT_EQ("AbortingMerging", fmt::format("{}", State::AbortingMerging));
31  EXPECT_EQ("Aborted", fmt::format("{}", State::Aborted));
32 
33  EXPECT_EQ("Completed", fmt::format("{}", State::Completed));
34 }
35 
37  // Setup
38  auto standard_without_final = {State::NotStarted,
39  State::Starting,
40  State::Acquiring,
41  State::Stopping,
42  State::NotScheduled,
43  State::Scheduled,
44  State::Transferring,
45  State::Merging,
46  State::Releasing};
47 
48  // Test
49  EXPECT_FALSE(daq::IsSubsequentState(State::AbortingAcquiring, State::Aborted));
50  EXPECT_FALSE(daq::IsSubsequentState(State::AbortingMerging, State::Aborted));
51  EXPECT_FALSE(daq::IsSubsequentState(State::AbortingMerging, State::AbortingAcquiring));
52  EXPECT_FALSE(daq::IsSubsequentState(State::AbortingAcquiring, State::AbortingMerging));
53 
54  EXPECT_TRUE(daq::IsSubsequentState(State::Aborted, State::AbortingAcquiring));
55  EXPECT_TRUE(daq::IsSubsequentState(State::Aborted, State::AbortingMerging));
56 
57  EXPECT_TRUE(daq::IsSubsequentState(State::Starting, State::NotStarted));
58  EXPECT_TRUE(daq::IsSubsequentState(State::Acquiring, State::Starting));
59  EXPECT_TRUE(daq::IsSubsequentState(State::Stopping, State::Acquiring));
60 
61  EXPECT_TRUE(daq::IsSubsequentState(State::Completed, State::Acquiring));
62  EXPECT_TRUE(daq::IsSubsequentState(State::Merging, State::Acquiring));
63  EXPECT_TRUE(daq::IsSubsequentState(State::Merging, State::Transferring));
64 
65  // Standard life-cycle states (excluding the final state)
66  for (auto state : standard_without_final) {
67  // Final states always comes after any other
68  EXPECT_TRUE(daq::IsSubsequentState(State::Completed, state));
69  EXPECT_TRUE(daq::IsSubsequentState(State::Aborted, state));
70 
71  EXPECT_FALSE(daq::IsSubsequentState(state, State::Completed));
72  EXPECT_FALSE(daq::IsSubsequentState(state, State::Aborted));
73  EXPECT_FALSE(daq::IsSubsequentState(state, state));
74  }
75 }
TEST(State, IsStateValid)
Definition: testState.cpp:14
Declares daq::State and related functions.
bool IsSubsequentState(State state1, State state2) noexcept
Compares states and returns whether state1 occurs after state2.
Definition: state.cpp:26
State
Observable states of the data acquisition process.
Definition: state.hpp:39
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")