Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 62 additions & 33 deletions test/caPutJsonLogTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ static std::string incLogMsg;

static void readFromClient(void *pParam)
{
char recvbuf[BUFFER_SIZE];
char recvbuf[BUFFER_SIZE] = {0};
int recvLength;
std::string

memset(recvbuf, 0, BUFFER_SIZE);
recvLength = recv(insock, recvbuf, BUFFER_SIZE, 0);
if (recvLength > 0) {
incLogMsg.append(recvbuf, recvLength);
Expand Down Expand Up @@ -455,41 +453,48 @@ void commonTests(JsonParser &jsonParser, const char* pvname, const char * testPr

// Test if is Json terminated with newline
testOk(*jsonParser.jsonLogMsg.rbegin() == *"\n",
"%s - %s", testPrefix, "New line terminator check");
"%s - %s - exp %#02x (\\n) act %#02x", testPrefix, "New line terminator check",
'\n', *jsonParser.jsonLogMsg.rbegin());

// Test prefix
testOk(!jsonParser.prefix.compare(logMsgPrefix),
"%s - %s", testPrefix, "Prefix check");
"%s - %s - exp '%s' act '%s'", testPrefix, "Prefix check",
logMsgPrefix, jsonParser.prefix.c_str());

// Test date format
testOk(jsonParser.date.length() == 10 &&
jsonParser.date.at(4) == *"-" &&
jsonParser.date.at(7) == *"-",
"%s - %s", testPrefix, "Date format check");
"%s - %s - exp '%s' act '%s'", testPrefix, "Date format check",
"YYYY-MM-DD", jsonParser.date.c_str());

// Test time format
testOk(jsonParser.time.length() == 12 &&
jsonParser.time.at(2) == *":" &&
jsonParser.time.at(5) == *":" &&
jsonParser.time.at(8) == *".",
"%s - %s", testPrefix, "Time format check");
"%s - %s - exp '%s' act '%s'", testPrefix, "Time format check",
"HH:MM:SS.ddd", jsonParser.time.c_str());

// Test hostname
char hostname[1024];
gethostname(hostname, 1024);

// asLibRoutines changes the hostnames to lower-case; some OSs are not so kind.
testOk(!epicsStrCaseCmp(hostname, jsonParser.host.c_str()),
"%s - %s", testPrefix, "Hostname check");
"%s - %s - exp '%s' act '%s'", testPrefix, "Hostname check",
hostname, jsonParser.host.c_str());

// Test username
char username[1024];
osiGetUserName(username, 1024);
testOk(!jsonParser.user.compare(username),
"%s - %s", testPrefix, "Username check");
"%s - %s - exp '%s' act '%s'", testPrefix, "Username check",
username, jsonParser.user.c_str());

testOk(!jsonParser.pv.compare(pvname),
"%s - %s", testPrefix, "PV name check");
"%s - %s - exp '%s' act '%s'", testPrefix, "PV name check",
pvname, jsonParser.pv.c_str());

