Fix bug in NTUtils::is_a
Previous implementation matches <type-name>:1x.0 and <type-name>:1.0, depending on the order of the arguments, e.g. NTUtils::is_a("epics:nt/NTTable:11.0", "epics:nt/NTTable:1.0") returned true. Fix this and add unit tests to cover this.
This commit is contained in:
@ -14,12 +14,15 @@ namespace epics { namespace nt {
|
||||
|
||||
bool NTUtils::is_a(const std::string &u1, const std::string &u2)
|
||||
{
|
||||
// remove minor for the u2
|
||||
size_t pos = u2.find_last_of('.');
|
||||
std::string su2 = (pos == string::npos) ? u2 : u2.substr(0, pos);
|
||||
// remove minor for the u1
|
||||
size_t pos1 = u1.find_last_of('.');
|
||||
std::string su1 = (pos1 == string::npos) ? u1 : u1.substr(0, pos1);
|
||||
|
||||
// "starts with comparison"
|
||||
return su2.size() <= u1.size() && u1.compare(0, su2.size(), su2) == 0;
|
||||
// remove minor for the u2
|
||||
size_t pos2 = u2.find_last_of('.');
|
||||
std::string su2 = (pos2 == string::npos) ? u2 : u2.substr(0, pos2);
|
||||
|
||||
return su2 == su1;
|
||||
}
|
||||
|
||||
}}
|
||||
|
@ -24,11 +24,13 @@ void test_is_a()
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:2.0"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:2.0", "epics:nt/NTTable:1.0"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.3", "epics:nt/NTTable:2.3"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:11.0"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:11.0", "epics:nt/NTTable:1.0"));
|
||||
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTMatrix:1.0"));
|
||||
}
|
||||
|
||||
MAIN(testNTUtils) {
|
||||
testPlan(8);
|
||||
testPlan(10);
|
||||
test_is_a();
|
||||
return testDone();
|
||||
}
|
||||
|
Reference in New Issue
Block a user