Merge remote-tracking branch 'trace/tizen'
[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
173             btnFile1.Clicked += (s, e) => LoadFile("TED/large/a.jpg");
174             btnFile2.Clicked += (s, e) => LoadFile("TED/large/b.jpg");
175             btnUri1.Clicked += (s, e) => LoadUri("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
176             btnStream1.Clicked += (s, e) => LoadStream(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/c.jpg"), FileMode.Open));
177
178             btnFileAsync1.Clicked += (s, e) => LoadFileAsync("TED/large/d.jpg");
179             btnFileAsync2.Clicked += (s, e) => LoadFileAsync("TED/large/e.jpg");
180             btnUriAsync1.Clicked += (s, e) => LoadUriAsync("http://pe.tedcdn.com/images/ted/2e306b9655267cee35e45688ace775590b820510_615x461.jpg");
181             btnStreamAsync1.Clicked += (s, e) => LoadStreamAsync(new FileStream(Path.Combine(TestRunner.ResourceDir, "TED/large/f.jpg"), FileMode.Open));
182             box.PackEnd(buttonBox1);
183             box.PackEnd(buttonBox2);
184             box.PackEnd(lbInfo);
185             box.PackEnd(image);
186         }
187
188         void LoadFile(string file)
189         {
190             bool ret = image.Load(Path.Combine(TestRunner.ResourceDir, file));
191             if (ret)
192                 UpdateLabelText(lbInfo, image.File);
193             else
194                 UpdateLabelText(lbInfo, "Loading Failed.");
195         }
196
197         void LoadUri(string uri)
198         {
199             bool ret = image.Load(uri);
200             if (ret)
201                 UpdateLabelText(lbInfo, image.File);
202             else
203                 UpdateLabelText(lbInfo, "Loading Failed.");
204         }
205
206         void LoadStream(Stream stream)
207         {
208             bool ret = image.Load(stream);
209             if (ret)
210                 UpdateLabelText(lbInfo, image.File);
211             else
212                 UpdateLabelText(lbInfo, "Loading Failed.");
213         }
214
215         async void LoadFileAsync(string file)
216         {
217             var ret = await image.LoadAsync(Path.Combine(TestRunner.ResourceDir, file));
218             if (ret)
219                 UpdateLabelText(lbInfo, image.File);
220             else
221                 UpdateLabelText(lbInfo, "Loading Failed.");
222         }
223
224         async void LoadUriAsync(string uri)
225         {
226             var ret = await image.LoadAsync(uri);
227             if (ret)
228                 UpdateLabelText(lbInfo, image.File);
229             else
230                 UpdateLabelText(lbInfo, "Loading Failed.");
231         }
232
233         async void LoadStreamAsync(Stream stream)
234         {
235             var ret = await image.LoadAsync(stream);
236             if (ret)
237                 UpdateLabelText(lbInfo, image.File);
238             else
239                 UpdateLabelText(lbInfo, "Loading Failed.");
240         }
241
242         void UpdateLabelText(Label lable, string text)
243         {
244             lable.Text = "<span color=#ffffff font_size=20>" + text + "</span>";
245         }
246     }
247 }