[NUI] Add method to DisposeRecursively. + Fix DisposeTest demo works
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / Tizen.NUI.Devel.Tests / testcase / TSImageView.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6
7 namespace Tizen.NUI.Devel.Tests
8 {
9     using tlog = Tizen.Log;
10
11     [TestFixture]
12     [Description("public/BaseComponents/ImageView")]
13     public class InternalImageViewTest
14     {
15         private const string tag = "NUITEST";
16         private string image_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "Image.png";
17         private string mask_path = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "star-mod.png";
18
19         [SetUp]
20         public void Init()
21         {
22             tlog.Info(tag, "Init() is called!");
23         }
24
25         [TearDown]
26         public void Destroy()
27         {
28             tlog.Info(tag, "Destroy() is called!");
29         }
30
31         [Test]
32         [Category("P1")]
33         [Description("internal API test in Ubuntu, ImageView.ResourceUrl")]
34         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.ResourceUrl")]
35         [Property("SPEC_URL", "-")]
36         [Property("CRITERIA", "PRO")]
37         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
38         public void ResourceUrl_SET_GET_VALUE()
39         {
40             /* TEST CODE */
41             ImageView testView = new ImageView();
42             string testUrl1 = "test1";
43             testView.ResourceUrl = testUrl1;
44
45             Assert.AreEqual(testView.ResourceUrl, testUrl1, "ResourceUrl is not equal");
46
47             testView.Dispose();
48         }
49
50         [Test]
51         [Category("P1")]
52         [Description("internal API test in Ubuntu, ImageView.AlphaMaskURL")]
53         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.AlphaMaskURL")]
54         [Property("SPEC_URL", "-")]
55         [Property("CRITERIA", "PRO")]
56         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
57         public void AlphaMaskURL_SET_GET_VALUE()
58         {
59             /* TEST CODE */
60             ImageView testView = new ImageView(image_path);
61             string testUrl1 = "test1";
62             testView.AlphaMaskURL = testUrl1;
63
64             Assert.AreEqual(testView.AlphaMaskURL, testUrl1, "AlphaMaskURL is not equal");
65
66             testView.Dispose();
67         }
68
69         [Test]
70         [Category("P1")]
71         [Description("internal API test in Ubuntu, ImageView.CropToMask")]
72         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.CropToMask")]
73         [Property("SPEC_URL", "-")]
74         [Property("CRITERIA", "PRO")]
75         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
76         public void CropToMask_SET_GET_VALUE()
77         {
78             /* TEST CODE */
79             ImageView testView = new ImageView(image_path);
80
81             Assert.AreEqual(testView.CropToMask, false, "CropToMask default is false when we don't set mask image url");
82
83             testView.CropToMask = true;
84
85             Assert.AreEqual(testView.CropToMask, true, "CropToMask is not updated");
86
87             testView.CropToMask = false;
88
89             Assert.AreEqual(testView.CropToMask, false, "CropToMask is not updated");
90
91             testView.AlphaMaskURL = mask_path;
92
93             Assert.AreEqual(testView.CropToMask, false, "CropToMask should not changed even we set mask image url");
94
95             testView.Dispose();
96         }
97
98         [Test]
99         [Category("P1")]
100         [Description("internal API test in Ubuntu, ImageView.PreMultipliedAlpha")]
101         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.PreMultipliedAlpha")]
102         [Property("SPEC_URL", "-")]
103         [Property("CRITERIA", "PRO")]
104         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
105         public void PreMultipliedAlpha_SET_GET_VALUE()
106         {
107             /* TEST CODE */
108             ImageView testView = new ImageView(image_path);
109
110             testView.PreMultipliedAlpha = true;
111
112             Assert.AreEqual(testView.PreMultipliedAlpha, true, "PreMultipliedAlpha is not updated");
113
114             testView.PreMultipliedAlpha = false;
115
116             Assert.AreEqual(testView.PreMultipliedAlpha, false, "PreMultipliedAlpha is not updated");
117
118             testView.Dispose();
119         }
120
121         [Test]
122         [Category("P1")]
123         [Description("internal API test in Ubuntu, ImageView.CropToMask with AlphaMaskURL")]
124         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.CropToMask")]
125         [Property("SPEC_URL", "-")]
126         [Property("CRITERIA", "PRO")]
127         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
128         public void CropToMask_DEFAULT_GET_VALUE()
129         {
130             /* TEST CODE */
131             ImageView testView = new ImageView(image_path);
132
133             Assert.AreEqual(testView.CropToMask, false, "CropToMask default is false when we don't set mask image url");
134
135             testView.AlphaMaskURL = image_path;
136
137             Assert.AreEqual(testView.CropToMask, true, "CropToMask default is true when we set mask image url");
138
139             testView.Dispose();
140         }
141
142         [Test]
143         [Category("P1")]
144         [Description("internal API test in Ubuntu, ImageView.NaturalSize2D")]
145         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.NaturalSize2D")]
146         [Property("SPEC_URL", "-")]
147         [Property("CRITERIA", "PRO")]
148         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
149         public void NaturalSize2D_GET_VALUE()
150         {
151             /* TEST CODE */
152             ImageView testView = new ImageView();
153             testView.ResourceUrl = image_path;
154             Size2D result = new Size2D(212, 150); // The size of image_path image.
155             Size2D size = testView.NaturalSize2D;
156
157             Assert.AreEqual(result.Width, size.Width, "NaturalSize Width is not equal");
158             Assert.AreEqual(result.Height, size.Height, "NaturalSize Height is not equal");
159
160             testView.Dispose();
161         }
162
163
164         [Test]
165         [Category("P1")]
166         [Description("internal API test in Ubuntu, ImageView.NaturalSize")]
167         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.NaturalSize")]
168         [Property("SPEC_URL", "-")]
169         [Property("CRITERIA", "PRO")]
170         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
171         public void NaturalSize_GET_VALUE()
172         {
173             /* TEST CODE */
174             ImageView testView = new ImageView();
175             testView.ResourceUrl = image_path;
176             Vector3 result = new Vector3(212, 150, 0); // The size of image_path image.
177             Vector3 size = testView.NaturalSize;
178
179             Assert.AreEqual(result.X, size.X, "NaturalSize Width is not equal");
180             Assert.AreEqual(result.Y, size.Y, "NaturalSize Height is not equal");
181
182             testView.Dispose();
183         }
184
185         [Test]
186         [Category("P1")]
187         [Description("internal API test in Ubuntu, ImageView.NaturalSize")]
188         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.NaturalSize")]
189         [Property("SPEC_URL", "-")]
190         [Property("CRITERIA", "PRO")]
191         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
192         public void NaturalSize_GET_VALUE_as_View_class()
193         {
194             /* TEST CODE */
195             ImageView testView = new ImageView();
196             testView.ResourceUrl = image_path;
197             Vector3 result = new Vector3(212, 150, 0); // The size of image_path image.
198             View testView2 = testView; // Convert class as View.
199             Vector3 size = testView2.NaturalSize; // Check whether virtual ImageView.GetNaturalSize() called well.
200
201             Assert.AreEqual(result.X, size.X, "NaturalSize Width is not equal");
202             Assert.AreEqual(result.Y, size.Y, "NaturalSize Height is not equal");
203
204             testView.Dispose();
205             testView2.Dispose();
206         }
207
208         [Test]
209         [Category("P1")]
210         [Description("internal API test in Ubuntu, ImageView.Image with ResourceUrl")]
211         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.Image")]
212         [Property("SPEC_URL", "-")]
213         [Property("CRITERIA", "PRO")]
214         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
215         public void Image_GET_VALUE_After_Set_ResourceUrl()
216         {
217             /* TEST CODE */
218             ImageView testView = new ImageView();
219             string resultUrl1 = "";
220
221             PropertyMap map1 = testView.Image;
222
223             bool ret1 = (map1.Find(ImageVisualProperty.URL)?.Get(out resultUrl1) ?? false) && string.IsNullOrEmpty(resultUrl1);
224
225             Assert.AreEqual(false, ret1, "map don't have ResourceUrl");
226
227             string testUrl1 = "test1";
228             testView.ResourceUrl = testUrl1;
229
230             PropertyMap map2 = testView.Image;
231
232             bool ret2 = (map2.Find(ImageVisualProperty.URL)?.Get(out resultUrl1) ?? false) && !string.IsNullOrEmpty(resultUrl1);
233
234             Assert.AreEqual(true, ret2, "map must have ResourceUrl");
235             Assert.AreEqual(testUrl1, resultUrl1, "...and That value must be equal what we added");
236
237             testView.Dispose();
238         }
239
240         [Test]
241         [Category("P1")]
242         [Description("internal API test in Ubuntu, ImageView.Image with something")]
243         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.Image")]
244         [Property("SPEC_URL", "-")]
245         [Property("CRITERIA", "PRO")]
246         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
247         public void Image_GET_VALUE_After_Set_something()
248         {
249             /* TEST CODE */
250             ImageView testView = new ImageView();
251             string resultString = "";
252             bool resultBool = false;
253
254             using(PropertyMap map = testView.Image)
255             {
256                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString);
257                 Assert.AreEqual(false, ret, "map don't have ResourceUrl");
258                 ret = map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false;
259                 Assert.AreEqual(false, ret, "map don't have AlphaMaskURL");
260                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
261                 Assert.AreEqual(false, ret, "map don't have CropToMask");
262                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
263                 Assert.AreEqual(false, ret, "map don't have SynchronousLoading");
264             }
265
266             string testUrl1 = "test1";
267             testView.AlphaMaskURL = testUrl1;
268             testView.CropToMask = true;
269             testView.SynchronousLoading = true;
270
271             using(PropertyMap map = testView.Image)
272             {
273                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString);
274                 Assert.AreEqual(false, ret, "map don't have ResourceUrl");
275                 ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString);
276                 Assert.AreEqual(false, ret, "map don't have AlphaMaskURL cause ResoureUrl is empty");
277                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
278                 Assert.AreEqual(false, ret, "map don't have CropToMask cause ResoureUrl is empty");
279                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
280                 Assert.AreEqual(false, ret, "map don't have SynchronousLoading cause ResoureUrl is empty");
281             }
282
283             testView.ResourceUrl = image_path;
284
285             using(PropertyMap map = testView.Image)
286             {
287                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
288                 Assert.AreEqual(true, ret, "map must have ResourceUrl");
289                 Assert.AreEqual(image_path, resultString, "...and That value must be equal what we added");
290                 ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
291                 Assert.AreEqual(true, ret, "map must have AlphaMaskURL");
292                 Assert.AreEqual(testUrl1, resultString, "...and That value must be equal what we added");
293                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
294                 Assert.AreEqual(true, ret, "map must have CropToMask");
295                 Assert.AreEqual(true, resultBool, "...and That value must be equal what we added");
296                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
297                 Assert.AreEqual(true, ret, "map must have SynchronousLoading");
298                 Assert.AreEqual(true, resultBool, "...and That value must be equal what we added");
299             }
300
301             // Insert empty resource Url
302             testView.ResourceUrl = "";
303
304             using(PropertyMap map = testView.Image)
305             {
306                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString);
307                 Assert.AreEqual(false, ret, "map don't have ResourceUrl");
308                 ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString);
309                 Assert.AreEqual(false, ret, "map don't have AlphaMaskURL cause ResoureUrl is empty");
310                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
311                 Assert.AreEqual(false, ret, "map don't have CropToMask cause ResoureUrl is empty");
312                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
313                 Assert.AreEqual(false, ret, "map don't have SynchronousLoading cause ResoureUrl is empty");
314             }
315
316             // Insert valid resource Url
317             testView.ResourceUrl = mask_path;
318
319             using(PropertyMap map = testView.Image)
320             {
321                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
322                 Assert.AreEqual(true, ret, "map must have ResourceUrl");
323                 Assert.AreEqual(mask_path, resultString, "...and That value must be equal what we added");
324                 ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
325                 Assert.AreEqual(true, ret, "map must have AlphaMaskURL");
326                 Assert.AreEqual(testUrl1, resultString, "...and That value must be equal what we added");
327                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
328                 Assert.AreEqual(true, ret, "map must have CropToMask");
329                 Assert.AreEqual(true, resultBool, "...and That value must be equal what we added");
330                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
331                 Assert.AreEqual(true, ret, "map must have SynchronousLoading");
332                 Assert.AreEqual(true, resultBool, "...and That value must be equal what we added");
333             }
334
335             testView.Dispose();
336         }
337
338         [Test]
339         [Category("P1")]
340         [Description("internal API test in Ubuntu, set ImageView.Image and check cached properties changed")]
341         [Property("SPEC", "Tizen.NUI.BaseComponents.ImageView.Image")]
342         [Property("SPEC_URL", "-")]
343         [Property("CRITERIA", "PRO")]
344         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
345         public void Image_SET_VALUE_After_Set_something()
346         {
347             /* TEST CODE */
348             ImageView testView = new ImageView();
349             string resultString = "";
350             bool resultBool = false;
351
352             using(PropertyMap map = testView.Image)
353             {
354                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && string.IsNullOrEmpty(resultString);
355                 Assert.AreEqual(false, ret, "map don't have ResourceUrl");
356                 ret = map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false;
357                 Assert.AreEqual(false, ret, "map don't have AlphaMaskURL");
358                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
359                 Assert.AreEqual(false, ret, "map don't have CropToMask");
360                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
361                 Assert.AreEqual(false, ret, "map don't have SynchronousLoading");
362             }
363
364             string testUrl1 = "test1";
365             string testUrl2 = "test2";
366             testView.ResourceUrl = testUrl1;
367             testView.AlphaMaskURL = testUrl2;
368             testView.CropToMask = true;
369             testView.SynchronousLoading = true;
370
371             using(PropertyMap map = testView.Image)
372             {
373                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
374                 Assert.AreEqual(true, ret, "map must have ResourceUrl");
375                 Assert.AreEqual(testUrl1, resultString, "...and That value must be equal what we added");
376                 ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
377                 Assert.AreEqual(true, ret, "map must have AlphaMaskURL");
378                 Assert.AreEqual(testUrl2, resultString, "...and That value must be equal what we added");
379                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
380                 Assert.AreEqual(true, ret, "map must have CropToMask");
381                 Assert.AreEqual(true, resultBool, "...and That value must be equal what we added");
382                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
383                 Assert.AreEqual(true, ret, "map must have SynchronousLoading");
384                 Assert.AreEqual(true, resultBool, "...and That value must be equal what we added");
385             }
386
387             // Update Image map by PropertyMap.
388             // Cached property map will be overwrited.
389             using(PropertyMap setImageMap = new PropertyMap())
390             {
391                 setImageMap[ImageVisualProperty.URL] = new PropertyValue(image_path);
392                 setImageMap[ImageVisualProperty.AlphaMaskURL] = new PropertyValue(mask_path);
393                 setImageMap[ImageVisualProperty.CropToMask] = new PropertyValue(false);
394                 setImageMap[ImageVisualProperty.SynchronousLoading] = new PropertyValue(false);
395                 testView.Image = setImageMap;
396             }
397
398             using(PropertyMap map = testView.Image)
399             {
400                 bool ret = (map.Find(ImageVisualProperty.URL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
401                 Assert.AreEqual(true, ret, "map must have ResourceUrl");
402                 Assert.AreEqual(image_path, resultString, "...and That value must be equal what we added");
403                 ret = (map.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out resultString) ?? false) && !string.IsNullOrEmpty(resultString);
404                 Assert.AreEqual(true, ret, "map must have AlphaMaskURL");
405                 Assert.AreEqual(mask_path, resultString, "...and That value must be equal what we added");
406                 ret = map.Find(ImageVisualProperty.CropToMask)?.Get(out resultBool) ?? false;
407                 Assert.AreEqual(true, ret, "map must have CropToMask");
408                 Assert.AreEqual(false, resultBool, "...and That value must be equal what we added");
409                 ret = map.Find(ImageVisualProperty.SynchronousLoading)?.Get(out resultBool) ?? false;
410                 Assert.AreEqual(true, ret, "map must have SynchronousLoading");
411                 Assert.AreEqual(false, resultBool, "...and That value must be equal what we added");
412             }
413         }
414
415         [Test]
416         [Category("P1")]
417         [Description("internal API test in Ubuntu, Container.DisposeRecursively")]
418         [Property("SPEC", "Tizen.NUI.Common.Container.DisposeRecursively M")]
419         [Property("SPEC_URL", "-")]
420         [Property("CRITERIA", "MR")]
421         [Property("AUTHOR", "eunkiki.hong@samsung.com")]
422         public void DisposeRecursively_VALUE()
423         {
424             /* TEST CODE */
425             View testParent = new View();
426             View testChildL0 = new View();
427             View testChildL1 = new View();
428
429             testParent.Add(testChildL0);
430             testChildL0.Add(testChildL1);
431
432             Assert.AreEqual(false, testParent.Disposed, "View should not disposed yet.");
433             Assert.AreEqual(false, testChildL0.Disposed, "View should not disposed yet.");
434             Assert.AreEqual(false, testChildL1.Disposed, "View should not disposed yet.");
435
436             testParent.DisposeRecursively();
437
438             Assert.AreEqual(true, testParent.Disposed, "View should be disposed now.");
439             Assert.AreEqual(true, testChildL0.Disposed, "View should be disposed now.");
440             Assert.AreEqual(true, testChildL1.Disposed, "View should be disposed now.");
441         }
442     }
443 }