[NUI] VectorGraphics: Add exception handling for Drawable.Transform()
authorJunsuChoi <jsuya.choi@samsung.com>
Wed, 24 Mar 2021 02:19:44 +0000 (11:19 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 1 Apr 2021 01:24:35 +0000 (10:24 +0900)
src/Tizen.NUI/src/public/BaseComponents/VectorGraphcis/Drawable.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs

index 1d2a94a..e03d5bf 100755 (executable)
@@ -14,6 +14,7 @@
 * limitations under the License.
 *
 */
+using System;
 using System.ComponentModel;
 
 namespace Tizen.NUI.BaseComponents.VectorGraphics
@@ -80,9 +81,19 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics
         /// </summary>
         /// <param name="matrix">The float type array of 3x3 matrix.</param>
         /// <returns>True when it's successful. False otherwise.</returns>
+        /// <exception cref="ArgumentNullException"> Thrown when matrix is null. </exception>
+        /// <exception cref="ArgumentException"> Thrown when matrix array length is not 9. </exception>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public bool Transform(float[] matrix)
         {   
+            if (matrix == null)
+            {
+                throw new ArgumentNullException(nameof(matrix));
+            }
+            if (matrix.Length != 9)
+            {
+                throw new ArgumentException("matrix array length is not 9.", nameof(matrix));
+            }
             bool ret = Interop.Drawable.Transform(BaseHandle.getCPtr(this), matrix);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
index f8c343a..23165ed 100644 (file)
@@ -1,8 +1,7 @@
+using System;
+using System.Collections.Generic;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.BaseComponents.VectorGraphics;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-
 
 namespace Tizen.NUI.Samples
 {
@@ -61,7 +60,7 @@ namespace Tizen.NUI.Samples
                 StrokeDash = new List<float>(){15.0f, 30.0f}.AsReadOnly(),
             };
             shape2.AddCircle(0.0f, 0.0f, 150.0f, 100.0f);
-            shape2.Transform(new float[] {0.6f, 0.0f, 350.0f, 0.0f, 0.6f, 100.0f, 0.0f, 0.0f, 1.0f});
+            shape2.Transform(new float[] {0.6f, 0.0f, 350.0f, 0.0f, 0.6f, 100.0f, 0.0f, 0.0f, 1.0f});        
 
             canvasView.AddDrawable(shape2);
 
@@ -135,6 +134,32 @@ namespace Tizen.NUI.Samples
             {
                 log.Debug(tag, "Shape4 StrokeDash : " + shape2.StrokeDash[i] + "\n");
             }
+
+            // Exception test.
+            try
+            {
+                shape2.Transform(new float[] {0.6f, 0.0f});
+            }
+            catch (ArgumentException e)
+            {
+                log.Debug(tag, "Transform : " + e.Message + "\n");
+            }
+            try
+            {
+                shape2.Transform(null);
+            }
+            catch (ArgumentException e)
+            {
+                log.Debug(tag, "Transform : " + e.Message + "\n");
+            }
+            try
+            {
+                shape2.StrokeDash = null;
+            }
+            catch (ArgumentException e)
+            {
+                log.Debug(tag, "StrokeDash setter : " + e.Message + "\n");
+            }
             
             root.Add(canvasView);