Implement EventSignalSender unit test 73/262973/4
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 24 Aug 2021 06:20:53 +0000 (15:20 +0900)
committerilho kim <ilho159.kim@samsung.com>
Wed, 25 Aug 2021 03:24:28 +0000 (03:24 +0000)
Change-Id: I473f648fd6182ac3d7ab191a5cad55c89c7767bd
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/res-copy/include/event_signal_sender.hh
tests/mock/pkgmgr_installer_mock.cc [new file with mode: 0644]
tests/mock/pkgmgr_installer_mock.h [new file with mode: 0644]
tests/unit_tests/res-copy/src/test_event_signal_sender.cc [new file with mode: 0644]

index 3f0c52d..495f059 100644 (file)
@@ -51,4 +51,4 @@ class EventSignalSender {
 
 }  // res_handler
 
-#endif  // PARAM_CHECKER_HH_
+#endif  // EVENT_SIGNAL_SENDER_HH_
diff --git a/tests/mock/pkgmgr_installer_mock.cc b/tests/mock/pkgmgr_installer_mock.cc
new file mode 100644 (file)
index 0000000..fbf408a
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include "mock/mock_hook.h"
+#include "mock/pkgmgr_installer_mock.h"
+#include "mock/test_fixture.h"
+
+extern "C" int pkgmgr_installer_send_res_copy_signal(pkgmgr_installer *pi,
+    const char *pkgid, const char *status, pkgmgr_res_event_info *event_info) {
+  return MOCK_HOOK_P4(PkgMgrInstallerMock,
+      pkgmgr_installer_send_res_copy_signal, pi, pkgid, status, event_info);
+}
diff --git a/tests/mock/pkgmgr_installer_mock.h b/tests/mock/pkgmgr_installer_mock.h
new file mode 100644 (file)
index 0000000..fe1f9ac
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef TESTS_MOCK_PKGMGR_INSTALLER_MOCK_H_
+#define TESTS_MOCK_PKGMGR_INSTALLER_MOCK_H_
+
+#include <tizen.h>
+#include <gmock/gmock.h>
+#include <pkgmgr_installer.h>
+
+#include "mock/module_mock.h"
+
+class PkgMgrInstallerMock : public virtual ModuleMock {
+ public:
+  virtual ~PkgMgrInstallerMock() {}
+
+  MOCK_METHOD4(pkgmgr_installer_send_res_copy_signal,
+      int(pkgmgr_installer*, const char*, const char*, pkgmgr_res_event_info*));
+};
+
+#endif  // TESTS_MOCK_PKGMGR_INSTALLER_MOCK_H_
diff --git a/tests/unit_tests/res-copy/src/test_event_signal_sender.cc b/tests/unit_tests/res-copy/src/test_event_signal_sender.cc
new file mode 100644 (file)
index 0000000..56a7d15
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+
+#include <memory>
+
+#include "mock/pkgmgr_installer_mock.h"
+#include "mock/test_fixture.h"
+#include "include/event_signal_sender.hh"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Invoke;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+using ::testing::InvokeArgument;
+using ::testing::SaveArg;
+
+using res_handler::EventSignalSender;
+
+class InstallerMocks : public ::testing::NiceMock<PkgMgrInstallerMock> {};
+
+class EventSignalSenderTest : public TestFixture {
+ public:
+  EventSignalSenderTest() : TestFixture(std::make_unique<InstallerMocks>()) {}
+  virtual ~EventSignalSenderTest() {}
+
+  virtual void SetUp() {}
+  virtual void TearDown() {}
+};
+
+TEST_F(EventSignalSenderTest, SendSignals) {
+  EXPECT_CALL(GetMock<PkgMgrInstallerMock>(),
+      pkgmgr_installer_send_res_copy_signal(_, _, _, _))
+      .WillRepeatedly(Return(0));
+
+  pkgmgr_installer* pi = pkgmgr_installer_offline_new();
+  EventSignalSender signal(pi);
+  signal.SetPkgID("org.test.targetpkgid");
+  signal.SetReqType(res_handler::ReqType::REQ_TYPE_NEW);
+  signal.SetUID(0);
+  signal.SetSessionID("session_id");
+
+  EXPECT_TRUE(signal.SendStart());
+  EXPECT_TRUE(signal.SendOK());
+  EXPECT_TRUE(signal.SendFail(res_handler::ErrorType::ERROR_NONE));
+}
+
+TEST_F(EventSignalSenderTest, SendSignalWithNullPkgMgrInstaller) {
+  EXPECT_CALL(GetMock<PkgMgrInstallerMock>(),
+      pkgmgr_installer_send_res_copy_signal(_, _, _, _))
+      .Times(0);
+
+  EventSignalSender signal(nullptr);
+  EXPECT_FALSE(signal.SendStart());
+  EXPECT_FALSE(signal.SendOK());
+  EXPECT_FALSE(signal.SendFail(res_handler::ErrorType::ERROR_NONE));
+}