ifw-daq  2.1.0-pre1
IFW Data Acquisition modules
testCfitsio.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_fits_test
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief Contains unit tests for cfitsio.cpp
7  */
8 #include <gmock/gmock.h>
9 #include <gtest/gtest.h>
10 
11 #include <daq/fits/cfitsio.hpp>
12 
13 #include "matchers.hpp"
14 
15 using namespace ::testing;
16 using namespace daq::fits;
17 
18 class TestCfitsio : public Test {
19 public:
20  TestCfitsio() : m_fits(4 * 2880) {
21  }
22  fitsfile* GetFile() const noexcept {
23  return m_fits.GetFile();
24  }
25 
27 };
28 
29 class TestReadKeywords : public TestCfitsio {};
30 class TestWriteKeywords : public TestCfitsio {};
31 
32 TEST_F(TestReadKeywords, ReadSimpleImg) {
33  int status = 0;
34  long naxes[2] = {128, 128};
35  fits_create_img(GetFile(), SHORT_IMG, 2, naxes, &status);
36  ASSERT_EQ(status, 0);
37 
38  auto kws = ReadKeywords(GetFile(), 1);
39  LiteralKeyword kw;
40  EXPECT_THAT(kws,
41  ElementsAre(IsKeyword("SIMPLE", KeywordType::Value),
42  IsKeyword("BITPIX", KeywordType::Value),
43  IsKeyword("NAXIS", KeywordType::Value),
44  IsKeyword("NAXIS1", KeywordType::Value),
45  IsKeyword("NAXIS2", KeywordType::Value),
46  IsKeyword("EXTEND", KeywordType::Value),
47  IsKeyword("COMMENT", KeywordType::Commentary),
48  IsKeyword("COMMENT", KeywordType::Commentary)))
49  << PrintToString(kws);
50 }
51 
52 TEST_F(TestReadKeywords, NoPrimaryData) {
53  InitPrimaryHduNoImage(GetFile());
54 
55  auto kws = ReadKeywords(GetFile(), 1);
56  LiteralKeyword kw;
57  EXPECT_THAT(kws,
58  ElementsAre(IsKeyword("SIMPLE", KeywordType::Value),
59  IsKeyword("BITPIX", KeywordType::Value),
60  IsKeyword("NAXIS", KeywordType::Value),
61  IsKeyword("EXTEND", KeywordType::Value)))
62  << PrintToString(kws);
63 }
64 
65 TEST_F(TestReadKeywords, WriteSimple) {
66  // Setup
67  InitPrimaryHduEmpty(GetFile());
68  std::vector<LiteralKeyword> write;
69  write.emplace_back("SIMPLE = T / Standard FITS");
70  write.emplace_back("BITPIX = 8 / # of bits per pix value");
71  write.emplace_back("NAXIS = 0 / # of axes in data array");
72 
73  // Test
74  WriteKeywords(GetFile(), 1, write);
75 
76  auto kws = ReadKeywords(GetFile(), 1);
77  LiteralKeyword kw;
78  EXPECT_THAT(kws,
79  ElementsAre(IsKeyword("SIMPLE", KeywordType::Value),
80  IsKeyword("BITPIX", KeywordType::Value),
81  IsKeyword("NAXIS", KeywordType::Value)))
82  << PrintToString(kws);
83 }
84 
85 
87  EXPECT_EQ(KeywordClass::Structure, GetKeywordClass("SIMPLE"));
88  EXPECT_EQ(KeywordClass::Structure, GetKeywordClass("BITPIX"));
89  EXPECT_EQ(KeywordClass::Checksum, GetKeywordClass("CHECKSUM"));
90  EXPECT_EQ(KeywordClass::User, GetKeywordClass("HIERARCH"));
91 }
daq::fits::MemoryFitsFile
In-memory FITS file.
Definition: cfitsio.hpp:37
daq::fits::KeywordClass::User
@ User
TestReadKeywords
Definition: testCfitsio.cpp:29
daq::fits::ReadKeywords
std::vector< LiteralKeyword > ReadKeywords(fitsfile *ptr, int hdu_num)
Read keywords from HDU identifed by absolute position hdu_num.
Definition: cfitsio.cpp:181
daq::fits::WriteKeywords
void WriteKeywords(fitsfile *ptr, int hdu_num, std::vector< LiteralKeyword > const &keywords, std::optional< ssize_t > *remaining_size)
Write keywords to HDU identified by number hdu_num.
Definition: cfitsio.cpp:247
TestCfitsio::TestCfitsio
TestCfitsio()
Definition: testCfitsio.cpp:20
daq::fits::InitPrimaryHduEmpty
void InitPrimaryHduEmpty(fitsfile *ptr)
Initializes an empty FITS file with an empty primary HDU (no keywords)
Definition: cfitsio.cpp:112
TestCfitsio::m_fits
MemoryFitsFile m_fits
Definition: testCfitsio.cpp:26
daq::fits
Definition: cfitsio.cpp:14
daq::fits::GetKeywordClass
KeywordClass GetKeywordClass(std::string_view name)
Get keyword class.
Definition: keyword.cpp:489
TestWriteKeywords
Definition: testCfitsio.cpp:30
daq::TEST_F
TEST_F(TestDpmDaqController, StatusUpdateInNotScheduledSucceeds)
Definition: testDpmDaqController.cpp:60
TestCfitsio
Definition: testCfitsio.cpp:18
daq::fits::Commentary
@ Commentary
A commentary keyword, which are keywords that do not fall into the previous categories.
Definition: keyword.hpp:76
daq::fits::KeywordClass
KeywordClass
Fits keyword type.
Definition: keyword.hpp:89
matchers.hpp
Contains common matchers.
cfitsio.hpp
Contains functions and data structures related to cfitsio.
daq::fits::Value
@ Value
A value keyword.
Definition: keyword.hpp:68
daq::fits::InitPrimaryHduNoImage
void InitPrimaryHduNoImage(fitsfile *ptr)
Initializes an empty FITS file with a primary HDU.
Definition: cfitsio.cpp:125
daq::fits::LiteralKeyword
Represents the literal 80-character FITS keyword record.
Definition: keyword.hpp:125
TestCfitsio::GetFile
fitsfile * GetFile() const noexcept
Definition: testCfitsio.cpp:22