Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Commit

Permalink
Added additional unit-tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenden committed Oct 30, 2014
1 parent 27d7dab commit 223f707
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Dialplan
else
break;
}
return matchingRoute;
return (matchingRoute == head ? 0 : matchingRoute);
}

Route *find(const char *e163) {
Expand Down Expand Up @@ -294,6 +294,9 @@ class Call
lenOfCall -= rem;

m = dp->match(this->destination.c_str());
if (!m) {
throw std::exception();
}
//m->dump();
total += m->price(rem);
vtotal += m->vendorPrice(rem);
Expand Down
74 changes: 74 additions & 0 deletions src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ TEST_F(CallDefaultTest, Default_Matching_Route) {
EXPECT_EQ(c->head->vendorPrice, 0.00175);
}

TEST_F(CallDefaultTest, No_Matching_Route) {
struct tm tm;
Call *c = new Call;
c->source = "1";
c->destination = "911";
c->seconds = 5;
strptime("2014-07-04 08:19:55", "%Y-%m-%d %H:%M:%S", &tm);
c->startTime = mktime(&tm);
c->endTime = c->startTime + c->seconds;
EXPECT_ANY_THROW(c->rate());
}

class CallSixtyTest : public ::testing::Test {

protected:
Expand Down Expand Up @@ -355,3 +367,65 @@ TEST_F(CallDoubleTest, Targeted_Matching_VeryLongCall_Route) {
EXPECT_EQ(c->head->next->next->price, 0.022);
EXPECT_DOUBLE_EQ(19.324, amount);
}

class CallDoubleDayTest : public ::testing::Test {

protected:
virtual void SetUp() {
Route *r1 = new Route, *r2 = new Route, *r3 = new Route;
r3->retail_price = 0.002;
r3->vendor_price = 0;
r3->billing_interval = 6;
r3->connect_charge = 0;
r2->destination[4] = r3;
r2->retail_price = 0.0035;
r2->vendor_price = 0.00175;
r2->billing_interval = 6;
r2->connect_charge = 0;
r1->destination[1] = r2;
dp1 = new Dialplan(r1);
dp1->startHour = 0;
dp1->endHour = 11;
dp1->dow = DOW_MONDAY;
dialplans = dp1;
dialplans_count = 1;

Route *r4 = new Route, *r5 = new Route, *r6 = new Route;
r6->retail_price = 0.0025;
r6->vendor_price = 0;
r6->billing_interval = 6;
r6->connect_charge = 0;
r5->destination[4] = r6;
r5->retail_price = 0.0035;
r5->vendor_price = 0.00175;
r5->billing_interval = 6;
r5->connect_charge = 0;
r4->destination[1] = r5;
dp2 = new Dialplan(r4);
dp2->startHour = 12;
dp2->endHour = 23;
dp2->dow = DOW_TUESDAY;
dialplans->next = dp2;
dialplans_count++;
}

virtual void TearDown() {
delete dp1;
delete dp2;
}

Dialplan *dp1, *dp2;
};

TEST_F(CallDoubleDayTest, Default_Matching_Route) {
struct tm tm;
Call *c = new Call;
c->source = "1";
c->destination = "12165551212";
c->seconds = 302;
memset(&tm, 0, sizeof(tm));
strptime("2014-07-04 11:58:55", "%Y-%m-%d %H:%M:%S", &tm);
c->startTime = mktime(&tm);
c->endTime = c->startTime + c->seconds;
EXPECT_ANY_THROW(c->rate());
}

0 comments on commit 223f707

Please sign in to comment.