[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / ImageTest1.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.IO;
19 using ElmSharp;
20 using System.Collections.Generic;
21
22 namespace ElmSharp.Test
23 {
24     public class ImageTest1 : TestCaseBase
25     {
26         public override string TestName => "ImageTest1";
27         public override string TestDescription => "To test basic operation of Image";
28
29         Image image;
30         Label lbInfo;
31
32         public override void Run(Window window)
33         {
34             Conformant conformant = new Conformant(window);
35             conformant.Show();
36             Box box = new Box(window);
37             conformant.SetContent(box);
38             box.Show();
39
40             Box buttonBox1 = new Box(window)
41             {
42                 IsHorizontal = true,
43                 AlignmentX = -1,
44                 AlignmentY = 0,
45             };
46             buttonBox1.Show();
47
48             Box buttonBox2 = new Box(window)
49             {
50                 IsHorizontal = true,
51                 AlignmentX = -1,
52                 AlignmentY = 0,
53             };
54             buttonBox2.Show();
55
56             Button btnFile1 = new Button(window)
57             {
58                 Text = "File1",
59                 AlignmentX = -1,
60                 AlignmentY = -1,
61                 WeightX = 1,
62                 WeightY = 1
63             };
64             btnFile1.Show();
65
66             Button btnFile2 = new Button(window)
67             {
68                 Text = "File2",
69                 AlignmentX = -1,
70                 AlignmentY = -1,
71                 WeightX = 1,
72                 WeightY = 1
73             };
74             btnFile2.Show();
75
76             Button btnUri1 = new Button(window)
77             {
78                 Text = "Uri",
79                 AlignmentX = -1,
80                 AlignmentY = -1,
81                 WeightX = 1,
82                 WeightY = 1
83             };
84             btnUri1.Show();
85
86             Button btnStream1 = new Button(window)
87             {
88                 Text = "Strm",
89                 AlignmentX = -1,
90                 AlignmentY = -1,
91                 WeightX = 1,
92                 WeightY = 1
93             };
94             btnStream1.Show();
95
96             buttonBox1.PackEnd(btnFile1);
97             buttonBox1.PackEnd(btnFile2);
98             buttonBox1.PackEnd(btnUri1);
99             buttonBox1.PackEnd(btnStream1);
100
101
102             Button btnFileAsync1 = new Button(window)
103             {
104                 Text = "FileA1",
105                 AlignmentX = -1,
106                 AlignmentY = -1,
107                 WeightX = 1,
108                 WeightY = 1
109             };
110             btnFileAsync1.Show();
111
112             Button btnFileAsync2 = new Button(window)
113             {
114                 Text = "FileA2",
115                 AlignmentX = -1,
116                 AlignmentY = -1,
117                 WeightX = 1,
118                 WeightY = 1
119             };
120             btnFileAsync2.Show();
121
122             Button btnUriAsync1 = new Button(window)
123             {
124                 Text = "UriA",
125                 AlignmentX = -1,
126                 AlignmentY = -1,
127                 WeightX = 1,
128                 WeightY = 1
129             };
130             btnUriAsync1.Show();
131
132             Button btnStreamAsync1 = new Button(window)
133             {
134                 Text = "StrmA",
135                 AlignmentX = -1,
136                 AlignmentY = -1,
137                 WeightX = 1,
138                 WeightY = 1
139             };
140             btnStreamAsync1.Show();
141
142             buttonBox2.PackEnd(btnFileAsync1);
143             buttonBox2.PackEnd(btnFileAsync2);
144             buttonBox2.PackEnd(btnUriAsync1);
145             buttonBox2.PackEnd(btnStreamAsync1);
146
147
148             lbInfo = new Label(window)
149             {
150                 Color = Color.White,
151                 AlignmentX = -1,
152                 AlignmentY = 0,
153                 WeightX = 1
154             };
155             lbInfo.Show();
156
157             image = new Image(window)
158             {
159                 IsFixedAspect = true,
160                 AlignmentX = -1,
161                 AlignmentY = -1,
162                 WeightX = 1,
163                 WeightY = 1
164             };
165             image.Show();
166             image.Load(Path.Combine(TestRunner.ResourceDir, "picture.png"));
167             image.Clicked += (s, e) =>
168             {
169                 Console.WriteLine("Image has been clicked. (IsFixedAspect = {0}", image.IsFixedAspect);
170                 image.IsFixedAspect = image.IsFixedAspect == true ? false : true;
171             };
172             image.LoadingCompleted += (s, e) =>
173             {
174                 Console.WriteLine("Image has been loaded successfully.");
175             };
176             image.LoadingFailed += (s, e) =>
177             {
178                 Console.WriteLine("Image loading has been failed.");
179             };
180
181             btnFile1.Clicked += (s, e) => LoadFile("TED/large/a.jpg");
182             btnFile2.Clicked += (s, e) => LoadFile("TED/large/b.jpg");
183             btnUri1.Clicked += (s, e) => LoadUri("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
184             btnStream1.Clicked += (s, e) => LoadStream(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/c.jpg"), FileMode.Open, FileAccess.Read));
185
186             btnFileAsync1.Clicked += (s, e) => LoadFileAsync("TED/large/d.jpg");
187             btnFileAsync2.Clicked += (s, e) => LoadFileAsync("TED/large/e.jpg");
188             btnUriAsync1.Clicked += (s, e) => LoadUriAsync("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
189             btnStreamAsync1.Clicked += (s, e) => LoadStreamAsync(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/f.jpg"), FileMode.Open, FileAccess.Read));
190             box.PackEnd(buttonBox1);
191             box.PackEnd(buttonBox2);
192             box.PackEnd(lbInfo);
193             box.PackEnd(image);
194         }
195
196         void LoadFile(string file)
197         {
198             bool ret = image.Load(Path.Combine(TestRunner.ResourceDir, file));
199             if (ret)
200                 UpdateLabelText(lbInfo, image.File);
201             else
202                 UpdateLabelText(lbInfo, "Loading Failed.");
203         }
204
205         void LoadUri(string uri)
206         {
207             bool ret = image.Load(uri);
208             if (ret)
209                 UpdateLabelText(lbInfo, image.File);
210             else
211                 UpdateLabelText(lbInfo, "Loading Failed.");
212         }
213
214         void LoadStream(Stream stream)
215         {
216             bool ret = image.Load(stream);
217             if (ret)
218                 UpdateLabelText(lbInfo, image.File);
219             else
220                 UpdateLabelText(lbInfo, "Loading Failed.");
221         }
222
223         async void LoadFileAsync(string file)
224         {
225             var ret = await image.LoadAsync(Path.Combine(TestRunner.ResourceDir, file));
226             if (ret)
227                 UpdateLabelText(lbInfo, image.File);
228             else
229                 UpdateLabelText(lbInfo, "Loading Failed.");
230         }
231
232         async void LoadUriAsync(string uri)
233         {
234             var ret = await image.LoadAsync(uri);
235             if (ret)
236                 UpdateLabelText(lbInfo, image.File);
237             else
238                 UpdateLabelText(lbInfo, "Loading Failed.");
239         }
240
241         async void LoadStreamAsync(Stream stream)
242         {
243             var ret = await image.LoadAsync(stream);
244             if (ret)
245                 UpdateLabelText(lbInfo, image.File);
246             else
247                 UpdateLabelText(lbInfo, "Loading Failed.");
248         }
249
250         void UpdateLabelText(Label lable, string text)
251         {
252             lable.Text = "<span color=#ffffff font_size=20>" + text + "</span>";
253         }
254     }
255 }