From: Bowon Ryu Date: Fri, 13 Aug 2021 09:20:00 +0000 (+0900) Subject: [Tizen] Change raw pointer to unique_ptr X-Git-Tag: accepted/tizen/unified/20210817.123144^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F14%2F262614%2F1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] Change raw pointer to unique_ptr The mPlaceholderFont pointer is allocated memory once only when the text-controller uses a placeholder. This will persist until mEventData is destroyed. Changed to a smart pointer suitable for maintenance. Additionally, In SetPlaceholderTextFontWidth() and SetPlaceholderTextFontSlant(), mPlaceholderFont can not be NULL. Even if there is no value in SetFontStyleProperty, it is always set to None, This is because an instance of mPlaceholderFont is created through SetPlaceholderTextFontWeight(), which is called first. So this causes coverage issues. Replace the duplicate code with CreatePlaceholderFont() solves this problem. Change-Id: Ibd11b02f22e505be8643c9360b5d5e5e2de1b318 Signed-off-by: Bowon Ryu --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index d89428a..d00dc75 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -3221,6 +3221,70 @@ int UtcDaliTextFieldSettingPlaceholder(void) END_TEST; } +int UtcDaliTextFieldPlaceholderCoverage(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextFieldPlaceholderCoverage"); + + // mPlaceholderFont is created only once, so create a new control for coverage. + TextField fieldForCoverage = TextField::New(); + DALI_TEST_CHECK(fieldForCoverage); + application.GetScene().Add(fieldForCoverage); + + // for SetPlaceholderFontFamily() coverage. + Property::Map fontFamilyMap; + fontFamilyMap[Text::PlaceHolder::Property::FONT_FAMILY] = "Arial"; + fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontFamilyMap); + + // mPlaceholderFont is created only once, so create a new control for coverage. + fieldForCoverage = TextField::New(); + DALI_TEST_CHECK(fieldForCoverage); + application.GetScene().Add(fieldForCoverage); + + // for SetPlaceholderTextFontSize coverage. + Property::Map fontSizeMap; + fontSizeMap[Text::PlaceHolder::Property::PIXEL_SIZE] = 15.0f; + fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontSizeMap); + + // mPlaceholderFont is created only once, so create a new control for coverage. + fieldForCoverage = TextField::New(); + DALI_TEST_CHECK(fieldForCoverage); + application.GetScene().Add(fieldForCoverage); + + // for SetPlaceholderTextFontWeight coverage. + Property::Map fontStyleWeightMap; + Property::Map fontStyleWeightPropertyMap; + fontStyleWeightPropertyMap.Insert("weight", "bold"); + fontStyleWeightMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWeightPropertyMap; + fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWeightMap); + + // mPlaceholderFont is created only once, so create a new control for coverage. + fieldForCoverage = TextField::New(); + DALI_TEST_CHECK(fieldForCoverage); + application.GetScene().Add(fieldForCoverage); + + // for SetPlaceholderTextFontWidth coverage. + Property::Map fontStyleWidthMap; + Property::Map fontStyleWidthPropertyMap; + fontStyleWidthPropertyMap.Insert("width", "expanded"); + fontStyleWidthMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWidthPropertyMap; + fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWidthMap); + + // mPlaceholderFont is created only once, so create a new control for coverage. + fieldForCoverage = TextField::New(); + DALI_TEST_CHECK(fieldForCoverage); + application.GetScene().Add(fieldForCoverage); + + // for SetPlaceholderTextFontSlant coverage. + Property::Map fontStyleSlantMap; + Property::Map fontStyleSlantPropertyMap; + fontStyleSlantPropertyMap.Insert("slant", "italic"); + fontStyleSlantMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleSlantPropertyMap; + fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleSlantMap); + + END_TEST; +} + int UtcDaliTextFieldSetPaddingProperty(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index c31fc93..3fe3322 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -85,7 +85,7 @@ namespace Text EventData::EventData(DecoratorPtr decorator, InputMethodContext& inputMethodContext) : mDecorator(decorator), mInputMethodContext(inputMethodContext), - mPlaceholderFont(NULL), + mPlaceholderFont(nullptr), mPlaceholderTextActive(), mPlaceholderTextInactive(), mPlaceholderTextColor(0.8f, 0.8f, 0.8f, 0.8f), // This color has been published in the Public API (placeholder-properties.h). diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 84d6193..02fbff8 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -116,12 +116,12 @@ struct EventData return (stateToCheck == EDITING || stateToCheck == EDITING_WITH_POPUP || stateToCheck == EDITING_WITH_GRAB_HANDLE || stateToCheck == EDITING_WITH_PASTE_POPUP); } - DecoratorPtr mDecorator; ///< Pointer to the decorator. - InputMethodContext mInputMethodContext; ///< The Input Method Framework Manager. - FontDefaults* mPlaceholderFont; ///< The placeholder default font. - std::string mPlaceholderTextActive; ///< The text to display when the TextField is empty with key-input focus. - std::string mPlaceholderTextInactive; ///< The text to display when the TextField is empty and inactive. - Vector4 mPlaceholderTextColor; ///< The in/active placeholder text color. + DecoratorPtr mDecorator; ///< Pointer to the decorator. + InputMethodContext mInputMethodContext; ///< The Input Method Framework Manager. + std::unique_ptr mPlaceholderFont; ///< The placeholder default font. + std::string mPlaceholderTextActive; ///< The text to display when the TextField is empty with key-input focus. + std::string mPlaceholderTextInactive; ///< The text to display when the TextField is empty and inactive. + Vector4 mPlaceholderTextColor; ///< The in/active placeholder text color. /** * This is used to delay handling events until after the model has been updated. diff --git a/dali-toolkit/internal/text/text-controller-placeholder-handler.cpp b/dali-toolkit/internal/text/text-controller-placeholder-handler.cpp index 81d491a..301dbcb 100644 --- a/dali-toolkit/internal/text/text-controller-placeholder-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-placeholder-handler.cpp @@ -111,10 +111,8 @@ void Controller::PlaceholderHandler::SetPlaceholderFontFamily(Controller& contro { if(NULL != controller.mImpl->mEventData) { - if(NULL == controller.mImpl->mEventData->mPlaceholderFont) - { - controller.mImpl->mEventData->mPlaceholderFont = new FontDefaults(); - } + // if mPlaceholderFont is null, create an instance. + CreatePlaceholderFont(controller); controller.mImpl->mEventData->mPlaceholderFont->mFontDescription.family = placeholderTextFontFamily; DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetPlaceholderFontFamily %s\n", placeholderTextFontFamily.c_str()); @@ -138,10 +136,8 @@ void Controller::PlaceholderHandler::SetPlaceholderTextFontWeight(Controller& co { if(NULL != controller.mImpl->mEventData) { - if(NULL == controller.mImpl->mEventData->mPlaceholderFont) - { - controller.mImpl->mEventData->mPlaceholderFont = new FontDefaults(); - } + // if mPlaceholderFont is null, create an instance. + CreatePlaceholderFont(controller); controller.mImpl->mEventData->mPlaceholderFont->mFontDescription.weight = weight; controller.mImpl->mEventData->mPlaceholderFont->weightDefined = true; @@ -173,10 +169,8 @@ void Controller::PlaceholderHandler::SetPlaceholderTextFontWidth(Controller& con { if(NULL != controller.mImpl->mEventData) { - if(NULL == controller.mImpl->mEventData->mPlaceholderFont) - { - controller.mImpl->mEventData->mPlaceholderFont = new FontDefaults(); - } + // if mPlaceholderFont is null, create an instance. + CreatePlaceholderFont(controller); controller.mImpl->mEventData->mPlaceholderFont->mFontDescription.width = width; controller.mImpl->mEventData->mPlaceholderFont->widthDefined = true; @@ -208,10 +202,8 @@ void Controller::PlaceholderHandler::SetPlaceholderTextFontSlant(Controller& con { if(NULL != controller.mImpl->mEventData) { - if(NULL == controller.mImpl->mEventData->mPlaceholderFont) - { - controller.mImpl->mEventData->mPlaceholderFont = new FontDefaults(); - } + // if mPlaceholderFont is null, create an instance. + CreatePlaceholderFont(controller); controller.mImpl->mEventData->mPlaceholderFont->mFontDescription.slant = slant; controller.mImpl->mEventData->mPlaceholderFont->slantDefined = true; @@ -243,10 +235,8 @@ void Controller::PlaceholderHandler::SetPlaceholderTextFontSize(Controller& cont { if(NULL != controller.mImpl->mEventData) { - if(NULL == controller.mImpl->mEventData->mPlaceholderFont) - { - controller.mImpl->mEventData->mPlaceholderFont = new FontDefaults(); - } + // if mPlaceholderFont is null, create an instance. + CreatePlaceholderFont(controller); switch(type) { @@ -533,6 +523,14 @@ void Controller::PlaceholderHandler::ShowPlaceholderText(Controller& controller) } } +void Controller::PlaceholderHandler::CreatePlaceholderFont(Controller& controller) +{ + if(nullptr == controller.mImpl->mEventData->mPlaceholderFont) + { + controller.mImpl->mEventData->mPlaceholderFont = std::unique_ptr(new FontDefaults()); + } +} + } // namespace Text } // namespace Toolkit diff --git a/dali-toolkit/internal/text/text-controller-placeholder-handler.h b/dali-toolkit/internal/text/text-controller-placeholder-handler.h index c69e003..ac2ba1b 100644 --- a/dali-toolkit/internal/text/text-controller-placeholder-handler.h +++ b/dali-toolkit/internal/text/text-controller-placeholder-handler.h @@ -56,6 +56,7 @@ struct Controller::PlaceholderHandler static void SetPlaceholderProperty(Controller& controller, const Property::Map& map); static void GetPlaceholderProperty(Controller& controller, Property::Map& map); static void ShowPlaceholderText(Controller& controller); + static void CreatePlaceholderFont(Controller& controller); }; } // namespace Text