--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include <iostream>
+#include <stdbool.h>
+#include <stdexcept>
+
+#include "rpc-port-parcel.h"
+
+using namespace std;
+using ::testing::AtLeast;
+
+class ParcelTest : public ::testing::Test {
+ public:
+ virtual void SetUp() {
+ int ret = rpc_port_parcel_create(&handle_);
+
+ ASSERT_NE(handle_, nullptr);
+ ASSERT_EQ(ret, 0);
+ }
+
+ virtual void TearDown() {
+ int ret = rpc_port_parcel_destroy(handle_);
+ ASSERT_EQ(ret, 0);
+ }
+
+ static void WriteParcelable(rpc_port_parcel_h h, void* data) {
+ const char str[] = "abcdef";
+ int ret = rpc_port_parcel_write_string(h, str);
+ ASSERT_EQ(ret, 0);
+
+ ret = rpc_port_parcel_write_double(h, 123.456f);
+ ASSERT_EQ(ret, 0);
+
+ ret = rpc_port_parcel_write_int32(h, 123456);
+ ASSERT_EQ(ret, 0);
+
+ ParcelTest* p = static_cast<ParcelTest*>(data);
+ ASSERT_NE(p, nullptr);
+ p->touch_to_ = true;
+ }
+
+ static void ReadParcelable(rpc_port_parcel_h h, void* data) {
+ char* s = nullptr;
+ int ret = rpc_port_parcel_read_string(h, &s);
+ ASSERT_EQ(ret, 0);
+ ASSERT_STREQ(s, "abcdef");
+
+ double b;
+ ret = rpc_port_parcel_read_double(h, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(b, 123.456f);
+
+ int i;
+ ret = rpc_port_parcel_read_int32(h, &i);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(i, 123456);
+
+ ParcelTest* p = static_cast<ParcelTest*>(data);
+ ASSERT_NE(p, nullptr);
+ p->touch_from_ = true;
+ }
+
+ rpc_port_parcel_h handle_;
+ bool touch_from_ = false;
+ bool touch_to_ = false;
+};
+
+TEST(rpc_port_parcel, rpc_port_parcel_create_destroy) {
+ rpc_port_parcel_h handle;
+
+ int ret = rpc_port_parcel_create(&handle);
+
+ ASSERT_NE(handle, nullptr);
+ ASSERT_EQ(ret, 0);
+
+ ret = rpc_port_parcel_destroy(handle);
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(ParcelTest, read_write_byte) {
+ int ret = rpc_port_parcel_write_byte(handle_, 'k');
+ ASSERT_EQ(ret, 0);
+
+ char b;
+ ret = rpc_port_parcel_read_byte(handle_, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(b, 'k');
+}
+
+TEST_F(ParcelTest, read_write_int16) {
+ int ret = rpc_port_parcel_write_int16(handle_, 123);
+ ASSERT_EQ(ret, 0);
+
+ short b;
+ ret = rpc_port_parcel_read_int16(handle_, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(b, 123);
+}
+
+TEST_F(ParcelTest, read_write_int32) {
+ int ret = rpc_port_parcel_write_int32(handle_, 123456);
+ ASSERT_EQ(ret, 0);
+
+ int b;
+ ret = rpc_port_parcel_read_int32(handle_, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(b, 123456);
+}
+
+TEST_F(ParcelTest, read_write_int64) {
+ int ret = rpc_port_parcel_write_int64(handle_, 12345678);
+ ASSERT_EQ(ret, 0);
+
+ long long b;
+ ret = rpc_port_parcel_read_int64(handle_, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(b, 12345678);
+}
+
+TEST_F(ParcelTest, read_write_float) {
+ int ret = rpc_port_parcel_write_float(handle_, 123.456f);
+ ASSERT_EQ(ret, 0);
+
+ float b;
+ ret = rpc_port_parcel_read_float(handle_, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(b, 123.456f);
+}
+
+TEST_F(ParcelTest, read_write_double) {
+ int ret = rpc_port_parcel_write_double(handle_, 123.456f);
+ ASSERT_EQ(ret, 0);
+
+ double b;
+ ret = rpc_port_parcel_read_double(handle_, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(b, 123.456f);
+}
+
+TEST_F(ParcelTest, read_write_string) {
+ const char str[] = "abcdef";
+ int ret = rpc_port_parcel_write_string(handle_, str);
+ ASSERT_EQ(ret, 0);
+
+ char* s = nullptr;
+ ret = rpc_port_parcel_read_string(handle_, &s);
+ ASSERT_EQ(ret, 0);
+ ASSERT_STREQ(s, str);
+ free(s);
+}
+
+TEST_F(ParcelTest, read_write_bool) {
+ int ret = rpc_port_parcel_write_bool(handle_, true);
+ ASSERT_EQ(ret, 0);
+
+ bool b = false;
+ ret = rpc_port_parcel_read_bool(handle_, &b);
+ ASSERT_EQ(ret, 0);
+ ASSERT_TRUE(b);
+}
+
+TEST_F(ParcelTest, read_write_bundle) {
+ bundle* b = bundle_create();
+ ASSERT_NE(b, nullptr);
+
+ int ret = bundle_add_str(b, "Test", "Value");
+ ASSERT_EQ(ret, BUNDLE_ERROR_NONE);
+
+ ret = rpc_port_parcel_write_bundle(handle_, b);
+ ASSERT_EQ(ret, 0);
+
+ bundle_free(b);
+ b = nullptr;
+
+ ret = rpc_port_parcel_read_bundle(handle_, &b);
+ ASSERT_EQ(ret, 0);
+
+ char* str;
+ ret = bundle_get_str(b, "Test", &str);
+ ASSERT_EQ(ret, BUNDLE_ERROR_NONE);
+ ASSERT_STREQ("Value", str);
+
+ bundle_free(b);
+}
+
+TEST_F(ParcelTest, read_write_array_count) {
+ int ret = rpc_port_parcel_write_array_count(handle_, 123);
+ ASSERT_EQ(ret, 0);
+
+ int c;
+ ret = rpc_port_parcel_read_array_count(handle_, &c);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(c, 123);
+}
+
+TEST_F(ParcelTest, read_write) {
+ rpc_port_parcelable_t p = {
+ .to = WriteParcelable,
+ .from = ReadParcelable
+ };
+
+ int ret = rpc_port_parcel_write(handle_, &p, this);
+ ASSERT_EQ(ret, 0);
+ ASSERT_TRUE(touch_to_);
+
+ ret = rpc_port_parcel_read(handle_, &p, this);
+ ASSERT_EQ(ret, 0);
+ ASSERT_TRUE(touch_from_);
+}