mem_hdr_test.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 "Generic.h"
13#include "mem_node.h"
14#include "stmem.h"
15
16#include <iostream>
17#include <sstream>
18
19static void
21{
22 mem_hdr aHeader;
23 assert (aHeader.lowestOffset() == 0);
24 assert (aHeader.write (StoreIOBuffer()));
25 assert (aHeader.lowestOffset() == 0);
26 assert (aHeader.write (StoreIOBuffer(0, 1, (char *)nullptr)));
27 assert (aHeader.lowestOffset() == 0);
28 char * sampleData = xstrdup ("A");
29 assert (aHeader.write (StoreIOBuffer(1, 100, sampleData)));
30 safe_free (sampleData);
31 assert (aHeader.lowestOffset() == 100);
32 assert (aHeader.endOffset() == 101);
33 sampleData = xstrdup ("B");
34 assert (aHeader.write (StoreIOBuffer(1, 10, sampleData)));
35 safe_free (sampleData);
36 assert (aHeader.lowestOffset() == 10);
37 assert (aHeader.endOffset() == 101);
41}
42
43static void
45{
46 Splay<mem_node *> aSplay;
47 mem_node *temp5;
48 temp5 = new mem_node(5);
49 temp5->nodeBuffer.length = 10;
50 aSplay.insert (temp5, mem_hdr::NodeCompare);
51 assert (aSplay.start()->data == temp5);
52 assert (aSplay.finish()->data == temp5);
53
54 mem_node *temp0;
55 temp0 = new mem_node(0);
56 temp0->nodeBuffer.length = 5;
57 aSplay.insert (temp0, mem_hdr::NodeCompare);
58 assert (aSplay.start()->data == temp0);
59 assert (aSplay.finish()->data == temp5);
60
61 mem_node *temp14;
62 temp14 = new mem_node (14);
63 temp14->nodeBuffer.length = 1;
64 assert (aSplay.find(temp14,mem_hdr::NodeCompare));
65 delete temp14;
66
67 mem_node ref13 (13);
68 assert (!aSplay.find(&ref13,mem_hdr::NodeCompare));
69 ref13.nodeBuffer.length = 1;
70 assert (aSplay.find(&ref13,mem_hdr::NodeCompare));
71 aSplay.destroy();
72}
73
74static void
76{
77 mem_hdr aHeader;
78 char * sampleData = xstrdup ("A");
79 assert (aHeader.write (StoreIOBuffer(1, 100, sampleData)));
80 safe_free (sampleData);
81 sampleData = xstrdup ("B");
82 assert (aHeader.write (StoreIOBuffer(1, 102, sampleData)));
83 safe_free (sampleData);
84 std::ostringstream result;
85 PointerPrinter<mem_node *> foo(result, "\n");
86 for_each (aHeader.getNodes().end(), aHeader.getNodes().end(), foo);
87 for_each (aHeader.getNodes().begin(), aHeader.getNodes().begin(), foo);
88 for_each (aHeader.getNodes().begin(), aHeader.getNodes().end(), foo);
89 std::ostringstream expectedResult;
90 expectedResult << "[100,101)" << std::endl << "[102,103)" << std::endl;
91 assert (result.str() == expectedResult.str());
92}
93
94int
95main(int, char *[])
96{
102 testHdrVisit();
104 return EXIT_SUCCESS;
105}
106
T & for_each(L const &head, T &visitor)
Definition: Generic.h:23
#define assert(EX)
Definition: assert.h:17
Definition: Range.h:19
Value data
Definition: splay.h:25
const_iterator begin() const
Definition: splay.h:384
Value const * find(FindValue const &, int(*compare)(FindValue const &a, Value const &b)) const
const_iterator end() const
Definition: splay.h:391
SplayNode< V > const * start() const
Definition: splay.h:345
void insert(Value const &, SPLAYCMP *compare)
Definition: splay.h:318
SplayNode< V > const * finish() const
Definition: splay.h:355
void destroy(SPLAYFREE *=DefaultFree)
Definition: splay.h:365
Definition: stmem.h:20
const Splay< mem_node * > & getNodes() const
Definition: stmem.cc:374
static Splay< mem_node * >::SPLAYCMP NodeCompare
Definition: stmem.h:42
bool write(StoreIOBuffer const &)
Definition: stmem.cc:305
int64_t endOffset() const
Definition: stmem.cc:45
bool hasContigousContentRange(Range< int64_t > const &range) const
Definition: stmem.cc:247
int64_t lowestOffset() const
Definition: stmem.cc:34
StoreIOBuffer nodeBuffer
Definition: mem_node.h:35
static size_t InUseCount()
Definition: mem_node.cc:55
static void testLowAndHigh()
Definition: mem_hdr_test.cc:20
static void testSplayOfNodes()
Definition: mem_hdr_test.cc:44
int main(int, char *[])
Definition: mem_hdr_test.cc:95
static void testHdrVisit()
Definition: mem_hdr_test.cc:75
#define xstrdup
#define safe_free(x)
Definition: xalloc.h:73

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors