Merge "[Telephony] Sample App implementation."
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / PerformanceTest.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
20 namespace ElmSharp.Test
21 {
22     public class PerformanceTest : TestCaseBase
23     {
24         public override string TestName => "PerformanceTest";
25         public override string TestDescription => "To test Performance of GenList";
26
27         const int TestItemMax = 2000;
28         const double TimeSet = 5.0;
29
30         string[] arrLabel = {
31             "Time Warner Cable(Cable)",
32             "ComCast (Cable)",
33             "Dish (Satellite)",
34             "DirecTV (Satellite)",
35             "Tata Sky (Satellite)",
36             "Nextra Cable(Cable)",
37             "DD Plus (Cable)",
38             "Tikona Cable(Cable)",
39             "True Provider (Cable)",
40             "Vodafone (Satellite)",
41             "Sample Text"
42         };
43
44         GenList list;
45         Box box;
46         Box box2;
47         GenListItem ItemTarget = null;
48         double _enteringSpeed = 0;
49         int _frameCount = 0;
50         int _ecoreCount = 0;
51         double _frameSet = 0;
52         IntPtr _anim = IntPtr.Zero;
53         double FrameFPS = 0;
54         double AnimatorFPS = 0;
55
56         public override void Run(Window window)
57         {
58             Conformant conformant = new Conformant(window);
59             conformant.Show();
60
61             Naviframe navi = new Naviframe(window)
62             {
63                 PreserveContentOnPop = true,
64                 DefaultBackButtonEnabled = true
65             };
66
67             box = new Box(window)
68             {
69                 AlignmentX = -1,
70                 AlignmentY = -1,
71                 WeightX = 1,
72                 WeightY = 1,
73             };
74             box.Show();
75
76             box2 = new Box(box);
77             //elm_box_padding_set(box2, ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10)); ºÎºÐ ºüÁü.
78             box2.Show();
79             box.PackEnd(box2);
80
81             list = new GenList(window)
82             {
83                 Homogeneous = true,
84                 AlignmentX = -1,
85                 AlignmentY = -1,
86                 WeightX = 1,
87                 WeightY = 1,
88                 Style = "solid/default"
89             };
90             box.PackEnd(list);
91             navi.Push(box, "Performance");
92
93             InitializeListItem();
94
95             list.Changed += List_Changed;
96             list.ScrollAnimationStarted += List_ScrollAnimationStarted;
97             list.ScrollAnimationStopped += List_ScrollAnimationStopped;
98             list.Show();
99
100             navi.Show();
101             conformant.SetContent(navi);
102         }
103
104         private void InitializeListItem()
105         {
106             GenItemClass defaultClass = new GenItemClass("default")
107             {
108                 GetTextHandler = (obj, part) =>
109                 {
110                     return (string)obj;
111                 }
112             };
113
114             for (int i = 0; i < TestItemMax; ++i)
115             {
116                 if (i == 999)
117                     ItemTarget = list.Append(defaultClass, new string(arrLabel[i % 10].ToCharArray()));
118                 else
119                     list.Append(defaultClass, new string(arrLabel[i % 10].ToCharArray()));
120             }
121         }
122
123         private void List_ScrollAnimationStopped(object sender, EventArgs e)
124         {
125             list.RenderPost -= List_RenderPostFrame;
126             list.ScrollAnimationStarted -= List_ScrollAnimationStarted;
127             list.ScrollAnimationStopped -= List_ScrollAnimationStopped;
128
129             EcoreAnimator.RemoveAnimator(_anim);
130             Elementary.BringInScrollFriction = _frameSet;
131
132             FrameFPS = _frameCount / TimeSet;
133             AnimatorFPS = _ecoreCount / TimeSet;
134
135             Button btn1 = new Button(box2)
136             {
137                 AlignmentX = -1,
138                 AlignmentY = -1,
139                 WeightX = 1,
140                 WeightY = 1,
141             };
142             btn1.Text = string.Format("Entering Speed : {0:f1} msec", _enteringSpeed);
143             btn1.Show();
144             box2.PackEnd(btn1);
145             Button btn2 = new Button(box2)
146             {
147                 AlignmentX = -1,
148                 AlignmentY = -1,
149                 WeightX = 1,
150                 WeightY = 1,
151             };
152             btn2.Text = string.Format("Animator FPS : {0:f1} fps", AnimatorFPS);
153             btn2.Show();
154             box2.PackEnd(btn2);
155             Button btn3 = new Button(box2)
156             {
157                 AlignmentX = -1,
158                 AlignmentY = -1,
159                 WeightX = 1,
160                 WeightY = 1,
161             };
162             btn3.Text = string.Format("Evas FPS : {0:f1} fps", FrameFPS);
163             btn3.Show();
164             box2.PackEnd(btn3);
165             box2.SetAlignment(-1, -1);
166             box2.SetWeight(1, 0.07);
167         }
168
169         private void List_RenderPost(object sender, EventArgs e)
170         {
171             list.RenderPost -= List_RenderPost;
172             _enteringSpeed = (EcoreAnimator.GetCurrentTime() - _enteringSpeed) * 1000;
173
174             _frameSet = Elementary.BringInScrollFriction;
175             Elementary.BringInScrollFriction = TimeSet;
176             list.ScrollTo(ItemTarget, ScrollToPosition.In, true);
177         }
178
179         private void List_ScrollAnimationStarted(object sender, EventArgs e)
180         {
181             _ecoreCount = 0;
182             _anim = EcoreAnimator.AddAnimator(OnEcoreCheck);
183             list.RenderPost += List_RenderPostFrame;
184         }
185
186         private bool OnEcoreCheck()
187         {
188             _ecoreCount++;
189             return true;
190         }
191
192         private void List_RenderPostFrame(object sender, EventArgs e)
193         {
194             _frameCount++;
195         }
196
197         private void List_Changed(object sender, EventArgs e)
198         {
199             _enteringSpeed = EcoreAnimator.GetCurrentTime();
200             list.Changed -= List_Changed;
201             list.RenderPost += List_RenderPost;
202         }
203     }
204 }