1from __future__ import unicode_literals
2
3import re
4import textwrap
5
6import ttfw_idf
7
8
9@ttfw_idf.idf_example_test(env_tag='Example_WIFI_Protocols')
10def test_examples_cbor(env, extra_data):
11
12    dut = env.get_dut('cbor', 'examples/protocols/cbor')
13    dut.start_app()
14    dut.expect(re.compile(r'example: encoded buffer size \d+'))
15    dut.expect('example: convert CBOR to JSON')
16    parsed_info = dut.expect(re.compile(r'\[\{"chip":"(\w+)","unicore":(\w+),"ip":\[(\d+),(\d+),(\d+),(\d+)\]\},'
17                                        r'3.1400001049041748'
18                                        r',"simple\(99\)","2019-07-10 09:00:00\+0000","undefined"\]'))
19    dut.expect('example: decode CBOR manually')
20
21    dut.expect(re.compile(textwrap.dedent(r'''
22                                           Array\[\s+
23                                             Map{{\s+
24                                               chip\s+
25                                               {}\s+
26                                               unicore\s+
27                                               {}\s+
28                                               ip\s+
29                                               Array\[\s+
30                                                 {}\s+
31                                                 {}\s+
32                                                 {}\s+
33                                                 {}\s+
34                                               \]\s+
35                                             }}\s+
36                                             3.14\s+
37                                             simple\(99\)\s+
38                                             2019-07-10 09:00:00\+0000\s+
39                                             undefined\s+
40                                           \]'''.format(*parsed_info)).replace('{', r'\{').replace('}', r'\}')))
41
42
43if __name__ == '__main__':
44    test_examples_cbor()
45