3 * $Id: mem_hdr_test.cc,v 1.5 2003/09/22 08:50:51 robertc Exp $
5 * DEBUG: section 19 Store Memory Primitives
6 * AUTHOR: Robert Collins
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
47 assert (aHeader
.lowestOffset() == 0);
48 assert (aHeader
.write (StoreIOBuffer()));
49 assert (aHeader
.lowestOffset() == 0);
50 assert (aHeader
.write (StoreIOBuffer(0, 1, NULL
)));
51 assert (aHeader
.lowestOffset() == 0);
52 char * sampleData
= xstrdup ("A");
53 assert (aHeader
.write (StoreIOBuffer(1, 100, sampleData
)));
54 safe_free (sampleData
);
55 assert (aHeader
.lowestOffset() == 100);
56 assert (aHeader
.endOffset() == 101);
57 sampleData
= xstrdup ("B");
58 assert (aHeader
.write (StoreIOBuffer(1, 10, sampleData
)));
59 safe_free (sampleData
);
60 assert (aHeader
.lowestOffset() == 10);
61 assert (aHeader
.endOffset() == 101);
62 assert (aHeader
.hasContigousContentRange(Range
<size_t>(10,11)));
63 assert (!aHeader
.hasContigousContentRange(Range
<size_t>(10,12)));
64 assert (!aHeader
.hasContigousContentRange(Range
<size_t>(10,101)));
70 Splay
<mem_node
*> aSplay
;
72 temp5
= new mem_node(5);
73 temp5
->nodeBuffer
.length
= 10;
74 aSplay
.insert (temp5
, mem_hdr::NodeCompare
);
75 assert (aSplay
.start()->data
== temp5
);
76 assert (aSplay
.finish()->data
== temp5
);
79 temp0
= new mem_node(0);
80 temp0
->nodeBuffer
.length
= 5;
81 aSplay
.insert (temp0
, mem_hdr::NodeCompare
);
82 assert (aSplay
.start()->data
== temp0
);
83 assert (aSplay
.finish()->data
== temp5
);
86 temp14
= new mem_node (14);
87 temp14
->nodeBuffer
.length
= 1;
88 assert (aSplay
.find(temp14
,mem_hdr::NodeCompare
));
92 assert (!aSplay
.find(&ref13
,mem_hdr::NodeCompare
));
93 ref13
.nodeBuffer
.length
= 1;
94 assert (aSplay
.find(&ref13
,mem_hdr::NodeCompare
));
95 aSplay
.destroy(SplayNode
<mem_node
*>::DefaultFree
);
102 char * sampleData
= xstrdup ("A");
103 assert (aHeader
.write (StoreIOBuffer(1, 100, sampleData
)));
104 safe_free (sampleData
);
105 sampleData
= xstrdup ("B");
106 assert (aHeader
.write (StoreIOBuffer(1, 102, sampleData
)));
107 safe_free (sampleData
);
108 std::ostringstream result
;
109 PointerPrinter
<mem_node
*> foo(result
, "\n");
110 for_each (aHeader
.getNodes().end(), aHeader
.getNodes().end(), foo
);
111 for_each (aHeader
.getNodes().begin(), aHeader
.getNodes().begin(), foo
);
112 for_each (aHeader
.getNodes().begin(), aHeader
.getNodes().end(), foo
);
113 std::ostringstream expectedResult
;
114 expectedResult
<< "[100,101)" << std::endl
<< "[102,103)" << std::endl
;
115 assert (result
.str() == expectedResult
.str());
119 main (int argc
, char *argv
)
121 assert (mem_node::InUseCount() == 0);
123 assert (mem_node::InUseCount() == 0);
125 assert (mem_node::InUseCount() == 0);
127 assert (mem_node::InUseCount() == 0);