%endif
%check
-ctest --output-on-failure %{?_smp_mflags}
+export LD_LIBRARY_PATH="../../"
+ctest -V
%if 0%{?gcov:1}
lcov -c --ignore-errors graph --no-external -q -d . -o %{name}.info
genhtml %{name}.info -o %{name}.out
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock/ UNIT_TESTS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock/ UNIT_TESTS_MOCK)
-ADD_EXECUTABLE(${TARGET_AUL_UNIT_TESTS} ${UNIT_TESTS_SRCS})
+ADD_EXECUTABLE(${TARGET_AUL_UNIT_TESTS}
+ ${UNIT_TESTS_SRCS}
+ ${UNIT_TESTS_MOCK}
+)
TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_UNIT_TESTS} PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/../"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../"
"${CMAKE_CURRENT_SOURCE_DIR}/../../include"
"${CMAKE_CURRENT_SOURCE_DIR}/../../src"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../aul"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../aul/api"
)
APPLY_PKG_CONFIG(${TARGET_AUL_UNIT_TESTS} PUBLIC
- GLIB_DEPS
GMOCK_DEPS
BUNDLE_DEPS
+ CAPI_SYSTEM_INFO_DEPS
+ DLOG_DEPS
+ GIO_DEPS
+ GLIB_DEPS
+ INIPARSER_DEPS
+ LIBSMACK_DEPS
+ LIBTZPLATFORM_CONFIG_DEPS
+ LIBXML_DEPS
+ PARCEL_DEPS
+ PKGMGR_INFO_DEPS
+ STORAGE_DEPS
+ TTRACE_DEPS
+ UUID_DEPS
+ VCONF_DEPS
+ XDGMIME_DEPS
)
TARGET_LINK_LIBRARIES(${TARGET_AUL_UNIT_TESTS} PUBLIC ${TARGET_AUL})
#include <gtest/gtest.h>
#include <gmock/gmock.h>
+//#define LOG_INTERNAL
+
+#include <dlog.h>
+
+extern "C" int __dlog_print(log_id_t log_id, int prio, const char *tag, const char *fmt, ...) {
+#ifdef LOG_INTERNAL
+ printf("%s:", tag);
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+#endif
+ return 0;
+}
+
int main(int argc, char** argv) {
try {
testing::InitGoogleTest(&argc, argv);
--- /dev/null
+/*
+ * 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 <glib.h>
+
+#include "mock/socket_mock.h"
+#include "mock/mock_hook.h"
+#include "mock/test_fixture.h"
+
+extern "C" ssize_t recv (int fd, void* buf, size_t n, int flags) {
+ return MOCK_HOOK_P4(SocketMock, recv, fd, buf, n, flags);
+}
+
+extern "C" ssize_t send (int fd, const void* buf, size_t n, int flags) {
+ return MOCK_HOOK_P4(SocketMock, send, fd, buf, n, flags);
+}
+
+extern "C" int socket (int domain, int type, int protocol) {
+ return MOCK_HOOK_P3(SocketMock, socket, domain, type, protocol);
+}
+
+extern "C" int connect(int sockfd, const struct sockaddr* addr,
+ socklen_t addrlen) {
+ return MOCK_HOOK_P3(SocketMock, connect, sockfd, addr, addrlen);
+}
+
+extern "C" int close(int fd) {
+ return 0;
+}
+
+extern "C" int fcntl(int fd, int cmd, ... /* arg */ ) {
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 TEST_UNIT_TESTS_MOCK_SOCKET_MOCK_H_
+#define TEST_UNIT_TESTS_MOCK_SOCKET_MOCK_H_
+
+#include <fcntl.h>
+#include <gmock/gmock.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "mock/module_mock.h"
+
+constexpr const int kFakeFd = 100;
+
+class SocketMock : public virtual ModuleMock {
+ public:
+ SocketMock() {
+ using ::testing::_;
+ using ::testing::Return;
+ using ::testing::Invoke;
+
+ ON_CALL(*this, send(_, _, _, _))
+ .WillByDefault(Invoke([&](
+ int, const void*, size_t size, int) -> ssize_t {
+ return size;
+ }));
+ ON_CALL(*this, socket(_, _, _))
+ .WillByDefault(Return(kFakeFd));
+ }
+
+ MOCK_METHOD4(recv, ssize_t (int, void*, size_t, int));
+ MOCK_METHOD4(send, ssize_t (int, const void*, size_t, int));
+ MOCK_METHOD3(socket, int (int, int, int));
+ MOCK_METHOD3(connect, int (int, const struct sockaddr*, socklen_t));
+};
+
+#endif // TEST_UNIT_TESTS_MOCK_SOCKET_MOCK_H_
+
--- /dev/null
+/*
+ * 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 <bundle_cpp.h>
+#include <iostream>
+#include <memory>
+#include <aul.h>
+
+#include "mock/socket_mock.h"
+#include "mock/mock_hook.h"
+#include "mock/test_fixture.h"
+#include "mock/socket_mock.h"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+using ::testing::Invoke;
+using ::testing::SaveArg;
+
+namespace {
+
+class Mocks : virtual public ::testing::NiceMock<SocketMock> {};
+
+} // namespace
+
+class LaunchTest : public TestFixture {
+ public:
+ LaunchTest() : TestFixture(std::make_unique<::Mocks>()) {}
+
+ virtual void SetUp() { }
+ virtual void TearDown() {}
+};
+
+TEST_F(LaunchTest, aul_launch_app) {
+ tizen_base::Bundle b;
+ EXPECT_CALL(GetMock<SocketMock>(), socket(_, _, _))
+ .Times(1);
+
+ EXPECT_CALL(GetMock<SocketMock>(), connect(_, _, _))
+ .Times(1);
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1);
+
+ EXPECT_CALL(GetMock<SocketMock>(), recv(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([](int fd, void* buf, size_t n, int flags) -> ssize_t {
+ int ret = 0;
+ memcpy(buf, &ret, sizeof(int));
+ return sizeof(int);
+ }));
+
+ int ret = aul_launch_app("test_appid", b.GetHandle());
+ EXPECT_EQ(ret, AUL_R_OK);
+}
+
+TEST_F(LaunchTest, aul_terminate_pid) {
+ tizen_base::Bundle b;
+ EXPECT_CALL(GetMock<SocketMock>(), socket(_, _, _))
+ .Times(1);
+
+ EXPECT_CALL(GetMock<SocketMock>(), connect(_, _, _))
+ .Times(1);
+
+ EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
+ .Times(1);
+
+ EXPECT_CALL(GetMock<SocketMock>(), recv(_, _, _, _))
+ .Times(1)
+ .WillOnce(Invoke([](int fd, void* buf, size_t n, int flags) -> ssize_t {
+ int ret = 0;
+ memcpy(buf, &ret, sizeof(int));
+ return sizeof(int);
+ }));
+
+ int ret = aul_terminate_pid(1000);
+ EXPECT_EQ(ret, AUL_R_OK);
+}