1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "aos/kernel.h"
4 #include "uagent.h"
5 #include "aos/errno.h"
6 #if AOS_COMP_CLI
7 #include "aos/cli.h"
8 #endif
9 
test_uagent_register_normal(void)10 static int test_uagent_register_normal(void)
11 {
12     const int ret = uagent_register(UAGENT_MOD_ULOG, "ulog",
13             "", UAGENT_FUNC_USER_BASE, "dummy",
14             NULL, NULL);
15     return ret;
16 }
17 
test_uagent_register_error_input(void)18 static int test_uagent_register_error_input(void)
19 {
20     const int ret = uagent_register(UAGENT_MOD_ULOG, NULL,
21             NULL, UAGENT_FUNC_USER_BASE, NULL,
22             NULL, NULL);
23     return ret;
24 }
25 
test_uagent_unregister_normal(void)26 static int test_uagent_unregister_normal(void)
27 {
28     const int ret = uagent_unregister(UAGENT_MOD_ULOG, UAGENT_FUNC_USER_BASE);
29 
30     return ret;
31 }
32 
test_uagent_request_service_normal(void)33 static int test_uagent_request_service_normal(void)
34 {
35     const int ret = uagent_request_service(UAGENT_MOD_UAGENT, UAGENT_MOD_ULOG, UAGENT_FUNC_USER_BASE, strlen("ulog level=5") + 1, "ulog level=5");
36 
37     return ret;
38 }
39 
test_uagent_request_service_error_input_1(void)40 static int test_uagent_request_service_error_input_1(void)
41 {
42     const int ret = uagent_request_service(UAGENT_MOD_UAGENT, UAGENT_MOD_ULOG, UAGENT_FUNC_USER_BASE, 12, NULL);
43 
44     return ret;
45 }
46 
test_uagent_request_service_error_input_2(void)47 static int test_uagent_request_service_error_input_2(void)
48 {
49     const int ret = uagent_request_service(UAGENT_MOD_UAGENT, UAGENT_MOD_ULOG, UAGENT_FUNC_USER_BASE, 65535, "ulog level=5");
50 
51     return ret;
52 }
53 
test_uagent_send_normal(void)54 static int test_uagent_send_normal(void)
55 {
56     const int ret = uagent_send(UAGENT_MOD_ULOG, UAGENT_FUNC_USER_BASE, strlen("helloworld") + 1, "helloworld", 0);
57     return ret;
58 }
59 
test_uagent_send_error_input(void)60 static int test_uagent_send_error_input(void)
61 {
62     const int ret = uagent_send(UAGENT_MOD_ULOG, UAGENT_FUNC_USER_BASE, strlen("helloworld") + 1, NULL, 0);
63     return ret;
64 }
65 
test_uagent_ext_comm_start_normal(char * pk,char * dn)66 static int test_uagent_ext_comm_start_normal(char *pk, char *dn)
67 {
68     const int ret = uagent_ext_comm_start(pk, dn);
69     return ret;
70 }
71 
test_uagent_ext_comm_start_error_input(void)72 static int test_uagent_ext_comm_start_error_input(void)
73 {
74     const int ret = uagent_ext_comm_start(NULL, NULL);
75     return ret;
76 }
77 
test_uagent_init(void * handle,char * pk,char * dn)78 int test_uagent_init(void *handle, char *pk, char *dn)
79 {
80     int ret = 0;
81     ret = uagent_init();
82     if (ret != 0) {
83         printf("uAgent Init Failed ret = %d\n", ret);
84         return ret;
85     }
86     ret = uagent_mqtt_client_set(handle);
87     if (ret != 0) {
88         printf("uAgent mqtt handle set failed ret = %d\n", ret);
89         return ret;
90     }
91     ret = uagent_ext_comm_start(pk, dn);
92     if (ret != 0) {
93         printf("uAgent ext comm  start failed ret = %d\n", ret);
94         return ret;
95     }
96     return 0;
97 }
98 
test_uagent_start(int argc,char ** argv)99 void test_uagent_start(int argc, char **argv)
100 {
101     int ret = 0;
102     ret = test_uagent_register_normal();
103 
104     aos_msleep(2000);
105 
106     ret = test_uagent_register_error_input();
107     aos_msleep(2000);
108 
109     ret = test_uagent_request_service_normal();
110     aos_msleep(2000);
111 
112     ret = test_uagent_request_service_error_input_1();
113     aos_msleep(2000);
114 
115     ret = test_uagent_request_service_error_input_2();
116     aos_msleep(2000);
117 
118     ret = test_uagent_ext_comm_start_error_input();
119     aos_msleep(2000);
120 
121     ret = test_uagent_send_normal();
122     aos_msleep(2000);
123 
124     ret = test_uagent_send_error_input();
125     aos_msleep(2000);
126 
127     ret = test_uagent_unregister_normal();
128     aos_msleep(2000);
129     return 0;
130 }
131 
132 #if AOS_COMP_CLI
133 /* reg args: fun, cmd, description*/
134 ALIOS_CLI_CMD_REGISTER(test_uagent_start, uagent_example, uagent component base example)
135 #endif
136