| THM1176InstrumentManager 1.2 Qt Object abstraction 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"
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;
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 * CTHM1176FileAccessTest::pResourceManager = nullptr;
40 CTHM1176Instrument<THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS> * CTHM1176FileAccessTest::pTHM1176 = 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
69 TEST_F(CTHM1176FileAccessTest, ReadFile)
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}
TEST_F
TEST_F(CTHM1176FileAccessTest, ReadFileDirectory)
Definition CTHM1176FileAccessTest.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
CTHM1176FileAccessTest
Test THM1176 API: File access.
Definition CTHM1176FileAccessTest.cpp:17
CTHM1176FileAccessTest::pTHM1176
static CTHM1176Instrument< THM1176_TEST_INSTRUMENT_CLASS, THM1176_TEST_RESOURCE_MANAGER_CLASS > * pTHM1176
Definition CTHM1176FileAccessTest.cpp:20
CTHM1176FileAccessTest::SetUpTestCase
static void SetUpTestCase()
Definition CTHM1176FileAccessTest.cpp:22
CTHM1176FileAccessTest::pResourceManager
static THM1176_TEST_RESOURCE_MANAGER_CLASS * pResourceManager
Definition CTHM1176FileAccessTest.cpp:19
CTHM1176FileAccessTest::TearDownTestCase
static void TearDownTestCase()
Definition CTHM1176FileAccessTest.cpp:31
MTL::Instrument::CTHM1176Instrument
THM1176 instrument class.
Definition THM1176.h:98
MTL::Instrument::THM1176Types
Definition THM1176TypeConversions.h:20
MTL::Instrument::THM1176Types::tFileList
std::vector< sFile > tFileList
List of directory entries.
Definition THM1176Types.h:532
MTL::Instrument
Definition THM1176.h:74