| THM1176InstrumentDriver 1.2 C++ API for Metrolab THM1176

Loading...
Searching...
No Matches
CTHM1176InitiateTest.cpp
Go to the documentation of this file.
1// Copyright (c) 2020 Metrolab Technology S.A., Geneva, Switzerland (www.metrolab.com)
2// See the included file LICENSE.txt for the licensing conditions.
3
7
8#include "gtest/gtest.h"
9#include "THM1176TestUtilities.h"
10#include <ctime>
11
12 using namespace MTL::Instrument;
13 using namespace MTL::Instrument::THM1176Types;
14
16 class CTHM1176InitiateTest : public ::testing::Test
17{
18 protected:
19 static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
20 static CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * pTHM1176;
21
22 static void SetUpTestCase()
23 {
24 ASSERT_EQ(true, ConnectToTHM1176(pResourceManager, pTHM1176));
25 ASSERT_NE(nullptr, pResourceManager);
26 ASSERT_NE(nullptr, pTHM1176);
27 ASSERT_EQ(true, pTHM1176->IsOpen());
28 ASSERT_EQ(true, pTHM1176->Reset());
29 }
30
31 static void TearDownTestCase()
32 {
33 delete pTHM1176;
34 pTHM1176 = nullptr;
35 delete pResourceManager;
36 pResourceManager = nullptr;
37 }
38
39 virtual void SetUp()
40 {
41 ASSERT_NE(pTHM1176, nullptr);
42 ASSERT_EQ(true, pTHM1176->Reset());
43 }
44};
45THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176InitiateTest::pResourceManager = nullptr;
46 CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * CTHM1176InitiateTest::pTHM1176 = nullptr;
47
49 TEST_F(CTHM1176InitiateTest, InitiateSingle)
50{
51 // Set timed trigger with default count, default period.
52 sInputTrigger<sBoundedParm> l_TrigBounds;
53 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_TrigBounds));
54 sInputTrigger<uParm> l_Trig;
55 l_Trig.Source = kInputTrigSrcTimer;
56 l_Trig.Count = l_TrigBounds.Count.Def;
57 l_Trig.Period_s = l_TrigBounds.Period_s.Def;
58 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
59
60 // Initiate once.
61 ASSERT_EQ(true, pTHM1176->Initiate());
62
63 // Check that we measured.
64 uOPERation l_OperationStatus;
65 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_OperationStatus.RawOPER));
66 EXPECT_EQ(1, l_OperationStatus.OPERation.MEASuring);
67
68 // Check that we are no longer measuring.
69 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
70 EXPECT_EQ(0, l_OperationStatus.OPERation.MEASuring);
71}
72
74 TEST_F(CTHM1176InitiateTest, InitiateContinuous)
75{
76 // Set timed trigger with default count, default period.
77 sInputTrigger<sBoundedParm> l_TrigBounds;
78 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_TrigBounds));
79 sInputTrigger<uParm> l_Trig;
80 l_Trig.Source = kInputTrigSrcTimer;
81 l_Trig.Count = l_TrigBounds.Count.Def;
82 l_Trig.Period_s = l_TrigBounds.Period_s.Def;
83 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
84
85 // Initiate continuously.
86 ASSERT_EQ(true, pTHM1176->Initiate(true));
87
88 // Check that we measured.
89 uOPERation l_OperationStatus;
90 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_OperationStatus.RawOPER));
91 EXPECT_EQ(1, l_OperationStatus.OPERation.MEASuring);
92
93 // Check that we are still measuring.
94 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
95 EXPECT_EQ(1, l_OperationStatus.OPERation.MEASuring);
96}
97
99 TEST_F(CTHM1176InitiateTest, Abort)
100{
101 // Set bus trigger.
102 sInputTrigger<sBoundedParm> l_TrigBounds;
103 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_TrigBounds));
104 sInputTrigger<uParm> l_Trig;
105 l_Trig.Source = kInputTrigSrcBus;
106 l_Trig.Count = 1;
107 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
108
109 // Initiate once.
110 ASSERT_EQ(true, pTHM1176->Initiate());
111
112 // Check that we are waiting for trigger.
113 uOPERation l_OperationStatus;
114 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
115 EXPECT_EQ(1, l_OperationStatus.OPERation.WaitingForTRIGger);
116
117 // Abort the measurement.
118 ASSERT_EQ(true, pTHM1176->Abort());
119
120 // Check that we are no longer waiting for trigger.
121 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
122 EXPECT_EQ(0, l_OperationStatus.OPERation.WaitingForTRIGger);
123
124 // Set timed trigger.
125 l_Trig.Source = kInputTrigSrcTimer;
126 l_Trig.Count = l_TrigBounds.Count.Max;
127 l_Trig.Period_s = l_TrigBounds.Period_s.Min;
128 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
129
130 // Initiate continuously.
131 ASSERT_EQ(true, pTHM1176->Initiate(true));
132
133 // Check that we are measuring.
134 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
135 EXPECT_EQ(1, l_OperationStatus.OPERation.MEASuring);
136
137 // Abort the measurement.
138 ASSERT_EQ(true, pTHM1176->Abort());
139
140 // Check that we are no longer measuring.
141 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
142 EXPECT_EQ(0, l_OperationStatus.OPERation.MEASuring);
143}
144
146 TEST_F(CTHM1176InitiateTest, SendBusTrigger)
147{
148 // Set bus trigger.
149 sInputTrigger<sBoundedParm> l_TrigBounds;
150 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_TrigBounds));
151 sInputTrigger<uParm> l_Trig;
152 l_Trig.Source = kInputTrigSrcBus;
153 l_Trig.Count = 1;
154 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
155
156 // Initiate once.
157 ASSERT_EQ(true, pTHM1176->Initiate());
158
159 // Check that we are waiting for trigger.
160 uOPERation l_OperationStatus;
161 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
162 EXPECT_EQ(1, l_OperationStatus.OPERation.WaitingForTRIGger);
163
164 // Generate a trigger.
165 ASSERT_EQ(true, pTHM1176->SendBusTrigger());
166
167 // Check that we are no longer waiting for trigger.
168 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusCondition), l_OperationStatus.RawOPER));
169 EXPECT_EQ(0, l_OperationStatus.OPERation.WaitingForTRIGger);
170}
TEST_F
TEST_F(CTHM1176InitiateTest, InitiateSingle)
Definition CTHM1176InitiateTest.cpp:49
THM1176TestUtilities.h
Utility functions used to test THM1176 API.
ConnectToTHM1176
bool ConnectToTHM1176(THM1176_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *&rpTHM1176)
Connect to a THM1176.
Definition THM1176TestUtilities.cpp:41
CTHM1176InitiateTest
Test THM1176 API: Initiate, Abort, Bus Trigger.
Definition CTHM1176InitiateTest.cpp:17
CTHM1176InitiateTest::SetUpTestCase
static void SetUpTestCase()
Definition CTHM1176InitiateTest.cpp:22
CTHM1176InitiateTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition CTHM1176InitiateTest.cpp:20
CTHM1176InitiateTest::SetUp
virtual void SetUp()
Definition CTHM1176InitiateTest.cpp:39
CTHM1176InitiateTest::TearDownTestCase
static void TearDownTestCase()
Definition CTHM1176InitiateTest.cpp:31
CTHM1176InitiateTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition CTHM1176InitiateTest.cpp:19
MTL::Instrument::CTHM1176Instrument
THM1176 instrument class.
Definition THM1176.h:98
MTL::Instrument::THM1176Types
Definition THM1176TypeConversions.h:20
MTL::Instrument::THM1176Types::kStatusCondition
@ kStatusCondition
Condition register.
Definition THM1176Types.h:47
MTL::Instrument::THM1176Types::kStatusEvent
@ kStatusEvent
Event register.
Definition THM1176Types.h:46
MTL::Instrument::THM1176Types::kInputTrigSrcTimer
@ kInputTrigSrcTimer
Timed trigger: start measurement at regular intervals.
Definition THM1176Types.h:419
MTL::Instrument::THM1176Types::kInputTrigSrcBus
@ kInputTrigSrcBus
Bus trigger: start measurement upon USB trigger message.
Definition THM1176Types.h:420
MTL::Instrument::THM1176Types::kStatusOperationStatusRegister
@ kStatusOperationStatusRegister
Operation Status Register.
Definition THM1176Types.h:41
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::THM1176Types::sInputTrigger
Input trigger parameter.
Definition THM1176Types.h:426
MTL::Instrument::THM1176Types::sInputTrigger::Count
ParmType< U16 > Count
Trigger count: take this many measurements before sending results.
Definition THM1176Types.h:429
MTL::Instrument::THM1176Types::sInputTrigger::Source
eInputTriggerSource Source
Trigger source.
Definition THM1176Types.h:427
MTL::Instrument::THM1176Types::sInputTrigger::Period_s
ParmType< F64 > Period_s
Trigger period, for timed trigger.
Definition THM1176Types.h:428
MTL::Instrument::THM1176Types::sStatusRegister
Complete identification of a SCPI status register.
Definition THM1176Types.h:52
MTL::Instrument::THM1176Types::uOPERation::sOPERation::WaitingForTRIGger
U16 WaitingForTRIGger
Waiting for trigger.
Definition THM1176Types.h:133
MTL::Instrument::THM1176Types::uOPERation::sOPERation::MEASuring
U16 MEASuring
Measuring magnetic field strength.
Definition THM1176Types.h:132
MTL::Instrument::THM1176Types::uOPERation
Union to access the Operation Status Register as integer or bit fields.
Definition THM1176Types.h:120
MTL::Instrument::THM1176Types::uOPERation::OPERation
struct MTL::Instrument::THM1176Types::uOPERation::sOPERation OPERation
Access the Operation Status Register as bit fields.
MTL::Instrument::THM1176Types::uOPERation::RawOPER
U16 RawOPER
Access the Operation Status Register as unsigned integer.
Definition THM1176Types.h:122