test_main() {
echo "test_main start"
export "GCOV_PREFIX=/tmp"
+ /usr/bin/rpc-port-util -n test_port &
/usr/bin/rpc-port_unittests
}
teardown() {
echo "teardown start"
set_perm
+ killall rpc-port-util
}
main() {
return 0;
}
+// LCOV_EXCL_START
int AccessController::CheckTrusted(const std::string& sender_appid) {
if (getuid() < kRegularUidMin)
return 0;
return 0;
}
+// LCOV_EXCL_STOP
int AccessController::Check(int fd, const std::string& sender_appid) {
Cynara cynara;
auto tmp_handle = new std::shared_ptr<AccessController>(shared_from_this());
Job job([=]() -> Job::Type {
if ((*tmp_handle).use_count() == 1) {
- delete tmp_handle;
- return Job::Type::Continue;
+ delete tmp_handle; // LCOV_EXCL_LINE
+ return Job::Type::Continue; // LCOV_EXCL_LINE
}
int res = Check(fd, sender_appid);
return G_SOURCE_REMOVE;
}, cbdata);
if (sid == 0) {
- _E("Failed to call g_idle_add");
- delete cbdata;
+ _E("Failed to call g_idle_add"); // LCOV_EXCL_LINE
+ delete cbdata; // LCOV_EXCL_LINE
}
delete tmp_handle;
cynara* cynara_inst = nullptr;
if (cynara_initialize(&cynara_inst, NULL) != CYNARA_API_SUCCESS) {
- _E("cynara_initialize() is failed"); // LCOV_EXL_LINE
+ _E("cynara_initialize() is failed"); // LCOV_EXCL_LINE
} else {
cynara_.reset(cynara_inst);
}
char* user = nullptr;
int ret = cynara_creds_socket_get_user(fd, USER_METHOD_DEFAULT, &user);
if (ret != CYNARA_API_SUCCESS) {
+ // LCOV_EXCL_START
char buf[128] = { 0, };
cynara_strerror(ret, buf, sizeof(buf));
_E("cynara_creds_socket_get_user() is failed. fd(%d), error(%d:%s)",
fd, ret, buf);
return -1;
+ // LCOV_EXCL_STOP
}
user_.reset(user);
char* client = nullptr;
ret = cynara_creds_socket_get_client(fd, CLIENT_METHOD_DEFAULT, &client);
if (ret != CYNARA_API_SUCCESS) {
+ // LCOV_EXCL_START
char buf[128] = { 0, };
cynara_strerror(ret, buf, sizeof(buf));
_E("cynara_creds_socket_get_client() is failed. fd(%d), error(%d:%s)",
fd, ret, buf);
return -1;
+ // LCOV_EXCL_STOP
}
client_.reset(client);
return 0;
}
+// LCOV_EXCL_START
int AccessController::Cynara::Check(const std::string& privilege) const {
_D("check privilege %s", privilege.c_str());
if (cynara_check(cynara_.get(), client_.get(), "", user_.get(),
return 0;
}
+// LCOV_EXCL_STOP
} // namespace internal
} // namespace rpc_port
char app_id[256] = { 0, };
int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id));
if (ret != AUL_R_OK) {
+ // LCOV_EXCL_START
_E("aul_app_get_appid_bypid() is failed. pid(%d), error(%d)", pid, ret);
char* name = nullptr;
ret = aul_proc_get_name(pid, &name);
std::unique_ptr<char, decltype(std::free)*> name_auto(name, std::free);
return std::string(name);
+ // LCOV_EXCL_STOP
}
return std::string(app_id);
int ret = aul_rpc_port_usr_get_path(app_id.c_str(), port_name.c_str(), uid,
&port_path);
if (ret != AUL_R_OK) {
- _E("aul_rpc_port_usr_get_path() is failed. error(%d)", ret);
- return {};
+ _E("aul_rpc_port_usr_get_path() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return {}; // LCOV_EXCL_LINE
}
std::unique_ptr<char, decltype(std::free)*> ptr(port_path, std::free);
int ret = aul_rpc_port_usr_exist(app_id.c_str(), port_name.c_str(), uid,
&exist);
if (ret != AUL_R_OK)
- _W("aul_rpc_port_usr_exist() is failed. error(%d)", ret);
+ _W("aul_rpc_port_usr_exist() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return exist;
}
void Aul::NotifyRpcFinished() {
int ret = aul_rpc_port_notify_rpc_finished();
if (ret != AUL_R_OK)
- _W("aul_rpc_port_notify_rpc_finished() is failed. error(%d)", ret);
+ _W("aul_rpc_port_notify_rpc_finished() is failed. error(%d)", ret); // LCOV_EXCL_LINE
}
} // namespace internal
ClientSocket::ClientSocket() {
fd_ = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd_ < 0) {
+ // LCOV_EXCL_START
fd_ = -errno;
_E("socket() is failed. errno(%d)", errno);
THROW(fd_);
+ // LCOV_EXCL_STOP
}
}
int ret = connect(GetFd(), sockaddr_ptr, len);
fcntl(GetFd(), F_SETFL, flag);
if (ret < 0) {
+ // LCOV_EXCL_START
ret = -errno;
_E("connect() is failed. errno(%d)", errno);
return ret;
+ // LCOV_EXCL_STOP
}
return 0;
while (len) {
ssize_t bytes = send(GetFd(), buffer, len, MSG_NOSIGNAL);
if (bytes < 0) {
+ // LCOV_EXCL_START
int ret = -errno;
_E("send() is failed. fd(%d), errno(%d)", GetFd(), errno);
return ret;
+ // LCOV_EXCL_STOP
}
len -= bytes;
while (len) {
ssize_t bytes = read(GetFd(), buffer, len);
if (bytes == 0) {
- _W("EOF. fd(%d)", GetFd());
- return -EIO;
+ _W("EOF. fd(%d)", GetFd()); // LCOV_EXCL_START
+ return -EIO; // LCOV_EXCL_STOP
}
if (bytes < 0)
- return -errno;
+ return -errno; // LCOV_EXCL_LINE
len -= bytes;
buffer += bytes;
return 0;
}
-int ClientSocket::GetReceiveBufferSize() {
- int value;
- socklen_t len = sizeof(int);
- int ret = getsockopt(GetFd(), SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<void*>(&value), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- return ret;
- }
-
- return value;
-}
-
-int ClientSocket::GetSendBufferSize() {
- int value;
- socklen_t len = sizeof(int);
- int ret = getsockopt(GetFd(), SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<void*>(&value), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- return ret;
- }
-
- return value;
-}
-
-int ClientSocket::GetReceiveTimeout() {
- struct timeval timeout = { 0, };
- socklen_t len = static_cast<socklen_t>(sizeof(struct timeval));
- int ret = getsockopt(GetFd(), SOL_SOCKET, SO_RCVTIMEO,
- reinterpret_cast<void*>(&timeout), &len);
- if (ret < 0) {
- ret = -errno;
- _E("getsockopt() is failed. errno(%d)", errno);
- return ret;
- }
-
- int value = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
- return value;
-}
-
-void ClientSocket::SetReceiveBufferSize(int size) {
- socklen_t len = static_cast<socklen_t>(sizeof(size));
- int ret = setsockopt(GetFd(), SOL_SOCKET, SO_RCVBUF, &size, len);
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
-void ClientSocket::SetSendBufferSize(int size) {
- socklen_t len = sizeof(size);
- int ret = setsockopt(GetFd(), SOL_SOCKET, SO_SNDBUF, &size, len);
- if (ret < 0) {
- ret = -errno;
- _E("setsockopt() is failed. errno(%d)", errno);
- THROW(ret);
- }
-}
-
void ClientSocket::SetReceiveTimeout(int timeout) {
if (timeout == INT_MAX)
- return;
+ return; // LCOV_EXCL_LINE
if (timeout == -1)
timeout = 5000;
if (timeout < 0) {
- _E("Invalid parameter");
- THROW(-EINVAL);
+ _E("Invalid parameter"); // LCOV_EXCL_LINE
+ THROW(-EINVAL); // LCOV_EXCL_LINE
}
struct timeval tv = {
socklen_t len = static_cast<socklen_t>(sizeof(struct timeval));
int ret = setsockopt(GetFd(), SOL_SOCKET, SO_RCVTIMEO, &tv, len);
if (ret < 0) {
+ // LCOV_EXCL_START
ret = -errno;
_E("setsockopt() is failed. errno(%d)", errno);
THROW(ret);
+ // LCOV_EXCL_STOP
}
}
int Connect(const std::string& endpoint);
int Send(const void* buf, unsigned int size);
int Receive(void* buf, unsigned int size);
- int GetReceiveBufferSize();
- int GetSendBufferSize();
- int GetReceiveTimeout();
- void SetReceiveBufferSize(int size);
- void SetSendBufferSize(int size);
void SetReceiveTimeout(int timeout);
bool IsClosed();
int GetFd() const;
thread_ = std::thread([this]() { ThreadRun(); });
}
+// LCOV_EXCL_START
CynaraThread::~CynaraThread() {
finished_ = true;
thread_.join();
}
+// LCOV_EXCL_STOP
void CynaraThread::ThreadRun() {
while (true) {
Job job = queue_.WaitAndPop();
if (finished_)
- return;
+ return; // LCOV_EXCL_LINE
job.Do();
}
namespace rpc_port {
namespace internal {
+// LCOV_EXCL_START
Exception::Exception(int error_code, const std::string& file, int line)
: error_code_(error_code),
message_(std::move(GetErrorMessage(error_code_, file, line))) {
return file.substr(file.find_last_of("/") + 1) + ":" + std::to_string(line) +
" error_code: " + std::to_string(error_code);
}
+// LCOV_EXCL_STOP
} // namespace internal
} // namespace rpc_port
class Exception : public std::exception {
public:
explicit Exception(int error_code, const std::string& file, int line);
- virtual ~Exception() = default;
+ virtual ~Exception() = default; // LCOV_EXCL_LINE
virtual const char* what() const noexcept;
int GetErrorCode();
namespace rpc_port {
namespace internal {
+// LCOV_EXCL_START
MessageSendingThread& MessageSendingThread::GetInst() {
static MessageSendingThread inst;
return inst;
GMainContext* MessageSendingThread::GetContext() {
return context_;
}
+// LCOV_EXCL_STOP
} // namespace internal
} // namespace rpc_port
* limitations under the License.
*/
+#include "parcel-internal.hh"
+
#include <memory>
+#include <utility>
#include "log-private.hh"
-#include "parcel-internal.hh"
namespace rpc_port {
namespace internal {
if (size > 0) {
auto* buf = static_cast<uint8_t*>(malloc(size));
if (buf == nullptr) {
- _E("Out of memory");
- return;
+ _E("Out of memory"); // LCOV_EXEC_LINE
+ return; // LCOV_EXCL_LINE
}
parcel->Read(buf, size);
handle_ = std::move(tizen_base::Parcel(buf, size, false));
}
} else {
+ // LCOV_EXCL_START
handle_ = std::move(
tizen_base::Parcel(parcel->GetData(), parcel->GetDataSize()));
+ // LCOV_EXCL_STOP
}
}
raw_parcel_.reset(raw_parcel);
}
+// LCOV_EXCL_START
tizen_base::Parcel* Parcel::GetRawParcel() const {
return raw_parcel_.get();
}
+// LCOV_EXCL_STOP
} // namespace internal
} // namespace rpc_port
int ret = getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
static_cast<void*>(&cred), &len);
if (ret != 0) {
- _E("getsockopt() is failed. fd(%d), errno(%d)", fd, errno);
- return nullptr;
+ _E("getsockopt() is failed. fd(%d), errno(%d)", fd, errno); // LCOV_EXCL_LINE
+ return nullptr; // LCOV_EXCL_LINE
}
return new (std::nothrow) PeerCred(cred.pid, cred.uid, cred.gid);
return uid_;
}
+
+// LCOV_EXCL_START
gid_t PeerCred::GetGid() const {
return gid_;
}
+// LCOV_EXCL_STOP
} // namespace internal
} // namespace rpc_port
} // namespace
+// LCOV_EXCL_START
Port::DelayMessage::DelayMessage(const char* msg, int index, int size)
: message_(msg, msg + size), index_(index), size_(size) {
}
ptr += index_;
return ptr;
}
+// LCOV_EXCL_STOP
Port::Port(int fd, std::string id)
: fd_(fd), id_(std::move(id)), instance_(""), seq_(0) {
int Port::SetPrivateSharing(const char* paths[], unsigned int size) {
int ret = aul_rpc_port_set_private_sharing(id_.c_str(), paths, size);
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
+
return RPC_PORT_ERROR_NONE;
}
const char* file_list[1] = {path};
int ret = aul_rpc_port_set_private_sharing(id_.c_str(), file_list, 1);
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
int Port::UnsetPrivateSharing() {
int ret = aul_rpc_port_unset_private_sharing(id_.c_str());
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
}
if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid fd(%d)", fd);
- return RPC_PORT_ERROR_IO_ERROR;
+ _E("Invalid fd(%d)", fd); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
while (left) {
}
if (!can_read) {
- _E("read_socket: ...timed out fd %d: errno %d", fd, errno);
- return RPC_PORT_ERROR_IO_ERROR;
+ _E("read_socket: ...timed out fd %d: errno %d", fd, errno); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
continue;
return true;
}
+// LCOV_EXCL_START
bool Port::CanWrite() {
struct pollfd fds[1];
fds[0].fd = fd_;
return true;
}
+// LCOV_EXCL_STOP
int Port::Write(const void* buf, unsigned int size) {
int sent_bytes = 0;
return RPC_PORT_ERROR_NONE;
else if (ret == PORT_STATUS_ERROR_IO_ERROR)
return RPC_PORT_ERROR_IO_ERROR;
- } else if (CanWrite()) {
+ } else if (CanWrite()) { // LCOV_EXCL_LINE
+ // LCOV_EXCL_START
while (!queue_.empty()) {
int port_status = PopDelayedMessage();
if (port_status != PORT_STATUS_ERROR_NONE) {
break;
}
}
+ // LCOV_EXCL_STOP
}
+ // LCOV_EXCL_START
if (delayed_message_size_ > QUEUE_SIZE_MAX) {
_E("cache fail : delayed_message_size (%d), count(%zu)",
delayed_message_size_, queue_.size());
return PushDelayedMessage(
std::make_shared<DelayMessage>(
static_cast<const char*>(buf), sent_bytes, size));
+ // LCOV_EXCL_STOP
}
int Port::Write(const void* buf, unsigned int size, int* sent_bytes) {
const char* buffer = static_cast<const char*>(buf);
if (fd_ < 0 || fd_ >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid fd(%d)", fd_);
- return PORT_STATUS_ERROR_IO_ERROR;
+ _E("Invalid fd(%d)", fd_); // LCOV_EXCL_LINE
+ return PORT_STATUS_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
while (left && (retry_cnt < MAX_RETRY_CNT)) {
nb = send(fd_, buffer, left, MSG_NOSIGNAL);
if (nb == -1) {
if (errno == EINTR) {
+ // LCOV_EXCL_START
LOGI("write_socket: EINTR continue ...");
retry_cnt++;
continue;
+ // LCOV_EXCL_STOP
}
if (errno == EAGAIN || errno == EWOULDBLOCK)
return PORT_STATUS_ERROR_NONE;
}
+// LCOV_EXCL_START
gboolean Port::OnEventReceived(GIOChannel* io, GIOCondition condition,
gpointer data) {
auto* ptr = static_cast<std::weak_ptr<Port>*>(data);
port->PopDelayedMessage();
return G_SOURCE_CONTINUE;
}
+// LCOV_EXCL_STOP
void Port::ClearQueue() {
std::lock_guard<std::recursive_mutex> lock(rw_mutex_);
void Port::IgnoreIOEvent() {
std::lock_guard<std::recursive_mutex> lock(rw_mutex_);
if (source_id_ != 0) {
+ // LCOV_EXCL_START
GSource* source = g_main_context_find_source_by_id(
MessageSendingThread::GetInst().GetContext(), source_id_);
if (source != nullptr && !g_source_is_destroyed(source))
g_source_destroy(source);
source_id_ = 0;
+ // LCOV_EXCL_STOP
}
if (channel_ != nullptr) {
- g_io_channel_unref(channel_);
- channel_ = nullptr;
+ g_io_channel_unref(channel_); // LCOV_EXCL_LINE
+ channel_ = nullptr; // LCOV_EXCL_LINE
}
}
+// LCOV_EXCL_START
int Port::ListenIOEvent() {
std::lock_guard<std::recursive_mutex> lock(rw_mutex_);
channel_ = g_io_channel_unix_new(fd_);
queue_.size(), delayed_message_size_);
return RPC_PORT_ERROR_NONE;
}
+// LCOV_EXCL_STOP
} // namespace internal
} // namespace rpc_port
}
private:
+ // LCOV_EXCL_START
bool CanRead(int timeout);
bool CanWrite();
void IgnoreIOEvent();
static gboolean OnEventReceived(GIOChannel* io,
GIOCondition condition, gpointer data);
void ClearQueue();
+ // LCOV_EXCL_STOP
int fd_;
std::string id_;
size_t size = parcel.GetDataSize();
int ret = client->Send(reinterpret_cast<void*>(&size), sizeof(size));
if (ret != 0) {
- _E("Send() is failed. error(%d)", ret);
- return -1;
+ _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
ret = client->Send(parcel.GetData(), size);
if (ret != 0) {
- _E("Send() is failed. error(%d)", ret);
- return -1;
+ _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
size_t size = 0;
int ret = client->Receive(reinterpret_cast<void*>(&size), sizeof(size));
if (ret != 0) {
- _E("Receive() is failed. error(%d)", ret);
- return -1;
+ _E("Receive() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
uint8_t* buf = static_cast<uint8_t*>(malloc(size));
if (buf == nullptr) {
- _E("Out of memory");
- return -1;
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
ret = client->Receive(buf, size);
if (ret != 0) {
+ // LCOV_EXCL_START
_E("Receive() is failed. error(%d)", ret);
free(buf);
return -1;
+ // LCOV_EXCL_STOP
}
tizen_base::Parcel parcel(buf, size, false);
*response = new (std::nothrow) Response();
if (*response == nullptr) {
- _E("Out of memory");
- return -1;
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
parcel.ReadParcelable(*response);
std::lock_guard<std::recursive_mutex> lock(GetMutex());
_D("Proxy::~Proxy()");
if (main_port_.get() != nullptr)
- DebugPort::RemoveSession(main_port_->GetFd());
+ DebugPort::RemoveSession(main_port_->GetFd()); // LCOV_EXCL_LINE
listener_ = nullptr;
UnsetIdler();
// Main Port
main_client_.reset(Client::Create(this, port_path));
if (main_client_.get() == nullptr)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
Request request(instance.c_str(), kPortTypeMain);
int ret = SendRequest(main_client_.get(), request);
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
if (sync) {
Response* response = nullptr;
ret = ReceiveResponse(main_client_.get(), &response);
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
std::unique_ptr<Response> response_auto(response);
if (response->GetResult() != 0) {
- _E("Permission denied");
- return RPC_PORT_ERROR_PERMISSION_DENIED;
+ _E("Permission denied"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_PERMISSION_DENIED; // LCOV_EXCL_LINE
}
main_client_->SetNonblock();
} else {
ret = main_client_->Watch();
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
// Delegate Port
delegate_client_.reset(Client::Create(this, port_path));
if (delegate_client_.get() == nullptr)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
request.SetPortType(kPortTypeDelegate);
ret = SendRequest(delegate_client_.get(), request);
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
if (sync) {
Response* response = nullptr;
ret = ReceiveResponse(delegate_client_.get(), &response);
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
std::unique_ptr<Response> response_auto(response);
if (response->GetResult() != 0) {
- _E("Permission denied");
- return RPC_PORT_ERROR_PERMISSION_DENIED;
+ _E("Permission denied"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_PERMISSION_DENIED; // LCOV_EXCL_LINE
}
delegate_client_->SetNonblock();
} else {
ret = delegate_client_->Watch();
if (ret != 0)
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
return RPC_PORT_ERROR_NONE;
std::lock_guard<std::recursive_mutex> lock(GetMutex());
if (HasRequested()) {
- _D("Already requested");
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ _D("Already requested"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
}
listener_ = listener;
ret = Watch();
if (ret != 0) {
- listener_ = nullptr;
- return RPC_PORT_ERROR_IO_ERROR;
+ listener_ = nullptr; // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
return RPC_PORT_ERROR_NONE;
} while (retry_count > 0);
if (!exist) {
+ // LCOV_EXCL_START
_E("%s:%s is not ready", real_appid_.c_str(), port_name_.c_str());
listener_ = nullptr;
return RPC_PORT_ERROR_IO_ERROR;
+ // LCOV_EXCL_STOP
}
ret = Connect(true);
if (ret != RPC_PORT_ERROR_NONE) {
- listener_ = nullptr;
- return ret;
+ listener_ = nullptr; // LCOV_EXCL_LINE
+ return ret; // LCOV_EXCL_LINE
}
main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false));
OnPortAppeared, OnPortVanished, this, rpc_port_get_target_uid(),
&watch_handle_);
if (ret != AUL_R_OK) {
- _E("aul_rpc_port_usr_add_watch() is failed. error(%d)", ret);
- return -1;
+ _E("aul_rpc_port_usr_add_watch() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
port_exist_ = Aul::ExistPort(real_appid_, port_name_,
return;
}
+ // LCOV_EXCL_START
std::unique_ptr<char, decltype(std::free)*> appid_ptr(appid, std::free);
real_appid_ = std::string(appid);
_W("alias_appid(%s), real_appid(%s)", alias_appid.c_str(), appid);
+ // LCOV_EXCL_STOP
}
std::recursive_mutex& Proxy::GetMutex() const {
void Proxy::SetConnTimer() {
if (conn_timer_data_) {
- _W("Already exists");
- return;
+ _W("Already exists"); // LCOV_EXCL_START
+ return; // LCOV_EXCL_START
}
conn_timer_data_ = CreateWeakPtr();
if (conn_timer_data_ == nullptr) {
- _E("Out of memory");
- return;
+ _E("Out of memory"); // LCOV_EXCL_START
+ return; // LCOV_EXCL_START
}
g_timeout_add_seconds(10, OnTimedOut, conn_timer_data_);
void Proxy::SetIdler() {
if (idler_data_) {
- _W("Already exists");
- return;
+ _W("Already exists"); // LCOV_EXCL_START
+ return; // LCOV_EXCL_START
}
idler_data_ = CreateWeakPtr();
if (idler_data_ == nullptr) {
- _E("Out of memory");
- return;
+ _E("Out of memory"); // LCOV_EXCL_START
+ return; // LCOV_EXCL_START
}
g_idle_add(OnIdle, idler_data_);
auto* listener = proxy->listener_;
if (listener == nullptr) {
- _E("Invalid context");
- return;
+ _E("Invalid context"); // LCOV_EXCL_START
+ return; // LCOV_EXCL_START
}
proxy->Cancel();
int ret = proxy->Connect(false);
if (ret != RPC_PORT_ERROR_NONE) {
+ // LCOV_EXCL_START
proxy->UnsetConnTimer();
proxy->listener_ = nullptr;
if (ret == RPC_PORT_ERROR_PERMISSION_DENIED)
listener->OnRejected(proxy->target_appid_, ret);
else
listener->OnDisconnected(proxy->target_appid_);
+ // LCOV_EXCL_STOP
}
}
auto* ptr = static_cast<std::weak_ptr<Proxy>*>(user_data);
auto proxy = ptr->lock();
if (proxy == nullptr) {
- _E("Proxy is nullptr");
- return G_SOURCE_REMOVE;
+ _E("Proxy is nullptr"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
if (proxy->conn_timer_data_ == nullptr) {
- _E("Invalid context. proxy(%p)", proxy.get());
- return G_SOURCE_REMOVE;
+ _E("Invalid context. proxy(%p)", proxy.get()); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
proxy->Cancel();
auto* listener = proxy->listener_;
if (listener == nullptr) {
- _E("Invalid context");
- return G_SOURCE_REMOVE;
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
proxy->listener_ = nullptr;
auto* ptr = static_cast<std::weak_ptr<Proxy>*>(user_data);
auto proxy = ptr->lock();
if (proxy == nullptr) {
- _E("Proxy is nullptr");
- return G_SOURCE_REMOVE;
+ _E("Proxy is nullptr"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
if (proxy->idler_data_ == nullptr) {
- _E("Invalid context. proxy(%p)", proxy.get());
- return G_SOURCE_REMOVE;
+ _E("Invalid context. proxy(%p)", proxy.get()); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
DestroyWeakPtr(proxy->idler_data_);
int Proxy::ProxyPort::Watch(bool receive) {
channel_ = g_io_channel_unix_new(GetFd());
if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
+ _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
disconn_source_ = g_io_add_watch(channel_,
static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
Proxy::ProxyPort::OnSocketDisconnected, parent_);
if (disconn_source_ == 0) {
- _E("g_io_add_watch() is failed");
- return -1;
+ _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
if (!receive)
source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
Proxy::ProxyPort::OnDataReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
- return -1;
+ _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
auto* listener = proxy->listener_;
if (listener == nullptr) {
- _E("Invalid context");
- return G_SOURCE_REMOVE;
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
int fd = g_io_channel_unix_get_fd(channel);
proxy->listener_ = nullptr;
listener->OnDisconnected(proxy->target_appid_);
DebugPort::RemoveSession(fd);
- return G_SOURCE_REMOVE;;
+ return G_SOURCE_REMOVE;
}
gboolean Proxy::ProxyPort::OnDataReceived(GIOChannel* channel,
std::lock_guard<std::recursive_mutex> lock(proxy->GetMutex());
auto* listener = proxy->listener_;
if (listener == nullptr) {
- _E("Invalid context");
- return G_SOURCE_REMOVE;
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
int fd = g_io_channel_unix_get_fd(channel);
try {
client.reset(new (std::nothrow) Proxy::Client(parent));
} catch (const Exception& e) {
- _E("Exception(%s) occurs", e.what());
- return nullptr;
+ _E("Exception(%s) occurs", e.what()); // LCOV_EXCL_LINE
+ return nullptr; // LCOV_EXCL_LINE
}
int ret;
if (ret == 0) {
break;
} else if (ret < 0) {
+ // LCOV_EXCL_START
_D("Connect() is failed");
usleep(100 * 1000);
retry_count--;
+ // LCOV_EXCL_STOP
}
} while (retry_count > 0);
if (ret != 0) {
- _E("Connect() is failed");
- return nullptr;
+ _E("Connect() is failed"); // LCOV_EXCL_LINE
+ return nullptr; // LCOV_EXCL_LINE
}
try {
client->SetReceiveTimeout(5000);
} catch (const Exception& e) {
- _E("Exception occurs. error(%s)", e.what());
- return nullptr;
+ _E("Exception occurs. error(%s)", e.what()); // LCOV_EXCL_LINE
+ return nullptr; // LCOV_EXCL_LINE
}
_W("endpoint(%s), fd(%d)", endpoint.c_str(), client->GetFd());
int Proxy::Client::Watch() {
channel_ = g_io_channel_unix_new(GetFd());
if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
+ _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
Proxy::Client::OnResponseReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
- return -1;
+ _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
disconn_source_ = g_io_add_watch(channel_,
static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
Proxy::Client::OnSocketDisconnected, parent_);
if (disconn_source_ == 0) {
- _E("g_io_add_watch() is failed");
- return -1;
+ _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
}
+// LCOV_EXCL_START
void Proxy::Client::SetDisconnectedSource(guint source) {
disconn_source_ = source;
}
+// LCOV_EXCL_STOP
void Proxy::Client::SetSource(guint source) {
source_ = source;
}
+// LCOV_EXCL_START
gboolean Proxy::Client::OnSocketDisconnected(GIOChannel* channel,
GIOCondition cond, gpointer user_data) {
auto* proxy = static_cast<Proxy*>(user_data);
listener->OnDisconnected(proxy->target_appid_);
return G_SOURCE_REMOVE;
}
+// LCOV_EXCL_STOP
gboolean Proxy::Client::OnResponseReceived(GIOChannel* channel,
GIOCondition cond, gpointer user_data) {
proxy->UnsetConnTimer();
auto* listener = proxy->listener_;
if (listener == nullptr) {
- _E("Invalid context");
- return G_SOURCE_REMOVE;
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
bool is_delegate = false;
}
if (client.get() == nullptr) {
- _E("Unknown fd(%d)", fd);
- return G_SOURCE_REMOVE;
+ _E("Unknown fd(%d)", fd); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
client->SetSource(0);
Response* response = nullptr;
int ret = ReceiveResponse(client.get(), &response);
if (ret != 0) {
+ // LCOV_EXCL_START
proxy->listener_ = nullptr;
proxy->main_client_.reset();
proxy->delegate_client_.reset();
listener->OnRejected(proxy->target_appid_, RPC_PORT_ERROR_IO_ERROR);
return G_SOURCE_REMOVE;
+ // LCOV_EXCL_STOP
}
std::unique_ptr<Response> response_auto(response);
RPC_API void rpc_port_set_target_uid(uid_t target_uid) {
__target_uid.exchange(target_uid);
+ set_last_result(RPC_PORT_ERROR_NONE);
}
RPC_API uid_t rpc_port_get_target_uid(void) {
* limitations under the License.
*/
+#include "include/rpc-port-parcel.h"
+
#include <parcel.hh>
#include <stdint.h>
#include <string.h>
#include <memory>
-#include "include/rpc-port-parcel.h"
#include "log-private.hh"
#include "parcel-internal.hh"
#include "port-internal.hh"
buf = static_cast<unsigned char*>(malloc(len));
if (buf == nullptr) {
- _E("Out of memory");
- return RPC_PORT_ERROR_IO_ERROR;
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
ret = rpc_port_read(port, buf, len);
if (ret != 0) {
- free(buf);
- return ret;
+ free(buf); // LCOV_EXCL_LINE
+ return ret; // LCOV_EXCL_LINE
}
}
auto* parcel = new (std::nothrow) internal::Parcel();
if (parcel == nullptr) {
+ // LCOV_EXCL_START
_E("Out of memory");
free(buf);
return RPC_PORT_ERROR_IO_ERROR;
+ // LCOV_EXCL_STOP
}
tizen_base::Parcel raw_parcel(buf, len, false);
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_byte(parcel->GetHandle(), b);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_read_byte() is failed. error(%d)", ret);
+ _E("parcel_read_byte() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_int16(parcel->GetHandle(), i);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_read_int16() is failed. error(%d)", ret);
+ _E("parcel_read_int16() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_int32(parcel->GetHandle(), i);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_read_int32() is failed. error(%d)", ret);
+ _E("parcel_read_int32() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
int64_t val = 0;
int ret = parcel_read_int64(parcel->GetHandle(), &val);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_read_int64() is failed. error(%d)", ret);
+ _E("parcel_read_int64() is failed. error(%d)", ret); // LCOV_EXCL_LINE
*i = static_cast<long long>(val);
return RPC_PORT_ERROR_NONE;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_float(parcel->GetHandle(), f);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_read_float() is failed. error(%d)", ret);
+ _E("parcel_read_float() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_double(parcel->GetHandle(), d);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_read_double() is failed. error(%d)", ret);
+ _E("parcel_read_double() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_string(parcel->GetHandle(), str);
if (ret != PARCEL_ERROR_NONE) {
- _E("parcel_read_string() is failed. error(%d)", ret);
- *str = strdup("");
+ _E("parcel_read_string() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ *str = strdup(""); // LCOV_EXCL_LINE
}
return RPC_PORT_ERROR_NONE;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_bool(parcel->GetHandle(), b);
if (ret != 0)
- _E("parcel_read_bool() is failed. error(%d)", ret);
+ _E("parcel_read_bool() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
char* raw = nullptr;
int ret = parcel_read_string(parcel->GetHandle(), &raw);
if (ret != 0) {
- _E("parcel_read_string() is failed. error(%d)", ret);
- *b = bundle_create();
+ _E("parcel_read_string() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ *b = bundle_create(); // LCOV_EXCL_LINE
} else {
*b = bundle_decode(reinterpret_cast<bundle_raw*>(raw), strlen(raw));
std::free(raw);
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_int32(parcel->GetHandle(), count);
if (ret != 0)
- _E("parcel_read_int32() is failed. error(%d)", ret);
+ _E("parcel_read_int32() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
int ret = parcel_burst_read(parcel->GetHandle(), static_cast<void*>(buf),
valid_size);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_read() is failed. error(%d)", ret);
+ _E("parcel_read() is failed. error(%d)", ret); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
*tag = strdup(raw_tag.c_str());
if (*tag == nullptr)
- return RPC_PORT_ERROR_OUT_OF_MEMORY;
+ return RPC_PORT_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
*raw = raw_parcel->GetData();
*size = static_cast<unsigned int>(raw_parcel->GetDataSize());
} else {
+ // LCOV_EXCL_START
_E("Out of memory");
*raw = nullptr;
*size = 0;
+ // LCOV_EXCL_STOP
}
return RPC_PORT_ERROR_NONE;
ret = rpc_port_parcel_from_array(parcel, raw, size);
if (ret != RPC_PORT_ERROR_NONE) {
- rpc_port_parcel_destroy(parcel);
- return ret;
+ rpc_port_parcel_destroy(parcel); // LCOV_EXCL_LINE
+ return ret; // LCOV_EXCL_LINE
}
*h = parcel;
auto p = new (std::nothrow) std::shared_ptr<::ProxyExt>(
new (std::nothrow) ::ProxyExt());
if (p == nullptr) {
- _E("Out of memory");
+ _E("Out of memory"); // LCOV_EXCL_LINE
} else if (p->get() == nullptr) {
+ // LCOV_EXCL_START
_E("Out of memory");
delete p;
p = nullptr;
+ // LCOV_EXCL_STOP
} else {
_W("rpc_port_proxy_create(%p)", p->get());
}
auto p = static_cast<std::shared_ptr<::ProxyExt>*>(h);
auto* proxy = p->get();
if (proxy->IsDestroying()) {
- _E("already destroyed. handle(%p)", proxy);
- abort();
+ _E("already destroyed. handle(%p)", proxy); // LCOV_EXCL_LINE
+ abort(); // LCOV_EXCL_LINE
}
_W("rpc_port_proxy_destroy(%p)", proxy);
_W("rpc_port_stub_destroy(%p)", h);
auto p = static_cast<::StubExt*>(h);
if (p->IsDestroying()) {
- _E("already destroyed. handle(%p)", h);
- abort();
+ _E("already destroyed. handle(%p)", h); // LCOV_EXCL_LINE
+ abort(); // LCOV_EXCL_LINE
}
p->SetDestroying(true);
int ret = aul_rpc_port_usr_create(p->GetPortName().c_str(),
rpc_port_get_target_uid(), &fd);
if (ret != AUL_R_OK) {
- _E("aul_rpc_port_usr_create() is failed. error(%d)", ret);
- return RPC_PORT_ERROR_IO_ERROR;
+ _E("aul_rpc_port_usr_create() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
return p->Listen(p, fd);
auto* addr_ptr = reinterpret_cast<struct sockaddr*>(&addr);
int client_fd = accept(GetFd(), addr_ptr, &len);
if (client_fd == -1) {
- _E("accept() is failed. errno(%d)", errno);
- return nullptr;
+ _E("accept() is failed. errno(%d)", errno); // LCOV_EXCL_LINE
+ return nullptr; // LCOV_EXCL_LINE
}
return new (std::nothrow) ClientSocket(client_fd);
return fd_;
}
+// LCOV_EXCL_START
int ServerSocket::Listen(int backlog) {
int ret = listen(GetFd(), backlog);
if (ret < 0) {
return 0;
}
+// LCOV_EXCL_STOP
void ServerSocket::Close() {
if (fd_ > -1) {
size_t size = 0;
int ret = client->Receive(reinterpret_cast<void*>(&size), sizeof(size));
if (ret != 0) {
- _E("Receive() is failed. error(%d)", ret);
- return -1;
+ _E("Receive() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
std::vector<uint8_t> buf(size);
ret = client->Receive(buf.data(), size);
if (ret != 0) {
- _E("Receive() is failed. error(%d)", ret);
- return -1;
+ _E("Receive() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
tizen_base::Parcel parcel(buf.data(), buf.size());
*request = new (std::nothrow) Request();
if (*request == nullptr) {
- _E("Out of memory");
- return -1;
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
parcel.ReadParcelable(*request);
size_t size = parcel.GetDataSize();
int ret = client->Send(reinterpret_cast<void*>(&size), sizeof(size));
if (ret != 0) {
- _E("Send() is failed. error(%d)", ret);
- return -1;
+ _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
ret = client->Send(parcel.GetData(), size);
if (ret != 0) {
- _E("Send() is failed. error(%d)", ret);
- return -1;
+ _E("Send() is failed. error(%d)", ret); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
return RPC_PORT_ERROR_INVALID_PARAMETER;
if (listener_ != nullptr) {
- _E("Already listening!");
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ _E("Already listening!"); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_INVALID_PARAMETER; // LCOV_EXCL_LINE
}
std::lock_guard<std::recursive_mutex> lock(GetMutex());
access_controller_->SetTrusted(trusted);
}
+// LCOV_EXCL_START
std::shared_ptr<Port> Stub::FindPort(const std::string& instance) const {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
for (auto& p : ports_) {
return {};
}
+// LCOV_EXCL_STOP
std::shared_ptr<Port> Stub::FindDelegatePort(
const std::string& instance) const {
std::lock_guard<std::recursive_mutex> lock(stub->GetMutex());
auto* listener = stub->listener_;
if (listener == nullptr) {
- _E("Invalid context");
- return G_SOURCE_REMOVE;
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
int fd = g_io_channel_unix_get_fd(channel);
std::lock_guard<std::recursive_mutex> lock(stub->GetMutex());
auto* listener = stub->listener_;
if (listener == nullptr) {
- _E("Invalid context");
- return G_SOURCE_REMOVE;
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
int fd = g_io_channel_unix_get_fd(channel);
Watch(watch);
}
+// LCOV_EXCL_START
Stub::AcceptedPort::AcceptedPort(Stub* parent, bool isDelegate, int fd,
std::string id, bool watch)
: Port(fd, std::move(id)), parent_(parent),
is_delegate_(isDelegate) {
Watch(watch);
}
+// LCOV_EXCL_STOP
Stub::AcceptedPort::~AcceptedPort() {
if (disconn_source_ > 0)
int Stub::AcceptedPort::Watch(bool receive) {
channel_ = g_io_channel_unix_new(GetFd());
if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
+ _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
disconn_source_ = g_io_add_watch(channel_,
static_cast<GIOCondition>(G_IO_ERR | G_IO_HUP | G_IO_NVAL),
OnSocketDisconnected, parent_);
if (disconn_source_ == 0) {
- _E("g_io_add_watch() is failed");
- return -1;
+ _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
if (!receive)
source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
OnDataReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
- return -1;
+ _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
int Stub::Server::Listen() {
channel_ = g_io_channel_unix_new(GetFd());
if (channel_ == nullptr) {
- _E("g_io_channel_unix_new() is failed");
- return -1;
+ _E("g_io_channel_unix_new() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
source_ = g_io_add_watch(channel_, static_cast<GIOCondition>(G_IO_IN),
OnRequestReceived, parent_);
if (source_ == 0) {
- _E("g_io_add_watch() is failed");
- return -1;
+ _E("g_io_add_watch() is failed"); // LCOV_EXCL_LINE
+ return -1; // LCOV_EXCL_LINE
}
return 0;
auto* stub = static_cast<Stub*>(user_data);
std::lock_guard<std::recursive_mutex> lock(stub->GetMutex());
if (stub->listener_ == nullptr) {
- _E("Invalid context");
- return G_SOURCE_REMOVE;
+ _E("Invalid context"); // LCOV_EXCL_LINE
+ return G_SOURCE_REMOVE; // LCOV_EXCL_LINE
}
std::shared_ptr<ClientSocket> client(stub->server_->Accept());
if (client.get() == nullptr) {
- _E("Out of memory");
- return G_SOURCE_CONTINUE;
+ _E("Out of memory"); // LCOV_EXCL_LINE
+ return G_SOURCE_CONTINUE; // LCOV_EXCL_LINE
}
Request* request = nullptr;
int ret = ReceiveRequest(client.get(), &request);
if (ret != 0)
- return G_SOURCE_CONTINUE;
+ return G_SOURCE_CONTINUE; // LCOV_EXCL_LINE
std::shared_ptr<Request> request_auto(request);
std::shared_ptr<PeerCred> cred(PeerCred::Get(client->GetFd()));
if (cred.get() == nullptr) {
- _E("Failed to create peer credentials");
- return G_SOURCE_CONTINUE;
+ _E("Failed to create peer credentials"); // LCOV_EXCL_LINE
+ return G_SOURCE_CONTINUE; // LCOV_EXCL_LINE
}
std::string app_id = Aul::GetAppId(cred->GetPid());
auto response_func = [=](int res) -> void {
if (freed_stubs_.find(stub) != freed_stubs_.end())
- return;
+ return; // LCOV_EXCL_LINE
Response response(res);
int ret = SendResponse(client.get(), response);
if (ret != 0)
- return;
+ return; // LCOV_EXCL_LINE
if (res != 0) {
- _E("Access denied. fd(%d), pid(%d)", client->GetFd(), cred->GetPid());
- return;
+ _E("Access denied. fd(%d), pid(%d)", client->GetFd(), cred->GetPid()); // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
client->SetNonblock();
int res;
if (cred->GetUid() >= kRegularUidMin) {
if (cred->GetUid() != getuid() && getuid() >= kRegularUidMin) {
- _E("Reject request. %u:%u", cred->GetUid(), getuid());
- res = -1;
+ _E("Reject request. %u:%u", cred->GetUid(), getuid()); // LCOV_EXCL_LINE
+ res = -1; // LCOV_EXCL_LINE
} else {
stub->access_controller_->CheckAsync(client->GetFd(), app_id,
response_func);
extern "C" int aul_rpc_port_usr_destroy(const char* port_name, uid_t uid) {
return MOCK_HOOK_P2(AulMock, aul_rpc_port_usr_destroy, port_name, uid);
}
+
+extern "C" int aul_proc_register(const char* proc_name, bundle* extra) {
+ return MOCK_HOOK_P2(AulMock, aul_proc_register, proc_name, extra);
+}
+
+extern "C" int aul_proc_deregister() {
+ return MOCK_HOOK_P0(AulMock, aul_proc_deregister);
+}
public:
virtual ~AulMock() {}
- MOCK_METHOD3(aul_app_get_appid_bypid,
- int (int, char*, int));
+ MOCK_METHOD3(aul_app_get_appid_bypid, int(int, char*, int));
MOCK_METHOD4(aul_rpc_port_usr_get_path,
- int (const char*, const char*, uid_t, char**));
+ int(const char*, const char*, uid_t, char**));
MOCK_METHOD3(aul_rpc_port_usr_prepare_stub,
- int (const char*, const char*, uid_t));
+ int(const char*, const char*, uid_t));
MOCK_METHOD4(aul_rpc_port_usr_exist,
- int (const char*, const char*, uid_t, bool*));
- MOCK_METHOD0(aul_rpc_port_notify_rpc_finished,
- int ());
+ int(const char*, const char*, uid_t, bool*));
+ MOCK_METHOD0(aul_rpc_port_notify_rpc_finished, int());
MOCK_METHOD3(aul_rpc_port_set_private_sharing,
- int (const char*, const char**, unsigned int));
- MOCK_METHOD1(aul_rpc_port_unset_private_sharing,
- int (const char*));
+ int(const char*, const char**, unsigned int));
+ MOCK_METHOD1(aul_rpc_port_unset_private_sharing, int(const char*));
MOCK_METHOD7(aul_rpc_port_usr_add_watch,
- int (const char*, const char*, aul_rpc_port_appeared_cb,
- aul_rpc_port_vanished_cb, void*, uid_t, aul_rpc_port_watch_h*));
- MOCK_METHOD1(aul_rpc_port_remove_watch,
- int (aul_rpc_port_watch_h));
- MOCK_METHOD2(aul_svc_get_appid_by_alias_appid,
- int (const char*, char**));
- MOCK_METHOD3(aul_rpc_port_usr_create,
- int (const char*, uid_t, int*));
- MOCK_METHOD2(aul_rpc_port_usr_destroy,
- int (const char*, uid_t));
+ int(const char*, const char*, aul_rpc_port_appeared_cb,
+ aul_rpc_port_vanished_cb, void*, uid_t,
+ aul_rpc_port_watch_h*));
+ MOCK_METHOD1(aul_rpc_port_remove_watch, int(aul_rpc_port_watch_h));
+ MOCK_METHOD2(aul_svc_get_appid_by_alias_appid, int(const char*, char**));
+ MOCK_METHOD3(aul_rpc_port_usr_create, int(const char*, uid_t, int*));
+ MOCK_METHOD2(aul_rpc_port_usr_destroy, int(const char*, uid_t));
+ MOCK_METHOD2(aul_proc_register, int(const char*, bundle*));
+ MOCK_METHOD0(aul_proc_deregister, int());
};
#endif // UNIT_TESTS_MOCK_AUL_MOCK_HH_
#include <stdexcept>
#include "rpc-port-parcel.h"
+#include "rpc-port-parcel-internal.h"
using ::testing::AtLeast;
bool touch_to_ = false;
};
-/*
- * @testcase rpc_port_parcel_create_destroy_P
- * @description Creates and destroys the rpc-port parcel handle
- * @apicovered rpc_port_parcel_create, rpc_port_parcel_destroy
- */
TEST(rpc_port_parcel, rpc_port_parcel_create_destroy_P) {
rpc_port_parcel_h handle;
ASSERT_EQ(ret, 0);
}
-/*
- * @testcase rpc_port_parcel_read_write_byte_P
- * @description Writes and reads the byte data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_byte, rpc_port_parcel_read_byte
- */
TEST_F(ParcelTest, rpc_port_parcel_write_read_byte_P) {
int ret = rpc_port_parcel_write_byte(handle_, 'k');
ASSERT_EQ(ret, 0);
ASSERT_EQ(b, 'k');
}
-/*
- * @testcase rpc_port_parcel_read_write_int16_P
- * @description Writes and reads the int16 data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_int16, rpc_port_parcel_read_int16
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_in16_P) {
int ret = rpc_port_parcel_write_int16(handle_, 123);
ASSERT_EQ(ret, 0);
ASSERT_EQ(b, 123);
}
-/*
- * @testcase rpc_port_parcel_read_write_int32_P
- * @description Writes and reads the int32 data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_int32, rpc_port_parcel_read_int32
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_int32_P) {
int ret = rpc_port_parcel_write_int32(handle_, 123456);
ASSERT_EQ(ret, 0);
ASSERT_EQ(b, 123456);
}
-/*
- * @testcase rpc_port_parcel_read_write_int64_P
- * @description Writes and reads the int64 data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_int64, rpc_port_parcel_read_int64
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_int64_P) {
int ret = rpc_port_parcel_write_int64(handle_, 12345678);
ASSERT_EQ(ret, 0);
ASSERT_EQ(b, 12345678);
}
-/*
- * @testcase rpc_port_parcel_read_write_float_P
- * @description Writes and reads the float data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_float, rpc_port_parcel_read_float
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_float_P) {
int ret = rpc_port_parcel_write_float(handle_, 123.456f);
ASSERT_EQ(ret, 0);
ASSERT_EQ(b, 123.456f);
}
-/*
- * @testcase rpc_port_parcel_read_write_double_P
- * @description Writes and reads the double data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_double, rpc_port_parcel_read_double
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_double_P) {
int ret = rpc_port_parcel_write_double(handle_, 123.456f);
ASSERT_EQ(ret, 0);
ASSERT_EQ(b, 123.456f);
}
-/*
- * @testcase rpc_port_parcel_read_write_string_P
- * @description Writes and reads the string data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_string, rpc_port_parcel_read_string
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_string_P) {
const char str[] = "abcdef";
int ret = rpc_port_parcel_write_string(handle_, str);
ASSERT_STREQ(s1.Get(), str);
}
-/*
- * @testcase rpc_port_parcel_read_write_bool_P
- * @description Writes and reads the boolean data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_bool, rpc_port_parcel_read_bool
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_bool_P) {
int ret = rpc_port_parcel_write_bool(handle_, true);
ASSERT_EQ(ret, 0);
ASSERT_TRUE(b);
}
-/*
- * @testcase rpc_port_parcel_read_write_bundle_P
- * @description Writes and reads the bundle data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_bundle, rpc_port_parcel_read_bundle
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_bundle_P) {
bundle* b = bundle_create();
ASSERT_NE(b, nullptr);
ASSERT_STREQ("Value", str);
}
-/*
- * @testcase rpc_port_parcel_read_write_array_count_P
- * @description Writes and reads the array count data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write_array_count, rpc_port_parcel_read_array_count
- */
TEST_F(ParcelTest, rpc_port_parcle_read_write_array_count_P) {
int ret = rpc_port_parcel_write_array_count(handle_, 123);
ASSERT_EQ(ret, 0);
ASSERT_EQ(c, 123);
}
-/*
- * @testcase rpc_port_parcel_read_write_P
- * @description Writes and reads the data to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_write, rpc_port_parcel_read
- */
TEST_F(ParcelTest, rpc_port_parcel_read_write_P) {
rpc_port_parcelable_t p = {
.to = WriteParcelable,
ASSERT_TRUE(touch_from_);
}
-/*
- * @testcase rpc_port_parcel_burst_read_write_P
- * @description Writes and reads the data by burst mode to the rpc-port parcel handle
- * @apicovered rpc_port_parcel_burst_write, rpc_port_parcel_burst_read
- */
TEST_F(ParcelTest, rpc_port_parcel_burst_read_write_P) {
unsigned char buf[] = { 0, 1, 2, 3, 4 };
int ret = rpc_port_parcel_burst_write(handle_, buf, sizeof(buf));
}
}
-/*
- * @testcase rpc_port_parcel_get_header_P
- * @description Gets the header handle from the rpc port parcel handle
- * @apicovered rpc_port_parcel_get_header
- */
TEST_F(ParcelTest, rpc_port_parcel_get_header_P) {
rpc_port_parcel_header_h header = nullptr;
int ret = rpc_port_parcel_get_header(handle_, &header);
ASSERT_NE(header, nullptr);
}
-/*
- * @testcase rpc_port_parcel_get_header_N
- * @description Gets the header handle from the rpc port parcel handle
- * @apicovered rpc_port_parcel_get_header
- */
TEST_F(ParcelTest, rpc_port_parcel_get_header_N) {
int ret = rpc_port_parcel_get_header(nullptr, nullptr);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
-/*
- * @testcase rpc_port_parcel_header_set_get_tag_P
- * @description Sets and gets the tag
- * @apicovered rpc_port_parcel_header_set_tag, rpc_port_parcel_header_get_tag
- */
TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_P) {
rpc_port_parcel_header_h header = nullptr;
int ret = rpc_port_parcel_get_header(handle_, &header);
ASSERT_STREQ(tag, out_tag);
}
-/*
- * @testcase rpc_port_parcel_header_set_get_tag_without_set_tag_P
- * @description gets the tag without set tag.
- * @apicovered rpc_port_parcel_header_get_tag
- */
TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_without_set_tag_P) {
rpc_port_parcel_header_h header = nullptr;
int ret = rpc_port_parcel_get_header(handle_, &header);
ASSERT_STREQ(out_tag, "");
}
-/*
- * @testcase rpc_port_parcel_header_set_get_tag_N
- * @description Sets and gets the tag
- * @apicovered rpc_port_parcel_header_set_tag, rpc_port_parcel_header_get_tag
- */
TEST_F(ParcelTest, rpc_port_parcel_header_set_get_tag_N) {
rpc_port_parcel_header_h header = nullptr;
int ret = rpc_port_parcel_get_header(handle_, &header);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
-/*
- * @testcase rpc_port_parcel_header_set_get_seq_num_P
- * @description Sets and gets the sequence number
- * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num
- */
TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_P) {
rpc_port_parcel_header_h header = nullptr;
int ret = rpc_port_parcel_get_header(handle_, &header);
ASSERT_EQ(seq_num, 100);
}
-/*
- * @testcase rpc_port_parcel_header_set_get_seq_num_N
- * @description Sets and gets the sequence number
- * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num
- */
TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_N) {
int ret = rpc_port_parcel_header_set_seq_num(nullptr, -1);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
-/*
- * @testcase rpc_port_parcel_header_get_timestamp_P
- * @description Gets the timestamp from the header handle of the rpc port parcel
- * @apicovered rpc_port_parcel_header_get_timestamp
- */
TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_P) {
rpc_port_parcel_header_h header = nullptr;
int ret = rpc_port_parcel_get_header(handle_, &header);
ASSERT_NE(timestamp.tv_nsec, 0);
}
-/*
- * @testcase rpc_port_parcel_header_get_timestamp_N
- * @description Gets the timestamp from the header handle of the rpc port parcel
- * @apicovered rpc_port_parcel_header_get_timestamp
- */
TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_N) {
int ret = rpc_port_parcel_header_get_timestamp(nullptr, nullptr);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
-/*
- * @testcase rpc_port_parcel_get_raw_P
- * @description Gets the raw data from the rpc port parcel handle
- * @apicovered rpc_port_parcel_get_raw
- */
TEST_F(ParcelTest, rpc_port_parcel_get_raw_P) {
int ret = rpc_port_parcel_write_string(handle_, "test");
ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
ASSERT_NE(raw_size, 0);
}
-/*
- * @testcase rpc_port_parcel_get_raw_N
- * @description Gets the raw data from the rpc port parcel handle
- * @apicovered rpc_port_parcel_get_raw
- */
TEST_F(ParcelTest, rpc_port_parcel_get_raw_N) {
int ret = rpc_port_parcel_get_raw(nullptr, nullptr, nullptr);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
-/*
- * @testcase rpc_port_parcel_create_from_raw_P
- * @description Creates the rpc parcel handle with given the raw data.
- * @apicovered rpc_port_parcel_create_from_raw
- */
TEST_F(ParcelTest, rpc_port_parcel_create_from_raw_P) {
int ret = rpc_port_parcel_write_string(handle_, "test");
ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
ASSERT_EQ(std::string(str), "test");
}
-/*
- * @testcase rpc_port_parcel_create_from_raw_N
- * @description Creates the rpc parcel handle with given the raw data.
- * @apicovered rpc_port_parcel_create_from_raw
- */
TEST_F(ParcelTest, rpc_port_parcel_create_from_raw_N) {
int ret = rpc_port_parcel_create_from_raw(nullptr, nullptr, 0);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
-/*
- * @testcase rpc_port_parcel_create_without_header_P
- * @description Creates the rpc parcel handle without the header.
- * @apicovered rpc_port_parcel_create_without_header
- */
TEST_F(ParcelTest, rpc_port_parcel_create_without_header_P) {
rpc_port_parcel_h parcel = nullptr;
int ret = rpc_port_parcel_create_without_header(&parcel);
ASSERT_EQ(header, nullptr);
}
-/*
- * @testcase rpc_port_parcel_create_without_header_N
- * @description Creates the rpc parcel handle without the header.
- * @apicovered rpc_port_parcel_create_without_header
- */
TEST_F(ParcelTest, rpc_port_parcel_create_without_header_N) {
int ret = rpc_port_parcel_create_without_header(nullptr);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
+
+TEST_F(ParcelTest, rpc_port_parcel_reset_reader_P) {
+ int ret = rpc_port_parcel_write_string(handle_, "test");
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ char* value = nullptr;
+ ret = rpc_port_parcel_read_string(handle_, &value);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ std::unique_ptr<char, decltype(std::free)*> value_auto(value, std::free);
+ ASSERT_EQ(std::string(value), "test");
+
+ ret = rpc_port_parcel_reset_reader(handle_);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ value = nullptr;
+ ret = rpc_port_parcel_read_string(handle_, &value);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ value_auto = std::unique_ptr<char, decltype(std::free)*>(value, std::free);
+ ASSERT_EQ(std::string(value), "test");
+}
+
+TEST_F(ParcelTest, rpc_port_parcel_reset_reader_N) {
+ int ret = rpc_port_parcel_reset_reader(nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(ParcelTest, rpc_port_parcel_to_array_P) {
+ int ret = rpc_port_parcel_write_string(handle_, "test");
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ char* array = nullptr;
+ unsigned int size = 0;
+ ret = rpc_port_parcel_to_array(handle_, reinterpret_cast<void**>(&array),
+ &size);
+ std::unique_ptr<char, decltype(std::free)*> array_auto(array, std::free);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_NE(array, nullptr);
+ ASSERT_NE(size, 0);
+}
+
+TEST_F(ParcelTest, rpc_port_parcel_to_array_N) {
+ int ret = rpc_port_parcel_to_array(nullptr, nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
void Vanish() {
if (vanished_cb_)
vanished_cb_(app_id_.c_str(), port_name_.c_str(), -1, user_data_);
-
}
private:
return 0;
}
+int FakeAulProcRegister(const char* proc_name, bundle* extra) {
+ if (proc_name == nullptr)
+ return -1;
+
+ return 0;
+}
+
+int FakeAulProcDeregister() {
+ return 0;
+}
+
} // namespace
class Mocks : public ::testing::NiceMock<AulMock> {};
EXPECT_CALL(GetMock<AulMock>(),
aul_rpc_port_usr_destroy(_, _))
.WillRepeatedly(Invoke(FakeAulRpcPortUsrDestroy));
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_proc_register(_, _))
+ .WillRepeatedly(Invoke(FakeAulProcRegister));
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_proc_deregister())
+ .WillRepeatedly(Invoke(FakeAulProcDeregister));
}
void RunMainLoop() {
rpc_port_h port, void *data) -> int {
RpcPortConnection* p = static_cast<RpcPortConnection*>(data);
p->stub_port_ = port;
- int ret = rpc_port_stub_get_port(p->stub_handle_,
+ pid_t pid = -1;
+ uid_t uid = 0;
+ int ret = rpc_port_get_peer_info(port, &pid, &uid);
+ if (ret != RPC_PORT_ERROR_NONE)
+ std::cerr << "Failed to get peer info" << std::endl;
+
+ rpc_port_h main_port = nullptr;
+ ret = rpc_port_stub_get_port(p->stub_handle_, RPC_PORT_PORT_MAIN,
+ instance, &main_port);
+ if (ret != RPC_PORT_ERROR_NONE)
+ std::cerr << "Failed to get main port" << std::endl;
+
+ ret = rpc_port_stub_get_port(p->stub_handle_,
RPC_PORT_PORT_CALLBACK, instance, &p->stub_callback_port_);
p->Finish();
- if (ret != 0)
+ if (ret != RPC_PORT_ERROR_NONE)
return -1;
- return 0;
+
+ return RPC_PORT_ERROR_NONE;
}, this);
- ASSERT_EQ(ret, 0);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
ret = rpc_port_stub_add_disconnected_event_cb(stub_handle_,
[](const char* sender, const char* instance, void *data) {
}, p);
},
this);
- ASSERT_EQ(ret, 0);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
ret = rpc_port_stub_add_privilege(stub_handle_,
"http://tizen.org/privilege/appmanager.launch");
- ASSERT_EQ(ret, 0);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ret = rpc_port_stub_set_trusted(stub_handle_, true);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
ret = rpc_port_stub_listen(stub_handle_);
- ASSERT_EQ(ret, 0);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
}
void ProxySetup() {
bool touch_proxy_received_event_cb_ = false;
};
-/*
- * @testcase rpc_port_event_connect_P
- * @description After the rpc_port_proxy_connect() is called,
- * the rambda function is called by connected events.
- * @apicovered rpc_port_stub_add_connected_event_cb, rpc_port_stub_listen,
- * rpc_port_proxy_add_connected_event_cb, rpc_port_proxy_connect,
- */
TEST_F(RpcPortBase, rpc_port_event_connect) {
int ret = rpc_port_stub_add_connected_event_cb(stub_handle_,
[](const char *sender, const char* instance, void *data) {
ASSERT_TRUE(touch_stub_connected_event_cb_);
}
-/*
- * @testcase rpc_port_event_connect_sync_P
- * @description After the rpc_port_proxy_connect_sync() is called,
- * the rambda function is called by connected events.
- * @apicovered rpc_port_stub_add_connected_event_cb, rpc_port_stub_listen,
- * rpc_port_proxy_add_connected_event_cb, rpc_port_proxy_connect_sync,
- */
TEST_F(RpcPortBase, rpc_port_event_connect_sync) {
int ret = rpc_port_stub_add_connected_event_cb(stub_handle_,
[](const char *sender, const char* instance, void *data) {
ASSERT_TRUE(touch_stub_connected_event_cb_);
}
-/*
- * @testcase rpc_port_proxy_event_reject_n
- * @description After the rpc_port_proxy_connect() is called,
- * the rambda function is called by the rejected event.
- * @apicovered rpc_port_proxy_add_connected_event_cb,
- * rpc_port_proxy_connect,
- */
+TEST_F(RpcPortBase, rpc_port_set_target_uid_P) {
+ rpc_port_set_target_uid(5001);
+ ASSERT_EQ(get_last_result(), RPC_PORT_ERROR_NONE);
+}
+
+TEST_F(RpcPortBase, rpc_port_get_target_uid_P) {
+ uid_t uid = rpc_port_get_target_uid();
+ ASSERT_EQ(uid, 5001);
+}
+
+TEST_F(RpcPortBase, rpc_port_register_proc_info_P) {
+ int ret = rpc_port_register_proc_info("UnitTest", nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+}
+
+TEST_F(RpcPortBase, rpc_port_register_proc_info_N) {
+ int ret = rpc_port_register_proc_info(nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(RpcPortBase, rpc_port_deregister_proc_info_P) {
+ int ret = rpc_port_deregister_proc_info();
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+}
+
+TEST_F(RpcPortBase, rpc_port_get_peer_info_N) {
+ int ret = rpc_port_get_peer_info(nullptr, nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
TEST_F(RpcPortBase, rpc_port_proxy_event_reject_N) {
int ret = rpc_port_proxy_add_rejected_event_cb(proxy_handle_,
[](const char *ep, const char *port_name, void *data) {
g_source_remove(tag);
}
-/*
- * @testcase rpc_port_proxy_event_receive_P
- * @description Writes and reads the data to the port handles.
- * And then, checks the data in callback functions.
- * @apicovered rpc_port_write, rpc_port_read
- */
TEST_F(RpcPortConnection, rpc_port_proxy_event_receive_p) {
char res[] = "OK";
char r_buf[256];
ASSERT_STREQ(res, r_buf);
}
-/*
- * @testcase rpc_port_read_write_P
- * @description Writes and reads the data to the port handles.
- * @apicovered rpc_port_write, rpc_port_read
- */
TEST_F(RpcPortConnection, rpc_port_read_write) {
char buf[] = "test message";
char res[] = "OK";
ASSERT_STREQ("OK", r_buf);
}
-/*
- * @testcase rpc_port_proxy_disconnected_N
- * @description Kills the stub port.
- * And then, checks whether the disconnected event callback is invoked or not.
- * @apicovered rpc_port_stub_add_disconnected_event_cb
- */
TEST_F(RpcPortConnection, rpc_port_proxy_disconnected_N) {
KillStub();
RunMainLoop();
ASSERT_TRUE(touch_proxy_disconnected_event_cb_);
}
-/*
- * @testcase rpc_port_stub_disconnected_N
- * @description Kills the proxy port.
- * And then, checks whether the disconnected event callback is invoked or not.
- * @apicovered rpc_port_proxy_add_disconnected_event_cb
- */
TEST_F(RpcPortConnection, rpc_port_stub_disconnected_N) {
KillProxy();
RunMainLoop();
ASSERT_TRUE(touch_stub_disconnected_event_cb_);
}
-/*
- * @testcase rpc_port_disconnect_P
- * @description disconnect the port.
- * And then, checks whether the disconnected event callback is invoked or not.
- * @apicovered rpc_port_disconnect
- */
TEST_F(RpcPortConnection, rpc_port_disconnect_P) {
char res[] = "test";
if (proxy_port_ == nullptr)