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;
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));
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);
188 void LoadFile(string file)
190 bool ret = image.Load(Path.Combine(TestRunner.ResourceDir, file));
192 UpdateLabelText(lbInfo, image.File);
194 UpdateLabelText(lbInfo, "Loading Failed.");
197 void LoadUri(string uri)
199 bool ret = image.Load(uri);
201 UpdateLabelText(lbInfo, image.File);
203 UpdateLabelText(lbInfo, "Loading Failed.");
206 void LoadStream(Stream stream)
208 bool ret = image.Load(stream);
210 UpdateLabelText(lbInfo, image.File);
212 UpdateLabelText(lbInfo, "Loading Failed.");
215 async void LoadFileAsync(string file)
217 var ret = await image.LoadAsync(Path.Combine(TestRunner.ResourceDir, file));
219 UpdateLabelText(lbInfo, image.File);
221 UpdateLabelText(lbInfo, "Loading Failed.");
224 async void LoadUriAsync(string uri)
226 var ret = await image.LoadAsync(uri);
228 UpdateLabelText(lbInfo, image.File);
230 UpdateLabelText(lbInfo, "Loading Failed.");
233 async void LoadStreamAsync(Stream stream)
235 var ret = await image.LoadAsync(stream);
237 UpdateLabelText(lbInfo, image.File);
239 UpdateLabelText(lbInfo, "Loading Failed.");
242 void UpdateLabelText(Label lable, string text)
244 lable.Text = "<span color=#ffffff font_size=20>" + text + "</span>";