//Test Metadata
testOk(metadata_compare(jsonParser.metadata, logger->getMetadata()),
Expand Down Expand Up @@ -526,19 +531,23 @@ void testDbf(const char *pv, chtype type,
for (size_t i = 0; i < json.newVal.size(); i++) {
if (isnan(*(value1 + i))) {
testOk(!json.newVal.at(i).compare("Nan"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 1",
i, "Nan", json.newVal.at(i).c_str());
}
else if (isinf(*(value1 + i) && *(value1 + i) > 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

else if (isinf(*(value1 + i)) && *(value1 + i) > 0) {
testOk(!json.newVal.at(i).compare("Infinity"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 1",
i, "Infinity", json.newVal.at(i).c_str());
}
else if (isinf(*(value1 + i) && *(value1 + i) < 0)) {
else if (isinf(*(value1 + i)) && *(value1 + i) < 0) {
testOk(!json.newVal.at(i).compare("-Infinity"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 1",
i, "-Infinity", json.newVal.at(i).c_str());
}
else {
testOk(!json.newVal.at(i).compare(toString(*(value1 + i))),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 1",
i, toString(*(value1 + i)).c_str(), json.newVal.at(i).c_str());
}
}
}
Expand All @@ -562,39 +571,47 @@ void testDbf(const char *pv, chtype type,
for (size_t i = 0; i < json.newVal.size(); i++) {
if (isnan(*(value2 + i))) {
testOk(!json.newVal.at(i).compare("Nan"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 2",
i, "Nan", json.newVal.at(i).c_str());
}
else if (isinf(*(value2 + i)) && *(value2 + i) > 0) {
testOk(!json.newVal.at(i).compare("Infinity"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 2",
i, "Infinity", json.newVal.at(i).c_str());
}
else if (isinf(*(value2 + i)) && *(value2 + i) < 0) {
testOk(!json.newVal.at(i).compare("-Infinity"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 2",
i, "-Infinity", json.newVal.at(i).c_str());
}
else {
testOk(!json.newVal.at(i).compare(toString(*(value2 + i))),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 2",
i, toString(*(value2 + i)).c_str(), json.newVal.at(i).c_str());
}
}

// Old Value check
for (size_t i = 0; i < json.oldVal.size(); i++) {
if (isnan(*(value1 + i))) {
testOk(!json.oldVal.at(i).compare("Nan"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "Old value check",
i, "Nan", json.oldVal.at(i).c_str());
}
else if (isinf(*(value1 + i) && *(value1 + i) > 0)) {
testOk(!json.oldVal.at(i).compare("Infinity"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "Old value check",
i, "Infinity", json.oldVal.at(i).c_str());
}
else if (isinf(*(value1 + i) && *(value1 + i) < 0)) {
testOk(!json.oldVal.at(i).compare("-Infinity"),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "Old value check",
i, "-Infinity", json.oldVal.at(i).c_str());
}
else {
testOk(!json.oldVal.at(i).compare(toString(*(value1 + i))),
"%s - %s", testPrefix, "New value check");
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "Old value check",
i, toString(*(value1 + i)).c_str(), json.oldVal.at(i).c_str());
}
}
}
Expand Down Expand Up @@ -627,8 +644,11 @@ void testDbf<dbr_string_t>(const char *pv, chtype type,

// New Value check
for (size_t i = 0; i < json.newVal.size(); i++) {
testOk(!json.newVal.at(i).compare(value1 + i*MAX_STRING_SIZE),
"%s - %s", testPrefix, "New value check");
char *cval = value1 + i*MAX_STRING_SIZE;
std::string sval(cval, std::min<size_t>(MAX_STRING_SIZE, strlen(cval)));
testOk(!json.newVal.at(i).compare(sval),
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 1",
i, sval.c_str(), json.newVal.at(i).c_str());
}
}

Expand All @@ -649,14 +669,20 @@ void testDbf<dbr_string_t>(const char *pv, chtype type,

// New Value check
for (size_t i = 0; i < json.newVal.size(); i++) {
testOk(!json.newVal.at(i).compare(value2 + i*MAX_STRING_SIZE),
"%s - %s", testPrefix, "New value check");
char *cval = value2 + i*MAX_STRING_SIZE;
std::string sval(cval, std::min<size_t>(MAX_STRING_SIZE, strlen(cval)));
testOk(!json.newVal.at(i).compare(sval),
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "New value check 2",
i, sval.c_str(), json.newVal.at(i).c_str());
}

// Old Value check
for (size_t i = 0; i < json.newVal.size(); i++) {
testOk(!json.oldVal.at(i).compare(value1 + i*MAX_STRING_SIZE),
"%s - %s", testPrefix, "Old value check");
char *cval = value1 + i*MAX_STRING_SIZE;
std::string sval(cval, std::min<size_t>(MAX_STRING_SIZE, strlen(cval)));
testOk(!json.oldVal.at(i).compare(sval),
"%s - %s - elem %lu exp '%s' act '%s'", testPrefix, "Old value check",
i, sval.c_str(), json.oldVal.at(i).c_str());
}
}
}
Expand Down Expand Up @@ -688,7 +714,8 @@ void testDbf(const char *pv, chtype type,

// New Value check
testOk(!json.newVal.at(0).compare(std::string(value1, value1Size)),
"%s - %s", testPrefix, "New value check");
"%s - %s - exp '%s' act '%s'", testPrefix, "New value check 1",
std::string(value1, value1Size).c_str(), json.newVal.at(0).c_str());
}

// Second put -> we check new and old value
Expand All @@ -708,11 +735,13 @@ void testDbf(const char *pv, chtype type,

// New Value check
testOk(!json.newVal.at(0).compare(std::string(value2, value2Size)),
"%s - %s", testPrefix, "New value check");
"%s - %s - exp '%s' act '%s'", testPrefix, "New value check 2",
std::string(value2, value2Size).c_str(), json.newVal.at(0).c_str());

// Old Value check
testOk(!json.oldVal.at(0).compare(std::string(value1, value1Size)),
"%s - %s", testPrefix, "New value check");
"%s - %s - exp '%s' act '%s'", testPrefix, "Old value check",
std::string(value1, value1Size).c_str(), json.oldVal.at(0).c_str());
}
}

Expand Down