message_initializer_2_unittest.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <log/message_initializer.h>
  15. #include <gtest/gtest.h>
  16. #include <util/unittests/resource.h>
  17. #include <util/unittests/check_valgrind.h>
  18. using namespace isc::log;
  19. // Declare a set of messages to go into the global dictionary.
  20. namespace {
  21. const char* values[] = {
  22. "GLOBAL1", "global message one",
  23. "GLOBAL2", "global message two",
  24. NULL
  25. };
  26. }
  27. TEST(MessageInitializerTest2, MessageLoadTest) {
  28. // Load the maximum number of message arrays allowed. Some arrays may
  29. // already have been loaded because of static initialization from modules
  30. // in libraries linked against the test program, hence the reason for the
  31. // loop starting from the value returned by getPendingCount() instead of 0.
  32. for (size_t i = MessageInitializer::getPendingCount();
  33. i < MessageInitializer::MAX_MESSAGE_ARRAYS; ++i) {
  34. MessageInitializer initializer1(values);
  35. }
  36. // Note: Not all systems have EXPECT_DEATH. As it is a macro we can just
  37. // test for its presence and bypass the test if not available.
  38. #ifdef EXPECT_DEATH
  39. // Adding one more should take us over the limit.
  40. if (!isc::util::unittests::runningOnValgrind()) {
  41. EXPECT_DEATH({
  42. isc::util::unittests::dontCreateCoreDumps();
  43. MessageInitializer initializer2(values);
  44. }, ".*");
  45. }
  46. #endif
  47. }