Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / Common / TSDisposable.cs
1 using NUnit.Framework;
2 using NUnit.Framework.TUnit;
3 using System;
4 using Tizen.NUI;
5
6 namespace Tizen.NUI.Devel.Tests
7 {
8     using tlog = Tizen.Log;
9
10     [TestFixture]
11     [Description("internal/Common/Disposable")]
12     public class DisposableTests
13     {
14         private const string tag = "NUITEST";
15
16         [SetUp]
17         public void Init()
18         {
19             Tizen.Log.Info(tag, " Init() is called!");
20         }
21
22         [TearDown]
23         public void Destroy()
24         {
25             Tizen.Log.Info(tag, " Destroy() is called!");
26         }
27
28         [Test]
29         [Category("P1")]
30         [Description("Create a Disposable object.Check whether object is successfully created or not.")]
31         [Property("SPEC", "Tizen.NUI.Disposable.Disposable C")]
32         [Property("SPEC_URL", "-")]
33         [Property("CRITERIA", "CONSTR")]
34         [Property("AUTHOR", "guowei.wang@samsung.com")]
35         public void Disposable_INIT()
36         {
37             tlog.Debug(tag, $"DisposableConstructor START");
38                         
39             var disposable = new Disposable();
40             Assert.IsNotNull(disposable, "Can't create success object Disposable");
41             Assert.IsInstanceOf<Disposable>(disposable, "Should be an instance of Disposable type.");
42                         
43                         tlog.Debug(tag, $"DisposableConstructor END (OK)");
44         }
45
46         [Test]
47         [Category("P1")]
48         [Description("Test Dispose, try to dispose the Disposable.")]
49         [Property("SPEC", "Tizen.NUI.Disposable.Dispose M")]
50         [Property("SPEC_URL", "-")]
51         [Property("CRITERIA", "MCST")]
52         [Property("AUTHOR", "guowei.wang@samsung.com")]
53         public void Dispose_TEST()
54         {
55             tlog.Debug(tag, $"DisposableWithDisposable START");
56                         
57             try
58             {
59                 Disposable disposable = new Disposable();
60                 disposable.Dispose();
61             }
62             catch (Exception e)
63             {
64                 tlog.Error(tag, "Caught Exception" + e.ToString());
65                 Assert.Fail("Caught Exception" + e.ToString());
66             }
67                         
68                         tlog.Debug(tag, $"DisposableWithDisposable END (OK)");
69         }
70
71         [Test]
72         [Category("P1")]
73         [Description("Test Dispose, try to dispose the Disposable.")]
74         [Property("SPEC", "Tizen.NUI.Disposable.Dispose M")]
75         [Property("SPEC_URL", "-")]
76         [Property("CRITERIA", "MCST")]
77         [Property("COVPARAM", "DisposeTypes")]
78         [Property("AUTHOR", "guowei.wang@samsung.com")]
79         public void Dispose_Implicit_TEST_WITH_DISPOSETYPE()
80         {
81             tlog.Debug(tag, $"DisposableImplicit START");
82                         
83             try
84             {
85                 MyDisposable myDisposable = new MyDisposable();
86                 myDisposable.DisposeImplicit();
87             }
88             catch (Exception e)
89             {
90                 tlog.Error(tag, "Caught Exception" + e.ToString());
91                 Assert.Fail("Caught Exception" + e.ToString());
92             }
93                         
94                         tlog.Debug(tag, $"DisposableImplicit END (OK)");
95         }
96
97         [Test]
98         [Category("P1")]
99         [Description("Test Dispose, try to dispose the Disposable.")]
100         [Property("SPEC", "Tizen.NUI.Disposable.Dispose M")]
101         [Property("SPEC_URL", "-")]
102         [Property("CRITERIA", "MCST")]
103         [Property("COVPARAM", "DisposeTypes")]
104         [Property("AUTHOR", "guowei.wang@samsung.com")]
105         public void Dispose_Explicit_TEST_WITH_DISPOSETYPE()
106         {
107             tlog.Debug(tag, $"DisposableExplicit START");
108                         
109             try
110             {
111                 MyDisposable myDisposable = new MyDisposable();
112                 myDisposable.DisposeExplicit();
113             }
114             catch (Exception e)
115             {
116                 tlog.Error(tag, "Caught Exception" + e.ToString());
117                 Assert.Fail("Caught Exception" + e.ToString());
118             }
119                         
120                         tlog.Debug(tag, $"DisposableExplicit END (OK)");
121         }
122     }
123
124     public class MyDisposable : Disposable
125     {
126         public void DisposeImplicit()
127         {
128             Dispose(DisposeTypes.Implicit);
129         }
130
131         public void DisposeExplicit()
132         {
133             Dispose(DisposeTypes.Explicit);
134         }
135
136         public bool Disposed
137         {
138             get
139             {
140                 return disposed;
141             }
142             set
143             {
144                 disposed = value;
145             }
146         }
147     }
148 }