[NUI][ACR-274] Add Disposable class to refactor dispose codes 29/215729/4
authorxb.teng <xb.teng@samsung.com>
Tue, 15 Oct 2019 04:00:49 +0000 (12:00 +0800)
committerxb.teng <xb.teng@samsung.com>
Tue, 15 Oct 2019 10:17:04 +0000 (18:17 +0800)
Change-Id: I56bbfc2b9d3d99456c0a827856fe920e300f2b6e

tct-suite-vs/Tizen.NUI.Tests/testcase/TSDisposable.cs [new file with mode: 0755]

diff --git a/tct-suite-vs/Tizen.NUI.Tests/testcase/TSDisposable.cs b/tct-suite-vs/Tizen.NUI.Tests/testcase/TSDisposable.cs
new file mode 100755 (executable)
index 0000000..abc562d
--- /dev/null
@@ -0,0 +1,141 @@
+using NUnit.Framework;
+using NUnit.Framework.TUnit;
+using System;
+using Tizen.NUI;
+using Tizen.NUI.Test;
+
+namespace Tizen.NUI.Tests
+{
+    [TestFixture]
+    [Description("Tizen.NUI.Disposable Tests")]
+    public class DisposableTests
+    {
+        private string TAG = "NUI";
+
+        [SetUp]
+        public void Init()
+        {
+            Tizen.Log.Info(TAG, " Init() is called!");
+            App.MainTitleChangeText("DisposableTests");
+            App.MainTitleChangeBackgroundColor(null);
+        }
+
+        [TearDown]
+        public void Destroy()
+        {
+            Tizen.Log.Info(TAG, " Destroy() is called!");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Create a Disposable object.Check whether object is successfully created or not.")]
+        [Property("SPEC", "Tizen.NUI.Disposable.Disposable C")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "CONSTR")]
+        [Property("AUTHOR", "Xianbing Teng, xb.teng@samsung.com")]
+        public void Disposable_INIT()
+        {
+            /* TEST CODE */
+            var disposable = new Disposable();
+
+            Assert.IsNotNull(disposable, "Can't create success object Disposable");
+            Assert.IsInstanceOf<Disposable>(disposable, "Should be an instance of Disposable type.");
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Test Dispose, try to dispose the Disposable.")]
+        [Property("SPEC", "Tizen.NUI.Disposable.Dispose M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MCST")]
+        [Property("AUTHOR", "Xianbing Teng, xb.teng@samsung.com")]
+        public void Dispose_TEST()
+        {
+            /* TEST CODE */
+            try
+            {
+                Disposable disposable = new Disposable();
+                disposable.Dispose();
+            }
+            catch (Exception e)
+            {
+                Tizen.Log.Error(TAG, "Caught Exception" + e.ToString());
+                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
+                Assert.Fail("Caught Exception" + e.ToString());
+            }
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Test Dispose, try to dispose the Disposable.")]
+        [Property("SPEC", "Tizen.NUI.Disposable.Dispose M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MCST")]
+        [Property("COVPARAM", "DisposeTypes")]
+        [Property("AUTHOR", "Xianbing Teng, xb.teng@samsung.com")]
+        public void Dispose_Implicit_TEST_WITH_DISPOSETYPE()
+        {
+            /* TEST CODE */
+            try
+            {
+                MyDisposable myDisposable = new MyDisposable();
+                myDisposable.DisposeImplicit();
+            }
+            catch (Exception e)
+            {
+                Tizen.Log.Error(TAG, "Caught Exception" + e.ToString());
+                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
+                Assert.Fail("Caught Exception" + e.ToString());
+            }
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Test Dispose, try to dispose the Disposable.")]
+        [Property("SPEC", "Tizen.NUI.Disposable.Dispose M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MCST")]
+        [Property("COVPARAM", "DisposeTypes")]
+        [Property("AUTHOR", "Xianbing Teng, xb.teng@samsung.com")]
+        public void Dispose_Explicit_TEST_WITH_DISPOSETYPE()
+        {
+            /* TEST CODE */
+            try
+            {
+                MyDisposable myDisposable = new MyDisposable();
+                myDisposable.DisposeExplicit();
+            }
+            catch (Exception e)
+            {
+                Tizen.Log.Error(TAG, "Caught Exception" + e.ToString());
+                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
+                Assert.Fail("Caught Exception" + e.ToString());
+            }
+        }
+    }
+
+    public class MyDisposable : Disposable
+    {
+        public void DisposeImplicit()
+        {
+            Dispose(DisposeTypes.Implicit);
+        }
+
+        public void DisposeExplicit()
+        {
+            Dispose(DisposeTypes.Explicit);
+        }
+
+        public bool Disposed
+        {
+            get
+            {
+                return disposed;
+            }
+            set
+            {
+                disposed = value;
+            }
+        }
+    }
+}