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 23namespace OHOS::CalendarApi::Native { 24const std::string TEST_NAME = "EventLocationTest"; 25static CalendarAccount account { 26 TEST_NAME, 27 "local", 28 "displayName_EventLocationTest" 29}; 30class EventLocationTest : public testing::Test { 31public: 32 static void SetUpTestSuite(void) 33 { 34 calendar = CalendarManager::GetInstance().CreateCalendar(account); 35 ASSERT_TRUE(calendar != nullptr); 36 } 37 38 static void TearDownTestSuite(void) 39 { 40 auto ret = CalendarManager::GetInstance().DeleteCalendar(*calendar.get()); 41 ASSERT_TRUE(ret); 42 } 43 void SetUp() {}; 44 void TearDown() {}; 45 static std::shared_ptr<Calendar> calendar; 46}; 47 48std::shared_ptr<Calendar> EventLocationTest::calendar = nullptr; 49 50HWTEST_F(EventLocationTest, AddEventWithLocation, testing::ext::TestSize.Level1) 51{ 52 Event event; 53 const string title = "AddEventWithLocation"; 54 event.title = title; 55 Location testLocation { 56 "test", 57 123, 58 456 59 }; 60 event.location = std::make_optional<Location>(testLocation); 61 auto eventId = calendar->AddEvent(event); 62 ASSERT_NE(eventId, 0); 63 auto events = calendar->GetEvents(FilterByTitle(title), {}); 64 ASSERT_EQ(events.size(), 1); 65 auto resultEvent = events.at(0); 66 EXPECT_EQ(resultEvent.title.value(), title); 67 ASSERT_NE(resultEvent.location, std::nullopt); 68 auto result = resultEvent.location.value(); 69 EXPECT_EQ(result.location.value(), testLocation.location.value()); 70 EXPECT_EQ(result.longitude.value(), testLocation.longitude.value()); 71 EXPECT_EQ(result.latitude.value(), testLocation.latitude.value()); 72} 73}