THM1176InstrumentManager 1.1
Qt Object abstraction 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"
10#include <regex>
11
12using namespace MTL::Instrument;
13using namespace MTL::Instrument::THM1176Types;
14
16class CTHM1176GetUtilitiesTest : public ::testing::Test
17{
18protected:
19 static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
21
22 static void SetUpTestCase()
23 {
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;
41
43TEST_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
61TEST_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
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
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
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
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
128TEST_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(CTHM1176GetUtilitiesTest, GetIdentificationString)
unsigned int U32
32-bit unsigned integer.
Definition OSDefines.h:31
double F64
64-bit floating-point number.
Definition OSDefines.h:34
Utility functions used to test THM1176 API.
bool ConnectToTHM1176(THM1176_TEST_RESOURCE_MANAGER_CLASS *&rpResourceManager, CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > *&rpTHM1176)
Connect to a THM1176.
Test THM1176 API: GetIdentification, GetAllRanges, GetAllUnits, GetDivisisor.
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
THM1176 instrument class.
Definition THM1176.h:98
List of flux density values.
@ kMHzp
Equivalent proton NMR resonant frequency, in Mega-Hertz.
ParmType< U16 > NoPoints
Number of points in block average.
Instrument's identification string - parsed version.
struct sVersion FirmwareVersion
Version numbers of firmware.
std::string Manufacturer
Manufacturer name ("Metrolab Technology SA")
struct sVersion ElectronicsVersion
Version numbers of electronics.
struct sVersion ProbeVersion
Version numbers of probe.
std::string Model
Model name (e.g. "THM1176-MF")
enum eInstrModel InstrModel
Enumerator of instrument model.
enum eModelRevision ModelRevision
Revision of Model.