]> git.ipfire.org Git - thirdparty/squid.git/blame - test-suite/test_tools.cc
Removed squid-old.h
[thirdparty/squid.git] / test-suite / test_tools.cc
CommitLineData
4c50505b 1/*
262a0e14 2 * $Id$
4c50505b 3 */
4
25f98340 5// XXX: This file is made of large pieces of src/tools.cc
0d9a5f13 6// with only a few minor modifications. TODO: redesign or delete.
7
582c2af2
FC
8#include "squid.h"
9#include "dlink.h"
4c50505b 10
11void
12xassert(const char *msg, const char *file, int line)
13{
14 std::cout << "Assertion failed: (" << msg << ") at " << file << ":" << line << std::endl;
15 exit (1);
16}
4c50505b 17
f5691f9c 18dlink_node *
af6a12ee
AJ
19dlinkNodeNew()
20{
25f98340 21 return new dlink_node;
f5691f9c 22}
23
24/* the node needs to be unlinked FIRST */
25void
af6a12ee
AJ
26dlinkNodeDelete(dlink_node * m)
27{
f5691f9c 28 if (m == NULL)
29 return;
30
25f98340 31 delete m;
f5691f9c 32}
33
34void
af6a12ee
AJ
35dlinkAdd(void *data, dlink_node * m, dlink_list * list)
36{
f5691f9c 37 m->data = data;
38 m->prev = NULL;
39 m->next = list->head;
40
41 if (list->head)
42 list->head->prev = m;
43
44 list->head = m;
45
46 if (list->tail == NULL)
47 list->tail = m;
48}
49
50void
af6a12ee
AJ
51dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list)
52{
f5691f9c 53 m->data = data;
54 m->prev = n;
55 m->next = n->next;
56
57 if (n->next)
58 n->next->prev = m;
59 else {
60 assert(list->tail == n);
61 list->tail = m;
62 }
63
64 n->next = m;
65}
66
67void
af6a12ee
AJ
68dlinkAddTail(void *data, dlink_node * m, dlink_list * list)
69{
f5691f9c 70 m->data = data;
71 m->next = NULL;
72 m->prev = list->tail;
73
74 if (list->tail)
75 list->tail->next = m;
76
77 list->tail = m;
78
79 if (list->head == NULL)
80 list->head = m;
81}
82
83void
af6a12ee
AJ
84dlinkDelete(dlink_node * m, dlink_list * list)
85{
f5691f9c 86 if (m->next)
87 m->next->prev = m->prev;
88
89 if (m->prev)
90 m->prev->next = m->next;
91
92 if (m == list->head)
93 list->head = m->next;
94
95 if (m == list->tail)
96 list->tail = m->prev;
97
98 m->next = m->prev = NULL;
99}