| THM1176InstrumentManager 1.2 Qt Object abstraction for Metrolab THM1176

Loading...
Searching...
No Matches
CIEEE488InstrumentReadWriteTest.h
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#pragma once
9
10#include <gtest/gtest.h>
11
12#include "IEEE488InstrumentTest.h"
13
14 using namespace testing;
15
16 class IEEE488InstrumentReadWriteTest : public ::testing::Test
17{
18 protected:
19 static IEEE4888_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
20 static IEEE4888_TEST_INSTRUMENT_CLASS * pInstrument;
21
22 static void SetUpTestCase()
23 {
24 ASSERT_EQ(true, ConnectToIEEE488Instrument(pResourceManager, pInstrument));
25 ASSERT_NE(nullptr, pResourceManager);
26 ASSERT_NE(nullptr, pInstrument);
27 ASSERT_EQ(true, pInstrument->IsOpen());
28 ASSERT_EQ(true, pInstrument->Clear());
29 }
30
31 static void TearDownTestCase()
32 {
33 delete pInstrument;
34 pInstrument = nullptr;
35 delete pResourceManager;
36 pResourceManager = nullptr;
37 }
38};
39
40IEEE4888_TEST_RESOURCE_MANAGER_CLASS * IEEE488InstrumentReadWriteTest::pResourceManager = nullptr;
41IEEE4888_TEST_INSTRUMENT_CLASS * IEEE488InstrumentReadWriteTest::pInstrument = nullptr;
42
44 TEST_F(IEEE488InstrumentReadWriteTest, IDN_Query_WriteCString)
45{
46 ASSERT_EQ(true, pInstrument->Write ("*IDN?"));
47 CSCPIBuffer l_Buffer;
48 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
49 EXPECT_EQ(true, CheckIDNResponse (l_Buffer));
50
51}
52
54 TEST_F(IEEE488InstrumentReadWriteTest, IDN_Query_WriteCPPString)
55{
56 ASSERT_EQ(true, pInstrument->Write (std::string("*IDN?")));
57 CSCPIBuffer l_Buffer;
58 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
59 EXPECT_EQ(true, CheckIDNResponse (l_Buffer));
60
61}
62
64 TEST_F(IEEE488InstrumentReadWriteTest, IDN_Query_WriteSCPIBuffer)
65{
66 const char * l_Command = "*IDN?";
67 CSCPIBuffer l_Buffer(l_Command, std::strlen(l_Command));
68 ASSERT_EQ(true, pInstrument->Write (l_Buffer));
69 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
70 EXPECT_EQ(true, CheckIDNResponse (l_Buffer));
71
72}
73
75 TEST_F(IEEE488InstrumentReadWriteTest, IDN_Query_MultipleBuffers)
76{
77 CSCPIBuffer l_Buffer(16);
78 ASSERT_EQ(true, pInstrument->Write ("*IDN?"));
79
80 ASSERT_EQ(true, pInstrument->Read (l_Buffer, false));
81 for (;;)
82 {
83 U16 l_Status;
84 ASSERT_EQ(true, pInstrument->ReadSTB (l_Status));
85 if ((l_Status & 0x0010) == 0) break;
86 ASSERT_EQ(true, pInstrument->Read (l_Buffer, true));
87 }
88
89 EXPECT_EQ(true, CheckIDNResponse(l_Buffer));
90
91}
92
94 TEST_F(IEEE488InstrumentReadWriteTest, IDN_Query_AfterSpuriousRead)
95{
96 // Perform a spurious read.
97 CSCPIBuffer l_Buffer;
98 ASSERT_EQ(false, pInstrument->Read (l_Buffer));
99
100 // Perform the *IDN? query.
101 ASSERT_EQ(true, pInstrument->Write ("*IDN?"));
102 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
103 EXPECT_EQ(true, CheckIDNResponse (l_Buffer));
104
105}
106
108 TEST_F(IEEE488InstrumentReadWriteTest, IDN_Query_AfterFailedWrite)
109{
110 // Write a long command with a very short timeout.
111 std::string l_LongCommand;
112 for (int i = 0; i < 100; i++)
113 l_LongCommand += "*RST;";
114 U32 l_Timeout = pInstrument->GetTimeout();
115 pInstrument->SetTimeout(1ul);
116 ASSERT_EQ(false, pInstrument->Write (l_LongCommand));
117
118 // Restore the default timeout and perform the *IDN? query.
119 pInstrument->SetTimeout(l_Timeout);
120 ASSERT_EQ(true, pInstrument->Write ("*IDN?"));
121 CSCPIBuffer l_Buffer;
122 ASSERT_EQ(true, pInstrument->Read (l_Buffer));
123 EXPECT_EQ(true, CheckIDNResponse (l_Buffer));
124
125}
126
TEST_F
TEST_F(IEEE488InstrumentReadWriteTest, IDN_Query_WriteCString)
Test *IDN? query with C string variant of Write.
Definition CIEEE488InstrumentReadWriteTest.h:44
ConnectToIEEE488Instrument
bool ConnectToIEEE488Instrument(IEEE4888_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, IEEE4888_TEST_INSTRUMENT_CLASS *&rpInstrument)
Connect to an IEEE488Instrument.
Definition IEEE488InstrumentTest.cpp:40
CheckIDNResponse
bool CheckIDNResponse(const CSCPIBuffer &rBuffer)
Sanity-check of the response to an *IDN? query.
Definition IEEE488InstrumentTest.cpp:70
IEEE488InstrumentTest.h
Utility functions used to test IEEE488Instrument API.
U32
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
U16
unsigned short U16
16-bit unsigned integer.
Definition OSDefines.h:30
IEEE488InstrumentReadWriteTest
Definition CIEEE488InstrumentReadWriteTest.h:17
IEEE488InstrumentReadWriteTest::TearDownTestCase
static void TearDownTestCase()
Definition CIEEE488InstrumentReadWriteTest.h:31
IEEE488InstrumentReadWriteTest::pInstrument
static IEEE4888_TEST_INSTRUMENT_CLASS * pInstrument
Definition CIEEE488InstrumentReadWriteTest.h:20
IEEE488InstrumentReadWriteTest::pResourceManager
static IEEE4888_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition CIEEE488InstrumentReadWriteTest.h:19
IEEE488InstrumentReadWriteTest::SetUpTestCase
static void SetUpTestCase()
Definition CIEEE488InstrumentReadWriteTest.h:22
MTL::Instrument::CSCPIBuffer
Instrument Buffer.
Definition SCPIInstrumentBuffer.h:44