]> git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/mem_node_test.cc
SourceFormat Enforcement
[thirdparty/squid.git] / test-suite / mem_node_test.cc
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 19 Store Memory Primitives */
10
11 #include "squid.h"
12 #include "mem_node.h"
13
14 #include <iostream>
15
16 #if 0
17 /* TODO: put this in a libTest */
18 void
19 xassert(const char *msg, const char *file, int line)
20 {
21 std::cout << "Assertion failed: (" << msg << ") at " << file << ":" << line << std::endl;
22 exit (1);
23 }
24 #endif
25
26 int
27 main(int argc, char **argv)
28 {
29 mem_node *aNode = new mem_node(0);
30 assert (aNode);
31 /* This will fail if MemPools are disabled. A knock on effect is that
32 * the store will never trim memory
33 */
34 assert (mem_node::InUseCount() == 1);
35 assert (SM_PAGE_SIZE > 50);
36 aNode->nodeBuffer.length = 45;
37 assert (aNode->start() == 0);
38 assert (aNode->end() == 45);
39 assert (aNode->dataRange().size() == 45);
40 aNode->nodeBuffer.offset = 50;
41 assert (aNode->start() == 50);
42 assert (aNode->end() == 95);
43 assert (aNode->dataRange().size() == 45);
44 assert (!aNode->contains(49));
45 assert (aNode->contains(50));
46 assert (aNode->contains(75));
47 assert (!aNode->contains(95));
48 assert (aNode->contains(94));
49 assert (!aNode->canAccept(50));
50 assert (aNode->canAccept(95));
51 assert (!aNode->canAccept(94));
52 aNode->nodeBuffer.length = SM_PAGE_SIZE - 1;
53 assert (aNode->canAccept (50 + SM_PAGE_SIZE - 1));
54 assert (!aNode->canAccept (50 + SM_PAGE_SIZE));
55 assert (mem_node (0) < mem_node (2));
56 assert (!(mem_node (0) < mem_node (0)));
57 assert (!(mem_node (2) < mem_node (0)));
58 delete aNode;
59 assert (mem_node::InUseCount() == 0);
60 return 0;
61 }
62