• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <gtest/gtest.h>
16 #include <gmock/gmock.h>
17 #include <memory>
18 #include "native_calendar.h"
19 #include "calendar_log.h"
20 #include "native_calendar_manager.h"
21 
22 
23 namespace OHOS::CalendarApi::Native {
24 const std::string TEST_NAME = "EventLocationTest";
25 static CalendarAccount account {
26     TEST_NAME,
27     "local",
28     "displayName_EventLocationTest"
29 };
30 class EventLocationTest : public testing::Test {
31 public:
SetUpTestSuite(void)32     static void SetUpTestSuite(void)
33     {
34         calendar = CalendarManager::GetInstance().CreateCalendar(account);
35         ASSERT_TRUE(calendar != nullptr);
36     }
37 
TearDownTestSuite(void)38     static void TearDownTestSuite(void)
39     {
40         auto ret = CalendarManager::GetInstance().DeleteCalendar(*calendar.get());
41         ASSERT_TRUE(ret);
42     }
SetUp()43     void SetUp() {};
TearDown()44     void TearDown() {};
45     static std::shared_ptr<Calendar> calendar;
46 };
47 
48 std::shared_ptr<Calendar> EventLocationTest::calendar = nullptr;
49 
50 HWTEST_F(EventLocationTest, AddEventWithLocation, testing::ext::TestSize.Level1)
51 {
52     Event event;
53     const string title = "AddEventWithLocation";
54     event.title = title;
55     Location testLocation {"test", 123.12, 45.45};
56     event.location = std::make_optional<Location>(testLocation);
57     auto eventId = calendar->AddEvent(event);
58     ASSERT_NE(eventId, 0);
59     auto events = calendar->GetEvents(FilterByTitle(title), {});
60     ASSERT_EQ(events.size(), 1);
61     auto resultEvent = events.at(0);
62     EXPECT_EQ(resultEvent.title.value(), title);
63     ASSERT_NE(resultEvent.location, std::nullopt);
64     auto result = resultEvent.location.value();
65     EXPECT_EQ(result.location.value(), testLocation.location.value());
66     EXPECT_EQ(result.longitude.value(), testLocation.longitude.value());
67     EXPECT_EQ(result.latitude.value(), testLocation.latitude.value());
68 }
69 
70 HWTEST_F(EventLocationTest, AddEventWithMaxLocation, testing::ext::TestSize.Level1)
71 {
72     Event event;
73     const string title = "AddEventWithMaxLocation";
74     event.title = title;
75     Location testLocation {
76         "test",
77         180,
78         90
79     };
80     event.location = std::make_optional<Location>(testLocation);
81     auto eventId = calendar->AddEvent(event);
82     ASSERT_NE(eventId, 0);
83     auto events = calendar->GetEvents(FilterByTitle(title), {});
84     ASSERT_EQ(events.size(), 1);
85     auto resultEvent = events.at(0);
86     EXPECT_EQ(resultEvent.title.value(), title);
87     ASSERT_NE(resultEvent.location, std::nullopt);
88     auto result = resultEvent.location.value();
89     EXPECT_EQ(result.location.value(), testLocation.location.value());
90     EXPECT_EQ(result.longitude.value(), testLocation.longitude.value());
91     EXPECT_EQ(result.latitude.value(), testLocation.latitude.value());
92 }
93 
94 HWTEST_F(EventLocationTest, AddEventWithMinLocation, testing::ext::TestSize.Level1)
95 {
96     Event event;
97     const string title = "AddEventWithMinLocation";
98     event.title = title;
99     Location testLocation {
100         "test",
101         -180,
102         -90
103     };
104     event.location = std::make_optional<Location>(testLocation);
105     auto eventId = calendar->AddEvent(event);
106     ASSERT_NE(eventId, 0);
107     auto events = calendar->GetEvents(FilterByTitle(title), {});
108     ASSERT_EQ(events.size(), 1);
109     auto resultEvent = events.at(0);
110     EXPECT_EQ(resultEvent.title.value(), title);
111     ASSERT_NE(resultEvent.location, std::nullopt);
112     auto result = resultEvent.location.value();
113     EXPECT_EQ(result.location.value(), testLocation.location.value());
114     EXPECT_EQ(result.longitude.value(), testLocation.longitude.value());
115     EXPECT_EQ(result.latitude.value(), testLocation.latitude.value());
116 }
117 
118 HWTEST_F(EventLocationTest, AddEventWithOutMinLocation, testing::ext::TestSize.Level1)
119 {
120     Event event;
121     const string title = "AddEventWithOutMinLocation";
122     event.title = title;
123     Location testLocation {
124         "test",
125         -180.99,
126         -90.99
127     };
128     event.location = std::make_optional<Location>(testLocation);
129     auto eventId = calendar->AddEvent(event);
130     ASSERT_NE(eventId, 0);
131     auto events = calendar->GetEvents(FilterByTitle(title), {});
132     ASSERT_EQ(events.size(), 1);
133     auto resultEvent = events.at(0);
134     EXPECT_EQ(resultEvent.title.value(), title);
135     ASSERT_NE(resultEvent.location, std::nullopt);
136     auto result = resultEvent.location.value();
137     EXPECT_EQ(result.location.value(), "test");
138     EXPECT_EQ(result.longitude.has_value(), false);
139     EXPECT_EQ(result.latitude.has_value(), false);
140 }
141 
142 HWTEST_F(EventLocationTest, AddEventWithOutMaxLocation, testing::ext::TestSize.Level1)
143 {
144     Event event;
145     const string title = "AddEventWithOutMaxLocation";
146     event.title = title;
147     Location testLocation {
148         "test",
149         180.99,
150         90.99
151     };
152     event.location = std::make_optional<Location>(testLocation);
153     auto eventId = calendar->AddEvent(event);
154     ASSERT_NE(eventId, 0);
155     auto events = calendar->GetEvents(FilterByTitle(title), {});
156     ASSERT_EQ(events.size(), 1);
157     auto resultEvent = events.at(0);
158     EXPECT_EQ(resultEvent.title.value(), title);
159     ASSERT_NE(resultEvent.location, std::nullopt);
160     auto result = resultEvent.location.value();
161     EXPECT_EQ(result.location.value(), "test");
162     EXPECT_EQ(result.longitude.has_value(), false);
163     EXPECT_EQ(result.latitude.has_value(), false);
164 }
165 }