mock_client.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 disableBadIterator() { use_baditerator_ = false; }
  47. const std::string type_;
  48. const data::ConstElementPtr configuration_;
  49. private:
  50. std::set<dns::Name> zones;
  51. bool have_a_; // control the iterator behavior whether to include A record
  52. bool use_baditerator_; // whether to use bogus zone iterators for tests
  53. };
  54. } // end of unittest
  55. } // end of datasrc
  56. } // end of isc
  57. // Local Variables:
  58. // mode: c++
  59. // End: