[NUI] Fix unmatched return values before LazyUpdate (#3937)
authorEunki Hong <h.pichulia@gmail.com>
Fri, 18 Feb 2022 04:04:55 +0000 (13:04 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 22 Feb 2022 06:15:10 +0000 (15:15 +0900)
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 <eunkiki.hong@samsung.com>
Co-authored-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/ImageView.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/Image.png [new file with mode: 0644]
test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/res/star-mod.png [new file with mode: 0755]
test/Tizen.NUI.Devel.Tests.Ubuntu/Tizen.NUI.Devel.Tests/testcase/TSImageView.cs [new file with mode: 0644]

index 255aaae..44ea173 100755 (executable)
@@ -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.
         /// </summary>
-        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
 
         /// <summary>
         /// Callback function to Lazy UpdateImage.
-        /// Or, We can call UpdateImage() function directly if we need.
         /// </summary>
         private void UpdateImage(object source, EventArgs e)
         {
@@ -1289,7 +1298,17 @@ namespace Tizen.NUI.BaseComponents
             _imagePropertyUpdateProcessAttachedFlag = false;
         }
 
-        private void UpdateImage()
+        /// <summary>
+        /// Update image-relative properties synchronously.
+        /// After call this API, All image properties updated.
+        /// </summary>
+        /// <remarks>
+        /// Current version ImageView property update asynchronously.
+        /// If you want to guarantee that ImageView property setuped,
+        /// Please call this ImageView.UpdateImage() API.
+        /// </remarks>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected void UpdateImage()
         {
             if(!_imagePropertyUpdatedFlag) return;
 
@@ -1400,6 +1419,17 @@ namespace Tizen.NUI.BaseComponents
             setValue?.Dispose();
         }
 
+        /// <summary>
+        /// GetNaturalSize() should be guaranteed that ResourceUrl property setuped.
+        /// So before get base.GetNaturalSize(), we should synchronous image properties
+        /// </summary>
+        internal override Vector3 GetNaturalSize()
+        {
+            // Sync as current properties
+            UpdateImage();
+            return base.GetNaturalSize();
+        }
+
         private void OnResourceLoaded(IntPtr view)
         {
             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
index d4e66d1..4c6d186 100755 (executable)
@@ -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);
index 29ca704..4a0fdb2 100755 (executable)
@@ -582,7 +582,11 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
-        internal Vector3 GetNaturalSize()
+        /// <summary>
+        /// 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
+        /// </summary>
+        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 (file)
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 (executable)
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 (file)
index 0000000..bde78a9
--- /dev/null
@@ -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();
+        }
+    }
+}