3 using Tizen.NUI.BaseComponents;
4 using System.Collections.Generic;
6 namespace Tizen.NUI.Samples
8 using tlog = Tizen.Log;
9 public class DisposeWithoutEventUnsubscribedTestAndAnimationDisposeTest : IExample
11 private const string tag = "NUITEST";
12 private const int NUMBER_OF_VIEW = 1000;
13 private const int INTERVAL_MS = 1000;
14 private const int MIN_POSITION = 100;
15 private const int MAX_POSITION = 900;
16 private const bool TURN_ON_GC = true;
19 private View rootView;
21 private List<View> list = new List<View>();
22 private Random rand = new Random();
23 private bool toggle, toggleRemoveMany;
27 public void Activate()
29 DisposeWithoutUnsubscribedEventTest();
30 AnimationDisposeTest();
32 public void Deactivate()
41 private void AnimationDisposeTest()
43 var ani = new Animation(1000);
44 ani.AnimateTo(rootView, "size", new Size(500, 500, 0));
49 tlog.Fatal(tag, "this should not be shown! test NG!");
53 if (e is ObjectDisposedException)
55 tlog.Fatal(tag, "Animation is used after disposed! test OK!");
59 tlog.Fatal(tag, $"unwanted exception came! test NG! exception:{e} msg:{e.Message}");
66 tlog.Fatal(tag, "this should not be shown! test NG!");
70 if (e is ObjectDisposedException)
72 tlog.Fatal(tag, "Animation is used after disposed! test OK!");
76 tlog.Fatal(tag, $"unwanted exception came! test NG! exception:{e} msg:{e.Message}");
81 private void DisposeWithoutUnsubscribedEventTest()
83 win = NUIApplication.GetDefaultWindow();
85 res = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
89 Size = new Size(100, 100),
90 BackgroundColor = Color.Blue,
92 rootView.Relayout += View_Relayout;
95 timer = new Timer(INTERVAL_MS);
96 timer.Tick += Timer_Tick;
100 private void AddManyObject()
102 tlog.Fatal(tag, $"AddManyObject()");
104 for (int i = 0; i < NUMBER_OF_VIEW; i++)
106 var child = new ImageView()
108 ResourceUrl = res + "images/Dali/DaliDemo/application-icon-1.png",
109 Size = new Size(60, 60),
110 Position = new Position(rand.Next(MIN_POSITION, MAX_POSITION), rand.Next(MIN_POSITION, MAX_POSITION)),
111 BackgroundColor = new Color((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble(), 1),
115 child.Relayout += Child_Relayout;
116 child.RemovedFromWindow += Child_RemovedFromWindow;
117 child.AddedToWindow += Child_AddedToWindow;
118 child.WheelEvent += Child_WheelEvent;
119 child.HoverEvent += Child_HoverEvent;
120 child.InterceptTouchEvent += Child_InterceptTouchEvent;
121 child.TouchEvent += Child_TouchEvent;
122 child.ResourcesLoaded += Child_ResourcesLoaded;
123 child.KeyEvent += Child_KeyEvent;
124 child.FocusLost += Child_FocusLost;
125 child.FocusGained += Child_FocusGained;
129 private void Child_FocusGained(object sender, EventArgs e)
131 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
133 tlog.Fatal(tag, $"Child_FocusGained() called!");
137 private void Child_FocusLost(object sender, EventArgs e)
139 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
141 tlog.Fatal(tag, $"Child_FocusLost() called!");
145 private bool Child_KeyEvent(object source, View.KeyEventArgs e)
147 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
149 tlog.Fatal(tag, $"Child_KeyEvent() called!");
154 private void Child_ResourcesLoaded(object sender, EventArgs e)
156 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
158 tlog.Fatal(tag, $"Child_ResourcesLoaded() called!");
162 private bool Child_TouchEvent(object source, View.TouchEventArgs e)
164 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
166 tlog.Fatal(tag, $"Child_TouchEvent() called!");
171 private bool Child_InterceptTouchEvent(object source, View.TouchEventArgs e)
173 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
175 tlog.Fatal(tag, $"Child_InterceptTouchEvent() called!");
180 private bool Child_HoverEvent(object source, View.HoverEventArgs e)
182 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
184 tlog.Fatal(tag, $"Child_HoverEvent() called!");
189 private bool Child_WheelEvent(object source, View.WheelEventArgs e)
191 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
193 tlog.Fatal(tag, $"Child_WheelEvent() called!");
198 private void Child_AddedToWindow(object sender, EventArgs e)
200 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
202 tlog.Fatal(tag, $"Child_AddedToWindow() called!");
206 private void Child_RemovedFromWindow(object sender, EventArgs e)
208 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
210 tlog.Fatal(tag, $"Child_RemovedFromWindow() called!");
214 private void Child_Relayout(object sender, EventArgs e)
216 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
218 tlog.Fatal(tag, $"Child_Relayout() called!");
222 private void View_Relayout(object sender, EventArgs e)
224 if (++cnt % (NUMBER_OF_VIEW * 3) == 1)
226 tlog.Fatal(tag, $"View_Relayout() called! cnt:{cnt}");
230 private void RemoveManyObject()
232 int childCnt = (int)rootView.ChildCount;
233 tlog.Fatal(tag, $"RemoveManyObject() child count:{childCnt}");
235 for (int i = childCnt - 1; i >= 0; i--)
237 var child = rootView.GetChildAt((uint)i);
238 rootView.Remove(child);
241 private void DisposeManyObject()
243 int childCnt = (int)rootView.ChildCount;
244 tlog.Fatal(tag, $"DisposeManyObject() child count:{childCnt}");
246 for (int i = childCnt - 1; i >= 0; i--)
248 var child = rootView.GetChildAt((uint)i);
249 rootView.Remove(child);
250 child.Size += new Size(100, 100);
251 child.Size -= new Size(100, 100);
252 child.Size += new Size(100, 100);
253 child.Size -= new Size(100, 100);
258 private bool Timer_Tick(object source, Timer.TickEventArgs e)
267 toggleRemoveMany = !toggleRemoveMany;
268 if (toggleRemoveMany)
285 private void FullGC()
287 global::System.GC.Collect();
288 global::System.GC.WaitForPendingFinalizers();
289 global::System.GC.Collect();