PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/test/tests.cpp

https://gitlab.com/github-cloud-corporation/cynara
C++ | 59 lines | 24 code | 9 blank | 26 comment | 1 complexity | 9f764ed86b542748ec058a2e3d6dc7d2 MD5 | raw file
  1. /*
  2. * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file test/tests.cpp
  18. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  19. * @version 1.0
  20. * @brief Unit-tests setup
  21. */
  22. #include <gmock/gmock.h>
  23. #include <gtest/gtest.h>
  24. #include "TestEventListenerProxy.h"
  25. class PropertyAwarePrettyUnitTestResultPrinter : public Cynara::TestEventListenerProxy {
  26. using Cynara::TestEventListenerProxy::TestEventListenerProxy;
  27. void OnTestEnd(const ::testing::TestInfo &testInfo) {
  28. auto result = testInfo.result();
  29. for (int i = 0; i < result->test_property_count(); ++i) {
  30. const auto &property = result->GetTestProperty(i);
  31. std::cout << " - "
  32. << property.key() << " = " << property.value()
  33. << std::endl;
  34. }
  35. originalListener()->OnTestEnd(testInfo);
  36. }
  37. };
  38. int main(int argc, char** argv) {
  39. // Disables elapsed time by default.
  40. ::testing::GTEST_FLAG(print_time) = false;
  41. // This allows the user to override the flag on the command line.
  42. ::testing::InitGoogleTest(&argc, argv);
  43. // Gets hold of the event listener list.
  44. auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
  45. // Remove original listener (PrettyUnitTestResultPrinter)
  46. // and wrap it with our proxy (PropertyAwarePrettyUnitTestResultPrinter)
  47. auto originalListener = listeners.Release(listeners.default_result_printer());
  48. listeners.Append(new PropertyAwarePrettyUnitTestResultPrinter(originalListener));
  49. return RUN_ALL_TESTS();
  50. }