TestLogClientEnv.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include <cppunit/extensions/HelperMacros.h>
  19. #include "CppAssertHelper.h"
  20. #include <string.h>
  21. #include <zookeeper.h>
  22. class Zookeeper_logClientEnv : public CPPUNIT_NS::TestFixture {
  23. CPPUNIT_TEST_SUITE(Zookeeper_logClientEnv);
  24. CPPUNIT_TEST(testLogClientEnv);
  25. CPPUNIT_TEST_SUITE_END();
  26. static void log_no_clientenv(const char *message) {
  27. CPPUNIT_ASSERT(::strstr(message, "Client environment") == NULL);
  28. }
  29. static void log_clientenv(const char *message) {
  30. static int first;
  31. if (!first) {
  32. CPPUNIT_ASSERT(::strstr(message, "Client environment") != NULL);
  33. first = 1;
  34. }
  35. }
  36. public:
  37. void testLogClientEnv() {
  38. zhandle_t* zh;
  39. zh = zookeeper_init2("localhost:22181", NULL, 0, NULL, NULL, 0, log_clientenv);
  40. CPPUNIT_ASSERT(zh != 0);
  41. zookeeper_close(zh);
  42. zh = zookeeper_init2("localhost:22181", NULL, 0, NULL, NULL, ZOO_NO_LOG_CLIENTENV, log_no_clientenv);
  43. CPPUNIT_ASSERT(zh != 0);
  44. zookeeper_close(zh);
  45. }
  46. };
  47. CPPUNIT_TEST_SUITE_REGISTRATION(Zookeeper_logClientEnv);