summaryrefslogtreecommitdiff
path: root/ElmSharp.Test/TC/PerformanceTest.cs
blob: 1bbb5b4a97140b3700c7f434bbdf24504471ccfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using ElmSharp;

namespace ElmSharp.Test
{
    public class PerformanceTest : TestCaseBase
    {
        public override string TestName => "PerformanceTest";
        public override string TestDescription => "To test Performance of GenList";

        const int TestItemMax = 2000;
        const double TimeSet = 5.0;

        string[] arrLabel = {
            "Time Warner Cable(Cable)",
            "ComCast (Cable)",
            "Dish (Satellite)",
            "DirecTV (Satellite)",
            "Tata Sky (Satellite)",
            "Nextra Cable(Cable)",
            "DD Plus (Cable)",
            "Tikona Cable(Cable)",
            "True Provider (Cable)",
            "Vodafone (Satellite)",
            "Sample Text"
        };
        GenList list;
        Box box;
        Box box2;
        GenListItem ItemTarget = null;
        double _enteringSpeed = 0;
        int _frameCount = 0;
        int _ecoreCount = 0;
        double _frameSet = 0;
        IntPtr _anim = IntPtr.Zero;
        double FrameFPS = 0;
        double AnimatorFPS = 0;

        public override void Run(Window window)
        {
            Conformant conformant = new Conformant(window);
            conformant.Show();

            Naviframe navi = new Naviframe(window)
            {
                PreserveContentOnPop = true,
                DefaultBackButtonEnabled = true
            };

            box = new Box(window)
            {
                AlignmentX = -1,
                AlignmentY = -1,
                WeightX = 1,
                WeightY = 1,
            };
            box.Show();

            box2 = new Box(box);
            //elm_box_padding_set(box2, ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10)); ºÎºÐ ºüÁü.
            box2.Show();
            box.PackEnd(box2);

            list = new GenList(window)
            {
                Homogeneous = true,
                AlignmentX = -1,
                AlignmentY = -1,
                WeightX = 1,
                WeightY = 1,
                Style = "solid/default"
            };
            box.PackEnd(list);
            navi.Push(box, "Performance");

            InitializeListItem();

            list.Changed += List_Changed;
            list.ScrollAnimationStarted += List_ScrollAnimationStarted;
            list.ScrollAnimationStopped += List_ScrollAnimationStopped;
            list.Show();

            navi.Show();
            conformant.SetContent(navi);
        }

        private void InitializeListItem()
        {
            GenItemClass defaultClass = new GenItemClass("default")
            {
                GetTextHandler = (obj, part) =>
                {
                    return (string)obj;
                }
            };

            for (int i = 0; i < TestItemMax; ++i)
            {
                if (i == 999)
                    ItemTarget = list.Append(defaultClass, new string(arrLabel[i % 10].ToCharArray()));
                else
                    list.Append(defaultClass, new string(arrLabel[i % 10].ToCharArray()));
            }
        }

        private void List_ScrollAnimationStopped(object sender, EventArgs e)
        {
            list.RenderPost -= List_RenderPostFrame;
            list.ScrollAnimationStarted -= List_ScrollAnimationStarted;
            list.ScrollAnimationStopped -= List_ScrollAnimationStopped;

            EcoreAnimator.RemoveAnimator(_anim);
            ElmScrollConfig.BringInScrollFriction = _frameSet;

            FrameFPS = _frameCount / TimeSet;
            AnimatorFPS = _ecoreCount / TimeSet;

            Button btn1 = new Button(box2)
            {
                AlignmentX = -1,
                AlignmentY = -1,
                WeightX = 1,
                WeightY = 1,
            };
            btn1.Text = string.Format("Entering Speed : {0:f1} msec", _enteringSpeed);
            btn1.Show();
            box2.PackEnd(btn1);
            Button btn2 = new Button(box2)
            {
                AlignmentX = -1,
                AlignmentY = -1,
                WeightX = 1,
                WeightY = 1,
            };
            btn2.Text = string.Format("Animator FPS : {0:f1} fps", AnimatorFPS);
            btn2.Show();
            box2.PackEnd(btn2);
            Button btn3 = new Button(box2)
            {
                AlignmentX = -1,
                AlignmentY = -1,
                WeightX = 1,
                WeightY = 1,
            };
            btn3.Text = string.Format("Evas FPS : {0:f1} fps", FrameFPS);
            btn3.Show();
            box2.PackEnd(btn3);
            box2.SetAlignment(-1, -1);
            box2.SetWeight(1, 0.07);
        }

        private void List_RenderPost(object sender, EventArgs e)
        {
            list.RenderPost -= List_RenderPost;
            _enteringSpeed = (EcoreAnimator.GetCurrentTime() - _enteringSpeed) * 1000;

            _frameSet = ElmScrollConfig.BringInScrollFriction;
            ElmScrollConfig.BringInScrollFriction = TimeSet;
            list.ScrollTo(ItemTarget, ScrollToPosition.In, true);
        }

        private void List_ScrollAnimationStarted(object sender, EventArgs e)
        {
            _ecoreCount = 0;
            _anim = EcoreAnimator.AddAmimator(OnEcoreCheck);
            list.RenderPost += List_RenderPostFrame;
        }

        private bool OnEcoreCheck()
        {
            _ecoreCount++;
            return true;
        }

        private void List_RenderPostFrame(object sender, EventArgs e)
        {
            _frameCount++;
        }

        private void List_Changed(object sender, EventArgs e)
        {
            _enteringSpeed = EcoreAnimator.GetCurrentTime();
            list.Changed -= List_Changed;
            list.RenderPost += List_RenderPost;
        }
    }
}