1 | /* |
2 | * libwebsockets - small server side websockets and web server implementation |
3 | * |
4 | * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to |
8 | * deal in the Software without restriction, including without limitation the |
9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
10 | * sell copies of the Software, and to permit persons to whom the Software is |
11 | * furnished to do so, subject to the following conditions: |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
22 | * IN THE SOFTWARE. |
23 | * |
24 | * This is an abstract transport useful for unit testing abstract protocols. |
25 | * |
26 | * Instead of passing data anywhere, you give the transport a list of packets |
27 | * to deliver and packets you expect back from the abstract protocol it's |
28 | * bound to. |
29 | */ |
30 | |
31 | enum { |
32 | LWS_AUT_EXPECT_TEST_END = (1 << 0), |
33 | LWS_AUT_EXPECT_LOCAL_CLOSE = (1 << 1), |
34 | LWS_AUT_EXPECT_DO_REMOTE_CLOSE = (1 << 2), |
35 | LWS_AUT_EXPECT_TX /* expect this as tx from protocol */ = (1 << 3), |
36 | LWS_AUT_EXPECT_RX /* present this as rx to protocol */ = (1 << 4), |
37 | LWS_AUT_EXPECT_SHOULD_FAIL = (1 << 5), |
38 | LWS_AUT_EXPECT_SHOULD_TIMEOUT = (1 << 6), |
39 | }; |
40 | |
41 | typedef enum { |
42 | LPE_CONTINUE, |
43 | LPE_SUCCEEDED, |
44 | LPE_FAILED, |
45 | LPE_FAILED_UNEXPECTED_TIMEOUT, |
46 | LPE_FAILED_UNEXPECTED_PASS, |
47 | LPE_FAILED_UNEXPECTED_CLOSE, |
48 | LPE_SKIPPED, |
49 | LPE_CLOSING |
50 | } lws_unit_test_packet_disposition; |
51 | |
52 | typedef int (*lws_unit_test_packet_test_cb)(const void *cb_user, int disposition); |
53 | typedef int (*lws_unit_test_packet_cb)(lws_abs_t *instance); |
54 | |
55 | /* each step in the unit test */ |
56 | |
57 | typedef struct lws_unit_test_packet { |
58 | void *buffer; |
59 | lws_unit_test_packet_cb pre; |
60 | size_t len; |
61 | |
62 | uint32_t flags; |
63 | } lws_unit_test_packet_t; |
64 | |
65 | /* each unit test */ |
66 | |
67 | typedef struct lws_unit_test { |
68 | const char * name; /* NULL indicates end of test array */ |
69 | lws_unit_test_packet_t * expect_array; |
70 | int max_secs; |
71 | } lws_unit_test_t; |
72 | |
73 | enum { |
74 | LTMI_PEER_V_EXPECT_TEST = LTMI_TRANSPORT_BASE, /* u.value */ |
75 | LTMI_PEER_V_EXPECT_RESULT_CB, /* u.value */ |
76 | LTMI_PEER_V_EXPECT_RESULT_CB_ARG, /* u.value */ |
77 | }; |
78 | |
79 | LWS_VISIBLE LWS_EXTERN const char * |
80 | lws_unit_test_result_name(int in); |
81 | |
82 | |