| THM1176InstrumentDriver 1.2 C++ API for Metrolab THM1176

Loading...
Searching...
No Matches
CTHM1176GetUtilitiesTest.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 <regex>
11
12 using namespace MTL::Instrument;
13 using namespace MTL::Instrument::THM1176Types;
14
16 class CTHM1176GetUtilitiesTest : 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};
39THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176GetUtilitiesTest::pResourceManager = nullptr;
40 CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * CTHM1176GetUtilitiesTest::pTHM1176 = nullptr;
41
43 TEST_F(CTHM1176GetUtilitiesTest, GetIdentificationString)
44{
45 std::string l_Identification;
46 ASSERT_EQ(true, pTHM1176->GetIdentification(l_Identification));
47
48 std::regex l_Regex("([^,]+),([^,]+),([^,]+),([^,]+)");
49 std::smatch l_Match;
50 ASSERT_EQ(true, std::regex_match(l_Identification, l_Match, l_Regex));
51 EXPECT_EQ("Metrolab Technology SA", l_Match[1].str());
52 EXPECT_EQ("THM1176", l_Match[2].str().substr(0, 7));
53
54 std::string l_SerialNumber = l_Match[3].str();
55 std::string l_Versions = l_Match[4].str();
56 EXPECT_EQ(true, std::regex_match(l_SerialNumber, std::regex("^0[0-9]+$")));
57 EXPECT_EQ(true, std::regex_match(l_Versions, l_Match, std::regex("^el[A-Z][0-9]-pr[A-Z][0-9]-fw[0-9]+\\.[0-9]+\\n$")));
58}
59
61 TEST_F(CTHM1176GetUtilitiesTest, GetIdentificationStruct)
62{
63 struct sIdentifier l_Identification;
64 ASSERT_EQ(true, pTHM1176->GetIdentification(l_Identification));
65
66 EXPECT_EQ("Metrolab Technology SA", l_Identification.Manufacturer);
67 EXPECT_EQ("THM1176", l_Identification.Model.substr(0, 7));
68 EXPECT_LT(0U, l_Identification.SerialNumber);
69 EXPECT_LT(0, l_Identification.ElectronicsVersion.Major);
70 EXPECT_LE(0, l_Identification.ElectronicsVersion.Minor);
71 EXPECT_LT(0, l_Identification.ProbeVersion.Major);
72 EXPECT_LE(0, l_Identification.ProbeVersion.Minor);
73 EXPECT_LT(0, l_Identification.FirmwareVersion.Major);
74 EXPECT_LT(0, l_Identification.FirmwareVersion.Minor);
75 EXPECT_LE(0, l_Identification.ModelRevision);
76 EXPECT_LE(0, l_Identification.InstrModel);
77}
78
80 TEST_F(CTHM1176GetUtilitiesTest, GetAllRanges)
81{
82 CFluxList l_Ranges;
83 ASSERT_EQ(true, pTHM1176->GetAllRanges(l_Ranges));
84 EXPECT_LT(0, l_Ranges.size());
85 for (auto l_Range : l_Ranges)
86 EXPECT_LT(0., l_Range);
87}
88
90 TEST_F(CTHM1176GetUtilitiesTest, GetAllUnits)
91{
92 CUnitsList l_Units;
93 ASSERT_EQ(true, pTHM1176->GetAllUnits(l_Units));
94 EXPECT_LT(0, l_Units.size());
95 for (auto l_Unit : l_Units)
96 {
97 EXPECT_LE(kT, l_Unit);
98 EXPECT_GE(kMHzp, l_Unit);
99 }
100}
101
103 TEST_F(CTHM1176GetUtilitiesTest, GetDivisor)
104{
105 CUnitsList l_Units;
106 ASSERT_EQ(true, pTHM1176->GetAllUnits(l_Units));
107 for (auto l_Unit : l_Units)
108 {
109 U32 l_Divisor;
110 ASSERT_EQ(true, pTHM1176->GetDivisor(l_Unit, l_Divisor));
111 EXPECT_LT(0U, l_Divisor);
112 }
113}
114
116 TEST_F(CTHM1176GetUtilitiesTest, GetRotationMatrix)
117{
118 // We expect the rotation matrix more or less to be an identity matrix.
119 Matrix3f l_Matrix;
120 ASSERT_EQ(true, pTHM1176->GetRotationMatrix(l_Matrix));
121 std::cout << l_Matrix << std::endl;
122 for (int i = 0; i< 3; i++)
123 for (int j = 0; j < 3; j++)
124 EXPECT_NEAR(l_Matrix(i,j), (i == j) ? 1. : 0., 0.1);
125}
126
128 TEST_F(CTHM1176GetUtilitiesTest, GetImmediateMeasurementPeriod)
129{
130 sAveraging<uParm> l_Avg;
131 F64 l_Period1, l_Period2, l_Period3;
132 struct sIdentifier l_Identification;
133 pTHM1176->GetIdentification(l_Identification)
134
135 // We expect that 0 averaging points to give an error.
136 l_Avg.NoPoints = 0;
137 EXPECT_EQ(false, pTHM1176->GetImmediateMeasurementPeriod(l_Avg, l_Identification.ModelRevision, l_Period1));
138 EXPECT_EQ(0., l_Period1);
139
140 // We expect that the time increases linearly with # averaging points.
141 l_Avg.NoPoints = 1;
142 EXPECT_EQ(true, pTHM1176->GetImmediateMeasurementPeriod(l_Avg, l_Identification.ModelRevision, l_Period1));
143 l_Avg.NoPoints = 2;
144 EXPECT_EQ(true, pTHM1176->GetImmediateMeasurementPeriod(l_Avg, l_Identification.ModelRevision, l_Period2));
145 l_Avg.NoPoints = 3;
146 EXPECT_EQ(true, pTHM1176->GetImmediateMeasurementPeriod(l_Avg, l_Identification.ModelRevision, l_Period3));
147 EXPECT_NEAR((l_Period2 - l_Period1), (l_Period3 - l_Period2), 1E-8);
148}
TEST_F
TEST_F(CTHM1176GetUtilitiesTest, GetIdentificationString)
Definition CTHM1176GetUtilitiesTest.cpp:43
U32
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
F64
double F64
64-bit floating-point number.
Definition OSDefines.h:34
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
CTHM1176GetUtilitiesTest
Test THM1176 API: GetIdentification, GetAllRanges, GetAllUnits, GetDivisisor.
Definition CTHM1176GetUtilitiesTest.cpp:17
CTHM1176GetUtilitiesTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition CTHM1176GetUtilitiesTest.cpp:20
CTHM1176GetUtilitiesTest::TearDownTestCase
static void TearDownTestCase()
Definition CTHM1176GetUtilitiesTest.cpp:31
CTHM1176GetUtilitiesTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition CTHM1176GetUtilitiesTest.cpp:19
CTHM1176GetUtilitiesTest::SetUpTestCase
static void SetUpTestCase()
Definition CTHM1176GetUtilitiesTest.cpp:22
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::kMHzp
@ kMHzp
Equivalent proton NMR resonant frequency, in Mega-Hertz.
Definition THM1176Types.h:190
MTL::Instrument::THM1176Types::kT
@ kT
Tesla.
Definition THM1176Types.h:183
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::sIdentifier
Instrument's identification string - parsed version.
Definition THM1176Types.h:353
MTL::Instrument::THM1176Types::sIdentifier::FirmwareVersion
struct sVersion FirmwareVersion
Version numbers of firmware.
Definition THM1176Types.h:359
MTL::Instrument::THM1176Types::sIdentifier::Manufacturer
std::string Manufacturer
Manufacturer name ("Metrolab Technology SA").
Definition THM1176Types.h:354
MTL::Instrument::THM1176Types::sIdentifier::ElectronicsVersion
struct sVersion ElectronicsVersion
Version numbers of electronics.
Definition THM1176Types.h:357
MTL::Instrument::THM1176Types::sIdentifier::SerialNumber
U32 SerialNumber
Serial number.
Definition THM1176Types.h:356
MTL::Instrument::THM1176Types::sIdentifier::ProbeVersion
struct sVersion ProbeVersion
Version numbers of probe.
Definition THM1176Types.h:358
MTL::Instrument::THM1176Types::sIdentifier::Model
std::string Model
Model name (e.g. "THM1176-MF").
Definition THM1176Types.h:355
MTL::Instrument::THM1176Types::sIdentifier::InstrModel
enum eInstrModel InstrModel
Enumerator of instrument model.
Definition THM1176Types.h:361
MTL::Instrument::THM1176Types::sIdentifier::ModelRevision
enum eModelRevision ModelRevision
Revision of Model.
Definition THM1176Types.h:360
MTL::Instrument::THM1176Types::sVersion::Minor
U8 Minor
Minor version number.
Definition THM1176Types.h:316
MTL::Instrument::THM1176Types::sVersion::Major
U8 Major
Major version number.
Definition THM1176Types.h:315