mem_hdr_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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 
19 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 *)NULL)));
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 
43 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 
74 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 
94 int
95 main(int, char *[])
96 {
101  assert (mem_node::InUseCount() == 0);
102  testHdrVisit();
103  assert (mem_node::InUseCount() == 0);
104  return EXIT_SUCCESS;
105 }
106 
void insert(Value const &, SPLAYCMP *compare)
Definition: splay.h:300
SplayNode< V > const * start() const
Definition: splay.h:327
int64_t endOffset() const
Definition: stmem.cc:46
#define assert(EX)
Definition: assert.h:17
const_iterator end() const
Definition: splay.h:373
int main(int, char *[])
Definition: unitTestMain.h:25
void testLowAndHigh()
Definition: mem_hdr_test.cc:20
#define xstrdup
#define safe_free(x)
Definition: xalloc.h:73
Definition: Range.h:18
Value const * find(FindValue const &, int(*compare)(FindValue const &a, Value const &b)) const
Definition: stmem.h:19
T & for_each(L const &head, T &visitor)
Definition: Generic.h:23
int64_t lowestOffset() const
Definition: stmem.cc:35
SplayNode< V > const * finish() const
Definition: splay.h:337
bool write(StoreIOBuffer const &)
Definition: stmem.cc:342
static size_t InUseCount()
Definition: mem_node.cc:55
const_iterator begin() const
Definition: splay.h:366
StoreIOBuffer nodeBuffer
Definition: mem_node.h:35
Value data
Definition: splay.h:27
void testHdrVisit()
Definition: mem_hdr_test.cc:75
static Splay< mem_node * >::SPLAYCMP NodeCompare
Definition: stmem.h:47
const Splay< mem_node * > & getNodes() const
Definition: stmem.cc:425
void destroy(SPLAYFREE *=SplayNode< V >::DefaultFree)
Definition: splay.h:347
bool hasContigousContentRange(Range< int64_t > const &range) const
Definition: stmem.cc:284
void testSplayOfNodes()
Definition: mem_hdr_test.cc:44
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors