8 #include <fmt/format.h>
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
11 #include <log4cplus/loggingmacros.h>
15 using namespace ::testing;
53 ,
m_logger(log4cplus::Logger::getInstance(
"test.dpm.merge"))
55 ,
m_params{
"arcfile.fits",
"origfile.fits"}
70 Invoke([](
auto const& kw) {
80 auto datasum = kws.back();
82 auto checksum = kws.back();
84 EXPECT_EQ(
"DATASUM", datasum.GetName().name);
85 EXPECT_EQ(
"CHECKSUM", checksum.GetName().name);
87 auto arcfile = kws.back();
89 auto origfile = kws.back();
92 EXPECT_EQ(
"ORIGFILE", origfile.GetName().name);
94 EXPECT_EQ(
"ARCFILE", arcfile.GetName().name);
114 std::vector<SourceTypes> sources;
117 EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).WillRepeatedly(DoDefault());
118 EXPECT_CALL(m_mock_sorter, SortKeywords(_));
121 Merge(m_ops, m_params, m_target, sources, m_dry_run);
123 ASSERT_EQ(after.size(), before.size() + 4u)
124 <<
"4 keywords should be added by DPM (2x checksum, ARCFILE, ORIFILE)";
125 ExpectStandardKeywords(after);
126 EXPECT_THAT(after, ContainerEq(before));
132 std::vector<SourceTypes> sources;
135 EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).WillRepeatedly(DoDefault());
136 EXPECT_CALL(m_mock_sorter, SortKeywords(_));
139 Merge(m_ops, m_params, m_target, sources, m_dry_run);
141 ASSERT_EQ(after.size(), before.size() + 4u)
142 <<
"4 keywords should be added by DPM (2x checksum, ARCFILE, ORIFILE)";
143 ExpectStandardKeywords(after);
145 EXPECT_THAT(after, ContainerEq(before));
151 std::vector<SourceTypes> sources;
156 sources.emplace_back(std::in_place_type<FitsKeywordsSource>,
160 std::make_unique<StandardKeywordRuleProcessor>());
162 expected_kws.push_back(kw1);
163 expected_kws.push_back(kw2);
165 EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).WillRepeatedly(DoDefault());
166 EXPECT_CALL(m_mock_sorter, SortKeywords(_));
169 Merge(m_ops, m_params, m_target, sources, m_dry_run);
173 ASSERT_EQ(after.size(), expected_kws.size() + 4u);
174 ExpectStandardKeywords(after);
176 EXPECT_THAT(after, ContainerEq(expected_kws));
181 std::vector<SourceTypes> sources;
185 auto kw_processor = std::make_unique<MockKeywordProcessor>();
186 EXPECT_CALL(*kw_processor, Process(_, _))
187 .WillRepeatedly(Throw(std::invalid_argument(
"keyword too long")));
188 sources.emplace_back(
189 std::in_place_type<FitsKeywordsSource>,
"tcs", kws, std::nullopt, std::move(kw_processor));
191 expected_kws.push_back(kw1);
193 EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).Times(0);
194 EXPECT_CALL(m_mock_sorter, SortKeywords(_)).Times(0);
197 EXPECT_THROW(
Merge(m_ops, m_params, m_target, sources, m_dry_run), std::runtime_error);
Contains functions and data structures related to cfitsio.
Interface for keyword rule processors.
virtual fits::KeywordVector Process(fits::KeywordVector const &, DefaultRule default_rule) const =0
virtual void SortKeywords(std::vector< fits::LiteralKeyword > &keywords)=0
Sort keywords.
Interface to reporter (implementations exist for JSON or human readable)
virtual void PostAlert(std::string const &id, std::string const &message)=0
Post event.
Fixture that sets up a in-place target FITS file with standard HDU keywords.
log4cplus::Logger m_logger
MockFormatter m_mock_formatter
MockReporter m_mock_reporter
void ExpectStandardKeywords(std::vector< fits::LiteralKeyword > &kws)
fits::MemoryFitsFile m_target_buffer
Represents the literal 80-character FITS keyword record.
void Merge(Operations ops, Params const ¶ms, TargetSource &target, std::vector< SourceTypes > const &sources, bool dry_run)
Merge sources into the target target.
TEST_F(TestMergeKeywords, MergeEmptyStillSortsKeywords)
LiteralKeyword Format(KeywordVariant const &keyword)
void InitPrimaryHduNoImage(fitsfile *ptr)
Initializes an empty FITS file with a primary HDU.
std::vector< KeywordVariant > KeywordVector
Vector of keywords.
std::variant< ValueKeyword, EsoKeyword, LiteralKeyword > KeywordVariant
The different variants of keywords that are supported.
std::vector< LiteralKeyword > ReadKeywords(fitsfile *ptr, int hdu_num)
Read keywords from HDU identifed by absolute position hdu_num.
MOCK_METHOD(fits::KeywordVector, Process,(fits::KeywordVector const &, KeywordRuleProcessor::DefaultRule),(const, override))
MOCK_METHOD(void, PostAlert,(std::string const &id, std::string const &message),(override))
MOCK_METHOD(void, SortKeywords,(std::vector< fits::LiteralKeyword > &keywords),())
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")
ASSERT_EQ(meta.keyword_rules.size(), 1u)