1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#define SIMDJSON_VERBOSE_LOGGING 1
#include "simdjson.h"
#include "test_ondemand.h"
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace simdjson;
namespace log_error_tests {
#if SIMDJSON_EXCEPTIONS
using namespace std;
bool tape_error()
{
TEST_START();
auto json = R"( {"a", "hello"} )"_padded;
ondemand::parser parser;
try {
ondemand::document doc = parser.iterate(json);
std::cout << doc["a"] << std::endl;
TEST_FAIL("Should have thrown an exception!")
} catch (simdjson_error& e) {
ASSERT_ERROR(e.error(), TAPE_ERROR);
}
TEST_SUCCEED();
}
bool no_such_field()
{
TEST_START();
auto json = R"( {"a": "hello"} )"_padded;
ondemand::parser parser;
try {
ondemand::document doc = parser.iterate(json);
std::cout << doc["missing_key"] << std::endl;
TEST_FAIL("Should have thrown an exception!")
} catch (simdjson_error& e) {
ASSERT_ERROR(e.error(), NO_SUCH_FIELD);
}
TEST_SUCCEED();
}
#endif // SIMDJSON_EXCEPTIONS
bool run()
{
SIMDJSON_PUSH_DISABLE_WARNINGS
SIMDJSON_DISABLE_DEPRECATED_WARNING // Disable CRT_SECURE warning on MSVC: manually verified this is safe
std::string str = "SIMDJSON_LOG_LEVEL=ERROR";
putenv(str.data());
bool rc =
#if SIMDJSON_EXCEPTIONS
tape_error() &&
no_such_field() &&
#endif // #if SIMDJSON_EXCEPTIONS
true;
SIMDJSON_POP_DISABLE_WARNINGS
return rc;
}
}
int main(int argc, char *argv[]) {
return test_main(argc, argv, log_error_tests::run);
}
|