ifw-daq  3.0.0-pre2
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 
91 }
Contains functions and data structures related to cfitsio.
fitsfile * GetFile() const noexcept
Definition: testCfitsio.cpp:22
MemoryFitsFile m_fits
Definition: testCfitsio.cpp:26
Represents the literal 80-character FITS keyword record.
Definition: keyword.hpp:125
In-memory FITS file.
Definition: cfitsio.hpp:38
Contains common matchers.
@ Commentary
A commentary keyword, which are keywords that do not fall into the previous categories.
Definition: keyword.hpp:76
@ Value
A value keyword.
Definition: keyword.hpp:68
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
KeywordClass GetKeywordClass(std::string_view name)
Get keyword class.
Definition: keyword.cpp:490
void InitPrimaryHduNoImage(fitsfile *ptr)
Initializes an empty FITS file with a primary HDU.
Definition: cfitsio.cpp:125
KeywordClass
Fits keyword type.
Definition: keyword.hpp:89
std::vector< LiteralKeyword > ReadKeywords(fitsfile *ptr, int hdu_num)
Read keywords from HDU identifed by absolute position hdu_num.
Definition: cfitsio.cpp:181
void InitPrimaryHduEmpty(fitsfile *ptr)
Initializes an empty FITS file with an empty primary HDU (no keywords)
Definition: cfitsio.cpp:112
TEST_F(TestDpmDaqController, StatusUpdateInNotScheduledSucceeds)
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")
ASSERT_EQ(meta.keyword_rules.size(), 1u)