1b8af0d5eSTrond Norbye/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2b8af0d5eSTrond Norbye/*
3b8af0d5eSTrond Norbye *     Copyright 2014 Couchbase, Inc
4b8af0d5eSTrond Norbye *
5b8af0d5eSTrond Norbye *   Licensed under the Apache License, Version 2.0 (the "License");
6b8af0d5eSTrond Norbye *   you may not use this file except in compliance with the License.
7b8af0d5eSTrond Norbye *   You may obtain a copy of the License at
8b8af0d5eSTrond Norbye *
9b8af0d5eSTrond Norbye *       http://www.apache.org/licenses/LICENSE-2.0
10b8af0d5eSTrond Norbye *
11b8af0d5eSTrond Norbye *   Unless required by applicable law or agreed to in writing, software
12b8af0d5eSTrond Norbye *   distributed under the License is distributed on an "AS IS" BASIS,
13b8af0d5eSTrond Norbye *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14b8af0d5eSTrond Norbye *   See the License for the specific language governing permissions and
15b8af0d5eSTrond Norbye *   limitations under the License.
16b8af0d5eSTrond Norbye */
17b8af0d5eSTrond Norbye
18b8af0d5eSTrond Norbye#include "config.h"
19b8af0d5eSTrond Norbye#include <iostream>
20b8af0d5eSTrond Norbye#include "JSON_checker.h"
21b8af0d5eSTrond Norbye
22b8af0d5eSTrond Norbye#define check(expr, msg) {if(!(expr)) \
23b8af0d5eSTrond Norbye    { std::cerr << "JSON test failed: " << msg << std::endl; exit(1); }}
24b8af0d5eSTrond Norbye#define CHECK_JSON(X) checkUTF8JSON((const unsigned char *)X, sizeof(X) - 1)
25b8af0d5eSTrond Norbye
26b8af0d5eSTrond Norbyeint main(void) {
27b8af0d5eSTrond Norbye    check(CHECK_JSON("{\"test\": 12}"), "simple json checks as OK");
28b8af0d5eSTrond Norbye    check(CHECK_JSON("{\"test\": [[[[[[[[[[[[[[[[[[[[[[12]]]]]]]]]]]]]]]]]]]]]]}"),
29b8af0d5eSTrond Norbye            "deep json checks as OK");
30b8af0d5eSTrond Norbye    check(!CHECK_JSON("{\"test\": [[[[[[[[[[[[[[[[[[[[[[12]]]]]]]]]]]]]]]]]]]]]]]]}"),
31b8af0d5eSTrond Norbye            "bad deep json is not OK");
32b8af0d5eSTrond Norbye    check(!CHECK_JSON("{bad stuff}"), "bad json starting with { is not OK");
33b8af0d5eSTrond Norbye    check(CHECK_JSON("null"), "bare values are OK");
34b8af0d5eSTrond Norbye    check(CHECK_JSON("99"), "bare numbers are OK");
35b8af0d5eSTrond Norbye    check(!CHECK_JSON("{\"test\xFF\": 12}"), "bad UTF-8 is not OK");
36b8af0d5eSTrond Norbye}
37