/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2022,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "common/config-file.hpp"

#include "tests/test-common.hpp"

#include <boost/property_tree/info_parser.hpp>
#include <fstream>
#include <sstream>

namespace nfd::tests {

BOOST_AUTO_TEST_SUITE(TestConfigFile)

static const std::string CONFIG = R"CONFIG(
  a
  {
    akey avalue
  }
  b
  {
    bkey bvalue
  }
)CONFIG";

// counts of the respective section counts in config_example.info
const int CONFIG_N_A_SECTIONS = 1;
const int CONFIG_N_B_SECTIONS = 1;

class DummySubscriber
{
public:
  DummySubscriber(ConfigFile& config, int nASections, int nBSections, bool expectDryRun)
    : m_nASections(nASections)
    , m_nBSections(nBSections)
    , m_nRemainingACallbacks(nASections)
    , m_nRemainingBCallbacks(nBSections)
    , m_expectDryRun(expectDryRun)
  {
  }

  void
  onA(const ConfigSection& section, bool isDryRun)
  {
    BOOST_CHECK_EQUAL(isDryRun, m_expectDryRun);
    --m_nRemainingACallbacks;
  }

  void
  onB(const ConfigSection& section, bool isDryRun)
  {
    BOOST_CHECK_EQUAL(isDryRun, m_expectDryRun);
    --m_nRemainingBCallbacks;
  }

  bool
  allCallbacksFired() const
  {
    return m_nRemainingACallbacks == 0 &&
      m_nRemainingBCallbacks == 0;
  }

  bool
  noCallbacksFired() const
  {
    return m_nRemainingACallbacks == m_nASections &&
      m_nRemainingBCallbacks == m_nBSections;
  }

private:
  int m_nASections;
  int m_nBSections;
  int m_nRemainingACallbacks;
  int m_nRemainingBCallbacks;
  bool m_expectDryRun;
};

class DummyAllSubscriber : public DummySubscriber
{
public:
  explicit
  DummyAllSubscriber(ConfigFile& config, bool expectDryRun = false)
    : DummySubscriber(config, CONFIG_N_A_SECTIONS, CONFIG_N_B_SECTIONS, expectDryRun)
  {
    config.addSectionHandler("a", std::bind(&DummySubscriber::onA, this, _1, _2));
    config.addSectionHandler("b", std::bind(&DummySubscriber::onB, this, _1, _2));
  }
};

class DummyOneSubscriber : public DummySubscriber
{
public:
  DummyOneSubscriber(ConfigFile& config, const std::string& sectionName, bool expectDryRun = false)
    : DummySubscriber(config,
                      (sectionName == "a"),
                      (sectionName == "b"),
                      expectDryRun)
  {
    if (sectionName == "a") {
      config.addSectionHandler(sectionName, std::bind(&DummySubscriber::onA, this, _1, _2));
    }
    else if (sectionName == "b") {
      config.addSectionHandler(sectionName, std::bind(&DummySubscriber::onB, this, _1, _2));
    }
    else {
      BOOST_FAIL("Test setup error: Unexpected section name '" << sectionName << "'");
    }
  }
};

class DummyNoSubscriber : public DummySubscriber
{
public:
  DummyNoSubscriber(ConfigFile& config, bool expectDryRun)
    : DummySubscriber(config, 0, 0, expectDryRun)
  {
  }
};

