From: Eunki Hong Date: Fri, 18 Feb 2022 04:04:55 +0000 (+0900) Subject: [NUI] Fix unmatched return values before LazyUpdate (#3937) X-Git-Tag: accepted/tizen/unified/20231205.024657~1161 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c8da837e7c674ef9d0e0b1a36f6bf3561d78205f;hp=922a5d8292cedfda2c031d18075a32807b0a2ad2;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Fix unmatched return values before LazyUpdate (#3937) 1. Call ImageView.UpdateImage() before get NaturalSize so we can guarantee that ResoureUrl properties updated 2. CropToMask value return true in default when we set AlphaMaskUrl. Signed-off-by: Eunki, Hong Co-authored-by: Eunki, Hong --- diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index 255aaae..44ea173 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -637,6 +637,15 @@ namespace Tizen.NUI.BaseComponents { PropertyValue setValue = new PropertyValue(value ?? ""); UpdateImage(ImageVisualProperty.AlphaMaskURL, setValue); + // When we never set CropToMask property before, we should set default value as true. + using(PropertyValue cropToMask = _imagePropertyMap?.Find(ImageVisualProperty.CropToMask)) + { + if(cropToMask == null) + { + using PropertyValue setCropValue = new PropertyValue(true); + UpdateImage(ImageVisualProperty.CropToMask, setCropValue); + } + } setValue?.Dispose(); } } @@ -1227,7 +1236,8 @@ namespace Tizen.NUI.BaseComponents /// Lazy call to UpdateImage. /// Collect Properties need to be update, and set properties that starts the Processing. /// - private void UpdateImage(int key, PropertyValue value) + [EditorBrowsable(EditorBrowsableState.Never)] + protected void UpdateImage(int key, PropertyValue value) { // If we set ResourceUrl as empty, Unregist visual. if (key == ImageVisualProperty.URL && string.IsNullOrEmpty(_resourceUrl)) @@ -1281,7 +1291,6 @@ namespace Tizen.NUI.BaseComponents /// /// Callback function to Lazy UpdateImage. - /// Or, We can call UpdateImage() function directly if we need. /// private void UpdateImage(object source, EventArgs e) { @@ -1289,7 +1298,17 @@ namespace Tizen.NUI.BaseComponents _imagePropertyUpdateProcessAttachedFlag = false; } - private void UpdateImage() + /// + /// Update image-relative properties synchronously. + /// After call this API, All image properties updated. + /// + /// + /// Current version ImageView property update asynchronously. + /// If you want to guarantee that ImageView property setuped, + /// Please call this ImageView.UpdateImage() API. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + protected void UpdateImage() { if(!_imagePropertyUpdatedFlag) return; @@ -1400,6 +1419,17 @@ namespace Tizen.NUI.BaseComponents setValue?.Dispose(); } + /// + /// GetNaturalSize() should be guaranteed that ResourceUrl property setuped. + /// So before get base.GetNaturalSize(), we should synchronous image properties + /// + internal override Vector3 GetNaturalSize() + { + // Sync as current properties + UpdateImage(); + return base.GetNaturalSize(); + } + private void OnResourceLoaded(IntPtr view) { ResourceLoadedEventArgs e = new ResourceLoadedEventArgs(); diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index d4e66d1..4c6d186 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -1292,7 +1292,7 @@ namespace Tizen.NUI.BaseComponents { get { - Vector3 ret = new Vector3(Interop.Actor.GetNaturalSize(SwigCPtr), true); + Vector3 ret = GetNaturalSize(); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); return ret; } @@ -1309,7 +1309,7 @@ namespace Tizen.NUI.BaseComponents { get { - Vector3 temp = new Vector3(Interop.Actor.GetNaturalSize(SwigCPtr), true); + Vector3 temp = GetNaturalSize(); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); Size2D sz = new Size2D((int)temp.Width, (int)temp.Height); diff --git a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs index 29ca704..4a0fdb2 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs @@ -582,7 +582,11 @@ namespace Tizen.NUI.BaseComponents return ret; } - internal Vector3 GetNaturalSize() + /// + /// GetNaturalSize() function behaviour can be changed for each subclass of View. + /// So we make GetNaturalSize() function virtual, and make subclass can define it's owned logic + /// + internal virtual Vector3 GetNaturalSize() { Vector3 ret = new Vector3(Interop.Actor.GetNaturalSize(SwigCPtr), true); if (NDalicPINVOKE.SWIGPendingException.Pending) diff --git a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/Image.png b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/Image.png new file mode 100644 index 0000000..3300464 Binary files /dev/null and b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/Image.png differ diff --git a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/star-mod.png b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/star-mod.png new file mode 100755 index 0000000..2e3212e Binary files /dev/null and b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/star-mod.png differ diff --git a/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/TSImageView.cs b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/TSImageView.cs new file mode 100644 index 0000000..bde78a9 --- /dev/null +++ b/test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/TSImageView.cs @@ -0,0 +1,185 @@ +using global::System; +using NUnit.Framework; +using NUnit.Framework.TUnit; +using Tizen.NUI.Components; +using Tizen.NUI.BaseComponents; + +namespace Tizen.NUI.Devel.Tests +{ + using tlog = Tizen.Log; + + [TestFixture] + [Description("public/BaseComponents/ImageView")] + public class InternalImageViewTest + { + private const string tag = "NUITEST"; + private string image_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "Image.png"; + private string mask_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "star-mod.png"; + + [SetUp] + public void Init() + { + tlog.Info(tag, "Init() is called!"); + } + + [TearDown] + public void Destroy() + { + tlog.Info(tag, "Destroy() is called!"); + } + + [Test] + [Category("P1")] + [Description("internal API test in Ubuntu, ImageView.ResourceUrl")] + [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.ResourceUrl")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void ResourceUrl_SET_GET_VALUE() + { + /* TEST CODE */ + ImageView testView = new ImageView(); + string testUrl1 = "test1"; + testView.ResourceUrl = testUrl1; + + Assert.AreEqual(testView.ResourceUrl, testUrl1, "ResourceUrl is not equal"); + + testView.Dispose(); + } + + [Test] + [Category("P1")] + [Description("internal API test in Ubuntu, ImageView.AlphaMaskURL")] + [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.AlphaMaskURL")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void AlphaMaskURL_SET_GET_VALUE() + { + /* TEST CODE */ + ImageView testView = new ImageView(image_path); + string testUrl1 = "test1"; + testView.AlphaMaskURL = testUrl1; + + Assert.AreEqual(testView.AlphaMaskURL, testUrl1, "AlphaMaskURL is not equal"); + + testView.Dispose(); + } + + [Test] + [Category("P1")] + [Description("internal API test in Ubuntu, ImageView.CropToMask")] + [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.CropToMask")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void CropToMask_SET_GET_VALUE() + { + /* TEST CODE */ + ImageView testView = new ImageView(image_path); + + Assert.AreEqual(testView.CropToMask, false, "CropToMask default is false when we don't set mask image url"); + + testView.CropToMask = true; + + Assert.AreEqual(testView.CropToMask, true, "CropToMask is not updated"); + + testView.CropToMask = false; + + Assert.AreEqual(testView.CropToMask, false, "CropToMask is not updated"); + + testView.AlphaMaskURL = mask_path; + + Assert.AreEqual(testView.CropToMask, false, "CropToMask should not changed even we set mask image url"); + + testView.Dispose(); + } + + [Test] + [Category("P1")] + [Description("internal API test in Ubuntu, ImageView.CropToMask with AlphaMaskURL")] + [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.CropToMask")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void CropToMask_DEFAULT_GET_VALUE() + { + /* TEST CODE */ + ImageView testView = new ImageView(image_path); + + Assert.AreEqual(testView.CropToMask, false, "CropToMask default is false when we don't set mask image url"); + + testView.AlphaMaskURL = image_path; + + Assert.AreEqual(testView.CropToMask, true, "CropToMask default is true when we set mask image url"); + + testView.Dispose(); + } + + [Test] + [Category("P1")] + [Description("internal API test in Ubuntu, ImageView.NaturalSize2D")] + [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.NaturalSize2D")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void NaturalSize2D_GET_VALUE() + { + /* TEST CODE */ + ImageView testView = new ImageView(); + testView.ResourceUrl = image_path; + Size2D result = new Size2D(212, 150); // The size of image_path image. + Size2D size = testView.NaturalSize2D; + + Assert.AreEqual(result.Width, size.Width, "NaturalSize Width is not equal"); + Assert.AreEqual(result.Height, size.Height, "NaturalSize Height is not equal"); + + testView.Dispose(); + } + + + [Test] + [Category("P1")] + [Description("internal API test in Ubuntu, ImageView.NaturalSize")] + [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.NaturalSize")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void NaturalSize_GET_VALUE() + { + /* TEST CODE */ + ImageView testView = new ImageView(); + testView.ResourceUrl = image_path; + Vector3 result = new Vector3(212, 150, 0); // The size of image_path image. + Vector3 size = testView.NaturalSize; + + Assert.AreEqual(result.X, size.X, "NaturalSize Width is not equal"); + Assert.AreEqual(result.Y, size.Y, "NaturalSize Height is not equal"); + + testView.Dispose(); + } + + [Test] + [Category("P1")] + [Description("internal API test in Ubuntu, ImageView.NaturalSize")] + [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.NaturalSize")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "eunkiki.hong@samsung.com")] + public void NaturalSize_GET_VALUE_as_View_class() + { + /* TEST CODE */ + ImageView testView = new ImageView(); + testView.ResourceUrl = image_path; + Vector3 result = new Vector3(212, 150, 0); // The size of image_path image. + View testView2 = testView; // Convert class as View. + Vector3 size = testView2.NaturalSize; // Check whether virtual ImageView.GetNaturalSize() called well. + + Assert.AreEqual(result.X, size.X, "NaturalSize Width is not equal"); + Assert.AreEqual(result.Y, size.Y, "NaturalSize Height is not equal"); + + testView.Dispose(); + testView2.Dispose(); + } + } +}