Line data Source code
1 : #include "catch.hpp"
2 : #include "DisplayList.h"
3 : #include "QuadTreeNode.h"
4 :
5 8 : SCENARIO( "DisplayList", "[DisplayList]" ) {
6 9 : GIVEN( "An empty display list" ) {
7 2 : DisplayList list;
8 :
9 3 : THEN( "head and tail are null" ) {
10 1 : REQUIRE(list.head == NULL);
11 1 : REQUIRE(list.tail == NULL);
12 1 : }
13 :
14 : // traverseList is a debug-only utility (PRINT_DEBUG_LVL(4,...)) that has
15 : // been vestigial since the initial commit — its body was a commented-out
16 : // cout statement in 2008. It is a compile-time no-op when DEBUG=0.
17 3 : WHEN( "traverseList on empty list" ) {
18 2 : THEN( "it does not crash" ) {
19 1 : list.traverseList();
20 1 : }
21 1 : }
22 2 : }
23 :
24 8 : GIVEN( "One node inserted" ) {
25 1 : DisplayList list;
26 1 : QuadTreeNode a;
27 :
28 1 : list.insertLast(&a);
29 :
30 2 : THEN( "head and tail both point to the single node" ) {
31 1 : REQUIRE(list.head == &a);
32 1 : REQUIRE(list.tail == &a);
33 1 : REQUIRE(list.head->next == NULL);
34 1 : }
35 1 : }
36 :
37 11 : GIVEN( "Two nodes inserted last" ) {
38 4 : DisplayList list;
39 4 : QuadTreeNode a, b;
40 :
41 4 : list.insertLast(&a);
42 4 : list.insertLast(&b);
43 :
44 5 : THEN( "head is first insert, tail is second" ) {
45 1 : REQUIRE(list.head == &a);
46 1 : REQUIRE(list.tail == &b);
47 1 : REQUIRE(list.head->next == &b);
48 1 : REQUIRE(list.tail->next == NULL);
49 1 : }
50 :
51 5 : WHEN( "traverseList is called with nodes" ) {
52 2 : THEN( "it does not crash" ) {
53 1 : list.traverseList();
54 1 : }
55 1 : }
56 :
57 : // clearList nulls head and tail but does not free nodes — ownership
58 : // stays with the QuadTree. The nodes remain valid in memory after clearing.
59 6 : WHEN( "clearList is called" ) {
60 2 : list.clearList();
61 3 : THEN( "list is empty" ) {
62 1 : REQUIRE(list.head == NULL);
63 1 : REQUIRE(list.tail == NULL);
64 1 : }
65 :
66 : // Mirrors the GameLevel frame cycle: clearList at the start of each
67 : // frame, then buildDisplayList re-populates via insertLast.
68 3 : AND_WHEN( "nodes are inserted after clearing" ) {
69 1 : QuadTreeNode c, d;
70 1 : list.insertLast(&c);
71 1 : list.insertLast(&d);
72 2 : THEN( "list is correctly rebuilt" ) {
73 1 : REQUIRE(list.head == &c);
74 1 : REQUIRE(list.tail == &d);
75 1 : REQUIRE(list.head->next == &d);
76 1 : REQUIRE(list.tail->next == NULL);
77 1 : }
78 1 : }
79 2 : }
80 4 : }
81 7 : }
|