Skip to content

Commit

Permalink
FIX refactoring in unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Aug 30, 2024
1 parent f3ebe3d commit 469ac63
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 156 deletions.
4 changes: 4 additions & 0 deletions test/unittests/apiTypesV2/EntityVector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
*/
TEST(EntityVector, render)
{
utInit();

Entity* eP = new Entity();
std::string rendered;
EntityVector eV;
Expand All @@ -50,4 +52,6 @@ TEST(EntityVector, render)
rendered = eV.toJson(NGSI_V2_NORMALIZED);

eV.release();

utExit();
}
4 changes: 2 additions & 2 deletions test/unittests/apiTypesV2/Entity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ TEST(Entity, check)
*/
TEST(Entity, checkV1)
{
Entity* enP = new Entity();

utInit();

Entity* enP = new Entity();

enP->id = "";
EXPECT_EQ(enP->check(BatchUpdateRequest), "entity id length: 0, min length supported: 1");

Expand Down
1 change: 0 additions & 1 deletion test/unittests/cache/SubscriptionCache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ extern void setMongoConnectionForUnitTest(orion::DBClientBase _connection);
*/
TEST(cache, SubscriptionCache)
{
LM_M(("In SubscriptionCache test"));
utInit();

std::vector<EntityInfo*> entityIdInfos;
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/ngsi/AttributeList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
*/
TEST(AttributeList, ok)
{
utInit();

StringList al;
std::string out;
const char* outfile1 = "ngsi.attributeList.ok.middle.json";

utInit();
const char* outfile1 = "ngsi.attributeList.ok.middle.json";

out = al.toJson();
EXPECT_STREQ("[]", out.c_str());
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/ngsi/ContextAttribute_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
*/
TEST(ContextAttribute, checkOne)
{
ContextAttribute* caP = new ContextAttribute();
std::string res;

utInit();

ContextAttribute* caP = new ContextAttribute();
std::string res;

caP->name = "";
res = caP->check(false);
EXPECT_EQ(res, "attribute name length: 0, min length supported: 1");
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/ngsi/ContextElementResponseVector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
*/
TEST(ContextElementResponseVector, render)
{
utInit();

ContextElementResponseVector cerv;
ContextElementResponse cer;
std::string out;

std::vector<std::string> emptyV;

utInit();
std::vector<std::string> emptyV;

out = cerv.toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL);
EXPECT_STREQ("[]", out.c_str());
Expand Down
22 changes: 11 additions & 11 deletions test/unittests/ngsi/ContextElementResponse_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@
*/
TEST(ContextElementResponse, render)
{
utInit();

ContextElementResponse cer;
const char* outfile = "ngsi.contextElementResponse.render.middle.json";
std::string out;

std::vector<std::string> emptyV;

cer.entity.id = "ID";
cer.entity.type = "Type";
cer.entity.isPattern = "false";

utInit();

cer.entity.id = "ID";
cer.entity.type = "Type";
cer.entity.isPattern = "false";

cer.statusCode.fill(SccOk, "details");
cer.statusCode.fill(SccOk, "details");

out = cer.toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL);;
EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
EXPECT_STREQ(expectedBuf, out.c_str());
out = cer.toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL);;
EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'";
EXPECT_STREQ(expectedBuf, out.c_str());

utExit();
utExit();
}
6 changes: 3 additions & 3 deletions test/unittests/ngsi/EntityId_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
*/
TEST(EntityId, render)
{
utInit();

EntityId eId;
std::string out;
const char* outfile1 = "ngsi.entityId.render.middle.json";

utInit();
const char* outfile1 = "ngsi.entityId.render.middle.json";

out = eId.toJson();
EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
Expand Down
8 changes: 4 additions & 4 deletions test/unittests/ngsi/ErrorCode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
*/
TEST(ErrorCode, render)
{
utInit();

ErrorCode e1;
std::string out;
const char* outfile1 = "ngsi.errorCode.render1.middle.json";

utInit();

out = e1.render();
EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
EXPECT_STREQ(expectedBuf, out.c_str());
Expand All @@ -55,6 +55,8 @@ TEST(ErrorCode, render)
*/
TEST(ErrorCode, check)
{
utInit();

ErrorCode e1(0, "REASON", "DETAILS");
ErrorCode e2(200, "", "DETAILS");
ErrorCode e3(200, "REASON", "DETAILS");
Expand All @@ -63,8 +65,6 @@ TEST(ErrorCode, check)
std::string expected2 = "no reason phrase";
std::string expected3 = "OK";

utInit();

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

Expand Down
4 changes: 2 additions & 2 deletions test/unittests/ngsi/MetadataVector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
*/
TEST(MetadataVector, render)
{
utInit();

Metadata m("Name", "Type", "Value");
Metadata m2("Name2", "Type2", "Value2");
MetadataVector mV;
const char* outfile1 = "ngsi.metadataVector.render1.middle.json";
const char* outfile2 = "ngsi.metadataVector.render3.middle.json";
std::string out;

utInit();

mV.push_back(&m);

std::vector<Metadata*> metadataFilter;
Expand Down
8 changes: 4 additions & 4 deletions test/unittests/ngsi/Metadata_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
*/
TEST(Metadata, constructor)
{
utInit();

Metadata m1;
Metadata m2("n2", "t2", "v2");
Metadata m3(&m2);

utInit();

EXPECT_EQ("", m1.name);
EXPECT_EQ("n2", m2.name);
EXPECT_EQ("n2", m3.name);
Expand All @@ -56,15 +56,15 @@ TEST(Metadata, constructor)
*/
TEST(Metadata, render)
{
utInit();

std::string out;
Metadata m1;
Metadata m2("Name", "Integer", "19");

const char* outfile1 = "ngsi.metdata.render1.middle.json";
const char* outfile2 = "ngsi.metdata.render2.middle.json";

utInit();

out = m1.toJson();
EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
EXPECT_STREQ(expectedBuf, out.c_str());
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/ngsi/ScopeVector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
*/
TEST(ScopeVector, getAndSize)
{
utInit();

ScopeVector sV;
Scope scope0("Type", "Value0");
Scope scope1("Type", "Value1");
Scope scope2("Type", "Value2");
Scope* scopeP;

utInit();

sV.push_back(&scope0);
sV.push_back(&scope1);
sV.push_back(&scope2);
Expand Down
8 changes: 4 additions & 4 deletions test/unittests/ngsi/StatusCode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
*/
TEST(StatusCode, render)
{
utInit();

StatusCode sc1;
StatusCode sc2;
std::string out;
const char* outfile1 = "ngsi.statusCode.render4.middle.json";

utInit();

sc2.fill(SccOk, "DETAILS");
out = sc2.toJson();
EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
Expand All @@ -62,13 +62,13 @@ TEST(StatusCode, render)
*/
TEST(StatusCode, fill)
{
utInit();

StatusCode sc;
StatusCode sc2;
StatusCode ec;
std::string out;

utInit();

sc.fill(SccForbidden, "D");
EXPECT_EQ(sc.code, SccForbidden);
EXPECT_STREQ(sc.reasonPhrase.c_str(), "Forbidden");
Expand Down
102 changes: 0 additions & 102 deletions test/unittests/ngsi/SubscriptionId_test.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions test/unittests/ngsi10/NotifyContextRequest_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
*/
TEST(NotifyContextRequest, json_render)
{
utInit();

const char* filename1 = "ngsi10.notifyContextRequest.jsonRender1.valid.json";
const char* filename2 = "ngsi10.notifyContextRequest.jsonRender2.valid.json";
const char* filename3 = "ngsi10.notifyContextRequest.jsonRender3.valid.json";
NotifyContextRequest* ncrP;
ContextElementResponse* cerP;
std::string rendered;

utInit();
std::string rendered;

// Preparation
ncrP = new NotifyContextRequest();
Expand Down
Loading

0 comments on commit 469ac63

Please sign in to comment.