Skip to content

Commit 96ad1c6

Browse files
authored
Fix JSON parsing in CCDB api test (#3470)
1 parent b8cfbc7 commit 96ad1c6

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

CCDB/test/testCcdbApi.cxx

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
#include <sys/types.h>
4141
#include <unistd.h>
4242

43+
#include <boost/property_tree/json_parser.hpp>
44+
#include <boost/property_tree/ptree.hpp>
45+
#include <boost/foreach.hpp>
46+
#include <boost/optional/optional.hpp>
47+
4348
using namespace std;
4449
using namespace o2::ccdb;
4550
namespace utf = boost::unit_test;
@@ -308,30 +313,16 @@ void countItems(const string& s, int& countObjects, int& countSubfolders)
308313
countObjects = 0;
309314
countSubfolders = 0;
310315
std::stringstream ss(s);
311-
std::string line;
312-
bool subfolderMode = false;
313-
while (std::getline(ss, line, '\n')) {
314-
o2::utils::ltrim(line);
315-
o2::utils::rtrim(line);
316-
if (line.length() == 0) {
317-
continue;
318-
}
319316

320-
if (line.find("subfolders") != std::string::npos) {
321-
subfolderMode = true;
322-
continue;
323-
}
317+
boost::property_tree::ptree pt;
318+
boost::property_tree::read_json(ss, pt);
324319

325-
if (subfolderMode) {
326-
countSubfolders++;
327-
if (line.find(']') != std::string::npos) {
328-
break;
329-
}
330-
}
320+
if (pt.count("objects") > 0) {
321+
countObjects = pt.get_child("objects").size();
322+
}
331323

332-
if (line.find(R"("path")") == 0) {
333-
countObjects++;
334-
}
324+
if (pt.count("subfolders") > 0) {
325+
countSubfolders = pt.get_child("subfolders").size();
335326
}
336327
}
337328

0 commit comments

Comments
 (0)