Skip to content

Commit

Permalink
Merge pull request #65 from telefonicaid/hardening/unit_tests_ngsi
Browse files Browse the repository at this point in the history
Hardening/unit tests ngsi
  • Loading branch information
fgalan committed Nov 7, 2013
2 parents 89b5253 + 6fc859b commit e6e2d2c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/unittests/ngsi/AttributeAssociationList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,31 @@ TEST(AttributeAssociationList, ok)

// Just to exercise the code ...
aal.present("");
}



/* ****************************************************************************
*
* invalidAttributeAssociation -
*/
TEST(AttributeAssociationList, invalidAttributeAssociation)
{
AttributeAssociationList aal;
AttributeAssociation aa;
std::string out;
std::string expected1 = "empty target";
std::string expected2 = "empty source";

aa.source = "S";
aa.target = "";

aal.push_back(&aa);
out = aal.check(RegisterContext, XML, "", "", 0);
EXPECT_EQ(expected1, out);

aa.source = "";
aa.target = "T";
out = aal.check(RegisterContext, XML, "", "", 0);
EXPECT_EQ(expected2, out);
}
19 changes: 19 additions & 0 deletions test/unittests/ngsi/ContextAttribute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,22 @@ TEST(ContextAttribute, present)

ca.present("", 0);
}



/* ****************************************************************************
*
* copyMetadatas -
*/
TEST(ContextAttribute, copyMetadatas)
{
ContextAttribute ca;
Metadata m1("m1", "int", "2");
Metadata m2("m2", "string", "sss");

ca.metadataVector.push_back(&m1);
ca.metadataVector.push_back(&m2);

ContextAttribute ca2(&ca);
EXPECT_EQ(2, ca2.metadataVector.size());
}
5 changes: 5 additions & 0 deletions test/unittests/ngsi/ErrorCode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ TEST(ErrorCode, check)
{
ErrorCode e1(0, "REASON", "DETAILS");
ErrorCode e2(200, "", "DETAILS");
ErrorCode e3(200, "REASON", "DETAILS");
std::string rendered;
std::string expected1 = "no code";
std::string expected2 = "no reason phrase";
std::string expected3 = "OK";

rendered = e1.check(RegisterContext, XML, "", "", 0);
EXPECT_STREQ(expected1.c_str(), rendered.c_str());

rendered = e2.check(RegisterContext, XML, "", "", 0);
EXPECT_STREQ(expected2.c_str(), rendered.c_str());

rendered = e3.check(RegisterContext, XML, "", "", 0);
EXPECT_STREQ(expected3.c_str(), rendered.c_str());
}
17 changes: 17 additions & 0 deletions test/unittests/ngsi/Metadata_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@



/* ****************************************************************************
*
* constructor -
*/
TEST(Metadata, constructor)
{
Metadata m1;
Metadata m2("n2", "t2", "v2");
Metadata m3(&m2);

EXPECT_EQ("", m1.name);
EXPECT_EQ("n2", m2.name);
EXPECT_EQ("n2", m3.name);
}



/* ****************************************************************************
*
* render -
Expand Down
5 changes: 5 additions & 0 deletions test/unittests/ngsi/Request_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ TEST(Request, requestType)
{ UpdateContextAttribute, "UpdateContextAttribute" },
{ LogRequest, "Log" },
{ VersionRequest, "Version" },
{ StatisticsRequest, "Statistics" },
{ ExitRequest, "Exit" },
{ LeakRequest, "Leak" },
{ InvalidRequest, "InvalidRequest" },
{ RegisterResponse, "RegisterResponse" }
};
Expand All @@ -78,4 +80,7 @@ TEST(Request, requestType)
{
EXPECT_STREQ(req[ix].string, requestType(req[ix].rt));
}

RequestType rt = (RequestType) (RegisterResponse + 1);
EXPECT_STREQ("", requestType(rt));
}

0 comments on commit e6e2d2c

Please sign in to comment.