mock_client.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 <datasrc/client.h>
  15. #include <dns/dns_fwd.h>
  16. #include <dns/rrset.h>
  17. #include <cc/data.h>
  18. #include <boost/shared_ptr.hpp>
  19. #include <set>
  20. #include <vector>
  21. namespace isc {
  22. namespace datasrc {
  23. namespace unittest {
  24. // A test data source. It pretends it has some zones.
  25. class MockDataSourceClient : public DataSourceClient {
  26. public:
  27. // Constructor from a list of zones.
  28. MockDataSourceClient(const char* zone_names[]);
  29. // Constructor from configuration. The list of zones will be empty, but
  30. // it will keep the configuration inside for further inspection.
  31. MockDataSourceClient(const std::string& type,
  32. const data::ConstElementPtr& configuration);
  33. virtual FindResult findZone(const dns::Name& name) const;
  34. // These methods are not used. They just need to be there to have
  35. // complete vtable.
  36. virtual ZoneUpdaterPtr getUpdater(const dns::Name&, bool, bool) const {
  37. isc_throw(isc::NotImplemented, "Not implemented");
  38. }
  39. virtual std::pair<ZoneJournalReader::Result, ZoneJournalReaderPtr>
  40. getJournalReader(const dns::Name&, uint32_t, uint32_t) const
  41. {
  42. isc_throw(isc::NotImplemented, "Not implemented");
  43. }
  44. virtual ZoneIteratorPtr getIterator(const dns::Name& name, bool) const;
  45. void disableA() { have_a_ = false; }
  46. void enableA() { have_a_ = true; }
  47. void disableBadIterator() { use_baditerator_ = false; }
  48. void enableBadIterator() { use_baditerator_ = true; }
  49. void eraseZone(const dns::Name& zone_name) {
  50. zones.erase(zone_name);
  51. }
  52. const std::string type_;
  53. const data::ConstElementPtr configuration_;
  54. private:
  55. std::set<dns::Name> zones;
  56. bool have_a_; // control the iterator behavior whether to include A record
  57. bool use_baditerator_; // whether to use bogus zone iterators for tests
  58. };
  59. } // end of unittest
  60. } // end of datasrc
  61. } // end of isc
  62. // Local Variables:
  63. // mode: c++
  64. // End: