[NUI] Add TCs for NUI.Components.Devel.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Components.Devel.Tests / testcase / Controls / TSMenu.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 System.Collections.Generic;
8 using System.Threading.Tasks;
9
10 namespace Tizen.NUI.Components.Devel.Tests
11 {
12     using tlog = Tizen.Log;
13
14     [TestFixture]
15     [Description("Controls/Menu")]
16     public class MenuTest
17     {
18         private const string tag = "NUITEST";
19         private string image_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "picture.png";
20
21         internal class MyMenu : Menu
22         {
23             public MyMenu() : base()
24             { }
25
26             public void OnDispose(DisposeTypes types)
27             {
28                 base.Dispose(types);
29             }
30
31             public View MyContent
32             {
33                 get
34                 { 
35                     return base.Content; 
36                 }
37                 set 
38                 {
39                     base.Add(value);
40                 }
41             }
42
43             public View MyScrim
44             {
45                 get
46                 {
47                     return base.Scrim;
48                 }
49                 set
50                 {
51                     base.Add(value);
52                 }
53             }
54         }
55
56         [SetUp]
57         public void Init()
58         {
59             tlog.Info(tag, "Init() is called!");
60         }
61
62         [TearDown]
63         public void Destroy()
64         {
65             tlog.Info(tag, "Destroy() is called!");
66         }
67
68         [Test]
69         [Category("P1")]
70         [Description("Menu Scrim.")]
71         [Property("SPEC", "Tizen.NUI.Components.Menu.Scrim M")]
72         [Property("SPEC_URL", "-")]
73         [Property("CRITERIA", "MR")]
74         [Property("COVPARAM", "")]
75         [Property("AUTHOR", "guowei.wang@samsung.com")]
76         public void MenuScrim()
77         {
78             tlog.Debug(tag, $"MenuScrim START");
79
80             var testingTarget = new MyMenu();
81             Assert.IsNotNull(testingTarget, "null handle");
82             Assert.IsInstanceOf<Menu>(testingTarget, "Should return Menu instance.");
83
84             View scrim = new View()
85             {
86                 BackgroundColor = Color.Red,
87             };
88             testingTarget.MyScrim = scrim;
89             testingTarget.MyScrim = scrim;
90
91             testingTarget.Dispose();
92             tlog.Debug(tag, $"MenuScrim END (OK)");
93         }
94
95         [Test]
96         [Category("P1")]
97         [Description("Menu GetRootView.")]
98         [Property("SPEC", "Tizen.NUI.Components.Menu.GetRootView M")]
99         [Property("SPEC_URL", "-")]
100         [Property("CRITERIA", "MR")]
101         [Property("COVPARAM", "")]
102         [Property("AUTHOR", "guowei.wang@samsung.com")]
103         public void MenuGetRootView()
104         {
105             tlog.Debug(tag, $"MenuGetRootView START");
106
107             var testingTarget = new MyMenu()
108             {
109                 Size = new Size(100, 200),
110                 BackgroundColor = Color.Green,
111             };
112             Assert.IsNotNull(testingTarget, "null handle");
113             Assert.IsInstanceOf<Menu>(testingTarget, "Should return Menu instance.");
114
115             NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(testingTarget);
116
117             testingTarget.HorizontalPositionToAnchor = Menu.RelativePosition.Start;
118             tlog.Debug(tag, "HorizontalPositionToAnchor :" + testingTarget.HorizontalPositionToAnchor);
119
120             testingTarget.VerticalPositionToAnchor = Menu.RelativePosition.Center;
121             tlog.Debug(tag, "HorizontalPositionToAnchor :" + testingTarget.HorizontalPositionToAnchor);
122
123             List<MenuItem> items = new List<MenuItem>();
124             MenuItem item = new MenuItem();
125             items.Add(item);
126             items.Add(item);
127             testingTarget.Items = items;
128
129             MenuItem item2 = new MenuItem();
130             items.Add(item2);
131             testingTarget.Items = items;
132
133             View content = new View()
134             {
135                 Size = new Size2D(100, 30),
136             };
137             testingTarget.MyContent = content;
138
139             View anchor1 = new View()
140             {
141                 Size = new Size(100, 30),
142                 BackgroundColor = Color.Cyan
143             };
144             testingTarget.Anchor = anchor1;
145
146             testingTarget.HorizontalPositionToAnchor = Menu.RelativePosition.Center;
147             tlog.Debug(tag, "HorizontalPositionToAnchor :" + testingTarget.HorizontalPositionToAnchor);
148
149             testingTarget.VerticalPositionToAnchor = Menu.RelativePosition.Start;
150             tlog.Debug(tag, "HorizontalPositionToAnchor :" + testingTarget.HorizontalPositionToAnchor);
151
152             View anchor2 = new View()
153             {
154                 Size = new Size(100, 30),
155                 BackgroundColor = Color.Black
156             };
157             testingTarget.Anchor = anchor2;
158
159             NUIApplication.GetDefaultWindow().GetDefaultLayer().Remove(testingTarget);
160
161             testingTarget.OnDispose(DisposeTypes.Explicit);
162             tlog.Debug(tag, $"MenuGetRootView END (OK)");
163         }
164
165         [Test]
166         [Category("P1")]
167         [Description("Menu OnRelayout.")]
168         [Property("SPEC", "Tizen.NUI.Components.Menu.OnRelayout M")]
169         [Property("SPEC_URL", "-")]
170         [Property("CRITERIA", "MR")]
171         [Property("COVPARAM", "")]
172         [Property("AUTHOR", "guowei.wang@samsung.com")]
173         public async Task MenuOnRelayout()
174         {
175             tlog.Debug(tag, $"MenuOnRelayout START");
176
177             var testingTarget = new MyMenu()
178             {
179                 Size = new Size(100, 200),
180                 BackgroundColor = Color.Green,
181             };
182             Assert.IsNotNull(testingTarget, "null handle");
183             Assert.IsInstanceOf<Menu>(testingTarget, "Should return Menu instance.");
184
185             View content = new View()
186             {
187                 Size = new Size2D(100, 30),
188             };
189             testingTarget.MyContent = content;
190
191             NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(testingTarget);
192
193             testingTarget.Size = new Size(50, 80);
194             testingTarget.BackgroundColor = Color.Blue;
195
196             await Task.Delay(200);
197             NUIApplication.GetDefaultWindow().GetDefaultLayer().Remove(testingTarget);
198
199             testingTarget.Dispose();
200             tlog.Debug(tag, $"MenuOnRelayout END (OK)");
201         }
202     }
203 }