THM1176InstrumentDriver 1.1
C++ API for Metrolab THM1176
Loading...
Searching...
No Matches
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"
10#include <ctime>
11
12using namespace MTL::Instrument;
13using namespace MTL::Instrument::THM1176Types;
14
16class CTHM1176FileAccessTest : 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 * CTHM1176FileAccessTest::pResourceManager = nullptr;
41
43TEST_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
89TEST_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}
TEST_F(CTHM1176FileAccessTest, ReadFileDirectory)
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: File access.
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
std::vector< sFile > tFileList
List of directory entries.