2 * Copyright (c) 2019 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
22 #include "include/bundle_cpp.h"
24 using ::testing::AtLeast;
25 using namespace tizen_base;
28 TEST(Bundle, CtorDtor) {
32 TEST(Bundle, CopyCtor) {
34 bundle.Add("TestKey", "TestVal");
37 EXPECT_EQ(b2.GetString("TestKey"), "TestVal");
40 TEST(Bundle, MoveCtor) {
42 bundle.Add("TestKey", "TestVal");
44 Bundle b2(std::move(bundle));
45 EXPECT_EQ(b2.GetString("TestKey"), "TestVal");
48 TEST(Bundle, AddStringGetString) {
50 bundle.Add("TestKey", "TestVal");
52 EXPECT_EQ(bundle.GetString("TestKey"), "TestVal");
55 TEST(Bundle, AddByteGetByte) {
57 std::vector<unsigned char> v = { 0, 1, 2, 3};
58 bundle.Add("TestKey", v);
59 auto v2 = bundle.GetByte("TestKey");
61 EXPECT_EQ(v2.size(), 4);
68 TEST(Bundle, AddStringArrayGetStringArray) {
70 bundle.Add("TestKey", { "TestVal1", "TestVal2", "TestVal3" });
72 auto v = bundle.GetStringArray("TestKey");
74 EXPECT_EQ(v.size(), 3);
75 EXPECT_EQ(v[0], "TestVal1");
76 EXPECT_EQ(v[1], "TestVal2");
77 EXPECT_EQ(v[2], "TestVal3");
82 bundle.Add("TestKey", "TestVal");
84 auto base64_r = bundle.ToRaw();
85 Bundle b2(std::move(base64_r));
86 EXPECT_EQ(bundle.GetString("TestKey"), "TestVal");
88 auto r = bundle.ToRaw(false);
89 Bundle b3(std::move(r), false);
90 EXPECT_EQ(bundle.GetString("TestKey"), "TestVal");
93 TEST(Bundle, GetCount) {
95 bundle.Add("TestKey1", "TestVal1");
96 bundle.Add("TestKey2", "TestVal2");
98 EXPECT_EQ(bundle.GetCount(), 2);
101 TEST(Bundle, Delete) {
103 int r = bundle.Add("TestKey1", "TestVal1");
106 r = bundle.Delete("TestKey1");
109 EXPECT_EQ(bundle.GetString("TestKey1"), "");
112 TEST(Bundle, GetKeys) {
114 bundle.Add("TestKey1", "TestVal1");
115 bundle.Add("TestKey2", "TestVal2");
116 bundle.Add("TestKey3", "TestVal3");
118 auto v = bundle.GetKeys();
120 EXPECT_EQ(bundle.GetCount(), 3);
123 EXPECT_EQ(i.GetType(), BUNDLE_TYPE_STR);
127 TEST(Bundle, GetKeysCopy) {
129 bundle.Add("TestKey1", "TestVal1");
130 bundle.Add("TestKey2", "TestVal2");
131 bundle.Add("TestKey3", "TestVal3");
133 auto v = bundle.GetKeys();
135 EXPECT_EQ(bundle.GetCount(), 3);
138 Bundle::KeyInfo copied = i;
139 EXPECT_EQ(copied.GetType(), BUNDLE_TYPE_STR);
140 EXPECT_EQ(copied.GetName(), i.GetName());
144 TEST(Bundle, GetKeysMove) {
146 bundle.Add("TestKey1", "TestVal1");
147 bundle.Add("TestKey2", "TestVal2");
148 bundle.Add("TestKey3", "TestVal3");
150 auto v = bundle.GetKeys();
152 EXPECT_EQ(bundle.GetCount(), 3);
155 string name = i.GetName();
156 Bundle::KeyInfo copied = move(i);
157 EXPECT_EQ(copied.GetType(), BUNDLE_TYPE_STR);
158 EXPECT_EQ(copied.GetName(), name);
162 TEST(Bundle, IsEmpty) {
164 EXPECT_TRUE(bundle.IsEmpty());
165 bundle.Add("TestKey1", "TestVal");
166 EXPECT_FALSE(bundle.IsEmpty());
169 TEST(Bundle, Export) {
171 bundle.Add("TestKey1", "TestVal1");
172 std::vector<std::string> argv = bundle.Export();
173 EXPECT_NE(argv.size(), 0);