10 #include <gtest/gtest.h>
16 using namespace testing;
25 pResourceManager =
new IEEE4888_TEST_RESOURCE_MANAGER_CLASS;
26 ASSERT_NE(
nullptr, pResourceManager);
27 ASSERT_EQ(
true, pResourceManager->Initialize());
32 delete pResourceManager;
33 pResourceManager =
nullptr;
43 std::string InstrumentName,
45 std::promise<bool> & rSucceeded,
46 std::promise<U32> & rNLoopsPerformed)
50 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
nullptr;
54 if (
nullptr == pResourceManager)
throw;
57 l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, InstrumentName);
58 if (
nullptr == l_pInstrument ||
59 !l_pInstrument->Open() ||
60 !l_pInstrument->SetTimeout(1000*NSeconds))
64 auto l_EndTime = std::chrono::system_clock::now() + std::chrono::seconds(NSeconds);
67 if (!l_pInstrument->LockExclusive(1000*NSeconds))
throw;
68 if (!l_pInstrument->Write (
"*IDN?"))
throw;
70 if (!l_pInstrument->Read (l_Buffer))
throw;
72 if (!l_pInstrument->Unlock())
throw;
74 }
while (std::chrono::system_clock::now() < l_EndTime);
83 if (
nullptr != l_pInstrument)
85 l_pInstrument->Close();
90 rSucceeded.set_value(l_Status);
91 rNLoopsPerformed.set_value(l_LoopCount);
97 std::string InstrumentName,
99 std::promise<bool> & rSucceeded)
101 bool l_Status =
true;
102 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
nullptr;
106 if (
nullptr == pResourceManager)
110 l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, InstrumentName);
111 if (
nullptr == l_pInstrument ||
112 !l_pInstrument->Open() ||
113 !l_pInstrument->LockExclusive(1000))
117 std::this_thread::sleep_for(std::chrono::seconds(NSeconds));
125 if (
nullptr != l_pInstrument)
127 l_pInstrument->Close();
128 delete l_pInstrument;
132 rSucceeded.set_value(l_Status);
140 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
141 ASSERT_EQ(
false, l_InstrumentList.empty());
144 std::string l_InstrumentName = l_InstrumentList.front();
145 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
146 ASSERT_NE(
nullptr, l_pInstrument);
147 ASSERT_EQ(
false, l_pInstrument->IsOpen());
150 ASSERT_EQ(
true, l_pInstrument->Open());
151 ASSERT_EQ(
true, l_pInstrument->IsOpen());
154 I32 l_Status = l_pInstrument->Status();
155 ASSERT_EQ(0, l_Status);
156 std::string l_StatusDescription = l_pInstrument->StatusDescription(l_Status);
157 std::regex l_Regex(
".*Success.*", std::regex::icase);
159 EXPECT_EQ(
true, std::regex_match(l_StatusDescription, l_Match, l_Regex));
162 l_pInstrument->Close();
163 ASSERT_EQ(
false, l_pInstrument->IsOpen());
166 delete l_pInstrument;
175 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
176 ASSERT_EQ(
false, l_InstrumentList.empty());
179 std::string l_InstrumentName = l_InstrumentList.front();
180 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
181 ASSERT_NE(
nullptr, l_pInstrument);
182 ASSERT_EQ(
false, l_pInstrument->IsOpen());
185 ASSERT_EQ(
true, l_pInstrument->Open());
186 ASSERT_EQ(
true, l_pInstrument->IsOpen());
189 I32 l_Status = l_pInstrument->Status();
190 ASSERT_EQ(0, l_Status);
191 std::string l_StatusDescription = l_pInstrument->StatusDescription(l_Status);
192 std::regex l_Regex(
".*Success.*", std::regex::icase);
194 EXPECT_EQ(
true, std::regex_match(l_StatusDescription, l_Match, l_Regex));
197 l_pInstrument->Close();
198 ASSERT_EQ(
false, l_pInstrument->IsOpen());
201 ASSERT_EQ(
true, l_pInstrument->Open());
202 ASSERT_EQ(
true, l_pInstrument->IsOpen());
205 l_Status = l_pInstrument->Status();
206 ASSERT_EQ(0, l_Status);
207 l_StatusDescription = l_pInstrument->StatusDescription(l_Status);
208 l_Regex = std::regex(
".*Success.*", std::regex::icase);
209 EXPECT_EQ(
true, std::regex_match(l_StatusDescription, l_Match, l_Regex));
212 ASSERT_EQ(
true, l_pInstrument->Open());
215 l_pInstrument->Close();
216 ASSERT_EQ(
false, l_pInstrument->IsOpen());
219 l_pInstrument->Close();
220 ASSERT_EQ(0, l_pInstrument->Status());
223 delete l_pInstrument;
232 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
233 ASSERT_EQ(
false, l_InstrumentList.empty());
236 std::string l_InstrumentName = l_InstrumentList.front();
237 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
238 ASSERT_NE(
nullptr, l_pInstrument);
241 std::promise<bool> l_PromisedStatus;
242 std::future<bool> l_FutureStatus = l_PromisedStatus.get_future();
243 std::promise<U32> l_PromisedLoopCount;
244 std::future<U32> l_FutureLoopcount = l_PromisedLoopCount.get_future();
248 EXPECT_EQ(
true, l_pInstrument->Open());
260 ASSERT_EQ(
true, l_pInstrument->Write (
"*IDN?"));
261 std::this_thread::sleep_for(std::chrono::milliseconds(10));
263 ASSERT_EQ(
true, l_pInstrument->Read (l_Buffer));
264 std::this_thread::sleep_for(std::chrono::milliseconds(10));
266 ASSERT_EQ(
true, l_pInstrument->Unlock());
268 }
while (std::chrono::system_clock::now() < l_EndTime);
272 EXPECT_GT(l_LoopCount, 10);
273 EXPECT_EQ(
true, l_FutureStatus.get());
274 EXPECT_GT(l_FutureLoopcount.get(), 10);
278 l_pInstrument->Close();
279 delete l_pInstrument;
287 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
288 ASSERT_EQ(
false, l_InstrumentList.empty());
291 std::string l_InstrumentName = l_InstrumentList.front();
292 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
295 std::promise<bool> l_PromisedStatus;
296 std::future<bool> l_FutureStatus = l_PromisedStatus.get_future();
298 std::this_thread::sleep_for(std::chrono::seconds(1));
302 ASSERT_EQ(
true, l_pInstrument->Open());
303 auto l_StartTime = std::chrono::system_clock::now();
305 auto l_StopTime = std::chrono::system_clock::now();
306 std::chrono::duration<F64> l_Duration = l_StopTime - l_StartTime;
310 EXPECT_EQ(
true, l_FutureStatus.get());
314 l_pInstrument->Close();
315 delete l_pInstrument;
323 ASSERT_EQ(
true, pResourceManager->FindResources(l_InstrumentList, IEEE4888_TEST_RESOURCE_FILTER));
324 ASSERT_EQ(
false, l_InstrumentList.empty());
327 std::string l_InstrumentName = l_InstrumentList.front();
328 IEEE4888_TEST_INSTRUMENT_CLASS * l_pInstrument =
new IEEE4888_TEST_INSTRUMENT_CLASS(*pResourceManager, l_InstrumentName);
331 std::promise<bool> l_PromisedStatus;
332 std::future<bool> l_FutureStatus = l_PromisedStatus.get_future();
334 std::this_thread::sleep_for(std::chrono::seconds(1));
338 ASSERT_EQ(
true, l_pInstrument->Open());
339 auto l_StartTime = std::chrono::system_clock::now();
341 auto l_StopTime = std::chrono::system_clock::now();
342 std::chrono::duration<F64> l_Duration = l_StopTime - l_StartTime;
346 EXPECT_EQ(
true, l_FutureStatus.get());
350 l_pInstrument->Close();
351 delete l_pInstrument;