[Assorted-commits] SF.net SVN: assorted:[1370] cpp-commons/trunk/src/test
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-05-07 01:28:02
|
Revision: 1370 http://assorted.svn.sourceforge.net/assorted/?rev=1370&view=rev Author: yangzhang Date: 2009-05-07 01:27:52 +0000 (Thu, 07 May 2009) Log Message: ----------- - tweaked Makefile - added tests for bit manip functions - added more tests for versioned_heap - added test for deque Modified Paths: -------------- cpp-commons/trunk/src/test/Makefile cpp-commons/trunk/src/test/memory.cc cpp-commons/trunk/src/test/versioned_heap.cc Added Paths: ----------- cpp-commons/trunk/src/test/deque.cc Modified: cpp-commons/trunk/src/test/Makefile =================================================================== --- cpp-commons/trunk/src/test/Makefile 2009-05-07 01:25:59 UTC (rev 1369) +++ cpp-commons/trunk/src/test/Makefile 2009-05-07 01:27:52 UTC (rev 1370) @@ -1,6 +1,5 @@ CXXFLAGS = \ - -MD \ - -g3 \ + -MD -g3 -pipe \ -Wall \ -Werror \ -Wextra \ Added: cpp-commons/trunk/src/test/deque.cc =================================================================== --- cpp-commons/trunk/src/test/deque.cc (rev 0) +++ cpp-commons/trunk/src/test/deque.cc 2009-05-07 01:27:52 UTC (rev 1370) @@ -0,0 +1,16 @@ +#include <commons/deque.h> +#include <boost/foreach.hpp> +#include "test.h" + +TEST(deque, basics) { + deque<int> d; + for (int i = 0; i < 10; ++i) { + d.push_back(i); + } + int i = 0; + foreach (int x, d) { + EXPECT_EQ(i, x); + ++i; + } + EXPECT_EQ(10, i); +} Modified: cpp-commons/trunk/src/test/memory.cc =================================================================== --- cpp-commons/trunk/src/test/memory.cc 2009-05-07 01:25:59 UTC (rev 1369) +++ cpp-commons/trunk/src/test/memory.cc 2009-05-07 01:27:52 UTC (rev 1370) @@ -11,3 +11,8 @@ EXPECT_EQ(2, whole_units(101, 100)); EXPECT_EQ(2, whole_units(102, 100)); } + +TEST(memory, bits) { + EXPECT_EQ(0xfff0UL, clear_bits_below(0xffffUL, 4)); + EXPECT_EQ(0x0fffUL, clear_bits_above(0xffffUL, 12)); +} Modified: cpp-commons/trunk/src/test/versioned_heap.cc =================================================================== --- cpp-commons/trunk/src/test/versioned_heap.cc 2009-05-07 01:25:59 UTC (rev 1369) +++ cpp-commons/trunk/src/test/versioned_heap.cc 2009-05-07 01:27:52 UTC (rev 1370) @@ -1,6 +1,8 @@ #include <commons/check.h> #include <commons/unique_ptr.h> #include <commons/versioned_heap.h> +#include <algorithm> +#include <vector> #include "test.h" struct s { char xs[40000]; }; @@ -9,6 +11,8 @@ typedef versioned_heap<s> heap; heap h; + vector<s*> ss; + s &a = h.construct(); EXPECT_EQ(0, h.hdrof(&a).version); s &b = h.construct(); @@ -17,6 +21,9 @@ EXPECT_EQ(2, h.hdrof(&c).version); EXPECT_EQ(&a + 1, &b); EXPECT_EQ(&b + 1, &c); + ss.push_back(&a); + ss.push_back(&b); + ss.push_back(&c); s &d = h.construct(); EXPECT_EQ(0, h.hdrof(&d).version); @@ -26,13 +33,24 @@ EXPECT_EQ(2, h.hdrof(&f).version); EXPECT_EQ(&d + 1, &e); EXPECT_EQ(&e + 1, &f); + ss.push_back(&d); + ss.push_back(&e); + ss.push_back(&f); h.touch(d); EXPECT_EQ(h.hdrof(&d).version, 3); h.destroy(d); EXPECT_EQ(h.hdrof(&d).version, 4); + ss.erase(find(ss.begin(), ss.end(), &d)); + EXPECT_EQ(5, ss.size()); + size_t i = 0; + for (versioned_heap<s>::iterator it = h.begin(); + it.cur() != nullptr; it.next()) { + EXPECT_EQ(ss[i++], it.cur()); + } + h.touch(a, 4); foreach (char *page, h.pages()) { EXPECT_EQ(h.hdrof(page).version, 4); @@ -40,7 +58,15 @@ s &g = h.construct(); EXPECT_EQ(&d, &g); + ss.insert(find(ss.begin(), ss.end(), &e), &g); + EXPECT_EQ(6, ss.size()); + i = 0; + for (versioned_heap<s>::iterator it = h.begin(); + it.cur() != nullptr; it.next()) { + EXPECT_EQ(ss[i++], it.cur()); + } + void *meta = new char[h.metasize()], *data; check0x(posix_memalign(&data, h.pgsz(), datasize(h))); unique_ptr<char[]> umeta(reinterpret_cast<char*>(meta)), @@ -59,3 +85,33 @@ } } } + +TEST(versioned_heap, simple_bitset) { + uint32_t buffer[20]; + simple_bitset &xs = *(new (buffer) simple_bitset(20, 0)); + xs.set(77); // word 2 + xs.set(188); // word 5 + xs.clr(77); + EXPECT_EQ(size_t(-1), xs.find_first(3)); + EXPECT_EQ(188, xs.find_first(20)); +} + +TEST(versioned_heap, realloc) { + using namespace std; + versioned_heap<s> h; + vector<s*> ss; + for (int i = 0; i < 10; ++i) { + ss.push_back(&h.construct()); + } + EXPECT_EQ(4, h.pages().size()); + + h.free(ss[2]); // last + h.free(ss[4]); // mid + h.free(ss[6]); // first + + for (int i = 0; i < 3; ++i) { + ss[2 + 2 * i] = &h.construct(); + } + + EXPECT_EQ(4, h.pages().size()); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |