2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using System.Collections.Generic;
22 namespace ElmSharp.Test
24 public class ImageTest1 : TestCaseBase
26 public override string TestName => "ImageTest1";
27 public override string TestDescription => "To test basic operation of Image";
32 public override void Run(Window window)
34 Conformant conformant = new Conformant(window);
36 Box box = new Box(window);
37 conformant.SetContent(box);
40 Box buttonBox1 = new Box(window)
48 Box buttonBox2 = new Box(window)
56 Button btnFile1 = new Button(window)
66 Button btnFile2 = new Button(window)
76 Button btnUri1 = new Button(window)
86 Button btnStream1 = new Button(window)
96 buttonBox1.PackEnd(btnFile1);
97 buttonBox1.PackEnd(btnFile2);
98 buttonBox1.PackEnd(btnUri1);
99 buttonBox1.PackEnd(btnStream1);
102 Button btnFileAsync1 = new Button(window)
110 btnFileAsync1.Show();
112 Button btnFileAsync2 = new Button(window)
120 btnFileAsync2.Show();
122 Button btnUriAsync1 = new Button(window)
132 Button btnStreamAsync1 = new Button(window)
140 btnStreamAsync1.Show();
142 buttonBox2.PackEnd(btnFileAsync1);
143 buttonBox2.PackEnd(btnFileAsync2);
144 buttonBox2.PackEnd(btnUriAsync1);
145 buttonBox2.PackEnd(btnStreamAsync1);
148 lbInfo = new Label(window)
157 image = new Image(window)
159 IsFixedAspect = true,
166 image.Load(Path.Combine(TestRunner.ResourceDir, "picture.png"));
167 image.Clicked += (s, e) =>
169 Console.WriteLine("Image has been clicked. (IsFixedAspect = {0}", image.IsFixedAspect);
170 image.IsFixedAspect = image.IsFixedAspect == true ? false : true;
172 image.LoadingCompleted += (s, e) =>
174 Console.WriteLine("Image has been loaded successfully.");
176 image.LoadingFailed += (s, e) =>
178 Console.WriteLine("Image loading has been failed.");
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));
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);
196 void LoadFile(string file)
198 bool ret = image.Load(Path.Combine(TestRunner.ResourceDir, file));
200 UpdateLabelText(lbInfo, image.File);
202 UpdateLabelText(lbInfo, "Loading Failed.");
205 void LoadUri(string uri)
207 bool ret = image.Load(uri);
209 UpdateLabelText(lbInfo, image.File);
211 UpdateLabelText(lbInfo, "Loading Failed.");
214 void LoadStream(Stream stream)
216 bool ret = image.Load(stream);
218 UpdateLabelText(lbInfo, image.File);
220 UpdateLabelText(lbInfo, "Loading Failed.");
223 async void LoadFileAsync(string file)
225 var ret = await image.LoadAsync(Path.Combine(TestRunner.ResourceDir, file));
227 UpdateLabelText(lbInfo, image.File);
229 UpdateLabelText(lbInfo, "Loading Failed.");
232 async void LoadUriAsync(string uri)
234 var ret = await image.LoadAsync(uri);
236 UpdateLabelText(lbInfo, image.File);
238 UpdateLabelText(lbInfo, "Loading Failed.");
241 async void LoadStreamAsync(Stream stream)
243 var ret = await image.LoadAsync(stream);
245 UpdateLabelText(lbInfo, image.File);
247 UpdateLabelText(lbInfo, "Loading Failed.");
250 void UpdateLabelText(Label lable, string text)
252 lable.Text = "<span color=#ffffff font_size=20>" + text + "</span>";