sync ElmSharp source code latest
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / GenListTest11.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 ElmSharp;
19 using System.Collections.Generic;
20
21 namespace ElmSharp.Test
22 {
23     class GenListTest11 : TestCaseBase
24     {
25         public override string TestName => "GenListTest11";
26         public override string TestDescription => "To test InsertSorted operation of GenList";
27
28         public int myCompare(object t1, object t2)
29         {
30             int c1 = Convert.ToInt32((string)t1);
31             int c2 = Convert.ToInt32((string)t2);
32
33             return c1 - c2;
34         }
35
36         public override void Run(Window window)
37         {
38             Conformant conformant = new Conformant(window);
39             conformant.Show();
40             Box box = new Box(window)
41             {
42                 AlignmentX = -1,
43                 AlignmentY = -1,
44                 WeightX = 1,
45                 WeightY = 1,
46             };
47             box.Show();
48             conformant.SetContent(box);
49
50             GenList list = new GenList(window)
51             {
52                 Homogeneous = true,
53                 AlignmentX = -1,
54                 AlignmentY = -1,
55                 WeightX = 1,
56                 WeightY = 1
57             };
58
59             GenItemClass defaultClass = new GenItemClass("default")
60             {
61                 GetTextHandler = (obj, part) =>
62                 {
63                     return string.Format("{0} - {1}", (string)obj, part);
64                 }
65             };
66
67             List<GenListItem> items = new List<GenListItem>();
68             int idx = 20;
69             for (int t = 1; t < 10; t++)
70             {
71                 items.Add(list.InsertSorted(defaultClass, idx.ToString(), myCompare, GenListItemType.Normal, null));
72                 idx--;
73             }
74             list.Show();
75             list.ItemSelected += List_ItemSelected;
76
77             box.PackEnd(list);
78             Button first = new Button(window)
79             {
80                 Text = "Check first and last item",
81                 AlignmentX = -1,
82                 WeightX = 1,
83             };
84
85             Button Add = new Button(window)
86             {
87                 Text = "Add",
88                 AlignmentX = -1,
89                 WeightX = 1,
90             };
91             Add.Clicked += (s, e) =>
92             {
93                 items.Add(list.InsertSorted(defaultClass, idx.ToString(), myCompare, GenListItemType.Normal, null));
94                 idx--;
95             };
96
97             first.Clicked += (s, e) =>
98             {
99                 Console.WriteLine("Last Item's Data : " + list.LastItem.Data);
100                 Console.WriteLine("First date of Items " + items[0].Data);
101                 Console.WriteLine("Result for comparinson " + (bool)(list.LastItem == list.LastItem));
102             };
103
104             first.Show();
105             Add.Show();
106             box.PackEnd(first);
107             box.PackEnd(Add);
108         }
109
110         private void List_ItemSelected(object sender, GenListItemEventArgs e)
111         {
112             Console.WriteLine("{0} Item was selected", (string)(e.Item.Data));
113         }
114     }
115 }