@@ -58,6 +58,28 @@ def test_linux_oc_mqtt_register():
5858 assert (result .test_id == mqtt_testid .TEST_OC_MQTT_REGISTER )
5959 assert (result .ret_code == 0 )
6060
61+
62+ # typedef enum
63+ # {
64+ # en_oc_mqtt_err_ok = 0, ///< this means the status ok
65+ # en_oc_mqtt_err_parafmt, ///< this means the parameter err format
66+ # en_oc_mqtt_err_network, ///< this means the network wrong status
67+ # en_oc_mqtt_err_conversion, ///< this means the mqtt version err
68+ # en_oc_mqtt_err_conclientid, ///< this means the client id is err
69+ # en_oc_mqtt_err_conserver, ///< this means the server refused the service for some reason(likely the id and pwd)
70+ # en_oc_mqtt_err_conuserpwd, ///< bad user name or passwd
71+ # en_oc_mqtt_err_conclient, ///< the client id /user/pwd is right, but does not allowed
72+ # en_oc_mqtt_err_subscribe, ///< this means subscribe the topic failed
73+ # en_oc_mqtt_err_publish, ///< this means subscribe the topic failed
74+ # en_oc_mqtt_err_configured, ///< this means we has configured, please deconfigured it and then do configure again
75+ # en_oc_mqtt_err_noconfigured, ///< this means we have not configure it yet,so could not connect
76+ # en_oc_mqtt_err_noconected, ///< this means the connection has not been built, so you could not send data
77+ # en_oc_mqtt_err_gethubaddrtimeout, ///< this means get the hub address timeout
78+ # en_oc_mqtt_err_sysmem, ///< this means the system memory is not enough
79+ # en_oc_mqtt_err_system, ///< this means that the system porting may have some problem,maybe not install yet
80+ # en_oc_mqtt_err_last,
81+ # }en_oc_mqtt_err_code_t;
82+
6183def test_linux_oc_mqtt_config_invalid ():
6284 fname = sys ._getframe ().f_code .co_name
6385 #invalid server ip
@@ -68,7 +90,7 @@ def test_linux_oc_mqtt_config_invalid():
6890 CB_NAME )
6991 assert (result )
7092 assert (result .test_id == mqtt_testid .TEST_OC_MQTT_CONFIG )
71- assert (result .ret_code == - 1 )
93+ assert (result .ret_code == 1 ) #en_oc_mqtt_err_parafmt
7294
7395 # invalid server port
7496 result = ts_call_single (mqtt_testid .TEST_OC_MQTT_CONFIG , fname ,
@@ -78,7 +100,7 @@ def test_linux_oc_mqtt_config_invalid():
78100 CB_NAME )
79101 assert (result )
80102 assert (result .test_id == mqtt_testid .TEST_OC_MQTT_CONFIG )
81- assert (result .ret_code == - 1 )
103+ assert (result .ret_code == 1 ) #en_oc_mqtt_err_parafmt
82104
83105 # invalid security type
84106 result = ts_call_single (mqtt_testid .TEST_OC_MQTT_CONFIG , fname ,
@@ -88,7 +110,7 @@ def test_linux_oc_mqtt_config_invalid():
88110 CB_NAME )
89111 assert (result )
90112 assert (result .test_id == mqtt_testid .TEST_OC_MQTT_CONFIG )
91- assert (result .ret_code == - 1 )
113+ assert (result .ret_code == 1 ) #en_oc_mqtt_err_parafmt
92114
93115
94116 # invalid ep name
@@ -99,7 +121,7 @@ def test_linux_oc_mqtt_config_invalid():
99121 CB_NAME )
100122 assert (result )
101123 assert (result .test_id == mqtt_testid .TEST_OC_MQTT_CONFIG )
102- assert (result .ret_code == - 1 )
124+ assert (result .ret_code == 1 ) #en_oc_mqtt_err_parafmt
103125
104126 # invalid passwd
105127 result = ts_call_single (mqtt_testid .TEST_OC_MQTT_CONFIG , fname ,
@@ -109,7 +131,7 @@ def test_linux_oc_mqtt_config_invalid():
109131 CB_NAME )
110132 assert (result )
111133 assert (result .test_id == mqtt_testid .TEST_OC_MQTT_CONFIG )
112- assert (result .ret_code == - 1 )
134+ assert (result .ret_code == 1 ) #en_oc_mqtt_err_parafmt
113135
114136
115137
@@ -260,126 +282,6 @@ def test_linux_oc_mqtt_deconfig_static():
260282 # assert (status == "OFFLINE")
261283 print (status )
262284
263-
264- def test_linux_oc_mqtt_config_bs ():
265- fname = sys ._getframe ().f_code .co_name
266- result = ts_call_single (mqtt_testid .TEST_OC_MQTT_CONFIG , fname ,
267- en_oc_boot_strap_mode_client_initialize , LIFE_TIME ,
268- BS_SERVER_IP4 , BS_SERVER_PORT , SEC_TYPE ,
269- mqtt_device_info .BS_MQTT_EP_USER , mqtt_device_info .BS_MQTT_EP_PASSWD ,
270- CB_NAME )
271- assert (result )
272- assert (result .test_id == mqtt_testid .TEST_OC_MQTT_CONFIG )
273- assert (result .ret_code == 0 )
274- time .sleep (2 )
275- # oc_mqtt_device_status_jduge_b(mqtt_device_info.BS_MQTT_DEVICEID, "ONLINE")
276-
277- def test_linux_oc_mqtt_json_fmt_req_bs ():
278- fname = sys ._getframe ().f_code .co_name
279- #must send 4 items here
280- result = ts_call_single (mqtt_testid .TEST_OC_MQTT_JSON_FMT_REQ , fname ,
281- "LED" , 0 , #LED is serviceId,0 means en_oc_mqtt_has_more_no
282- "LED1" , 0 , 1 ,#LED1 is item name, 0 means en_key_value_type_int, 1 means value
283- "LED2" , 0 , 2 ,
284- "LED3" , 0 , 35 ,
285- "LED4" , 0 , 78
286- )
287- assert (result )
288- assert (result .test_id == mqtt_testid .TEST_OC_MQTT_JSON_FMT_REQ )
289- assert (result .ret_code == 1 )
290- print ("----------------------------------------------" )
291- print ("hhhh" )
292- print (json .loads (result .data ).get ("data" )[0 ])
293- print ("----------------------------------------------" )
294- # typedef enum
295- # {
296- # en_oc_mqtt_has_more_no = 0,
297- # en_oc_mqtt_has_more_yes = 1,
298- # }en_oc_mqtt_has_more;
299- # typedef enum
300- # {
301- # en_key_value_type_int = 0,
302- # en_key_value_type_string,
303- # en_key_value_type_array,
304- # }en_value_type;
305- # parase received json data
306- # {
307- # "msgType": "deviceReq",
308- # "hasMore": 0,
309- # "data": [{
310- # "serviceId": "LED",
311- # "serviceData": {
312- # "LED1": 1,
313- # "LED2": 2,
314- # "LED2": 35,
315- # "LED2": 78
316- # }
317- # }]
318- # }
319-
320- assert (json .loads (result .data ).get ("msgType" ) == "deviceReq" )
321- assert (json .loads (result .data ).get ("hasMore" ) == 0 )
322- data = json .loads (result .data ).get ("data" )[0 ]
323- assert (data ["serviceId" ] == "LED" )
324- print ("+++++++++++++++++++++++++++++++++++++++++++" )
325- print (result .data )
326- print (data )
327- print (data ["serviceData" ])
328- print ("+++++++++++++++++++++++++++++++++++++++++++" )
329- assert (data .get ("serviceData" ).get ("LED1" ) == 1 )
330- assert (data .get ("serviceData" ).get ("LED2" ) == 2 )
331- assert (data .get ("serviceData" ).get ("LED3" ) == 35 )
332- assert (data .get ("serviceData" ).get ("LED4" ) == 78 )
333-
334-
335- def test_linux_oc_mqtt_json_fmt_res_bs ():
336- fname = sys ._getframe ().f_code .co_name
337- # must send 1 items here
338- result = ts_call_single (mqtt_testid .TEST_OC_MQTT_JSON_FMT_RES , fname ,
339- 0 , 0 , 1 , # 0 means en_oc_mqtt_has_more_no, second means no error, 1 means mid
340- "body_para" , 1 , "body_para" # body_para is item name, second means string type, third means value
341- )
342- print (result )
343- assert (result )
344- assert (result .test_id == mqtt_testid .TEST_OC_MQTT_JSON_FMT_RES )
345- assert (result .ret_code == 1 )
346- print (result .data )
347-
348- # {
349- # "msgType": "deviceRsp",
350- # "mid": 1,
351- # "errcode": 0,
352- # "hasMore": 0,
353- # "body": {
354- # "body_para": "body_para"
355- # }
356- # }
357-
358- assert (json .loads (result .data ).get ("msgType" ) == "deviceRsp" )
359- assert (json .loads (result .data ).get ("mid" ) == 1 )
360- assert (json .loads (result .data ).get ("errcode" ) == 0 )
361- assert (json .loads (result .data ).get ("hasMore" ) == 0 )
362- assert (json .loads (result .data ).get ("body" ).get ("body_para" ) == "body_para" )
363-
364-
365- def test_linux_oc_mqtt_publish_bs ():
366- fname = sys ._getframe ().f_code .co_name
367- result = ts_call_single (mqtt_testid .TEST_OC_MQTT_PUBLISH , fname )
368- assert (result )
369- assert (result .test_id == mqtt_testid .TEST_OC_MQTT_PUBLISH )
370- assert (result .ret_code == 0 )
371-
372- def test_linux_oc_mqtt_deconfig_bs ():
373- fname = sys ._getframe ().f_code .co_name
374- result = ts_call_single (mqtt_testid .TEST_OC_MQTT_DECONFIG , fname )
375- assert (result )
376- assert (result .test_id == mqtt_testid .TEST_OC_MQTT_DECONFIG )
377- assert (result .ret_code == 0 )
378- time .sleep (15 )
379- # oc_mqtt_device_status_jduge_b(mqtt_device_info.BS_MQTT_DEVICEID, "OFFLINE")
380-
381-
382-
383285def test_linux_oc_mqtt_deinit ():
384286 fname = sys ._getframe ().f_code .co_name
385287 result = ts_call_single (mqtt_testid .TEST_OC_MQTT_DEINIT , fname )
@@ -394,16 +296,11 @@ def test_linux_oc_mqtt_deinit():
394296 print ("hello world" )
395297 test_linux_oc_mqtt_init ()
396298 test_linux_oc_mqtt_register ()
397- # test_linux_oc_mqtt_config_invalid()
299+ test_linux_oc_mqtt_config_invalid ()
398300 test_linux_oc_mqtt_config_static ()
399- # test_linux_oc_mqtt_json_fmt_req_static()
400- # test_linux_oc_mqtt_json_fmt_res_static()
401- # test_linux_oc_mqtt_report_static ()
301+ test_linux_oc_mqtt_json_fmt_req_static ()
302+ test_linux_oc_mqtt_json_fmt_res_static ()
303+ test_linux_oc_mqtt_publish_static ()
402304 test_linux_oc_mqtt_sendcmd_static ()
403305 test_linux_oc_mqtt_deconfig_static ()
404- # test_linux_oc_mqtt_config_bs()
405- # test_linux_oc_mqtt_json_fmt_req_bs()
406- # test_linux_oc_mqtt_json_fmt_res_bs()
407- # test_linux_oc_mqtt_report_bs()
408- # test_linux_oc_mqtt_deconfig_bs()
409306 test_linux_oc_mqtt_deinit ()
0 commit comments