From cbbc37a6cf87b0a0d40e6c3ead0007ef8f234262 Mon Sep 17 00:00:00 2001 From: p60040350 Date: Mon, 9 Dec 2024 14:09:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9attendee=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=8F=8A=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ly --- .../napi/src/calendar_enum_napi.cpp | 23 +++-- calendarmanager/napi/src/napi_util.cpp | 96 ++++--------------- calendarmanager/native/src/native_util.cpp | 10 +- .../test/unittest/src/calendar_test.cpp | 16 +--- .../src/event_recurrence_rule_test.cpp | 9 ++ 5 files changed, 53 insertions(+), 101 deletions(-) diff --git a/calendarmanager/napi/src/calendar_enum_napi.cpp b/calendarmanager/napi/src/calendar_enum_napi.cpp index 06dd26b..3dcf8af 100644 --- a/calendarmanager/napi/src/calendar_enum_napi.cpp +++ b/calendarmanager/napi/src/calendar_enum_napi.cpp @@ -70,23 +70,26 @@ static const std::vector g_attendeeRole = { { "PARTICIPANT", "participant" }, }; -static const std::vector g_attendeeStatus = { - { "UNKNOWN", "unknown" }, - { "TENTATIVE", "tentative" }, - { "ACCEPTED", "accepted"}, - { "DECLINED", "declined" }, - { "UNRESPONSIVE", "unresponsive"}, +static const std::vector g_attendeeStatus = { + {"UNKNOWN", AttendeeStatus::UNKNOWN}, + {"TENTATIVE", AttendeeStatus::TENTATIVE}, + {"ACCEPTED", AttendeeStatus::ACCEPTED}, + {"DECLINED", AttendeeStatus::DECLINED}, + {"UNRESPONSIVE", AttendeeStatus::UNRESPONSIVE}, }; -static const std::vector g_attendeeType = { - { "REQUIRED", "required" }, - { "OPTIONAL", "optional" }, - { "RESOURCE", "resource" }, +static const std::vector g_attendeeType = { + {"REQUIRED", AttendeeType::REQUIRED}, + {"OPTIONAL", AttendeeType::OPTIONAL}, + {"RESOURCE", AttendeeType::RESOURCE}, }; static const std::map&> g_intEnumClassMap = { { "EventType", g_eventType}, { "RecurrenceFrequency", g_recurrenceFrequency}, + {"AttendeeStatus", g_attendeeStatus}, + {"AttendeeType", g_attendeeType}}; + }; static const std::map&> g_stringEnumClassMap = { diff --git a/calendarmanager/napi/src/napi_util.cpp b/calendarmanager/napi/src/napi_util.cpp index 4671575..61cbc56 100644 --- a/calendarmanager/napi/src/napi_util.cpp +++ b/calendarmanager/napi/src/napi_util.cpp @@ -452,43 +452,30 @@ napi_status SetValue(napi_env env, const RecurrenceRule& in, napi_value& out) } /* napi_value <-> Attendee */ -napi_status GetValue(napi_env env, napi_value in, Attendee& out) +napi_status GetValue(napi_env env, napi_value in, Attendee &out) { LOG_DEBUG("Attendee -> napi_value "); NapiUtil::GetNamedProperty(env, in, "name", out.name); NapiUtil::GetNamedProperty(env, in, "email", out.email); - optional value; - NapiUtil::GetNamedPropertyOptional(env, in, "role", value); - if (value.has_value()) { - if (value == "organizer") { + optional role = std::nullopt; + optional status = std::nullopt; + optional type = std::nullopt; + NapiUtil::GetNamedPropertyOptional(env, in, "role", role); + if (role.has_value()) { + if (role == "organizer") { out.role = ORGANIZER; } else { out.role = PARTICIPANT; } } - NapiUtil::GetNamedPropertyOptional(env, in, "status", value); - if (value.has_value()) { - if (value == "unknown") { - out.status = UNKNOWN; - } else if (value == "tentative") { - out.status = TENTATIVE; - } else if (value == "accepted") { - out.status = ACCEPTED; - } else if (value == "declined") { - out.status = DECLINED; - } else { - out.status = UNRESPONSIVE; - } + NapiUtil::GetNamedPropertyOptional(env, in, "status", status); + if (status.has_value()) { + out.status = static_cast(status.value()); + LOG_INFO("status.value() %{public}d", status.value()); } - NapiUtil::GetNamedPropertyOptional(env, in, "type", value); - if (value.has_value()) { - if (value == "required") { - out.type = REQUIRED; - } else if (value == "optional") { - out.type = OPTIONAL; - } else { - out.type = RESOURCE; - } + NapiUtil::GetNamedPropertyOptional(env, in, "type", type); + if (type.has_value()) { + out.type = static_cast(type.value()); } return napi_ok; } @@ -507,67 +494,24 @@ napi_status SetValue(napi_env env, const Attendee& in, napi_value& out) status = SetValue(env, in.email, emailValue); CHECK_RETURN((status == napi_ok), "invalid entry type", status); napi_set_named_property(env, out, "email", emailValue); + optional value = std::nullopt; if (in.role.has_value()) { - std::string value; if (in.role == ORGANIZER) { value = "organizer"; } else { value = "participant"; } - napi_value roleValue = nullptr; - status = SetValue(env, value, roleValue); - CHECK_RETURN((status == napi_ok), "invalid role", status); - napi_set_named_property(env, out, "role", roleValue); } - status = NapiUtil::SetAttendeeStatus(env, in, out); + if (value.has_value()) { + SetNamedPropertyOptional(env, "role", value, out); + } + SetNamedPropertyOptional(env, "status", in.status, out); CHECK_RETURN((status == napi_ok), "invalid status", status); - status = NapiUtil::SetAttendeeType(env, in, out); + SetNamedPropertyOptional(env, "type", in.type, out); CHECK_RETURN((status == napi_ok), "invalid type", status); return napi_ok; } -napi_status SetAttendeeStatus(napi_env env, const Attendee& in, napi_value& out) -{ - std::string value; - if (in.status.has_value()) { - if (in.status == UNKNOWN) { - value = "unknown"; - } else if (in.status == TENTATIVE) { - value = "tentative"; - } else if (in.status == ACCEPTED) { - value = "accepted"; - } else if (in.status == DECLINED) { - value = "declined"; - } else { - value = "unresponsive"; - } - napi_value statusValue = nullptr; - napi_status status = SetValue(env, value, statusValue); - napi_set_named_property(env, out, "status", statusValue); - return status; - } - return napi_ok; -} - -napi_status SetAttendeeType(napi_env env, const Attendee& in, napi_value& out) -{ - std::string value; - if (in.type.has_value()) { - if (in.type == REQUIRED) { - value = "required"; - } else if (in.type == OPTIONAL) { - value = "optional"; - } else { - value = "resource"; - } - napi_value typeValue = nullptr; - napi_status status = SetValue(env, value, typeValue); - napi_set_named_property(env, out, "type", typeValue); - return status; - } - return napi_ok; -} - /* napi_value <-> std::vector */ napi_status GetValue(napi_env env, napi_value in, std::vector& out) { diff --git a/calendarmanager/native/src/native_util.cpp b/calendarmanager/native/src/native_util.cpp index f0c04cf..69b976a 100644 --- a/calendarmanager/native/src/native_util.cpp +++ b/calendarmanager/native/src/native_util.cpp @@ -578,12 +578,18 @@ std::time_t TimeToUTC(const std::string &strTime) const int monCount = 12; const int monRectify = 11; const int micSecond = 1000; + const int timeStrLenMin = 8; + const int timeStrLen = 15; - std::tm expireTime = { 0 }; + std::tm expireTime = {0}; + if (strTime.size() < timeStrLenMin) { + LOG_DEBUG("strTime length error"); + return 0; + } expireTime.tm_year = StringToInt(strTime.substr(0, yearOffset)) - baseYear; expireTime.tm_mon = (StringToInt(strTime.substr(monBase, offset)) + monRectify) % monCount; expireTime.tm_mday = StringToInt(strTime.substr(dayBase, offset)); - if (strTime.find("T") != std::string::npos) { + if (strTime.find("T") != std::string::npos && strTime.length() >= timeStrLen) { expireTime.tm_hour = StringToInt(strTime.substr(hourBase, offset)); expireTime.tm_min = StringToInt(strTime.substr(minBase, offset)); expireTime.tm_sec = StringToInt(strTime.substr(secBase, offset)); diff --git a/calendarmanager/test/unittest/src/calendar_test.cpp b/calendarmanager/test/unittest/src/calendar_test.cpp index 7d46b15..e579e80 100644 --- a/calendarmanager/test/unittest/src/calendar_test.cpp +++ b/calendarmanager/test/unittest/src/calendar_test.cpp @@ -205,8 +205,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) @@ -215,7 +215,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()); } @@ -234,16 +234,6 @@ HWTEST_F(CalendarTest, SetConfig_with_color_test, testing::ext::TestSize.Level1) EXPECT_EQ(config, configExpect); } -HWTEST_F(CalendarTest, SetConfig_with_Black_test, testing::ext::TestSize.Level1) -{ - CalendarConfig config; - config.color = "#000000"; - config.enableReminder = true; - ASSERT_TRUE(calendar->SetConfig(config)); - auto configExpect = calendar->GetConfig(); - EXPECT_EQ(config, configExpect); -} - HWTEST_F(CalendarTest, UpdateEvent_test_3, testing::ext::TestSize.Level1) { Event event; diff --git a/calendarmanager/test/unittest/src/event_recurrence_rule_test.cpp b/calendarmanager/test/unittest/src/event_recurrence_rule_test.cpp index 6f869c1..e34d7ad 100644 --- a/calendarmanager/test/unittest/src/event_recurrence_rule_test.cpp +++ b/calendarmanager/test/unittest/src/event_recurrence_rule_test.cpp @@ -266,6 +266,15 @@ HWTEST_F(EventRecurrenceRuleTest, TimeToUTC, testing::ext::TestSize.Level1) EXPECT_EQ(timeValue, timeUTCValue); } +HWTEST_F(EventRecurrenceRuleTest, TimeToUTCError, testing::ext::TestSize.Level1) +{ + const int64_t timeValue = 0; + const std::string timeStr = "202404"; + + const int64_t timeUTCValue = TimeToUTC(timeStr); + + EXPECT_EQ(timeValue, timeUTCValue); +} HWTEST_F(EventRecurrenceRuleTest, GetRuleWithDay, testing::ext::TestSize.Level1) { const int64_t timeValue = 1713672150000; -- Gitee From 376a18b7ec97f6141c0ac5a9557538ab1ddfcfed Mon Sep 17 00:00:00 2001 From: p60040350 Date: Mon, 9 Dec 2024 14:45:43 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9attendee=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=8F=8A=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ly --- calendarmanager/napi/src/calendar_enum_napi.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/calendarmanager/napi/src/calendar_enum_napi.cpp b/calendarmanager/napi/src/calendar_enum_napi.cpp index 3dcf8af..82db17a 100644 --- a/calendarmanager/napi/src/calendar_enum_napi.cpp +++ b/calendarmanager/napi/src/calendar_enum_napi.cpp @@ -96,8 +96,6 @@ static const std::map&> { "CalendarType", g_calendarTypeKey }, { "ServiceType", g_serviceType }, { "AttendeeRole", g_attendeeRole }, - { "AttendeeStatus", g_attendeeStatus }, - { "AttendeeType", g_attendeeType } }; napi_value CalendarEnumNapi::JsEnumIntInit(napi_env env, napi_value exports) -- Gitee From 45a159c9f94ead9484f8bbdb734acb0cec862b0f Mon Sep 17 00:00:00 2001 From: p60040350 Date: Mon, 9 Dec 2024 15:38:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9attendee=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=8F=8A=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ly --- calendarmanager/napi/src/calendar_enum_napi.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/calendarmanager/napi/src/calendar_enum_napi.cpp b/calendarmanager/napi/src/calendar_enum_napi.cpp index 82db17a..d90c6c2 100644 --- a/calendarmanager/napi/src/calendar_enum_napi.cpp +++ b/calendarmanager/napi/src/calendar_enum_napi.cpp @@ -88,8 +88,7 @@ static const std::map&> g_ { "EventType", g_eventType}, { "RecurrenceFrequency", g_recurrenceFrequency}, {"AttendeeStatus", g_attendeeStatus}, - {"AttendeeType", g_attendeeType}}; - + {"AttendeeType", g_attendeeType} }; static const std::map&> g_stringEnumClassMap = { -- Gitee