util/uri.c: remove brackets that wrap `return` statement's content.
[qemu.git] / tests / qapi-schema / test-qapi.py
blobac43d3458eac29b12d7edcd5f5fcd1355e2d9854
2 # QAPI parser test harness
4 # Copyright (c) 2013 Red Hat Inc.
6 # Authors:
7 # Markus Armbruster <armbru@redhat.com>
9 # This work is licensed under the terms of the GNU GPL, version 2 or later.
10 # See the COPYING file in the top-level directory.
13 from __future__ import print_function
14 from qapi import *
15 from pprint import pprint
16 import os
17 import sys
20 class QAPISchemaTestVisitor(QAPISchemaVisitor):
21 def visit_enum_type(self, name, info, values, prefix):
22 print('enum %s %s' % (name, values))
23 if prefix:
24 print(' prefix %s' % prefix)
26 def visit_object_type(self, name, info, base, members, variants):
27 print('object %s' % name)
28 if base:
29 print(' base %s' % base.name)
30 for m in members:
31 print(' member %s: %s optional=%s' % \
32 (m.name, m.type.name, m.optional))
33 self._print_variants(variants)
35 def visit_alternate_type(self, name, info, variants):
36 print('alternate %s' % name)
37 self._print_variants(variants)
39 def visit_command(self, name, info, arg_type, ret_type,
40 gen, success_response, boxed):
41 print('command %s %s -> %s' % \
42 (name, arg_type and arg_type.name, ret_type and ret_type.name))
43 print(' gen=%s success_response=%s boxed=%s' % \
44 (gen, success_response, boxed))
46 def visit_event(self, name, info, arg_type, boxed):
47 print('event %s %s' % (name, arg_type and arg_type.name))
48 print(' boxed=%s' % boxed)
50 @staticmethod
51 def _print_variants(variants):
52 if variants:
53 print(' tag %s' % variants.tag_member.name)
54 for v in variants.variants:
55 print(' case %s: %s' % (v.name, v.type.name))
57 schema = QAPISchema(sys.argv[1])
58 schema.visit(QAPISchemaTestVisitor())
60 for doc in schema.docs:
61 if doc.symbol:
62 print('doc symbol=%s' % doc.symbol)
63 else:
64 print('doc freeform')
65 print(' body=\n%s' % doc.body.text)
66 for arg, section in doc.args.items():
67 print(' arg=%s\n%s' % (arg, section.text))
68 for section in doc.sections:
69 print(' section=%s\n%s' % (section.name, section.text))