From b0b89c531f6a8377e01c210e9cf3909a6d10db9a Mon Sep 17 00:00:00 2001 From: ly Date: Thu, 12 Dec 2024 17:14:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9config=E6=8E=A5=E5=8F=A3=20Si?= =?UTF-8?q?gned-off-by:=20p60040350=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calendarmanager/napi/src/napi_util.cpp | 3 +++ calendarmanager/native/include/native_util.h | 1 + .../native/src/native_calendar.cpp | 24 +++++++------------ calendarmanager/native/src/native_util.cpp | 20 ++++++++++++++++ .../test/unittest/src/calendar_test.cpp | 6 ++--- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/calendarmanager/napi/src/napi_util.cpp b/calendarmanager/napi/src/napi_util.cpp index 1927862..393684d 100644 --- a/calendarmanager/napi/src/napi_util.cpp +++ b/calendarmanager/napi/src/napi_util.cpp @@ -357,6 +357,9 @@ napi_status SetValue(napi_env env, const CalendarConfig& in, napi_value& out) ss >> color; const int rgbLen = 5; const int argbLen = 7; + while (color.size() < rgbLen) { + color = '0' + color; + } if (color.size() == rgbLen || color.size() == argbLen) { color = '0' + color; } diff --git a/calendarmanager/native/include/native_util.h b/calendarmanager/native/include/native_util.h index f5e9b98..34b8fd9 100644 --- a/calendarmanager/native/include/native_util.h +++ b/calendarmanager/native/include/native_util.h @@ -51,6 +51,7 @@ namespace OHOS::CalendarApi::Native { DataShareResultSetPtr &resultSet, const std::set& columns); int ResultSetToAttendees(std::vector &attendees, DataShareResultSetPtr &resultSet); int ResultSetToReminders(std::vector &reminders, DataShareResultSetPtr &resultSet); + void ResultSetToConfig(CalendarConfig &config, DataShareResultSetPtr &resultSet); void SetField(const std::vector& eventKey, std::vector& queryField, std::set& resultSetField); diff --git a/calendarmanager/native/src/native_calendar.cpp b/calendarmanager/native/src/native_calendar.cpp index 3c92a2b..ea5698f 100644 --- a/calendarmanager/native/src/native_calendar.cpp +++ b/calendarmanager/native/src/native_calendar.cpp @@ -130,21 +130,6 @@ bool Calendar::DeleteEvent(int id) predicates.EqualTo("_id", id); predicates.EqualTo("calendar_id", GetId()); auto ret = DataShareHelperManager::GetInstance().Delete(*(m_eventUri.get()), predicates); - LOG_INFO("DeleteEvent number %{public}d", ret); - { - // delete attendee - DataShare::DataSharePredicates predicates; - predicates.EqualTo("event_id", id); - auto ret = DataShareHelperManager::GetInstance().Delete(*(m_attendeeUri.get()), predicates); - LOG_INFO("Delete attendee num %{public}d", ret); - } - { - // delete reminder - DataShare::DataSharePredicates predicates; - predicates.EqualTo("event_id", id); - auto ret = DataShareHelperManager::GetInstance().Delete(*(m_reminderUrl.get()), predicates); - LOG_INFO("Delete reminder num %{public}d", ret); - } return ret == 1; } @@ -308,6 +293,15 @@ std::vector Calendar::GetEvents(std::shared_ptr filter, cons CalendarConfig Calendar::GetConfig() { + DataShare::DataSharePredicates predicates; + predicates.EqualTo("_id", m_id); + std::vector columns = {"calendar_color", "canReminder"}; + DataShare::DatashareBusinessError error; + auto result = DataShareHelperManager::GetInstance().Query(*(m_calendarUri.get()), predicates, columns, &error); + if (result != nullptr) { + ResultSetToConfig(m_config, result); + }; + LOG_INFO(" query config finished"); return m_config; } diff --git a/calendarmanager/native/src/native_util.cpp b/calendarmanager/native/src/native_util.cpp index 882ef37..14bdd55 100644 --- a/calendarmanager/native/src/native_util.cpp +++ b/calendarmanager/native/src/native_util.cpp @@ -864,6 +864,26 @@ int ResultSetToReminders(std::vector &reminders, DataShareResultSetPtr &res return 0; } +void ResultSetToConfig(CalendarConfig &config, DataShareResultSetPtr &resultSet) +{ + int rowCount = 0; + resultSet->GetRowCount(rowCount); + LOG_INFO("GetRowCount is %{public}d", rowCount); + auto err = resultSet->GoToFirstRow(); + if (err != DataShare::E_OK) { + LOG_ERROR("Failed GoToFirstRow %{public}d", err); + } + do { + int enableReminder; + std::int64_t color; + GetValue(resultSet, "canReminder", enableReminder); + GetValue(resultSet, "calendar_color", color); + config.enableReminder = static_cast(enableReminder); + LOG_INFO("enableReminder is %{public}d", enableReminder); + config.color = color; + } while (resultSet->GoToNextRow() == DataShare::E_OK); +} + bool IsValidHexString(const std::string& colorStr) { if (colorStr.empty()) { diff --git a/calendarmanager/test/unittest/src/calendar_test.cpp b/calendarmanager/test/unittest/src/calendar_test.cpp index 8bb059e..a693236 100644 --- a/calendarmanager/test/unittest/src/calendar_test.cpp +++ b/calendarmanager/test/unittest/src/calendar_test.cpp @@ -206,8 +206,8 @@ HWTEST_F(CalendarTest, UpdateEvents_test_1, testing::ext::TestSize.Level1) HWTEST_F(CalendarTest, GetConfig_default_test, testing::ext::TestSize.Level1) { auto config = calendar->GetConfig(); - EXPECT_FALSE(config.enableReminder.has_value()); - EXPECT_TRUE(std::get<0>(config.color).empty()); + EXPECT_TRUE(config.enableReminder.has_value()); + EXPECT_TRUE(std::get<1>(config.color) == 0); } HWTEST_F(CalendarTest, SetConfig_empty_param_test, testing::ext::TestSize.Level1) @@ -216,7 +216,7 @@ HWTEST_F(CalendarTest, SetConfig_empty_param_test, testing::ext::TestSize.Level1 auto ret = calendar->SetConfig(config); ASSERT_TRUE(ret); auto configExpect = calendar->GetConfig(); - EXPECT_FALSE(configExpect.enableReminder.has_value()); + EXPECT_TRUE(configExpect.enableReminder.has_value()); EXPECT_TRUE(std::get<0>(config.color).empty()); } -- Gitee