BOOST_AUTO_TEST_CASE(ParseFromStream)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  std::ifstream input("tests/daemon/common/config_example.info");
  BOOST_REQUIRE(input.is_open());

  file.parse(input, false, "config_example.info");
  BOOST_CHECK(sub.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromEmptyStream)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  std::istringstream input;

  file.parse(input, false, "empty");
  BOOST_CHECK(sub.noCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromStreamDryRun)
{
  ConfigFile file;
  DummyAllSubscriber sub(file, true);

  std::ifstream input("tests/daemon/common/config_example.info");
  BOOST_REQUIRE(input.is_open());

  file.parse(input, true, "tests/daemon/common/config_example.info");
  BOOST_CHECK(sub.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromConfigSection)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  std::istringstream input(CONFIG);
  ConfigSection section;
  boost::property_tree::read_info(input, section);

  file.parse(section, false, "dummy-config");
  BOOST_CHECK(sub.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromString)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  file.parse(CONFIG, false, "dummy-config");
  BOOST_CHECK(sub.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromEmptyString)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  file.parse("", false, "empty");
  BOOST_CHECK(sub.noCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromMalformedString)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  const std::string malformed = R"CONFIG(
    a
    {
      akey avalue
    }
    b
      bkey bvalue
    }
  )CONFIG";

  BOOST_CHECK_THROW(file.parse(malformed, false, "dummy-config"), ConfigFile::Error);
  BOOST_CHECK(sub.noCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromStringDryRun)
{
  ConfigFile file;
  DummyAllSubscriber sub(file, true);

  file.parse(CONFIG, true, "dummy-config");
  BOOST_CHECK(sub.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromFilename)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  file.parse("tests/daemon/common/config_example.info", false);
  BOOST_CHECK(sub.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromFilenameNonExistent)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  BOOST_CHECK_THROW(file.parse("i_made_this_up.info", false), ConfigFile::Error);
  BOOST_CHECK(sub.noCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromFilenameMalformed)
{
  ConfigFile file;
  DummyAllSubscriber sub(file);

  BOOST_CHECK_THROW(file.parse("tests/daemon/common/config_malformed.info", false), ConfigFile::Error);
  BOOST_CHECK(sub.noCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseFromFilenameDryRun)
{
  ConfigFile file;
  DummyAllSubscriber sub(file, true);

  file.parse("tests/daemon/common/config_example.info", true);
  BOOST_CHECK(sub.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ReplaceSubscriber)
{
  ConfigFile file;
  DummyAllSubscriber sub1(file);
  DummyAllSubscriber sub2(file);

  file.parse(CONFIG, false, "dummy-config");

  BOOST_CHECK(sub1.noCallbacksFired());
  BOOST_CHECK(sub2.allCallbacksFired());
}

class MissingCallbackFixture
{
public:
  void
  checkMissingHandler(const std::string& filename,
                      const std::string& sectionName,
                      const ConfigSection& section,
                      bool isDryRun)
  {
    m_missingFired = true;
  }

protected:
  bool m_missingFired = false;
};

BOOST_FIXTURE_TEST_CASE(UncoveredSections, MissingCallbackFixture)
{
  ConfigFile file;
  BOOST_REQUIRE_THROW(file.parse(CONFIG, false, "dummy-config"), ConfigFile::Error);

  ConfigFile permissiveFile(std::bind(&MissingCallbackFixture::checkMissingHandler,
                                      this, _1, _2, _3, _4));
  DummyOneSubscriber subA(permissiveFile, "a");

  BOOST_REQUIRE_NO_THROW(permissiveFile.parse(CONFIG, false, "dummy-config"));
  BOOST_CHECK(subA.allCallbacksFired());
  BOOST_CHECK(m_missingFired);
}

BOOST_AUTO_TEST_CASE(CoveredByPartialSubscribers)
{
  ConfigFile file;
  DummyOneSubscriber subA(file, "a");
  DummyOneSubscriber subB(file, "b");

  file.parse(CONFIG, false, "dummy-config");

  BOOST_CHECK(subA.allCallbacksFired());
  BOOST_CHECK(subB.allCallbacksFired());
}

BOOST_AUTO_TEST_CASE(ParseNumber)
{
  std::istringstream input(R"CONFIG(
    a -125
    b 156
    c 100000
    d efg
    e 123.456e-10
    f 123abc
    g ""
    h " -1"
  )CONFIG");
  ConfigSection section;
  boost::property_tree::read_info(input, section);

  // Read various types and ensure they return the correct value
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<short>(section.get_child("a"), "a", "section"), -125);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<int>(section.get_child("a"), "a", "section"), -125);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<long>(section.get_child("a"), "a", "section"), -125);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<double>(section.get_child("a"), "a", "section"), -125.0);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<float>(section.get_child("a"), "a", "section"), -125.0);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<short>(section.get_child("b"), "b", "section"), 156);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<int>(section.get_child("b"), "b", "section"), 156);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<long>(section.get_child("b"), "b", "section"), 156);
  BOOST_CHECK_CLOSE(ConfigFile::parseNumber<double>(section.get_child("e"), "e", "section"), 123.456e-10, 0.0001);
  BOOST_CHECK_CLOSE(ConfigFile::parseNumber<float>(section.get_child("e"), "e", "section"), 123.456e-10, 0.0001);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<int>(section.get_child("h"), "h", "section"), -1);

  // Check throw on out of range
  BOOST_CHECK_THROW(ConfigFile::parseNumber<int16_t>(section.get_child("c"), "c", "section"),
                    ConfigFile::Error);

  // Check throw on non-integer for integer types
  BOOST_CHECK_THROW(ConfigFile::parseNumber<int>(section.get_child("d"), "d", "section"),
                    ConfigFile::Error);
  BOOST_CHECK_THROW(ConfigFile::parseNumber<int>(section.get_child("e"), "e", "section"),
                    ConfigFile::Error);
  BOOST_CHECK_THROW(ConfigFile::parseNumber<int>(section.get_child("f"), "f", "section"),
                    ConfigFile::Error);
  BOOST_CHECK_THROW(ConfigFile::parseNumber<int>(section.get_child("g"), "g", "section"),
                    ConfigFile::Error);

  // Should throw exception if try to read unsigned from negative value
  BOOST_CHECK_THROW(ConfigFile::parseNumber<uint16_t>(section.get_child("a"), "a", "section"),
                    ConfigFile::Error);
  BOOST_CHECK_EQUAL(ConfigFile::parseNumber<uint16_t>(section.get_child("b"), "b", "section"), 156);
  BOOST_CHECK_THROW(ConfigFile::parseNumber<uint32_t>(section.get_child("h"), "h", "section"),
                    ConfigFile::Error);
}

