[NUI] Update TCs to improve function coverage of NUI.Components.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Components.Devel.Tests / testcase / Extension / TSSlidingSwitchExtension.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI;
5 using Tizen.NUI.Components;
6 using Tizen.NUI.BaseComponents;
7 using Tizen.NUI.Components.Extension;
8
9 namespace Tizen.NUI.Components.Devel.Tests
10 {
11     using static Tizen.NUI.BaseComponents.View;
12     using tlog = Tizen.Log;
13
14     [TestFixture]
15     [Description("Controls/Extension/SlidingSwitchExtension")]
16     public class SlidingSwitchExtensionTest
17     {
18         private const string tag = "NUITEST";
19         private string image_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "picture.png";
20
21         internal class MySlidingSwitchExtension : SlidingSwitchExtension
22         {
23             public MySlidingSwitchExtension() : base()
24             { }
25
26             public void MyOnSelectedChanged(Switch button)
27             {
28                 base.OnSelectedChanged(button);
29             }
30
31             public void MyDispose(bool disposing)
32             {
33                 base.Dispose(disposing);
34             }
35         }
36
37         [SetUp]
38         public void Init()
39         {
40             tlog.Info(tag, "Init() is called!");
41         }
42
43         [TearDown]
44         public void Destroy()
45         {
46             tlog.Info(tag, "Destroy() is called!");
47         }
48
49         [Test]
50         [Category("P1")]
51         [Description("SlidingSwitchExtension OnSelectedChanged.")]
52         [Property("SPEC", "Tizen.NUI.Components.SlidingSwitchExtension.OnSelectedChanged M")]
53         [Property("SPEC_URL", "-")]
54         [Property("CRITERIA", "MR")]
55         [Property("COVPARAM", "")]
56         [Property("AUTHOR", "guowei.wang@samsung.com")]
57         public void SlidingSwitchExtensionOnSelectedChanged()
58         {
59             tlog.Debug(tag, $"SlidingSwitchExtensionOnSelectedChanged START");
60
61             var testingTarget = new MySlidingSwitchExtension();
62             Assert.IsNotNull(testingTarget, "null handle");
63             Assert.IsInstanceOf<MySlidingSwitchExtension>(testingTarget, "Should return SlidingSwitchExtension instance.");
64
65             SwitchStyle style = new SwitchStyle()
66             {
67                 Track = new ImageViewStyle()
68                 {
69                     BackgroundImage = image_path,
70                 },
71                 Thumb = new ImageViewStyle()
72                 {
73                     BackgroundImage = image_path,
74                 },
75             };
76
77             using (Switch button = new Switch(style) )
78             {
79
80                 Window.Instance.Add(button);
81
82                 try
83                 {
84                     testingTarget.MyOnSelectedChanged(button);
85                 }
86                 catch (Exception e)
87                 {
88                     tlog.Debug(tag, e.Message.ToString());
89                     Assert.Fail("Caught Exception : Failed!");
90                 }
91             }
92
93             testingTarget.MyDispose(true);
94             tlog.Debug(tag, $"SlidingSwitchExtensionOnSelectedChanged END (OK)");
95         }
96
97         [Test]
98         [Category("P1")]
99         [Description("SlidingSwitchExtension Dispose.")]
100         [Property("SPEC", "Tizen.NUI.Components.SlidingSwitchExtension.Dispose M")]
101         [Property("SPEC_URL", "-")]
102         [Property("CRITERIA", "MR")]
103         [Property("COVPARAM", "")]
104         [Property("AUTHOR", "guowei.wang@samsung.com")]
105         public void SlidingSwitchExtensionDispose()
106         {
107             tlog.Debug(tag, $"SlidingSwitchExtensionDispose START");
108
109             var testingTarget = new SlidingSwitchExtension();
110             Assert.IsNotNull(testingTarget, "null handle");
111             Assert.IsInstanceOf<SlidingSwitchExtension>(testingTarget, "Should return SlidingSwitchExtension instance.");
112
113             try
114             {
115                 testingTarget.Dispose();
116             }
117             catch (Exception e)
118             {
119                 tlog.Debug(tag, e.Message.ToString());
120                 Assert.Fail("Caught Exception : Failed!");
121             }
122
123             tlog.Debug(tag, $"SlidingSwitchExtensionDispose END (OK)");
124         }
125     }
126 }