ReactOS 0.4.16-dev-340-g0540c21
test_mqtt.c
Go to the documentation of this file.
1#include "test_mqtt.h"
2
3#include "lwip/pbuf.h"
4#include "lwip/apps/mqtt.h"
6#include "lwip/netif.h"
7
8const ip_addr_t test_mqtt_local_ip = IPADDR4_INIT_BYTES(192, 168, 1, 1);
9const ip_addr_t test_mqtt_remote_ip = IPADDR4_INIT_BYTES(192, 168, 1, 2);
10const ip_addr_t test_mqtt_netmask = IPADDR4_INIT_BYTES(255, 255, 255, 0);
11
12static err_t test_mqtt_netif_output(struct netif *netif, struct pbuf *p,
13 const ip4_addr_t *ipaddr)
14{
16 LWIP_UNUSED_ARG(ipaddr);
18 return ERR_OK;
19}
20
21static void
22test_mqtt_init_netif(struct netif *netif, const ip_addr_t *ip_addr, const ip_addr_t *netmask)
23{
24 struct netif *n;
25 memset(netif, 0, sizeof(struct netif));
28 ip_addr_copy_from_ip4(netif->netmask, *ip_2_ip4(netmask));
29 ip_addr_copy_from_ip4(netif->ip_addr, *ip_2_ip4(ip_addr));
30 for (n = netif_list; n != NULL; n = n->next) {
31 if (n == netif) {
32 return;
33 }
34 }
35 netif->next = NULL;
37}
38
39/* Setups/teardown functions */
40static struct netif *old_netif_list;
41static struct netif *old_netif_default;
42
43static void
45{
50 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
51}
52
53static void
55{
58 /* restore netif_list for next tests (e.g. loopif) */
61 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
62}
63
65{
69}
70
71START_TEST(basic_connect)
72{
74 struct netif netif;
75 err_t err;
77 "dumm",
78 NULL, NULL,
79 10,
80 NULL, NULL, 0, 0
81 };
82 struct pbuf *p;
83 unsigned char rxbuf[] = {0x20, 0x02, 0x00, 0x00};
85
87
89 fail_unless(client != NULL);
91 fail_unless(err == ERR_OK);
92
93 client->conn->connected(client->conn->callback_arg, client->conn, ERR_OK);
94 p = pbuf_alloc(PBUF_RAW, sizeof(rxbuf), PBUF_REF);
95 fail_unless(p != NULL);
96 p->payload = rxbuf;
97 /* since we hack the rx path, we have to hack the rx window, too: */
98 client->conn->rcv_wnd -= p->tot_len;
99 if (client->conn->recv(client->conn->callback_arg, client->conn, p, ERR_OK) != ERR_OK) {
100 pbuf_free(p);
101 }
102
104 /* fixme: mqtt_client_fre() is missing... */
106}
107END_TEST
108
109Suite* mqtt_suite(void)
110{
111 testfunc tests[] = {
112 TESTFUNC(basic_connect),
113 };
114 return create_suite("MQTT", tests, sizeof(tests)/sizeof(testfunc), mqtt_setup, mqtt_teardown);
115}
#define START_TEST(x)
Definition: atltest.h:75
#define mem_free(ptr, bsize)
Definition: types.h:124
#define NULL
Definition: types.h:112
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
s8_t err_t
Definition: err.h:96
@ ERR_OK
Definition: err.h:55
mqtt_connection_status_t
Definition: mqtt.h:96
#define NETIF_FLAG_LINK_UP
Definition: netif.h:93
#define NETIF_FLAG_UP
Definition: netif.h:84
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:224
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:727
@ PBUF_REF
Definition: pbuf.h:160
@ PBUF_RAW
Definition: pbuf.h:111
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define SKIP_POOL(x)
Definition: lwip_check.h:48
void lwip_check_ensure_no_alloc(unsigned int skip)
#define TESTFUNC(x)
Definition: lwip_check.h:22
static struct test_info tests[]
void mqtt_disconnect(mqtt_client_t *client)
err_t mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ipaddr, u16_t port, mqtt_connection_cb_t cb, void *arg, const struct mqtt_connect_client_info_t *client_info)
mqtt_client_t * mqtt_client_new(void)
struct netif * netif_list
Definition: netif.c:113
struct netif * netif_default
Definition: netif.c:115
#define err(...)
#define memset(x, y, z)
Definition: compat.h:39
static FILE * client
Definition: client.c:41
struct define * next
Definition: compiler.c:65
Definition: netif.h:269
u8_t flags
Definition: netif.h:354
struct netif * next
Definition: netif.h:272
Definition: pbuf.h:186
Definition: ps.c:97
const ip_addr_t test_mqtt_remote_ip
Definition: test_mqtt.c:9
const ip_addr_t test_mqtt_local_ip
Definition: test_mqtt.c:8
static struct netif * old_netif_list
Definition: test_mqtt.c:40
static struct netif * old_netif_default
Definition: test_mqtt.c:41
static void mqtt_teardown(void)
Definition: test_mqtt.c:54
END_TEST Suite * mqtt_suite(void)
Definition: test_mqtt.c:109
static err_t test_mqtt_netif_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
Definition: test_mqtt.c:12
static void test_mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status)
Definition: test_mqtt.c:64
static void test_mqtt_init_netif(struct netif *netif, const ip_addr_t *ip_addr, const ip_addr_t *netmask)
Definition: test_mqtt.c:22
const ip_addr_t test_mqtt_netmask
Definition: test_mqtt.c:10
static void mqtt_setup(void)
Definition: test_mqtt.c:44