Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions parsers/test_jsonpp_0_1_1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# src files
jsonpp/*
Binary file added parsers/test_jsonpp_0_1_1/bin/test_jsonpp
Binary file not shown.
40 changes: 40 additions & 0 deletions parsers/test_jsonpp_0_1_1/build.sh
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 35 additions & 0 deletions parsers/test_jsonpp_0_1_1/test_jsonpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "jsonpp.hpp"

#include <string>
#include <fstream>
#include <iterator>

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<char>(file)),
(std::istreambuf_iterator<char>())
);
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;
}
}
5 changes: 5 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
}
}

Expand Down