# @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
# @brief Cmake for tests
#
-PKG_CHECK_MODULES(PKGS REQUIRED gmock_main)
+PKG_CHECK_MODULES(PKGS REQUIRED gmock)
ADD_DEFINITIONS("-DCYNARA_NO_LOGS")
SET(CYNARA_SRC ${PROJECT_SOURCE_DIR}/src)
storage/serializer/serialize.cpp
common/types/policybucket.cpp
helpers.cpp
+ TestEventListenerProxy.cpp
+ tests.cpp
)
INCLUDE_DIRECTORIES(
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file TestEventListenerProxy.cpp
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Proxy for ::testing::TestEventListener
+ */
+
+#include "TestEventListenerProxy.h"
+
+namespace Cynara {
+
+TestEventListenerProxy::TestEventListenerProxy(TestEventListener *originalListener)
+ : m_originalListener(originalListener) {};
+
+TestEventListenerProxy::~TestEventListenerProxy() {
+ delete m_originalListener;
+};
+
+void TestEventListenerProxy::OnTestProgramStart(const UnitTest &unit_test) {
+ m_originalListener->OnTestProgramStart(unit_test);
+}
+
+void TestEventListenerProxy::OnTestIterationStart(const UnitTest &unit_test, int iteration) {
+ m_originalListener->OnTestIterationStart(unit_test, iteration);
+}
+
+void TestEventListenerProxy::OnEnvironmentsSetUpStart(const UnitTest &unit_test) {
+ m_originalListener->OnEnvironmentsSetUpStart(unit_test);
+}
+
+void TestEventListenerProxy::OnEnvironmentsSetUpEnd(const UnitTest &unit_test) {
+ m_originalListener->OnEnvironmentsSetUpEnd(unit_test);
+}
+
+void TestEventListenerProxy::OnTestCaseStart(const TestCase &test_case) {
+ m_originalListener->OnTestCaseStart(test_case);
+}
+
+void TestEventListenerProxy::OnTestStart(const TestInfo &test_info) {
+ m_originalListener->OnTestStart(test_info);
+}
+
+void TestEventListenerProxy::OnTestPartResult(const TestPartResult &result) {
+ m_originalListener->OnTestPartResult(result);
+}
+
+void TestEventListenerProxy::OnTestEnd(const TestInfo &test_info) {
+ m_originalListener->OnTestEnd(test_info);
+}
+
+void TestEventListenerProxy::OnTestCaseEnd(const TestCase &test_case) {
+ m_originalListener->OnTestCaseEnd(test_case);
+}
+
+void TestEventListenerProxy::OnEnvironmentsTearDownStart(const UnitTest &unit_test) {
+ m_originalListener->OnEnvironmentsTearDownStart(unit_test);
+}
+
+void TestEventListenerProxy::OnEnvironmentsTearDownEnd(const UnitTest &unit_test) {
+ m_originalListener->OnEnvironmentsTearDownEnd(unit_test);
+}
+
+void TestEventListenerProxy::OnTestIterationEnd(const UnitTest &unit_test, int iteration) {
+ m_originalListener->OnTestIterationEnd(unit_test, iteration);
+}
+
+void TestEventListenerProxy::OnTestProgramEnd(const UnitTest &unit_test) {
+ m_originalListener->OnTestProgramEnd(unit_test);
+}
+
+} /* namespace Cynara */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file TestEventListenerProxy.h
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Proxy for ::testing::TestEventListener
+ */
+
+#ifndef TEST_TESTEVENTLISTENERPROXY_H_
+#define TEST_TESTEVENTLISTENERPROXY_H_
+
+#include <gtest/gtest.h>
+
+namespace Cynara {
+
+using namespace testing;
+
+class TestEventListenerProxy : public TestEventListener
+{
+public:
+ explicit TestEventListenerProxy(TestEventListener *originalListener);
+ virtual ~TestEventListenerProxy();
+
+ virtual void OnTestProgramStart(const UnitTest &unit_test);
+ virtual void OnTestIterationStart(const UnitTest &unit_test, int iteration);
+ virtual void OnEnvironmentsSetUpStart(const UnitTest &unit_test);
+ virtual void OnEnvironmentsSetUpEnd(const UnitTest &unit_test);
+ virtual void OnTestCaseStart(const TestCase &test_case);
+ virtual void OnTestStart(const TestInfo &test_info);
+ virtual void OnTestPartResult(const TestPartResult &result);
+ virtual void OnTestEnd(const TestInfo &test_info);
+ virtual void OnTestCaseEnd(const TestCase &test_case);
+ virtual void OnEnvironmentsTearDownStart(const UnitTest &unit_test);
+ virtual void OnEnvironmentsTearDownEnd(const UnitTest &unit_test);
+ virtual void OnTestIterationEnd(const UnitTest &unit_test, int iteration);
+ virtual void OnTestProgramEnd(const UnitTest &unit_test);
+
+protected:
+ TestEventListener *originalListener() {
+ return m_originalListener;
+ }
+
+private:
+ TestEventListener *m_originalListener;
+};
+
+} /* namespace Cynara */
+
+#endif /* TEST_TESTEVENTLISTENERPROXY_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file tests.cpp
+ * @author Aleksander Zdyb <a.zdyb@partner.samsung.com>
+ * @version 1.0
+ * @brief Unit-tests setup
+ */
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "TestEventListenerProxy.h"
+
+class PropertyAwarePrettyUnitTestResultPrinter : public Cynara::TestEventListenerProxy {
+ using Cynara::TestEventListenerProxy::TestEventListenerProxy;
+
+ void OnTestEnd(const ::testing::TestInfo &testInfo) {
+ auto result = testInfo.result();
+ for (int i = 0; i < result->test_property_count(); ++i) {
+ const auto &property = result->GetTestProperty(i);
+ std::cout << " - "
+ << property.key() << " = " << property.value()
+ << std::endl;
+ }
+ originalListener()->OnTestEnd(testInfo);
+ }
+};
+
+int main(int argc, char** argv) {
+ // Disables elapsed time by default.
+ ::testing::GTEST_FLAG(print_time) = false;
+
+ // This allows the user to override the flag on the command line.
+ ::testing::InitGoogleTest(&argc, argv);
+
+ // Gets hold of the event listener list.
+ auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
+
+ // Remove original listener (PrettyUnitTestResultPrinter)
+ // and wrap it with our proxy (PropertyAwarePrettyUnitTestResultPrinter)
+ auto originalListener = listeners.Release(listeners.default_result_printer());
+ listeners.Append(new PropertyAwarePrettyUnitTestResultPrinter(originalListener));
+
+ return RUN_ALL_TESTS();
+}