Improve unit TCs
[platform/core/api/notification.git] / unittest / src / test_bundle.cc
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <string>
18
19 #include <gtest/gtest.h>
20 #include <gmock/gmock.h>
21
22 #include "notification-ex/ex_bundle.h"
23
24 using ::testing::AtLeast;
25 using namespace notification;
26
27 TEST(Bundle, CtorDtor) {
28   Bundle bundle;
29 }
30
31 TEST(Bundle, CopyCtor) {
32   Bundle bundle;
33   bundle.Add("TestKey", "TestVal");
34
35   Bundle b2(bundle);
36   EXPECT_EQ(b2.GetString("TestKey"), "TestVal");
37 }
38
39 TEST(Bundle, MoveCtor) {
40   Bundle bundle;
41   bundle.Add("TestKey", "TestVal");
42
43   Bundle b2(std::move(bundle));
44   EXPECT_EQ(b2.GetString("TestKey"), "TestVal");
45 }
46
47 TEST(Bundle, AddStringGetString) {
48   Bundle bundle;
49   bundle.Add("TestKey", "TestVal");
50
51   EXPECT_EQ(bundle.GetString("TestKey"), "TestVal");
52 }
53
54 TEST(Bundle, AddByteGetByte) {
55   Bundle bundle;
56   std::vector<unsigned char> v = { 0, 1, 2, 3};
57   bundle.Add("TestKey", v);
58   auto v2 = bundle.GetByte("TestKey");
59
60   EXPECT_EQ(v2.size(), 4);
61   EXPECT_EQ(v2[0], 0);
62   EXPECT_EQ(v2[1], 1);
63   EXPECT_EQ(v2[2], 2);
64   EXPECT_EQ(v2[3], 3);
65 }
66
67 TEST(Bundle, AddStringArrayGetStringArray) {
68   Bundle bundle;
69   bundle.Add("TestKey", { "TestVal1", "TestVal2", "TestVal3" });
70
71   auto v = bundle.GetStringArray("TestKey");
72
73   EXPECT_EQ(v.size(), 3);
74   EXPECT_EQ(v[0], "TestVal1");
75   EXPECT_EQ(v[1], "TestVal2");
76   EXPECT_EQ(v[2], "TestVal3");
77 }
78
79 TEST(Bundle, ToRaw) {
80   Bundle bundle;
81   bundle.Add("TestKey", "TestVal");
82
83   auto r = bundle.ToRaw();
84   Bundle b2(std::move(r));
85   EXPECT_EQ(bundle.GetString("TestKey"), "TestVal");
86 }
87
88 TEST(Bundle, GetCount) {
89   Bundle bundle;
90   bundle.Add("TestKey1", "TestVal1");
91   bundle.Add("TestKey2", "TestVal2");
92
93   EXPECT_EQ(bundle.GetCount(), 2);
94 }
95
96 TEST(Bundle, Remove) {
97   Bundle bundle;
98   int r = bundle.Add("TestKey1", "TestVal1");
99   EXPECT_EQ(r, 0);
100
101   r = bundle.Remove("TestKey1");
102   EXPECT_EQ(r, 0);
103
104   EXPECT_EQ(bundle.GetString("TestKey1"), "");
105 }
106
107 TEST(Bundle, GetKeys) {
108   Bundle bundle;
109   bundle.Add("TestKey1", "TestVal1");
110   bundle.Add("TestKey2", "TestVal2");
111   bundle.Add("TestKey3", "TestVal3");
112
113   auto v = bundle.GetKeys();
114
115   EXPECT_EQ(bundle.GetCount(), 3);
116
117   for (auto& i : v) {
118     EXPECT_EQ(i.GetType(), BUNDLE_TYPE_STR);
119   }
120 }