| THM1176InstrumentManager 1.2 Qt Object abstraction for Metrolab THM1176

Loading...
Searching...
No Matches
CTHM1176SetGetParametersTest.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 using namespace MTL::Instrument;
12 using namespace MTL::Instrument::THM1176Types;
13
15 class CTHM1176SetGetParametersTest : public ::testing::Test
16{
17 protected:
18 static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
19 static CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * pTHM1176;
20
21 static void SetUpTestCase()
22 {
23 ASSERT_EQ(true, ConnectToTHM1176(pResourceManager, pTHM1176));
24 ASSERT_NE(nullptr, pResourceManager);
25 ASSERT_NE(nullptr, pTHM1176);
26 ASSERT_EQ(true, pTHM1176->IsOpen());
27 ASSERT_EQ(true, pTHM1176->Reset());
28 }
29
30 static void TearDownTestCase()
31 {
32 delete pTHM1176;
33 pTHM1176 = nullptr;
34 delete pResourceManager;
35 pResourceManager = nullptr;
36 }
37};
38THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176SetGetParametersTest::pResourceManager = nullptr;
39 CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * CTHM1176SetGetParametersTest::pTHM1176 = nullptr;
40
42 TEST_F(CTHM1176SetGetParametersTest, ParmAveraging)
43{
44 sAveraging<uParm> l_Avg;
45 sAveraging<sBoundedParm> l_AvgBounds;
46
47 ASSERT_EQ(true, pTHM1176->ParmAveragingGet(l_AvgBounds));
48 EXPECT_EQ(1, l_AvgBounds.NoPoints.Min);
49 EXPECT_LE(l_AvgBounds.NoPoints.Min, l_AvgBounds.NoPoints.Val);
50 EXPECT_LE(l_AvgBounds.NoPoints.Val, l_AvgBounds.NoPoints.Max);
51 EXPECT_EQ(l_AvgBounds.NoPoints.Max, 0xffff);
52 EXPECT_EQ(1, l_AvgBounds.NoPoints.Def);
53 EXPECT_EQ(l_AvgBounds.NoPoints.Def, l_AvgBounds.NoPoints.Val);
54
55 l_Avg.NoPoints = 100;
56 ASSERT_EQ(true, pTHM1176->ParmAveragingSet(l_Avg));
57 l_Avg.NoPoints = 0;
58 ASSERT_EQ(true, pTHM1176->ParmAveragingGet(l_Avg));
59 EXPECT_EQ(100, l_Avg.NoPoints);
60
61 ASSERT_EQ(true, pTHM1176->ParmAveragingGet(l_AvgBounds));
62 EXPECT_EQ(1, l_AvgBounds.NoPoints.Min);
63 EXPECT_LE(l_AvgBounds.NoPoints.Min, l_AvgBounds.NoPoints.Val);
64 EXPECT_LE(l_AvgBounds.NoPoints.Val, l_AvgBounds.NoPoints.Max);
65 EXPECT_EQ(l_AvgBounds.NoPoints.Max, 0xffff);
66 EXPECT_EQ(1, l_AvgBounds.NoPoints.Def);
67 EXPECT_EQ(100, l_AvgBounds.NoPoints.Val);
68
69 l_Avg.NoPoints = l_AvgBounds.NoPoints.Min;
70 ASSERT_EQ(true, pTHM1176->ParmAveragingSet(l_Avg));
71 l_Avg.NoPoints = l_AvgBounds.NoPoints.Max;
72 ASSERT_EQ(true, pTHM1176->ParmAveragingSet(l_Avg));
73 l_Avg.NoPoints = 0;
74 ASSERT_EQ(false, pTHM1176->ParmAveragingSet(l_Avg));
75 {
76 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
77 ASSERT_EQ(1, l_ErrorList.size());
78 EXPECT_EQ(-222, l_ErrorList[0].Code);
79 EXPECT_EQ("Data out of range", l_ErrorList[0].Description);
80 EXPECT_EQ(":AVER:COUN 0", l_ErrorList[0].Context);
81 }
82}
83
85 TEST_F(CTHM1176SetGetParametersTest, ParmSleep)
86{
87 bool l_Sleep = false;
88
89 ASSERT_EQ(true, pTHM1176->ParmSleepSet(true));
90 ASSERT_EQ(true, pTHM1176->ParmSleepGet(l_Sleep));
91 EXPECT_EQ(true, l_Sleep);
92
93 ASSERT_EQ(true, pTHM1176->ParmSleepSet(false));
94 ASSERT_EQ(true, pTHM1176->ParmSleepGet(l_Sleep));
95 EXPECT_EQ(false, l_Sleep);
96}
97
99 TEST_F(CTHM1176SetGetParametersTest, ParmTriggerInput)
100{
101 sInputTrigger<uParm> l_Trig;
102 sInputTrigger<sBoundedParm> l_TrigBounds;
103
104 // Test Bounds
105 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_TrigBounds));
106
107 EXPECT_EQ(kInputTrigSrcImmediate, l_TrigBounds.Source);
108
109 EXPECT_DOUBLE_EQ(122e-6, l_TrigBounds.Period_s.Min);
110 EXPECT_LE(l_TrigBounds.Period_s.Min, l_TrigBounds.Period_s.Val);
111 EXPECT_LE(l_TrigBounds.Period_s.Val, l_TrigBounds.Period_s.Max);
112 EXPECT_DOUBLE_EQ(l_TrigBounds.Period_s.Max, 2.79);
113 EXPECT_DOUBLE_EQ(0.1, l_TrigBounds.Period_s.Def);
114 EXPECT_DOUBLE_EQ(l_TrigBounds.Period_s.Val, l_TrigBounds.Period_s.Def);
115
116 EXPECT_EQ(1, l_TrigBounds.Count.Min);
117 EXPECT_LE(l_TrigBounds.Count.Min, l_TrigBounds.Count.Val);
118 EXPECT_LE(l_TrigBounds.Count.Val, l_TrigBounds.Count.Max);
119 EXPECT_EQ(l_TrigBounds.Count.Max, 4096);
120 EXPECT_EQ(1, l_TrigBounds.Count.Def);
121 EXPECT_EQ(l_TrigBounds.Count.Val, l_TrigBounds.Count.Def);
122
123 // Test Source
124 l_Trig.Period_s = l_TrigBounds.Period_s.Def;
125 l_Trig.Count = l_TrigBounds.Count.Def;
126
127 l_Trig.Source = kInputTrigSrcImmediate;
128 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
129 l_Trig.Source = kInputTrigSrcTimer;
130 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_Trig));
131 EXPECT_EQ(kInputTrigSrcImmediate, l_Trig.Source);
132 EXPECT_DOUBLE_EQ(l_TrigBounds.Period_s.Def, l_Trig.Period_s);
133 EXPECT_EQ(l_TrigBounds.Count.Def, l_Trig.Count);
134
135 l_Trig.Source = kInputTrigSrcTimer;
136 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
137 l_Trig.Source = kInputTrigSrcBus;
138 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_Trig));
139 EXPECT_EQ(kInputTrigSrcTimer, l_Trig.Source);
140 EXPECT_DOUBLE_EQ(l_TrigBounds.Period_s.Def, l_Trig.Period_s);
141 EXPECT_EQ(l_TrigBounds.Count.Def, l_Trig.Count);
142
143 l_Trig.Source = kInputTrigSrcBus;
144 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
145 l_Trig.Source = kInputTrigSrcImmediate;
146 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_Trig));
147 EXPECT_EQ(kInputTrigSrcBus, l_Trig.Source);
148 EXPECT_DOUBLE_EQ(l_TrigBounds.Period_s.Def, l_Trig.Period_s);
149 EXPECT_EQ(l_TrigBounds.Count.Def, l_Trig.Count);
150
151 // Test Period_s
152 l_Trig.Source = kInputTrigSrcTimer;
153 l_Trig.Count = l_TrigBounds.Count.Def;
154
155 l_Trig.Period_s = 1.;
156 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
157 l_Trig.Period_s = 0;
158 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_Trig));
159 EXPECT_EQ(kInputTrigSrcTimer, l_Trig.Source);
160 EXPECT_DOUBLE_EQ(1., l_Trig.Period_s);
161 EXPECT_EQ(l_TrigBounds.Count.Def, l_Trig.Count);
162
163 l_Trig.Period_s = l_TrigBounds.Period_s.Min;
164 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
165 l_Trig.Period_s = l_TrigBounds.Period_s.Max;
166 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
167 l_Trig.Period_s = 0;
168 ASSERT_EQ(false, pTHM1176->ParmTriggerInputSet(l_Trig));
169 {
170 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
171 ASSERT_EQ(1, l_ErrorList.size());
172 EXPECT_EQ(-222, l_ErrorList[0].Code);
173 EXPECT_EQ("Data out of range", l_ErrorList[0].Description);
174 EXPECT_EQ(":TRIG:SOUR TIM;COUN 1;TIM 0.000000000000000e+00", l_ErrorList[0].Context);
175 }
176 l_Trig.Period_s = 10.;
177 ASSERT_EQ(false, pTHM1176->ParmTriggerInputSet(l_Trig));
178 {
179 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
180 ASSERT_EQ(1, l_ErrorList.size());
181 EXPECT_EQ(-222, l_ErrorList[0].Code);
182 EXPECT_EQ("Data out of range", l_ErrorList[0].Description);
183 EXPECT_EQ(":TRIG:SOUR TIM;COUN 1;TIM 1.000000000000000e+01", l_ErrorList[0].Context);
184 }
185
186 // Test Count
187 l_Trig.Source = kInputTrigSrcImmediate;
188
189 l_Trig.Count = 100;
190 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
191 l_Trig.Count = 0;
192 ASSERT_EQ(true, pTHM1176->ParmTriggerInputGet(l_Trig));
193 EXPECT_EQ(kInputTrigSrcImmediate, l_Trig.Source);
194 EXPECT_EQ(100, l_Trig.Count);
195
196 l_Trig.Count = l_TrigBounds.Count.Min;
197 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
198 l_Trig.Count = l_TrigBounds.Count.Max;
199 ASSERT_EQ(true, pTHM1176->ParmTriggerInputSet(l_Trig));
200 l_Trig.Count = 0;
201 ASSERT_EQ(false, pTHM1176->ParmTriggerInputSet(l_Trig));
202 {
203 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
204 ASSERT_EQ(1, l_ErrorList.size());
205 EXPECT_EQ(-222, l_ErrorList[0].Code);
206 EXPECT_EQ("Data out of range", l_ErrorList[0].Description);
207 EXPECT_EQ(":TRIG:SOUR IMM;COUN 0", l_ErrorList[0].Context);
208 }
209 l_Trig.Count = 4097;
210 ASSERT_EQ(false, pTHM1176->ParmTriggerInputSet(l_Trig));
211 {
212 std::vector<sError> l_ErrorList = pTHM1176->CurrentErrorList();
213 ASSERT_EQ(1, l_ErrorList.size());
214 EXPECT_EQ(-222, l_ErrorList[0].Code);
215 EXPECT_EQ("Data out of range", l_ErrorList[0].Description);
216 EXPECT_EQ(":TRIG:SOUR IMM;COUN 4097", l_ErrorList[0].Context);
217 }
218}
219
221 TEST_F(CTHM1176SetGetParametersTest, ParmUnits)
222{
223 CUnitsList l_Units;
224 ASSERT_EQ(true, pTHM1176->GetAllUnits(l_Units));
225 for (auto l_Unit : l_Units)
226 {
227 ASSERT_EQ(true, pTHM1176->ParmUnitsSet(l_Unit));
228 eUnits l_UnitRead;
229 ASSERT_EQ(true, pTHM1176->ParmUnitsGet(l_UnitRead));
230 EXPECT_EQ(l_Unit, l_UnitRead);
231 }
232}
233
235 TEST_F(CTHM1176SetGetParametersTest, ParmUseCalibration)
236{
237 bool l_UseCalibration = false;
238
239 ASSERT_EQ(true, pTHM1176->ParmUseCalibrationSet(true));
240 ASSERT_EQ(true, pTHM1176->ParmUseCalibrationGet(l_UseCalibration));
241 EXPECT_EQ(true, l_UseCalibration);
242
243 ASSERT_EQ(true, pTHM1176->ParmUseCalibrationSet(false));
244 ASSERT_EQ(true, pTHM1176->ParmUseCalibrationGet(l_UseCalibration));
245 EXPECT_EQ(false, l_UseCalibration);
246}
247
249 TEST_F(CTHM1176SetGetParametersTest, ParmRange)
250{
251 sRange<uParm> l_RangeStruct;
252 sRange<sBoundedParm> l_RangeStructBounds;
253 CFluxList l_Ranges;
254 ASSERT_EQ(true, pTHM1176->GetAllRanges(l_Ranges));
255
256 // Test Bounds.
257 ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_RangeStructBounds));
258 EXPECT_EQ(true, l_RangeStructBounds.Auto);
259 EXPECT_FLOAT_EQ(l_Ranges.front(), l_RangeStructBounds.Range.Min);
260 EXPECT_LE(l_RangeStructBounds.Range.Min, l_RangeStructBounds.Range.Val);
261 EXPECT_LE(l_RangeStructBounds.Range.Val, l_RangeStructBounds.Range.Max);
262 EXPECT_FLOAT_EQ(l_RangeStructBounds.Range.Max, l_Ranges.back());
263 EXPECT_FLOAT_EQ(l_Ranges.back(), l_RangeStructBounds.Range.Def);
264 EXPECT_FLOAT_EQ(l_RangeStructBounds.Range.Def, l_RangeStructBounds.Range.Val);
265
266 // Test Auto
267 l_RangeStruct.Range = l_RangeStructBounds.Range.Def;
268
269 l_RangeStruct.Auto = true;
270 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_RangeStruct));
271 l_RangeStruct.Auto = false;
272 ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_RangeStruct));
273 EXPECT_EQ(true, l_RangeStruct.Auto);
274
275 l_RangeStruct.Auto = false;
276 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_RangeStruct));
277 l_RangeStruct.Auto = true;
278 ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_RangeStruct));
279 EXPECT_EQ(false, l_RangeStruct.Auto);
280
281 // Test Range.
282 l_RangeStruct.Auto = false;
283 for (auto l_Range : l_Ranges)
284 {
285 l_RangeStruct.Range = l_Range;
286 ASSERT_EQ(true, pTHM1176->ParmRangeSet(l_RangeStruct));
287 l_RangeStruct.Auto = 0.;
288 ASSERT_EQ(true, pTHM1176->ParmRangeGet(l_RangeStruct));
289 EXPECT_EQ(false, l_RangeStruct.Auto);
290 EXPECT_FLOAT_EQ(l_Range, l_RangeStruct.Range);
291 }
292}
293
TEST_F
TEST_F(CTHM1176SetGetParametersTest, ParmAveraging)
Definition CTHM1176SetGetParametersTest.cpp:42
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
CTHM1176SetGetParametersTest
Test THM1176 API: Set/get parameters.
Definition CTHM1176SetGetParametersTest.cpp:16
CTHM1176SetGetParametersTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition CTHM1176SetGetParametersTest.cpp:19
CTHM1176SetGetParametersTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition CTHM1176SetGetParametersTest.cpp:18
CTHM1176SetGetParametersTest::SetUpTestCase
static void SetUpTestCase()
Definition CTHM1176SetGetParametersTest.cpp:21
CTHM1176SetGetParametersTest::TearDownTestCase
static void TearDownTestCase()
Definition CTHM1176SetGetParametersTest.cpp:30
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::kInputTrigSrcTimer
@ kInputTrigSrcTimer
Timed trigger: start measurement at regular intervals.
Definition THM1176Types.h:419
MTL::Instrument::THM1176Types::kInputTrigSrcImmediate
@ kInputTrigSrcImmediate
Immediate trigger: start measurement immediately after previous one completes.
Definition THM1176Types.h:418
MTL::Instrument::THM1176Types::kInputTrigSrcBus
@ kInputTrigSrcBus
Bus trigger: start measurement upon USB trigger message.
Definition THM1176Types.h:420
MTL::Instrument::THM1176Types::eUnits
eUnits
Enumeration of possible measurement units.
Definition THM1176Types.h:182
MTL::Instrument
Definition THM1176.h:74
MTL::Instrument::THM1176Types::sAveraging
Averaging parameter.
Definition THM1176Types.h:388
MTL::Instrument::THM1176Types::sAveraging::NoPoints
ParmType< U16 > NoPoints
Number of points in block average.
Definition THM1176Types.h:389
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::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