Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
eventhandler_test.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "bin/eventhandler.h"
6#include "platform/assert.h"
7#include "vm/unit_test.h"
8
9namespace dart {
10namespace bin {
11
14
15 EXPECT(!list.HasHead());
16
17 list.Add(1);
18 EXPECT(list.HasHead());
19 EXPECT(list.head() == 1);
20
21 // Test: Inserts don't move head.
22 for (int i = 2; i <= 100; i++) {
23 list.Add(i);
24 EXPECT(list.head() == 1);
25 }
26
27 // Test: Rotate cycle through all elements in insertion order.
28 for (int i = 1; i <= 100; i++) {
29 EXPECT(list.HasHead());
30 EXPECT(list.head() == i);
31 list.Rotate();
32 }
33
34 // Test: Removing head results in next element to be head.
35 for (int i = 1; i <= 100; i++) {
36 list.RemoveHead();
37 for (int j = i + 1; j <= 100; j++) {
38 EXPECT(list.HasHead());
39 EXPECT(list.head() == j);
40 list.Rotate();
41 }
42 }
43
44 // Test: Removing all items individually make list empty.
45 EXPECT(!list.HasHead());
46
47 // Test: Removing all items at once makes list empty.
48 for (int i = 1; i <= 100; i++) {
49 list.Add(i);
50 }
51 list.RemoveAll();
52 EXPECT(!list.HasHead());
53
54 // Test: Remove individual items just deletes them without modifying head.
55 for (int i = 1; i <= 10; i++) {
56 list.Add(i);
57 }
58 for (int i = 2; i <= 9; i++) {
59 list.Remove(i);
60 }
61 EXPECT(list.head() == 1);
62 list.Rotate();
63 EXPECT(list.head() == 10);
64 list.Rotate();
65 EXPECT(list.head() == 1);
66
67 // Test: Remove nonexistent element leaves list un-changed.
68 list.Remove(4242);
69 EXPECT(list.head() == 1);
70
71 // Test: Remove head element individually moves head to next element.
72 list.Remove(1);
73 EXPECT(list.HasHead());
74 EXPECT(list.head() == 10);
75 list.Remove(10);
76 EXPECT(!list.HasHead());
77
78 // Test: Remove nonexistent element from empty list works.
79 list.Remove(4242);
80}
81
82} // namespace bin
83} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
void RemoveAll(ClearFun clear=nullptr)
void RemoveHead(ClearFun clear=nullptr)
#define VM_UNIT_TEST_CASE(name)
Definition unit_test.h:33