master_lexer_unittest.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_lexer.h>
  15. #include <gtest/gtest.h>
  16. #include <boost/lexical_cast.hpp>
  17. #include <string>
  18. #include <sstream>
  19. using namespace isc::dns;
  20. using std::string;
  21. using std::stringstream;
  22. using boost::lexical_cast;
  23. namespace {
  24. class MasterLexerTest : public ::testing::Test {
  25. protected:
  26. MasterLexerTest() {}
  27. MasterLexer lexer;
  28. stringstream ss;
  29. };
  30. TEST_F(MasterLexerTest, preOPen) {
  31. // Initially sources stack is empty, and getXXX() returns accordingly.
  32. EXPECT_TRUE(lexer.getSourceName().empty());
  33. EXPECT_EQ(0, lexer.getSourceLine());
  34. }
  35. TEST_F(MasterLexerTest, openStream) {
  36. lexer.open(ss);
  37. EXPECT_EQ(string("stream-") + lexical_cast<string>(&ss),
  38. lexer.getSourceName());
  39. // From the point of view of this test, we only have to check (though
  40. // indirectly) getSourceLine calls InputSource::getCurrentLine. It should
  41. // return 1 initially.
  42. EXPECT_EQ(1, lexer.getSourceLine());
  43. }
  44. TEST_F(MasterLexerTest, openFile) {
  45. // We use zone file (-like) data, but in this test that actually doesn't
  46. // matter.
  47. lexer.open(TEST_DATA_SRCDIR "/masterload.txt");
  48. EXPECT_EQ(TEST_DATA_SRCDIR "/masterload.txt", lexer.getSourceName());
  49. EXPECT_EQ(1, lexer.getSourceLine());
  50. }
  51. }