THM1176InstrumentDriver  1.0
C++ API for Metrolab THM1176
CTHM1176FileAccessTest.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 <ctime>
11 
12 using namespace MTL::Instrument;
13 using namespace MTL::Instrument::THM1176Types;
14 
16 class CTHM1176FileAccessTest : public ::testing::Test
17 {
18 protected:
19  static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager;
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 };
39 THM1176_TEST_RESOURCE_MANAGER_CLASS * CTHM1176FileAccessTest::pResourceManager = nullptr;
41 
43 TEST_F(CTHM1176FileAccessTest, ReadFileDirectory)
44 {
45  U32 l_UsedBytes;
46  U32 l_AvailableBytes;
47  tFileList l_FileList;
48 
49  ASSERT_EQ(true, pTHM1176->ReadFileDirectory(l_UsedBytes, l_AvailableBytes, l_FileList));
50  EXPECT_LT(0U, l_UsedBytes);
51  EXPECT_EQ(0, l_AvailableBytes);
52  EXPECT_EQ(4, l_FileList.size());
53 
54  EXPECT_EQ("cal.dat", l_FileList[0].Path);
55  EXPECT_EQ("help.dat", l_FileList[1].Path);
56  EXPECT_EQ("info.dat", l_FileList[2].Path);
57  EXPECT_EQ("zero.dat", l_FileList[3].Path);
58 
59  EXPECT_EQ("BINARY", l_FileList[0].Type);
60  EXPECT_EQ("ASCII", l_FileList[1].Type);
61  EXPECT_EQ("BINARY", l_FileList[2].Type);
62  EXPECT_EQ("BINARY", l_FileList[3].Type);
63 
64  for (auto l_File : l_FileList)
65  EXPECT_LT(0, l_FileList[3].Size);
66 }
67 
70 {
71  U32 l_UsedBytes;
72  U32 l_AvailableBytes;
73  tFileList l_FileList;
74  std::string l_Content;
75 
76  ASSERT_EQ(true, pTHM1176->ReadFileDirectory(l_UsedBytes, l_AvailableBytes, l_FileList));
77 
78  ASSERT_EQ(true, pTHM1176->ReadFile(l_FileList[0].Path, l_Content));
79  EXPECT_EQ("Calibration", l_Content.substr(0, 11));
80  ASSERT_EQ(true, pTHM1176->ReadFile(l_FileList[1].Path, l_Content));
81  EXPECT_EQ("Help", l_Content.substr(0, 4));
82  ASSERT_EQ(true, pTHM1176->ReadFile(l_FileList[2].Path, l_Content));
83  EXPECT_EQ("Info", l_Content.substr(0, 4));
84  ASSERT_EQ(true, pTHM1176->ReadFile(l_FileList[3].Path, l_Content));
85  EXPECT_EQ("Zero", l_Content.substr(0, 4));
86 }
87 
89 TEST_F(CTHM1176FileAccessTest, ReadInformationDates)
90 {
91  std::string l_SManufacturingDate;
92  std::time_t l_ManufacturingDate;
93  std::string l_SCalibrationDate;
94  std::time_t l_CalibrationDate;
95  std::time_t l_CurrentTime = std::time(NULL);
96  static const F64 THM1176_MAX_MFG = 60. * 60. * 24. * 365.25 * 20.; // 20 years in seconds
97  static const F64 THM1176_MAX_CAL = 60. * 60. * 24. * 365.25 * 3.; // 3 years in seconds
98 
99  ASSERT_EQ(true, pTHM1176->ReadInformationDates(l_SManufacturingDate, l_ManufacturingDate, l_SCalibrationDate, l_CalibrationDate));
100  EXPECT_LT(0., difftime(l_CurrentTime, l_ManufacturingDate));
101  EXPECT_GT(THM1176_MAX_MFG, difftime(l_CurrentTime, l_ManufacturingDate));
102  EXPECT_LT(0., difftime(l_CurrentTime, l_CalibrationDate));
103  EXPECT_GT(THM1176_MAX_CAL, difftime(l_CurrentTime, l_CalibrationDate));
104 }
CTHM1176FileAccessTest
Test THM1176 API: File access.
Definition: CTHM1176FileAccessTest.cpp:17
THM1176TestUtilities.h
Utility functions used to test THM1176 API.
MTL::Instrument::CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS >
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
MTL::Instrument
Definition: THM1176.h:75
MTL::Instrument::THM1176Types
Definition: THM1176TypeConversions.h:20
TEST_F
TEST_F(CTHM1176FileAccessTest, ReadFileDirectory)
Definition: CTHM1176FileAccessTest.cpp:43
MTL::Instrument::THM1176Types::tFileList
std::vector< sFile > tFileList
List of directory entries.
Definition: THM1176Types.h:511
CTHM1176FileAccessTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition: CTHM1176FileAccessTest.cpp:20
CTHM1176FileAccessTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition: CTHM1176FileAccessTest.cpp:19
MTL::Instrument::CTHM1176Instrument::Reset
bool Reset()
Reset the instrument to power-on configuration.
Definition: THM1176.cpp:2104
F64
double F64
64-bit floating-point number.
Definition: OSDefines.h:35
CTHM1176FileAccessTest::SetUpTestCase
static void SetUpTestCase()
Definition: CTHM1176FileAccessTest.cpp:22
U32
unsigned int U32
32-bit unsigned integer.
Definition: OSDefines.h:32
CTHM1176FileAccessTest::TearDownTestCase
static void TearDownTestCase()
Definition: CTHM1176FileAccessTest.cpp:31