[Tizen.MachineLearning.Inference][TCSACR-308] Add TCs for new APIs in SingleShot 45/229045/3
authorJaeyun <jy1210.jung@samsung.com>
Fri, 27 Mar 2020 08:21:38 +0000 (17:21 +0900)
committerJaeyun <jy1210.jung@samsung.com>
Fri, 3 Apr 2020 07:15:10 +0000 (16:15 +0900)
Add testcases for new APIs in SingleShot class (SetValue/GetValue)

Change-Id: I2a84e296b564aa49c2c24db2cab6c185179ac101
Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSSingleShot.cs

index 72d177dcce78871ef088c54b9baf89af8a8cc5e8..0648f2ab9526826b3a1395b16235506c6473c1a0 100755 (executable)
@@ -26,7 +26,7 @@ namespace Tizen.MachineLearning.Inference.Tests {
 
     [TestFixture]
     [Description("Tizen.MachineLearning.Inference.SingleShot Tests")]
-    public class TSSingleShot
+    public class SingleShotTests
     {
         private readonly string TAG = "Tizen.MachineLearning.Inference.Tests";
         private readonly string _modelPath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mobilenet_v1_1.0_224_quant.tflite";
@@ -577,10 +577,10 @@ namespace Tizen.MachineLearning.Inference.Tests {
                 Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
                 Assert.IsNotNull(single, "Failed to create SingleShot instance");
 
-                TensorsInfo in_info = new TensorsInfo();
-                in_info.AddTensorInfo(TensorType.Float32, new int[4] { 5, 1, 1, 1 });
+                var in_info = new TensorsInfo();
+                Assert.IsNotNull(in_info, "Failed to create TensorsInfo instance");
                 Assert.IsInstanceOf<TensorsInfo>(in_info, "Should return TensorsInfo instance");
-                Assert.IsNotNull(in_info, "Failed to create tensorsInfo instance");
+                in_info.AddTensorInfo(TensorType.Float32, new int[4] { 5, 1, 1, 1 });
 
                 /* TEST CODE */
                 single.Input = in_info;
@@ -915,10 +915,10 @@ namespace Tizen.MachineLearning.Inference.Tests {
                 Assert.IsNotNull(single, "Failed to create SingleShot instance");
 
                 /* In case of 5 : 1 : 1 : 1 */
-                TensorsInfo in_info = new TensorsInfo();
-                in_info.AddTensorInfo(TensorType.Float32, new int[4] { 5, 1, 1, 1 });
+                var in_info = new TensorsInfo();
+                Assert.IsNotNull(in_info, "Failed to create TensorsInfo instance");
                 Assert.IsInstanceOf<TensorsInfo>(in_info, "Should return TensorsInfo instance");
-                Assert.IsNotNull(in_info, "Failed to create tensorsInfo instance");
+                in_info.AddTensorInfo(TensorType.Float32, new int[4] { 5, 1, 1, 1 });
 
                 /* Input data */
                 var in_data = new float[] { 0, 1, 2, 3, 4 };
@@ -1007,5 +1007,404 @@ namespace Tizen.MachineLearning.Inference.Tests {
                 }
             }
         }
+
+        [Test]
+        [Category("P1")]
+        [Description("Get value from SingleShot instance and check exceptions")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.GetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("COVPARAM", "string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void GetValue_NO_EXCEPTION()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                var in_dim = single.GetValue("input");
+                Assert.IsInstanceOf<string>(in_dim, "Should return string");
+                Assert.AreEqual(in_dim, "3:224:224:1", "Failed to get input dimension");
+
+                single.Dispose();
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when getting value with empty name")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.GetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void GetValue_CHECK_ArgumentException_Empty_Name()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                var in_dim = single.GetValue("");
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when getting value with null name")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.GetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void GetValue_CHECK_ArgumentException_Null_Name()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                var in_dim = single.GetValue(null);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when getting value with unknown name")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.GetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void GetValue_CHECK_NotSupportedException_Unknown_Name()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                var in_dim = single.GetValue("unknown_prop");
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    /* Unknown property name raises not-supported exception */
+                    if (_isMachineLeanringInferenceSupported)
+                        Assert.Pass("NotSupportedException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Set value and check exceptions")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("COVPARAM", "string, string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void SetValue_NO_EXCEPTION()
+        {
+            Assert.IsTrue(File.Exists(_dynamicModelPath), "Cannot find the add.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_dynamicModelPath, NNFWType.Any, HWType.Any);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                single.SetValue("input", "5:1:1:1");
+                Assert.AreEqual("5:1:1:1", single.GetValue("input"), "Failed to set input dimension");
+
+                single.Dispose();
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when setting value with unknown name")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string, string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void SetValue_CHECK_NotSupportedException_Unknown_Name()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                single.SetValue("unknown_prop", "unknown");
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    /* Unknown property name raises not-supported exception */
+                    if (_isMachineLeanringInferenceSupported)
+                        Assert.Pass("NotSupportedException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when setting value with empty name")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string, string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void SetValue_ArgumentException_Empty_Name()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                single.SetValue("", "ANY");
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when setting value with null name")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string, string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void SetValue_ArgumentException_Null_Name()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                single.SetValue(null, "ANY");
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when setting empty value")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string, string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void SetValue_ArgumentException_Empty_Value()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                single.SetValue("input", "");
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check exception when setting null value")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SetValue M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("COVPARAM", "string, string")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void SetValue_ArgumentException_Null_Value()
+        {
+            Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file");
+
+            try
+            {
+                var single = new SingleShot(_modelPath, _in_info, _out_info);
+                Assert.IsNotNull(single, "Failed to create SingleShot instance");
+                Assert.IsInstanceOf<SingleShot>(single, "Should return SingleShot instance");
+
+                /* TEST CODE */
+                single.SetValue("input", null);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.True(false, e.Message);
+                }
+            }
+        }
     }
 }