Skip to content

Commit

Permalink
Added osmChange JSON parser
Browse files Browse the repository at this point in the history
Added simple testcase

Rename osmchange xml parser files

make check fix

Cont'd Unit tests for json diff upload

Fixes

More generic payload_error exception class

Added unit test case for large json messages

Added JSON diffResult
  • Loading branch information
mmd-osm committed Jul 6, 2024
1 parent 8ae875a commit 336ddaa
Show file tree
Hide file tree
Showing 24 changed files with 1,528 additions and 152 deletions.
20 changes: 10 additions & 10 deletions include/cgimap/api06/changeset_upload/changeset_input_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace api06 {
if (element == "osm")
m_context = context::top;
else
throw xml_error{ "Unknown top-level element, expecting osm" };
throw payload_error{ "Unknown top-level element, expecting osm" };

break;

Expand All @@ -70,7 +70,7 @@ namespace api06 {
changeset_element_found = true;
}
else
throw xml_error{ "Unknown element, expecting changeset" };
throw payload_error{ "Unknown element, expecting changeset" };
break;

case context::in_changeset:
Expand All @@ -79,7 +79,7 @@ namespace api06 {
add_tag(attrs);
}
else
throw xml_error{ "Unknown element, expecting tag" };
throw payload_error{ "Unknown element, expecting tag" };
break;

case context::in_tag:
Expand All @@ -100,7 +100,7 @@ namespace api06 {
assert(element == "osm");
m_context = context::root;
if (!changeset_element_found)
throw xml_error{ "Cannot parse valid changeset from xml string. XML doesn't contain an osm/changeset element" };
throw payload_error{ "Cannot parse valid changeset from xml string. XML doesn't contain an osm/changeset element" };
break;
case context::in_changeset:
assert(element == "changeset");
Expand All @@ -116,7 +116,7 @@ namespace api06 {

try {
throw;
} catch (const xml_error& e) {
} catch (const payload_error& e) {
throw_with_context(e, location);
}
}
Expand All @@ -128,13 +128,13 @@ namespace api06 {
void add_tag(const std::string &key, const std::string &value) {

if (key.empty())
throw xml_error("Key may not be empty");
throw payload_error("Key may not be empty");

if (unicode_strlen(key) > 255)
throw xml_error("Key has more than 255 unicode characters");
throw payload_error("Key has more than 255 unicode characters");

if (unicode_strlen(value) > 255)
throw xml_error("Value has more than 255 unicode characters");
throw payload_error("Value has more than 255 unicode characters");

m_tags[key] = value;

Expand Down Expand Up @@ -166,10 +166,10 @@ namespace api06 {
});

if (!k)
throw xml_error{"Mandatory field k missing in tag element"};
throw payload_error{"Mandatory field k missing in tag element"};

if (!v)
throw xml_error{"Mandatory field v missing in tag element"};
throw payload_error{"Mandatory field v missing in tag element"};

add_tag(*k, *v);
}
Expand Down
24 changes: 15 additions & 9 deletions include/cgimap/api06/changeset_upload/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Node : public OSMObject {
try {
_lat = std::stod(lat);
} catch (std::invalid_argument &e) {
throw xml_error("Latitude is not numeric");
throw payload_error("Latitude is not numeric");
} catch (std::out_of_range &e) {
throw xml_error("Latitude value is too large");
throw payload_error("Latitude value is too large");
}

set_lat(_lat);
Expand All @@ -51,27 +51,27 @@ class Node : public OSMObject {
try {
_lon = std::stod(lon);
} catch (std::invalid_argument &e) {
throw xml_error("Longitude is not numeric");
throw payload_error("Longitude is not numeric");
} catch (std::out_of_range &e) {
throw xml_error("Longitude value is too large");
throw payload_error("Longitude value is too large");
}

set_lon(_lon);
}

void set_lat(double lat) {
if (lat < -90 || lat > 90)
throw xml_error("Latitude outside of valid range");
throw payload_error("Latitude outside of valid range");
else if (!std::isfinite(lat))
throw xml_error("Latitude not a valid finite number");
throw payload_error("Latitude not a valid finite number");
m_lat = lat;
}

void set_lon(double lon) {
if (lon < -180 || lon > 180)
throw xml_error("Longitude outside of valid range");
throw payload_error("Longitude outside of valid range");
else if (!std::isfinite(lon))
throw xml_error("Longitude not a valid finite number");
throw payload_error("Longitude not a valid finite number");
m_lon = lon;
}

Expand All @@ -86,7 +86,13 @@ class Node : public OSMObject {
}
}

std::string get_type_name() override { return "Node"; }
std::string get_type_name() const override { return "Node"; }

bool operator==(const Node &o) const {
return (OSMObject::operator==(o) &&
o.m_lat == m_lat &&
o.m_lon == m_lon);
}

private:
std::optional<double> m_lat;
Expand Down
Loading

0 comments on commit 336ddaa

Please sign in to comment.