[Assorted-commits] SF.net SVN: assorted:[1354] cpp-commons/trunk/src/test
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-04-29 05:24:34
|
Revision: 1354 http://assorted.svn.sourceforge.net/assorted/?rev=1354&view=rev Author: yangzhang Date: 2009-04-29 05:24:26 +0000 (Wed, 29 Apr 2009) Log Message: ----------- added tests for versioned_heap and squeue Added Paths: ----------- cpp-commons/trunk/src/test/squeue.cc cpp-commons/trunk/src/test/versioned_heap.cc Added: cpp-commons/trunk/src/test/squeue.cc =================================================================== --- cpp-commons/trunk/src/test/squeue.cc (rev 0) +++ cpp-commons/trunk/src/test/squeue.cc 2009-04-29 05:24:26 UTC (rev 1354) @@ -0,0 +1,14 @@ +#include <commons/squeue.h> +#include <commons/unique_ptr.h> +#include "test.h" + +TEST(squeue, move) { + concurrent_queue<unique_ptr<int> > q; + q.push(unique_ptr<int>(new int(0))); + q.push(unique_ptr<int>(new int(1))); + unique_ptr<int> p1; + q.pop(p1); + EXPECT_EQ(0, *p1); + unique_ptr<int> p2 = q.take(); + EXPECT_EQ(1, *p2); +} Added: cpp-commons/trunk/src/test/versioned_heap.cc =================================================================== --- cpp-commons/trunk/src/test/versioned_heap.cc (rev 0) +++ cpp-commons/trunk/src/test/versioned_heap.cc 2009-04-29 05:24:26 UTC (rev 1354) @@ -0,0 +1,40 @@ +#include <commons/versioned_heap.h> +#include "test.h" + +struct s { char xs[40000]; }; + +TEST(versioned_heap, basics) { + versioned_heap<s> h; + + s &a = h.construct(); + EXPECT_EQ(h.hdrof(&a).version, 0); + s &b = h.construct(); + EXPECT_EQ(h.hdrof(&b).version, 1); + s &c = h.construct(); + EXPECT_EQ(h.hdrof(&c).version, 2); + EXPECT_EQ(&a + 1, &b); + EXPECT_EQ(&b + 1, &c); + + s &d = h.construct(); + EXPECT_EQ(h.hdrof(&d).version, 0); + s &e = h.construct(); + EXPECT_EQ(h.hdrof(&e).version, 1); + s &f = h.construct(); + EXPECT_EQ(h.hdrof(&f).version, 2); + EXPECT_EQ(&d + 1, &e); + EXPECT_EQ(&e + 1, &f); + + h.touch(d); + EXPECT_EQ(h.hdrof(&d).version, 3); + + h.free(d); + EXPECT_EQ(h.hdrof(&d).version, 4); + + h.touch(a, 4); + foreach (char *page, h.pages()) { + EXPECT_EQ(h.hdrof(page).version, 4); + } + + s &g = h.construct(); + EXPECT_EQ(&d, &g); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |