1 # ==================================================================================
2 # Copyright (c) 2019 Nokia
3 # Copyright (c) 2018-2019 AT&T Intellectual Property.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # 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 implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
28 MRC = rmr.rmr_init(b"4562", rmr.RMR_MAX_RCV_BYTES, 0x00)
29 while rmr.rmr_ready(MRC) == 0:
33 def teardown_module():
37 def _assert_new_sbuf(sbuf):
39 verify the initial state of an alloced message is what we expect
41 summary = rmr.message_summary(sbuf)
42 assert summary["payload"] == b""
43 assert summary["payload length"] == 0
44 assert summary["transaction id"] == b""
45 assert summary["message state"] == 0
46 assert summary["message status"] == "RMR_OK"
47 assert summary["meid"] is None
48 assert summary["errno"] == 0
51 def test_get_constants(expected_constants):
53 test getting constants
55 assert rmr._get_constants() == expected_constants
58 def test_get_mapping_dict(expected_states):
60 test getting mapping string
62 assert rmr._get_mapping_dict() == expected_states
63 assert rmr._state_to_status(0) == "RMR_OK"
64 assert rmr._state_to_status(12) == "RMR_ERR_TIMEOUT"
65 assert rmr._state_to_status(666) == "UNKNOWN STATE"
68 def test_meid_prettify():
70 test the printing of meid based on it's value
72 # TODO?? weirdness: setting it takes bytes, but getting it returns a string. This does NOT happen for payload; bytes in, bytes come out.
73 sbuf = rmr.rmr_alloc_msg(MRC, SIZE)
74 rmr.rmr_set_meid(sbuf, b"\x00" * 32, 32)
75 summary = rmr.message_summary(sbuf)
76 assert summary["meid"] is None # summary does a pretty print" of 32 null bytes
77 assert rmr.get_meid(sbuf) == "\x00" * 32 # real underlying value
80 def test_rmr_set_get():
84 sbuf = rmr.rmr_alloc_msg(MRC, SIZE)
85 _assert_new_sbuf(sbuf)
89 rmr.set_payload_and_length(pay, sbuf)
90 summary = rmr.message_summary(sbuf)
91 assert summary["payload"] == pay
92 assert summary["payload length"] == 3
94 # test transid (note we cant test payload because it's randomly gen)
95 assert summary["transaction id"] == b""
96 assert len(summary["transaction id"]) == 0
97 rmr.generate_and_set_transaction_id(sbuf)
98 summary = rmr.message_summary(sbuf)
99 assert summary["transaction id"] != b""
100 assert len(summary["transaction id"]) == 32
103 assert rmr.get_meid(sbuf) == "\x00" * 32
104 assert summary["meid"] is None # the summary printing function shows the above horridness as None
105 rmr.rmr_set_meid(sbuf, b"666", 3)
106 summary = rmr.message_summary(sbuf)
107 # TODO?? weirdness: setting it takes bytes, but getting it returns a string. This does NOT happen for payload; bytes in, bytes come out.
108 assert rmr.get_meid(sbuf) == summary["meid"] == "666" + "\x00" * 29