[NUI] Update TCs of NUI.Devel.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / Theme / TSTheme.cs
1 using NUnit.Framework;
2 using System;
3 using System.Collections.Generic;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.Binding;
6
7 namespace Tizen.NUI.Devel.Tests
8 {
9     using tlog = Tizen.Log;
10
11     [TestFixture]
12     [Description("public/Theme/Theme")]
13     internal class PublicThemeTest
14     {
15         private const string tag = "NUITEST";
16         private Theme theme = null;
17         private string path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "Test_Theme.xaml";
18         private string image = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "picture.png";
19         private string IOException_file = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "1.xaml";
20         private string ParseException_file = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "Test_View.xaml";
21         private IEnumerable<KeyValuePair<string, string>> changedResources = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("Version", "2.0") };
22
23         [SetUp]
24         public void Init()
25         {
26             tlog.Info(tag, "Init() is called!");
27             theme = new Theme(path);
28         }
29
30         [TearDown]
31         public void Destroy()
32         {
33             theme = null;
34             tlog.Info(tag, "Destroy() is called!");
35         }
36
37         [Test]
38         [Category("P2")]
39         [Description("Theme construcotr. xaml file path is null.")]
40         [Property("SPEC", "Tizen.NUI.Theme.Theme C")]
41         [Property("SPEC_URL", "-")]
42         [Property("CRITERIA", "CONSTR")]
43         [Property("COVPARAM", "")]
44         public void ThemeConstructorWithUnavailablePath()
45         {
46             tlog.Debug(tag, $"ThemeConstructorWithUnavailablePath START");
47
48             try
49             {
50                 var testingTarget = new Theme("");
51             }
52             catch (ArgumentNullException e)
53             {
54                 tlog.Debug(tag, e.Message.ToString());
55                 tlog.Debug(tag, $"ThemeConstructorWithUnavailablePath END (OK)");
56                 Assert.Pass("Caught ArgumentNullException : Passed!");
57             }
58         }
59
60         [Test]
61         [Category("P2")]
62         [Description("Theme construcotr. Could not parse.")]
63         [Property("SPEC", "Tizen.NUI.Theme.Theme C")]
64         [Property("SPEC_URL", "-")]
65         [Property("CRITERIA", "CONSTR")]
66         [Property("COVPARAM", "")]
67         public void ThemeConstructorWithFileCouldNotBeParsed()
68         {
69             tlog.Debug(tag, $"ThemeConstructorWithFileCouldNotBeParsed START");
70
71             try
72             {
73                 var testingTarget = new Theme(image);
74             }
75             catch (Exception e)
76             {
77                 tlog.Debug(tag, e.Message.ToString());
78                 tlog.Debug(tag, $"ThemeConstructorWithFileCouldNotBeParsed END (OK)");
79                 Assert.Pass("Caught Exception : Passed!");
80             }
81         }
82
83         [Test]
84         [Category("P2")]
85         [Description("Theme construcotr. IOException.")]
86         [Property("SPEC", "Tizen.NUI.Theme.Theme C")]
87         [Property("SPEC_URL", "-")]
88         [Property("CRITERIA", "CONSTR")]
89         [Property("COVPARAM", "")]
90         public void ThemeConstructorIOException()
91         {
92             tlog.Debug(tag, $"ThemeConstructorIOException START");
93
94             try
95             {
96                 var testingTarget = new Theme(IOException_file);
97             }
98             catch (Exception e)
99             {
100                 tlog.Debug(tag, e.Message.ToString());
101                 tlog.Debug(tag, $"ThemeConstructorIOException END (OK)");
102                 Assert.Pass("Caught IOException : Passed!");
103             }
104         }
105
106         [Test]
107         [Category("P2")]
108         [Description("Theme construcotr. XamlParseException.")]
109         [Property("SPEC", "Tizen.NUI.Theme.Theme C")]
110         [Property("SPEC_URL", "-")]
111         [Property("CRITERIA", "CONSTR")]
112         [Property("COVPARAM", "")]
113         public void ThemeConstructorXamlParseException()
114         {
115             tlog.Debug(tag, $"ThemeConstructorXamlParseException START");
116
117             try
118             {
119                 var testingTarget = new Theme(ParseException_file);
120             }
121             catch (Exception e)
122             {
123                 tlog.Debug(tag, e.Message.ToString());
124                 tlog.Debug(tag, $"ThemeConstructorXamlParseException END (OK)");
125                 Assert.Pass("Caught XamlParseException : Passed!");
126             }
127         }
128
129         [Test]
130         [Category("P1")]
131         [Description("test Theme BasedOn.")]
132         [Property("SPEC", "Tizen.NUI.Theme.BasedOn A")]
133         [Property("SPEC_URL", "-")]
134         [Property("CRITERIA", "PRW")]
135         [Property("COVPARAM", "")]
136         public void ThemeBasedOn()
137         {
138             tlog.Debug(tag, $"ThemeBasedOn START");
139
140             var baseOn = "Tizen.NUI.Theme.Common";
141             theme.BasedOn = baseOn;
142             tlog.Debug(tag, "BaseOn : " + theme.BasedOn);
143
144             tlog.Debug(tag, $"ThemeBasedOn END (OK)");
145         }
146
147         [Test]
148         [Category("P1")]
149         [Description("test Theme IsResourcesCreated .")]
150         [Property("SPEC", "Tizen.NUI.Theme.IsResourcesCreated  A")]
151         [Property("SPEC_URL", "-")]
152         [Property("CRITERIA", "PRW")]
153         [Property("COVPARAM", "")]
154         public void ThemeIsResourcesCreated()
155         {
156             tlog.Debug(tag, $"ThemeIsResourcesCreated START");
157
158             var result = theme.IsResourcesCreated;
159             tlog.Debug(tag, "IsResourcesCreated : " + result);
160
161             tlog.Debug(tag, $"ThemeIsResourcesCreated END (OK)");
162         }
163
164         [Test]
165         [Category("P1")]
166         [Description("test Theme Resources .")]
167         [Property("SPEC", "Tizen.NUI.Theme.Resources  A")]
168         [Property("SPEC_URL", "-")]
169         [Property("CRITERIA", "PRW")]
170         [Property("COVPARAM", "")]
171         public void ThemeResources()
172         {
173             tlog.Debug(tag, $"ThemeResources START");
174
175             var result = theme.Resources;
176             tlog.Debug(tag, "Resources : " + result);
177
178             theme.SetChangedResources(changedResources);
179
180             // resources == value
181             theme.Resources = result;
182             tlog.Debug(tag, "Resouces : " + theme.Resources);
183
184             // resources != null
185             ResourceDictionary dic = new ResourceDictionary();
186             theme.Resources = dic;
187             tlog.Debug(tag, "Resouces : " + theme.Resources);
188
189             tlog.Debug(tag, $"ThemeResources END (OK)");
190         }
191
192         [Test]
193         [Category("P1")]
194         [Description("test Theme this .")]
195         [Property("SPEC", "Tizen.NUI.Theme.this  A")]
196         [Property("SPEC_URL", "-")]
197         [Property("CRITERIA", "PRW")]
198         [Property("COVPARAM", "")]
199         public void ThemeThis()
200         {
201             tlog.Debug(tag, $"ThemeThis START");
202
203             ViewStyle style = new ViewStyle()
204             {
205                 Color = Color.Cyan,
206             };
207
208             theme.AddStyle("style", style);
209
210             tlog.Debug(tag, "Count : " + theme.Count);
211             tlog.Debug(tag, "theme[\"style\"] : " + theme["style"]);
212
213             ViewStyle newStyle = new ViewStyle()
214             {
215                 Size = new Size(100, 50),
216                 Color = Color.Red
217             };
218
219             theme["Style"] = newStyle;
220             tlog.Debug(tag, "theme[\"style\"] : " + theme["style"]);
221
222             tlog.Debug(tag, $"ThemeThis END (OK)");
223         }
224
225         [Test]
226         [Category("P1")]
227         [Description("test Theme this .")]
228         [Property("SPEC", "Tizen.NUI.Theme.this  A")]
229         [Property("SPEC_URL", "-")]
230         [Property("CRITERIA", "PRW")]
231         [Property("COVPARAM", "")]
232         public void ThemeThisSetVauleIsNUll()
233         {
234             tlog.Debug(tag, $"ThemeThisSetVauleIsNUll START");
235
236             ViewStyle style = new ViewStyle()
237             {
238                 Color = Color.Cyan,
239             };
240
241             theme.AddStyle("style", style);
242
243             tlog.Debug(tag, "Count : " + theme.Count);
244             tlog.Debug(tag, "theme[\"style\"] : " + theme["style"]);
245
246             ViewStyle newStyle = null;
247
248             theme["Style"] = newStyle;
249             tlog.Debug(tag, "theme[\"style\"] : " + theme["style"]);
250
251             tlog.Debug(tag, $"ThemeThisSetVauleIsNUll END (OK)");
252         }
253
254         [Test]
255         [Category("P1")]
256         [Description("test Theme Clear .")]
257         [Property("SPEC", "Tizen.NUI.Theme.Clear  M")]
258         [Property("SPEC_URL", "-")]
259         [Property("CRITERIA", "MR")]
260         [Property("COVPARAM", "")]
261         public void ThemeClear()
262         {
263             tlog.Debug(tag, $"ThemeClear START");
264             
265             try
266             {
267                 theme.Clear();
268             }
269             catch (Exception e)
270             {
271                 tlog.Debug(tag, e.Message.ToString());
272                 Assert.Fail("Caught Exception : Failed!");
273             }
274             
275             tlog.Debug(tag, $"ThemeClear END (OK)");
276         }
277
278         [Test]
279         [Category("P1")]
280         [Description("test Theme AddStyle .")]
281         [Property("SPEC", "Tizen.NUI.Theme.AddStyle  M")]
282         [Property("SPEC_URL", "-")]
283         [Property("CRITERIA", "MR")]
284         [Property("COVPARAM", "")]
285         public void ThemeAddStyle()
286         {
287             tlog.Debug(tag, $"ThemeAddStyle START");
288
289             ViewStyle style = new ViewStyle()
290             {
291                 Color = Color.Cyan,
292             };
293
294             try
295             {
296                 theme.AddStyle("style", style);
297             }
298             catch (Exception e)
299             {
300                 tlog.Debug(tag, e.Message.ToString());
301                 Assert.Fail("Caught Exception : Failed!");
302             }
303
304             tlog.Debug(tag, "HasStyle : " + theme.HasStyle("style"));
305             tlog.Debug(tag, "RemoveStyle : " + theme.RemoveStyle("style"));
306
307             tlog.Debug(tag, $"ThemeAddStyle END (OK)");
308         }
309
310         [Test]
311         [Category("P2")]
312         [Description("test Theme AddStyle .")]
313         [Property("SPEC", "Tizen.NUI.Theme.AddStyle  M")]
314         [Property("SPEC_URL", "-")]
315         [Property("CRITERIA", "MR")]
316         [Property("COVPARAM", "")]
317         public void ThemeAddStyleNullStyleName()
318         {
319             tlog.Debug(tag, $"ThemeAddStyleNullStyleName START");
320
321             ViewStyle style = new ViewStyle()
322             {
323                 Color = Color.Cyan,
324             };
325
326             try
327             {
328                 theme.AddStyle(null, style);
329             }
330             catch (ArgumentNullException e)
331             {
332                 tlog.Debug(tag, e.Message.ToString());
333                 tlog.Debug(tag, $"ThemeAddStyleNullStyleName END (OK)");
334                 Assert.Pass("Caught Exception : Passed!");
335             }
336         }
337
338         [Test]
339         [Category("P1")]
340         [Description("test Theme Clone .")]
341         [Property("SPEC", "Tizen.NUI.Theme.Clone  M")]
342         [Property("SPEC_URL", "-")]
343         [Property("CRITERIA", "MR")]
344         [Property("COVPARAM", "")]
345         public void ThemeClone()
346         {
347             tlog.Debug(tag, $"ThemeClone START");
348
349             try
350             {
351                 theme.Clone();
352             }
353             catch (Exception e)
354             {
355                 tlog.Debug(tag, e.Message.ToString());
356                 Assert.Fail("Caught Exception : Failed!");
357             }
358
359             tlog.Debug(tag, $"ThemeClone END (OK)");
360         }
361
362         [Test]
363         [Category("P1")]
364         [Description("Theme Merge .")]
365         [Property("SPEC", "Tizen.NUI.Theme.Merge  M")]
366         [Property("SPEC_URL", "-")]
367         [Property("CRITERIA", "MR")]
368         [Property("COVPARAM", "")]
369         public void ThemeMerge()
370         {
371             tlog.Debug(tag, $"ThemeMerge START");
372
373             var testingTarget = new Theme();
374             Assert.IsNotNull(testingTarget, "should be not null");
375             Assert.IsInstanceOf<Theme>(testingTarget, "should be an instance of testing target class!");
376
377             ViewStyle style = new ViewStyle()
378             {
379                 Size = new Size2D(100, 30),
380                 Focusable = true
381             };
382             testingTarget.Version = "0.1";
383             testingTarget.AddStyle("myStyle", style);
384
385             try
386             {
387                 theme.Merge(testingTarget); // merge with Theme
388                 theme.Merge(path);  // merge with xaml file
389             }
390             catch (Exception e)
391             {
392                 tlog.Debug(tag, e.Message.ToString());
393                 Assert.Fail("Caught Exception: Failed!");
394             }
395
396             tlog.Debug(tag, $"ThemeMerge END (OK)");
397         }
398
399         [Test]
400         [Category("P2")]
401         [Description("Theme Merge. Parameter is null.")]
402         [Property("SPEC", "Tizen.NUI.Theme.Merge  M")]
403         [Property("SPEC_URL", "-")]
404         [Property("CRITERIA", "MR")]
405         [Property("COVPARAM", "")]
406         public void ThemeMergeWithNullParameter()
407         {
408             tlog.Debug(tag, $"ThemeMergeWithNullParameter START");
409
410             try
411             {
412                 Theme newtheme = null;
413                 theme.Merge(newtheme);
414             }
415             catch (ArgumentNullException e)
416             {
417                 tlog.Debug(tag, e.Message.ToString());
418                 tlog.Debug(tag, $"ThemeMergeWithNullParameter END (OK)");
419                 Assert.Pass("Caught ArgumentNullException: Passed!");
420             }
421         }
422
423         [Test]
424         [Category("P2")]
425         [Description("Theme Merge.")]
426         [Property("SPEC", "Tizen.NUI.Theme.Merge  M")]
427         [Property("SPEC_URL", "-")]
428         [Property("CRITERIA", "MR")]
429         [Property("COVPARAM", "")]
430         public void ThemeMergeIdAndVersionIsNull()
431         {
432             tlog.Debug(tag, $"ThemeMergeIdAndVersionIsNull START");
433             
434             var testingTarget = new Theme();
435             Assert.IsNotNull(testingTarget, "should be not null");
436             Assert.IsInstanceOf<Theme>(testingTarget, "should be an instance of testing target class!");
437             
438             testingTarget.Merge(theme);
439             Assert.AreEqual(testingTarget.Id, theme.Id, "Should be equal!");
440             Assert.AreEqual(testingTarget.Version, theme.Version, "Should be equal!");
441
442             testingTarget = null;
443             tlog.Debug(tag, $"ThemeMergeIdAndVersionIsNull END (OK)");
444         }
445
446         [Test]
447         [Category("P1")]
448         [Description("test Theme HasSameIdAndVersion .")]
449         [Property("SPEC", "Tizen.NUI.Theme.HasSameIdAndVersion  M")]
450         [Property("SPEC_URL", "-")]
451         [Property("CRITERIA", "MR")]
452         [Property("COVPARAM", "")]
453         public void ThemeHasSameIdAndVersion()
454         {
455             tlog.Debug(tag, $"ThemeHasSameIdAndVersion START");
456
457             var result = theme.HasSameIdAndVersion("Tizen.NUI.Theme.Wearable", "1.0");
458             tlog.Debug(tag, "HasSameIdAndVersion : " + result);
459
460             tlog.Debug(tag, $"ThemeHasSameIdAndVersion END (OK)");
461         }
462     }
463 }
464