diff --git a/c_extensions/inferrer/structures.cc b/c_extensions/inferrer/structures.cc index 1da0af3..e314673 100644 --- a/c_extensions/inferrer/structures.cc +++ b/c_extensions/inferrer/structures.cc @@ -1,6 +1,6 @@ #include "structures.h" -RQueue::RQueue(redisContext *c, string key,bool am_listener) +RQueue::RQueue(redisContext *c, string key, bool am_listener) { this->key = key; this->c = c; diff --git a/c_extensions/inferrer/test/Makefile b/c_extensions/inferrer/test/Makefile index 5821e73..6e8e4fd 100644 --- a/c_extensions/inferrer/test/Makefile +++ b/c_extensions/inferrer/test/Makefile @@ -2,8 +2,8 @@ CC = g++ GTESTDIR = gtest TESTS = $(wildcard test_*.cc) OBJECTS = $(patsubst %.cc, %.o, $(wildcard *.cc)) -CFLAGS = -I$(GTESTDIR)/include -std=c++0x -LIBS = $(GTESTDIR)/libgtest.a ../../hiredis/libhiredis.a -lpthread +CFLAGS = -I$(GTESTDIR)/include -std=c++0x -g +LIBS = $(GTESTDIR)/build/libgtest_main.a $(GTESTDIR)/build/libgtest.a -lhiredis -lpthread %.o: %.cc $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@ diff --git a/c_extensions/inferrer/test/test_pathset.cc b/c_extensions/inferrer/test/test_pathset.cc index f6b39a1..b3bd057 100644 --- a/c_extensions/inferrer/test/test_pathset.cc +++ b/c_extensions/inferrer/test/test_pathset.cc @@ -1,12 +1,12 @@ #include #include "../structures.h" -class PathSetTest : public ::testing::Test +class PathSetTest : public ::testing::Test { protected: virtual void SetUp() { - p1_ = new Path("['1', '2', '3', '4']"); - p2_ = new Path("['5', '6', '7', '8']"); + p1_ = Path_ptr(new Path("['1', '2', '3', '4']")); + p2_ = Path_ptr(new Path("['5', '6', '7', '8']")); origin = ASN_encode("1234"); ps_.add(origin,p1_); } @@ -17,8 +17,8 @@ class PathSetTest : public ::testing::Test ps_.clear(origin2); } - Path *p1_; - Path *p2_; + Path_ptr p1_; + Path_ptr p2_; PathSet ps_; asn_t origin; @@ -38,7 +38,7 @@ TEST_F(PathSetTest, AddInsertsNewPath) TEST_F(PathSetTest, DifferentPtrsCompareEqualIfPathsEqual) { - Path *p1dup = new Path(*p1_); + Path_ptr p1dup = Path_ptr(new Path(*p1_)); PathPtrCmp cmp; EXPECT_NE(p1dup,p1_); @@ -57,7 +57,7 @@ TEST_F(PathSetTest, ComparatorCorrectlyOrders) p1_->prepend("99",true); ASSERT_FALSE(cmp(p1_,p2_)) << p2_->cstr(true) << " should come before " << p1_->cstr(true); - ASSERT_TRUE(cmp(p2_,p1_)); + ASSERT_TRUE(cmp(p2_,p1_)); p2_->prepend("20",false); ASSERT_TRUE(cmp(p1_,p2_)) << p1_->cstr(true) << " should come before " << p2_->cstr(true); @@ -67,35 +67,35 @@ TEST_F(PathSetTest, ComparatorCorrectlyOrders) TEST_F(PathSetTest, PeekNoCopyReturnsSameObject) { - Path *p = ps_.peek(origin, false); - ASSERT_EQ(p1_, p) + Path_ptr p = ps_.peek(origin, false); + ASSERT_EQ(p1_, p) << "Inserted object pointer not equal to return value of peek()"; } TEST_F(PathSetTest, PeekCopyCreatesNew) { - Path *p = ps_.peek(origin, true); - ASSERT_NE(p1_, p) + Path_ptr p = ps_.peek(origin, true); + ASSERT_NE(p1_, p) << "Inserted object pointer equal to return value of peek()"; } TEST_F(PathSetTest, ClearRemovesElementsForOrigin) { - ASSERT_EQ(1,ps_.size(origin)); + ASSERT_EQ(1, ps_.size(origin)); ps_.clear(origin); - ASSERT_EQ(0,ps_.size(origin)); - Path *p = ps_.peek(origin,false); - ASSERT_EQ(0,p); + ASSERT_EQ(0, ps_.size(origin)); + Path_ptr p = ps_.peek(origin, false); + ASSERT_FALSE(p); } -TEST_F(PathSetTest, AddIdenticalIncrFrequency) +TEST_F(PathSetTest, AddIdenticalIncrFrequency) { ps_.add(origin,p1_); - Path *ret = ps_.peek(origin,false); - ASSERT_EQ(2, ret->frequency) + Path_ptr ret = ps_.peek(origin,false); + ASSERT_EQ(2, ret->frequency) << "Adding duplicate "<< ret->cstr() << " should increment frequency"; - Path *p1dup = new Path(*p1_); + Path_ptr p1dup = Path_ptr(new Path(*p1_)); ps_.add(origin,p1dup); ret = ps_.peek(origin,false); ASSERT_EQ(3, ret->frequency) @@ -105,34 +105,34 @@ TEST_F(PathSetTest, AddIdenticalIncrFrequency) TEST_F(PathSetTest, PeekReturnsBestPath) { - Path *ret = ps_.peek(origin,false); + Path_ptr ret = ps_.peek(origin,false); ASSERT_EQ(ret, p1_); asn_t origin2 = ASN_encode("5678"); ASSERT_EQ(0, ps_.size(origin2)); - Path *p4 = new Path(*p1_); + Path_ptr p4 = Path_ptr(new Path(*p1_)); p4->prepend("99",false); ps_.add(origin2,p4); ret = ps_.peek(origin2,false); - ASSERT_EQ(p4, ret) - << "[" << p4 << "] " << p4->cstr(false) - << " should be better than " + ASSERT_EQ(p4, ret) + << "[" << p4 << "] " << p4->cstr(false) + << " should be better than " << "[" << ret << "] " << ret->cstr(false); ps_.add(origin2,p2_); ret = ps_.peek(origin2,false); - ASSERT_EQ(p2_, ret) - << "[" << p2_ << "] " << p2_->cstr(false) - << " should be better than " + ASSERT_EQ(p2_, ret) + << "[" << p2_ << "] " << p2_->cstr(false) + << " should be better than " << "[" << ret << "] " << ret->cstr(false); - Path *p3 = new Path("1 2 3"); + Path_ptr p3 = Path_ptr(new Path("1 2 3")); ps_.add(origin2,p3); ret = ps_.peek(origin2,false); - ASSERT_EQ(p3, ret) - << "[" << p3 << "] " << p3->cstr(false) - << " should be better than " + ASSERT_EQ(p3, ret) + << "[" << p3 << "] " << p3->cstr(false) + << " should be better than " << "[" << ret << "] " << ret->cstr(false); ps_.clear(origin2); diff --git a/c_extensions/inferrer/test/test_rqueue.cc b/c_extensions/inferrer/test/test_rqueue.cc index 36f9032..1b7060e 100644 --- a/c_extensions/inferrer/test/test_rqueue.cc +++ b/c_extensions/inferrer/test/test_rqueue.cc @@ -1,4 +1,5 @@ #include +#include #include "../structures.h" #include "../infer.h" @@ -82,18 +83,18 @@ TEST_F(RQueueTest, DeleteRemovesListenerKey) { ASSERT_REDIS(c_); - RQueue *rq = new RQueue(c_,"sladfkjew",false); + RQueue *rq = new RQueue(c_, "sladfkjew", true); char buf[64]; strncpy(buf,rq->listener_key,64); r = rCommand(c_,"GET %s",buf); int res = atoi(r->str); - ASSERT_EQ(1,res); + ASSERT_EQ(1, res); freeReplyObject(r); delete rq; r = rCommand(c_,"GET %s", buf); res = atoi(r->str); - ASSERT_EQ(1,res); + ASSERT_EQ(0,res); freeReplyObject(r); }