diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-07-08 14:38:49 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-07-08 14:38:49 -0700 |
commit | af6091db5a71ae7cd21a2d8348368d1917867bab (patch) | |
tree | 9704f82eff1f638dfbc02d6ba5e76afad878e0fb /src | |
parent | 4c75c696b3162c72e7dec21ce0b3f69cae9d1034 (diff) | |
download | qtlocation-mapboxgl-af6091db5a71ae7cd21a2d8348368d1917867bab.tar.gz |
update headless testing to be configurable
Diffstat (limited to 'src')
-rw-r--r-- | src/style/style.cpp | 4 | ||||
-rw-r--r-- | src/util/io.cpp | 22 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/style/style.cpp b/src/style/style.cpp index fc2364da81..006376172c 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -4,6 +4,7 @@ #include <llmr/style/style_bucket.hpp> #include <llmr/util/constants.hpp> #include <llmr/util/time.hpp> +#include <llmr/util/error.hpp> #include <csscolorparser/csscolorparser.hpp> #include <rapidjson/document.h> @@ -102,6 +103,9 @@ void Style::loadJSON(const uint8_t *const data) { rapidjson::Document doc; doc.Parse<0>((const char *const)data); + if (doc.HasParseError()) { + throw error::style_parse(doc.GetErrorOffset(), doc.GetParseError()); + } StyleParser parser; parser.parse(const_cast<const rapidjson::Document &>(doc)); diff --git a/src/util/io.cpp b/src/util/io.cpp index bf519b0573..fb36998e07 100644 --- a/src/util/io.cpp +++ b/src/util/io.cpp @@ -1,8 +1,14 @@ #include <llmr/util/io.hpp> #include <cstdio> +#include <iostream> +#include <sstream> +#include <fstream> -void llmr::util::write_file(const std::string &filename, const std::string &data) { +namespace llmr { +namespace util { + +void write_file(const std::string &filename, const std::string &data) { FILE *fd = fopen(filename.c_str(), "wb"); if (fd) { fwrite(data.data(), sizeof(std::string::value_type), data.size(), fd); @@ -11,3 +17,17 @@ void llmr::util::write_file(const std::string &filename, const std::string &data fprintf(stderr, "Failed to open file\n"); } } + +std::string read_file(const std::string &filename) { + std::ifstream file(filename); + if (file.good()) { + std::stringstream data; + data << file.rdbuf(); + return data.str(); + } else { + throw std::runtime_error("Cannot read file " + filename); + } +} + +} +}
\ No newline at end of file |