Unblock the unit test execution 38/309038/2
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 4 Apr 2024 05:58:02 +0000 (14:58 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 4 Apr 2024 06:36:24 +0000 (15:36 +0900)
Change-Id: I2566339b65956a908150c3d87dee550525a7f865
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
packaging/pkgmgr.spec
test/unit_tests/mock/unistd_mock.cc [new file with mode: 0644]
test/unit_tests/mock/unistd_mock.hh [new file with mode: 0644]
test/unit_tests/test_client.cc

index af8ed3db75ee26a5d87f6e27827cfd33f5c27be9..2a21bb2dcb689e108c9fa2f80b3dcb7139b37822 100644 (file)
@@ -124,7 +124,7 @@ chmod 755 %{buildroot}%{_sysconfdir}/package-manager/backend/pkgtool
 
 %check
 export LD_LIBRARY_PATH=../../client
-##ctest -V
+ctest -V
 
 %fdupes %{buildroot}
 
diff --git a/test/unit_tests/mock/unistd_mock.cc b/test/unit_tests/mock/unistd_mock.cc
new file mode 100644 (file)
index 0000000..f46db19
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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/unistd_mock.hh"
+#include "mock/mock_hook.hh"
+#include "mock/test_fixture.hh"
+
+extern "C" int access(const char* pathname, int mode) {
+  return MOCK_HOOK_P2(UnistdMock, access, pathname, mode);
+}
diff --git a/test/unit_tests/mock/unistd_mock.hh b/test/unit_tests/mock/unistd_mock.hh
new file mode 100644 (file)
index 0000000..5b49b99
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 UNIT_TESTS_MOCK_UNISTD_MOCK_HH_
+#define UNIT_TESTS_MOCK_UNISTD_MOCK_HH_
+
+#include <gmock/gmock.h>
+#include <unistd.h>
+
+#include "mock/module_mock.hh"
+
+class UnistdMock : public virtual ModuleMock {
+ public:
+  UnistdMock() {
+    using ::testing::_;
+    using ::testing::Return;
+    using ::testing::Invoke;
+
+    ON_CALL(*this, access(_, _))
+        .WillByDefault(Return(0));
+  }
+
+  MOCK_METHOD2(access, int (const char*, int));
+
+ private:
+  static int dummy_;
+};
+
+#endif  // UNIT_TESTS_MOCK_UNISTD_MOCK_HH_
+
index c5fb6e719e23304cfba5d971907b18be733521c4..b9eb28986bdbdea110673803f600c45059c67afc 100644 (file)
@@ -3,16 +3,18 @@
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
 
-#include "unit_tests/mock/rpc_port_mock.hh"
 #include "unit_tests/mock/app_event_mock.hh"
+#include "unit_tests/mock/rpc_port_mock.hh"
 #include "unit_tests/mock/test_fixture.hh"
+#include "unit_tests/mock/unistd_mock.hh"
 
 using ::testing::_;
 using ::testing::Invoke;
 
 namespace {
 class Mocks : public ::testing::NiceMock<RpcPortMock>,
-    virtual public ::testing::NiceMock<AppEventMock> {};
+    virtual public ::testing::NiceMock<AppEventMock>,
+    virtual public ::testing::NiceMock<UnistdMock> {};
 
 }  // namespace
 
@@ -621,7 +623,7 @@ TEST_F(ClientTest, pkgmgr_client_get_package_size_info) {
 
   int ret = pkgmgr_client_get_package_size_info(GetHandle(), "org.tizen.test",
       GetDefaultPkgSizeHandler(), nullptr);
-  EXPECT_TRUE(ret > 0);
+  EXPECT_EQ(ret, PKGMGR_R_OK);
 }
 
 TEST_F(ClientTest, pkgmgr_client_get_package_size_info_n) {