2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to you under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
* implied. See the License for the specific language governing
15
* permissions and limitations under the License.
19
#include "avro_private.h"
25
avro_writer_t avro_stderr;
27
static void test_helper(const char *json,
29
avro_schema_t expected)
33
avro_schema_error_t serror;
35
rc = avro_schema_from_json(json, strlen(json), &base, &serror);
39
"Error parsing Avro schema:\n%s\n",
44
avro_schema_t actual =
45
avro_schema_get_subschema(base, name);
50
"No subschema named \"%s\" in %s\n",
51
name, avro_schema_type_name(base));
55
if (!avro_schema_equal(actual, expected))
58
"Subschema \"%s\" should be %s, "
61
avro_schema_type_name(expected),
62
avro_schema_type_name(actual));
66
avro_schema_decref(base);
67
avro_schema_decref(expected);
70
static void test_array_schema_01()
74
" \"type\": \"array\","
75
" \"items\": \"long\""
78
test_helper(JSON, "[]", avro_schema_long());
81
static void test_map_schema_01()
86
" \"values\": \"long\""
89
test_helper(JSON, "{}", avro_schema_long());
92
static void test_record_schema_01()
96
" \"type\": \"record\","
97
" \"name\": \"test\","
99
" { \"name\": \"a\", \"type\": \"long\" }"
103
test_helper(JSON, "a", avro_schema_long());
106
static void test_union_schema_01()
112
" \"type\": \"record\","
113
" \"name\": \"test\","
115
" { \"name\": \"a\", \"type\": \"long\" }"
120
test_helper(JSON, "long", avro_schema_long());
123
int main(int argc, char *argv[])
128
test_array_schema_01();
130
test_map_schema_01();
132
test_record_schema_01();
134
test_union_schema_01();