BOOST_AUTO_TEST_CASE(CheckRange)
{
  {
    uint32_t value = 8000;
    uint32_t min = 8000;
    uint32_t max = 8999;
    ConfigFile::checkRange(value, min, max, "key", "section");
  }

  {
    size_t value = 8999;
    size_t min = 8000;
    size_t max = 8999;
    ConfigFile::checkRange(value, min, max, "key", "section");
  }

  {
    int64_t value = -7000;
    int64_t min = -7999;
    int64_t max = 1000;
    ConfigFile::checkRange(value, min, max, "key", "section");
  }

  {
    uint32_t value = 7999;
    uint32_t min = 8000;
    uint32_t max = 8999;
    BOOST_CHECK_THROW(ConfigFile::checkRange(value, min, max, "key", "section"), ConfigFile::Error);
  }

  {
    int16_t value = 9000;
    int16_t min = 8000;
    int16_t max = 8999;
    BOOST_CHECK_THROW(ConfigFile::checkRange(value, min, max, "key", "section"), ConfigFile::Error);
  }

  {
    int32_t value = -8000;
    int32_t min = -7999;
    int32_t max = 1000;
    BOOST_CHECK_THROW(ConfigFile::checkRange(value, min, max, "key", "section"), ConfigFile::Error);
  }

  {
    int64_t value = 0x1001;
    int64_t min = -0x7fff;
    int64_t max = 0x1000;
    BOOST_CHECK_THROW(ConfigFile::checkRange(value, min, max, "key", "section"), ConfigFile::Error);
  }
}

BOOST_AUTO_TEST_SUITE_END() // TestConfigFile

} // namespace nfd::tests
