| THM1176InstrumentManager 1.2 Qt Object abstraction for Metrolab THM1176

Loading...
Searching...
No Matches
CTHM1176HighLevelMeasurementsTest.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
11#include <ctime>
12
13 using namespace MTL::Instrument;
14 using namespace MTL::Instrument::THM1176Types;
15
17 class CTHM1176HighLevelMeasurementsTest : public ::testing::Test
18{
19 protected:
20 static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
21 static CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * pTHM1176;
22
23 static void SetUpTestCase()
24 {
25 ASSERT_EQ(true, ConnectToTHM1176(pResourceManager, pTHM1176));
26 ASSERT_NE(nullptr, pResourceManager);
27 ASSERT_NE(nullptr, pTHM1176);
28 ASSERT_EQ(true, pTHM1176->IsOpen());
29 ASSERT_EQ(true, pTHM1176->Reset());
30 }
31
32 static void TearDownTestCase()
33 {
34 delete pTHM1176;
35 pTHM1176 = nullptr;
36 delete pResourceManager;
37 pResourceManager = nullptr;
38 }
39
40 virtual void SetUp()
41 {
42 // Reset the instrument.
43 ASSERT_NE(pTHM1176, nullptr);
44 ASSERT_EQ(true, pTHM1176->Reset());
45 }
46};
47THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176HighLevelMeasurementsTest::pResourceManager = nullptr;
48 CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * CTHM1176HighLevelMeasurementsTest::pTHM1176 = nullptr;
49
51 TEST_F(CTHM1176HighLevelMeasurementsTest, MeasureSingle)
52{
53 tFlux l_Bx, l_By, l_Bz;
54 uOPERation l_Operation;
55 eUnits l_Units;
56
57 // Set lowest range, and read OPERation Event register to clear it.
58 sRange<sBoundedParm> l_RangeBounds;
59 ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_RangeBounds));
60 sRange<uParm> l_Range;
61 l_Range.Auto = false;
62 l_Range.Range = l_RangeBounds.Range.Min;
63 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_Range));
64 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
65
66 // Measure with DefaultParms=true.
67 // This should re-select auto-ranging, so the RANGing bit should be set.
68 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz));
69 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
70 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
71 EXPECT_EQ(1, l_Operation.OPERation.RANGing);
72
73 // Set lowest range, and read OPERation Event register to clear it.
74 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_Range));
75 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
76
77 // Measure with DefaultParms=false.
78 // This should leave manual ranging, and not set the RANGing bit.
79 // Units should be T, the default.
80 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, false));
81 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
82 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
83 EXPECT_EQ(0, l_Operation.OPERation.RANGing);
84 ASSERT_EQ(true, pTHM1176->ParmUnitsGet(l_Units));
85 EXPECT_EQ(kT, l_Units);
86
87 // Measure with non-default Units.
88 CUnitsList l_AllUnits;
89 ASSERT_EQ(true, pTHM1176->GetAllUnits(l_AllUnits));
90 ASSERT_LT(1, l_AllUnits.size());
91 ASSERT_NE(kT, l_AllUnits[1]);
92 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, false, l_AllUnits[1]));
93 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
94 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
95 EXPECT_EQ(0, l_Operation.OPERation.RANGing);
96 ASSERT_EQ(true, pTHM1176->ParmUnitsGet(l_Units));
97 EXPECT_EQ(l_AllUnits[1], l_Units);
98
99 // Measure with non-default ExpectedField, which should cause RANGing.
100 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, false, l_AllUnits[1], l_RangeBounds.Range.Max / 2.0f));
101 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
102 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
103 EXPECT_EQ(1, l_Operation.OPERation.RANGing);
104
105 // Measure with different number of Digits.
106 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, 0., 0));
107 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, 0., 1));
108 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, 0., 2));
109 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, 0., 3));
110 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, 0., 4));
111 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, 0., 5));
112 EXPECT_EQ(false, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, 0., 6));
113 {
114 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
115 EXPECT_EQ(3, l_ErrorList.size());
116 EXPECT_EQ(-222, l_ErrorList[0].Code);
117 EXPECT_EQ(-222, l_ErrorList[1].Code);
118 EXPECT_EQ(-222, l_ErrorList[2].Code);
119 }
120
121 // Measure with non-default ExpectedField and different number of Digits.
122 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, l_RangeBounds.Range.Max / 2.0f, 0));
123 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, l_RangeBounds.Range.Max / 2.0f, 1));
124 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, l_RangeBounds.Range.Max / 2.0f, 2));
125 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, l_RangeBounds.Range.Max / 2.0f, 3));
126 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, l_RangeBounds.Range.Max / 2.0f, 4));
127 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, l_RangeBounds.Range.Max / 2.0f, 5));
128 EXPECT_EQ(false, pTHM1176->Measure(l_Bx, l_By, l_Bz, true, kT, l_RangeBounds.Range.Max / 2.0f, 6));
129 {
130 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
131 EXPECT_EQ(3, l_ErrorList.size());
132 EXPECT_EQ(-222, l_ErrorList[0].Code);
133 EXPECT_EQ(-222, l_ErrorList[1].Code);
134 EXPECT_EQ(-222, l_ErrorList[2].Code);
135 }
136}
137
139 TEST_F(CTHM1176HighLevelMeasurementsTest, MeasureMultiple)
140{
141 CFluxList l_Bx, l_By, l_Bz;
142 uOPERation l_Operation;
143 eUnits l_Units;
144
145 // Set lowest range, and read OPERation Event register to clear it.
146 sRange<sBoundedParm> l_RangeBounds;
147 ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_RangeBounds));
148 sRange<uParm> l_Range;
149 l_Range.Auto = false;
150 l_Range.Range = l_RangeBounds.Range.Min;
151 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_Range));
152 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
153
154 // Measure with DefaultParms=true.
155 // This should re-select auto-ranging, so the RANGing bit should be set.
156 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz));
157 EXPECT_EQ(1, l_Bx.size());
158 EXPECT_EQ(1, l_By.size());
159 EXPECT_EQ(1, l_Bz.size());
160 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
161 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
162 EXPECT_EQ(1, l_Operation.OPERation.RANGing);
163
164 // Set lowest range, and read OPERation Event register to clear it.
165 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_Range));
166 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
167
168 // Measure with DefaultParms=true, NoMeasurements=2.
169 // This should re-select auto-ranging, so the RANGing bit should be set.
170 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2));
171 EXPECT_EQ(2, l_Bx.size());
172 EXPECT_EQ(2, l_By.size());
173 EXPECT_EQ(2, l_Bz.size());
174 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
175 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
176 EXPECT_EQ(1, l_Operation.OPERation.RANGing);
177
178 // Set lowest range, and read OPERation Event register to clear it.
179 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_Range));
180 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
181
182 // Measure with DefaultParms=false.
183 // This should leave manual ranging, and not set the RANGing bit.
184 // Units should be T, the default.
185 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, false));
186 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
187 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
188 EXPECT_EQ(0, l_Operation.OPERation.RANGing);
189 ASSERT_EQ(true, pTHM1176->ParmUnitsGet(l_Units));
190 EXPECT_EQ(kT, l_Units);
191
192 // Measure with non-default Units.
193 CUnitsList l_AllUnits;
194 ASSERT_EQ(true, pTHM1176->GetAllUnits(l_AllUnits));
195 ASSERT_LT(1, l_AllUnits.size());
196 ASSERT_NE(kT, l_AllUnits[1]);
197 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, false, l_AllUnits[1]));
198 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
199 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
200 EXPECT_EQ(0, l_Operation.OPERation.RANGing);
201 ASSERT_EQ(true, pTHM1176->ParmUnitsGet(l_Units));
202 EXPECT_EQ(l_AllUnits[1], l_Units);
203
204 // Measure with non-default ExpectedField, which should cause RANGing.
205 ASSERT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, false, l_AllUnits[1], l_RangeBounds.Range.Max / 2.0f));
206 ASSERT_EQ(true, pTHM1176->StatusGet(sStatusRegister(kStatusOperationStatusRegister, kStatusEvent), l_Operation.RawOPER));
207 EXPECT_EQ(1, l_Operation.OPERation.MEASuring);
208 EXPECT_EQ(1, l_Operation.OPERation.RANGing);
209
210 // Measure with different number of Digits.
211 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, 0., 0));
212 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, 0., 1));
213 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, 0., 2));
214 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, 0., 3));
215 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, 0., 4));
216 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, 0., 5));
217 EXPECT_EQ(false, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, 0., 6));
218 {
219 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
220 EXPECT_EQ(3, l_ErrorList.size());
221 EXPECT_EQ(-222, l_ErrorList[0].Code);
222 EXPECT_EQ(-222, l_ErrorList[1].Code);
223 EXPECT_EQ(-222, l_ErrorList[2].Code);
224 }
225
226 // Measure with non-default ExpectedField and different number of Digits.
227 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, l_RangeBounds.Range.Max / 2.0f, 0));
228 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, l_RangeBounds.Range.Max / 2.0f, 1));
229 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, l_RangeBounds.Range.Max / 2.0f, 2));
230 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, l_RangeBounds.Range.Max / 2.0f, 3));
231 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, l_RangeBounds.Range.Max / 2.0f, 4));
232 EXPECT_EQ(true, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, l_RangeBounds.Range.Max / 2.0f, 5));
233 EXPECT_EQ(false, pTHM1176->Measure(l_Bx, l_By, l_Bz, 2, true, kT, l_RangeBounds.Range.Max / 2.0f, 6));
234 {
235 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
236 EXPECT_EQ(3, l_ErrorList.size());
237 EXPECT_EQ(-222, l_ErrorList[0].Code);
238 EXPECT_EQ(-222, l_ErrorList[1].Code);
239 EXPECT_EQ(-222, l_ErrorList[2].Code);
240 }
241}
TEST_F
TEST_F(CTHM1176HighLevelMeasurementsTest, MeasureSingle)
Definition CTHM1176HighLevelMeasurementsTest.cpp:51
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
CTHM1176HighLevelMeasurementsTest
Test THM1176 API: High-level measurement methods.
Definition CTHM1176HighLevelMeasurementsTest.cpp:18
CTHM1176HighLevelMeasurementsTest::TearDownTestCase
static void TearDownTestCase()
Definition CTHM1176HighLevelMeasurementsTest.cpp:32
CTHM1176HighLevelMeasurementsTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition CTHM1176HighLevelMeasurementsTest.cpp:20
CTHM1176HighLevelMeasurementsTest::SetUp
virtual void SetUp()
Definition CTHM1176HighLevelMeasurementsTest.cpp:40
CTHM1176HighLevelMeasurementsTest::SetUpTestCase
static void SetUpTestCase()
Definition CTHM1176HighLevelMeasurementsTest.cpp:23
CTHM1176HighLevelMeasurementsTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition CTHM1176HighLevelMeasurementsTest.cpp:21
MTL::Instrument::CTHM1176Instrument
THM1176 instrument class.
Definition THM1176.h:98
MTL::Instrument::THM1176Types::CFluxList
List of flux density values.
Definition THM1176Types.h:170
MTL::Instrument::THM1176Types::CUnitsList
List of measurement units.
Definition THM1176Types.h:194
MTL::Instrument::THM1176Types
Definition THM1176TypeConversions.h:20
MTL::Instrument::THM1176Types::kStatusEvent
@ kStatusEvent
Event register.
Definition THM1176Types.h:46
MTL::Instrument::THM1176Types::tFlux
F32 tFlux
Flux density value, as 32-bit floating-point number.
Definition THM1176Types.h:30
MTL::Instrument::THM1176Types::eUnits
eUnits
Enumeration of possible measurement units.
Definition THM1176Types.h:182
MTL::Instrument::THM1176Types::kT
@ kT
Tesla.
Definition THM1176Types.h:183
MTL::Instrument::THM1176Types::kStatusOperationStatusRegister
@ kStatusOperationStatusRegister
Operation Status Register.
Definition THM1176Types.h:41
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::THM1176Types::sRange
Measurement range parameter.
Definition THM1176Types.h:479
MTL::Instrument::THM1176Types::sRange::Auto
bool Auto
Auto-ranging enabled.
Definition THM1176Types.h:480
MTL::Instrument::THM1176Types::sRange::Range
ParmType< tFlux > Range
Measurement range, if auto-ranging is not enabled.
Definition THM1176Types.h:481
MTL::Instrument::THM1176Types::sStatusRegister
Complete identification of a SCPI status register.
Definition THM1176Types.h:52
MTL::Instrument::THM1176Types::uOPERation::sOPERation::RANGing
U16 RANGing
Changing range.
Definition THM1176Types.h:130
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