Debian Codegraph @

python/tests/interop-generate

raw
1 #!/usr/bin/env python
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing,
14 # software distributed under the License is distributed on an
15 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 # KIND, either express or implied. See the License for the
17 # specific language governing permissions and limitations
18 # under the License.
19 #
20
21 # Generate encoded AMQP fragments for interop testing.
22
23 import logging, optparse, os, struct, sys, time, traceback, types, cgi
24 from proton import *
25
26 def main(argv):
27
28 def write(data, filename):
29 f = open(filename+".amqp", 'w')
30 f.write(data.encode())
31 f.close()
32
33 # message
34 m = Message()
35 d = Data()
36 d.put_string("hello")
37 m.body = d.encode()
38 write(m, "message")
39
40 # null
41 d = Data()
42 d.put_null()
43 write(d, "null")
44
45 # primitive types
46 d = Data()
47 d.put_bool(True)
48 d.put_bool(False)
49 d.put_ubyte(42)
50 d.put_ushort(42)
51 d.put_short(-42)
52 d.put_uint(12345)
53 d.put_int(-12345)
54 d.put_ulong(12345)
55 d.put_long(-12345)
56 d.put_float(0.125)
57 d.put_double(0.125)
58 write(d, "primitives")
59
60 # string types
61 d = Data()
62 d.put_binary("abc\0defg")
63 d.put_string("abcdefg")
64 d.put_symbol("abcdefg")
65 d.put_binary("")
66 d.put_string("")
67 d.put_symbol("")
68 write(d, "strings")
69
70 # described types
71 d = Data()
72 d.put_described()
73 d.enter()
74 d.put_symbol("foo-descriptor")
75 d.put_string("foo-value")
76 d.exit()
77
78 d.put_described()
79 d.enter()
80 d.put_int(12)
81 d.put_int(13)
82 d.exit()
83
84 write(d, "described")
85
86 # described array
87 d = Data()
88 d.put_array(True, Data.INT)
89 d.enter()
90 d.put_symbol("int-array")
91 for i in xrange(0,10): d.put_int(i)
92 d.exit()
93 write(d, "described_array")
94
95
96 # Arrays
97
98 # Integer array
99 d = Data()
100 d.put_array(False, Data.INT)
101 d.enter()
102 for i in xrange(0,100): d.put_int(i)
103 d.exit()
104
105 # String array
106 d.put_array(False, Data.STRING)
107 d.enter()
108 for i in ["a", "b", "c"]: d.put_string(i)
109 d.exit()
110
111 # empty array
112 d.put_array(False, Data.INT)
113
114 write(d, "arrays")
115
116 # List - mixed types
117 d = Data()
118 d.put_list()
119 d.enter()
120 d.put_int(32)
121 d.put_string("foo")
122 d.put_bool(True)
123 d.exit()
124
125 d.put_list() # Empty list
126 write(d, "lists")
127
128 # Maps
129 d = Data()
130 d.put_map()
131 d.enter()
132 for k,v in {"one":1, "two":2, "three":3}.items():
133 d.put_string(k)
134 d.put_int(v)
135 d.exit()
136
137 d.put_map()
138 d.enter()
139 for k,v in {1:"one", 2:"two", 3:"three"}.items():
140 d.put_int(k)
141 d.put_string(v)
142 d.exit()
143
144 d.put_map() # Empty map
145 write(d, "maps")
146
147 return 0
148
149 if __name__ == "__main__":
150 sys.exit(main(sys.argv))