diff --git a/parsers/test_jsonpp_0_1_1/.gitignore b/parsers/test_jsonpp_0_1_1/.gitignore new file mode 100644 index 0000000..de5537b --- /dev/null +++ b/parsers/test_jsonpp_0_1_1/.gitignore @@ -0,0 +1,2 @@ +# src files +jsonpp/* \ No newline at end of file diff --git a/parsers/test_jsonpp_0_1_1/bin/test_jsonpp b/parsers/test_jsonpp_0_1_1/bin/test_jsonpp new file mode 100755 index 0000000..69cb110 Binary files /dev/null and b/parsers/test_jsonpp_0_1_1/bin/test_jsonpp differ diff --git a/parsers/test_jsonpp_0_1_1/build.sh b/parsers/test_jsonpp_0_1_1/build.sh new file mode 100755 index 0000000..a342bc6 --- /dev/null +++ b/parsers/test_jsonpp_0_1_1/build.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +# get the absolute path of the script +BASE_DIR="$(cd "$(dirname "$0")" && pwd)" +SRC_URL="https://github.com/mikami-w/jsonpp/archive/refs/tags/v0.1.1.tar.gz" + +echo "[JSONpp] Preparing directories..." +# for storing source code +mkdir -p "$BASE_DIR/jsonpp" +# for storing binaries +mkdir -p "$BASE_DIR/bin" + +echo "[JSONpp] Downloading source code..." +if command -v curl >/dev/null 2>&1; then + curl -L "$SRC_URL" -o "$BASE_DIR/jsonpp.tar.gz" +elif command -v wget >/dev/null 2>&1; then + wget "$SRC_URL" -O "$BASE_DIR/jsonpp.tar.gz" +else + echo "Error: Neither curl nor wget found." + exit 1 +fi + +echo "[JSONpp] Extracting..." +tar -xzf "$BASE_DIR/jsonpp.tar.gz" --strip-components=1 -C "$BASE_DIR/jsonpp" + +echo "[JSONpp] Compiling..." + +# input: $BASE_DIR/test_jsonpp/main.cpp +# output: $BASE_DIR/bin/test_jsonpp +# headers: $BASE_DIR/jsonpp/src +g++ "$BASE_DIR/test_jsonpp/main.cpp" \ + -o "$BASE_DIR/bin/test_jsonpp" \ + -std=c++17 \ + -I"$BASE_DIR/jsonpp/src" + +rm "$BASE_DIR/jsonpp.tar.gz" + +echo "[JSONpp] Build success!" +echo "Binary location: $BASE_DIR/bin/test_jsonpp" \ No newline at end of file diff --git a/parsers/test_jsonpp_0_1_1/test_jsonpp/main.cpp b/parsers/test_jsonpp_0_1_1/test_jsonpp/main.cpp new file mode 100644 index 0000000..6804909 --- /dev/null +++ b/parsers/test_jsonpp_0_1_1/test_jsonpp/main.cpp @@ -0,0 +1,35 @@ +#include "jsonpp.hpp" + +#include +#include +#include + +std::string readFile(std::string_view filename) { + std::ifstream file(filename.data()); + if (!file.is_open()) { + throw std::runtime_error("Could not open file"); + } + std::string content( + (std::istreambuf_iterator(file)), + (std::istreambuf_iterator()) + ); + file.close(); + return content; +} + +int main(int argc, const char **argv) +{ + using namespace JSONpp; + char const* path = argv[1]; + auto data = readFile(path); + try + { + auto j = json::parse(data); + if (j.empty()) + return 1; + return 0; + } catch (const JsonException& e) + { + return 1; + } +} \ No newline at end of file diff --git a/run_tests.py b/run_tests.py index 462edb6..6c67ed9 100755 --- a/run_tests.py +++ b/run_tests.py @@ -518,6 +518,11 @@ { "url":"https://github.com/nlohmann/json", "commands":[os.path.join(PARSERS_DIR, "test_nlohmann_json_20190718/bin/test_nlohmann_json")] + }, + "C++ Jsonpp v0.1.1": + { + "url":"https://github.com/mikami-w/jsonpp", + "commands":[os.path.join(PARSERS_DIR, "test_jsonpp_0_1_1/bin/test_jsonpp")] } }