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"}
 
   59                    std::make_unique<StandardKeywordRuleProcessor>(),
 
   69                 Invoke([](
auto const& kw) {
 
   79         auto datasum = kws.back();
 
   81         auto checksum = kws.back();
 
   83         EXPECT_EQ(
"DATASUM", datasum.GetName().name);
 
   84         EXPECT_EQ(
"CHECKSUM", checksum.GetName().name);
 
   86         auto arcfile = kws.back();
 
   88         auto origfile = kws.back();
 
   91         EXPECT_EQ(
"ORIGFILE", origfile.GetName().name);
 
   92         EXPECT_EQ(fmt::format(
"'{}'", 
m_params.
origfile), origfile.GetComponents().value);
 
   93         EXPECT_EQ(
"ARCFILE", arcfile.GetName().name);
 
   94         EXPECT_EQ(fmt::format(
"'{}'", 
m_params.
arcfile), arcfile.GetComponents().value);
 
  113     std::vector<SourceTypes> sources;
 
  116     EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).WillRepeatedly(DoDefault());
 
  117     EXPECT_CALL(m_mock_sorter, SortKeywords(_));
 
  120     Merge(m_ops, m_params, m_target, sources, m_dry_run);
 
  122     ASSERT_EQ(after.size(), before.size() + 4u)
 
  123         << 
"4 keywords should be added by DPM (2x checksum, ARCFILE, ORIFILE)";
 
  124     ExpectStandardKeywords(after);
 
  125     EXPECT_THAT(after, ContainerEq(before));
 
  131     std::vector<SourceTypes> sources;
 
  134     EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).WillRepeatedly(DoDefault());
 
  135     EXPECT_CALL(m_mock_sorter, SortKeywords(_));
 
  138     Merge(m_ops, m_params, m_target, sources, m_dry_run);
 
  140     ASSERT_EQ(after.size(), before.size() + 4u)
 
  141         << 
"4 keywords should be added by DPM (2x checksum, ARCFILE, ORIFILE)";
 
  142     ExpectStandardKeywords(after);
 
  144     EXPECT_THAT(after, ContainerEq(before));
 
  150     std::vector<SourceTypes> sources;
 
  155     sources.emplace_back(std::in_place_type<FitsKeywordsSource>,
 
  158                          std::make_unique<StandardKeywordRuleProcessor>());
 
  160     expected_kws.push_back(kw1);
 
  161     expected_kws.push_back(kw2);
 
  163     EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).WillRepeatedly(DoDefault());
 
  164     EXPECT_CALL(m_mock_sorter, SortKeywords(_));
 
  167     Merge(m_ops, m_params, m_target, sources, m_dry_run);
 
  171     ASSERT_EQ(after.size(), expected_kws.size() + 4u);
 
  172     ExpectStandardKeywords(after);
 
  174     EXPECT_THAT(after, ContainerEq(expected_kws));
 
  179     std::vector<SourceTypes> sources;
 
  183     auto kw_processor = std::make_unique<MockKeywordProcessor>();
 
  184     EXPECT_CALL(*kw_processor, Process(_, _))
 
  185         .WillRepeatedly(Throw(std::invalid_argument(
"keyword too long")));
 
  186     sources.emplace_back(
 
  187         std::in_place_type<FitsKeywordsSource>, 
"tcs", kws, std::move(kw_processor));
 
  189     expected_kws.push_back(kw1);
 
  191     EXPECT_CALL(m_mock_formatter, FormatKeyword(_)).Times(0);
 
  192     EXPECT_CALL(m_mock_sorter, SortKeywords(_)).Times(0);
 
  195     EXPECT_THROW(
Merge(m_ops, m_params, m_target, sources, m_dry_run), std::runtime_error);