master_loader_unittest.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <dns/master_loader_callbacks.h>
  15. #include <dns/master_loader.h>
  16. #include <gtest/gtest.h>
  17. #include <boost/bind.hpp>
  18. #include <boost/scoped_ptr.hpp>
  19. using namespace isc::dns;
  20. class MasterLoaderTest : public ::testing::Test {
  21. public:
  22. MasterLoaderTest() :
  23. callbacks_(boost::bind(&MasterLoaderTest::callback, this,
  24. true, _1, _2, _3),
  25. boost::bind(&MasterLoaderTest::callback, this,
  26. false, _1, _2, _3))
  27. {}
  28. /// Concatenate file, line, and reason, and add it to either errors
  29. /// or warnings
  30. void
  31. callback(bool error, const std::string& file, size_t line,
  32. const std::string reason)
  33. {
  34. std::stringstream ss;
  35. ss << file << line << reason;
  36. if (error) {
  37. errors.push_back(ss.str());
  38. } else {
  39. warnings.push_back(ss.str());
  40. }
  41. }
  42. void addRRset(const RRsetPtr&) {
  43. // TODO
  44. }
  45. void
  46. setLoader(const char* file, const Name& origin, const RRClass rrclass,
  47. const MasterLoader::Options options)
  48. {
  49. loader.reset(new MasterLoader(file, origin, rrclass, callbacks_,
  50. boost::bind(&MasterLoaderTest::addRRset,
  51. this, _1), options));
  52. }
  53. MasterLoaderCallbacks callbacks_;
  54. boost::scoped_ptr<MasterLoader> loader;
  55. std::vector<std::string> errors;
  56. std::vector<std::string> warnings;
  57. };
  58. TEST_F(MasterLoaderTest, basicLoad) {
  59. setLoader("testdata/loader_test.txt",
  60. Name("example.com."),
  61. RRClass::IN(),
  62. MasterLoader::MANY_ERRORS);
  63. ASSERT_FALSE(loader->loadIncremental(1));
  64. }