13
13
#include <stdlib.h>
14
14
#include <stdbool.h>
15
15
#include <esp_websocket_client.h>
16
-
16
+ #include "esp_event.h"
17
17
#include "unity.h"
18
+ #include "test_utils.h"
19
+
20
+ #include "unity_fixture.h"
18
21
#include "memory_checks.h"
19
22
20
- static void test_leak_setup (const char * file , long line )
23
+ TEST_GROUP (websocket );
24
+
25
+ TEST_SETUP (websocket )
21
26
{
22
- printf ("%s:%ld\n" , file , line );
27
+ #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL (5 , 1 , 0 )
28
+ /* IDF v5.0 runs some lazy inits within printf()
29
+ * This test sets the leak threshold to 0, so we need to call printf()
30
+ * before recording the heap size in test_utils_record_free_mem()
31
+ */
32
+ printf ("TEST_SETUP: websocket\n" );
33
+ #endif
23
34
test_utils_record_free_mem ();
35
+ TEST_ESP_OK (test_utils_set_leak_level (0 , ESP_LEAK_TYPE_CRITICAL , ESP_COMP_LEAK_GENERAL ));
24
36
}
25
37
26
- TEST_CASE ("websocket init and deinit" , "[websocket][leaks=0]" )
38
+ TEST_TEAR_DOWN (websocket )
39
+ {
40
+ test_utils_finish_and_evaluate_leaks (0 , 0 );
41
+ }
42
+
43
+
44
+ TEST (websocket , websocket_init_deinit )
27
45
{
28
- test_leak_setup (__FILE__ , __LINE__ );
29
46
const esp_websocket_client_config_t websocket_cfg = {
30
47
// no connection takes place, but the uri has to be valid for init() to succeed
31
48
.uri = "ws://echo.websocket.org" ,
@@ -35,22 +52,32 @@ TEST_CASE("websocket init and deinit", "[websocket][leaks=0]")
35
52
esp_websocket_client_destroy (client );
36
53
}
37
54
38
- TEST_CASE ( " websocket init with invalid url" , "[websocket][leaks=0]" )
55
+ TEST ( websocket , websocket_init_invalid_url )
39
56
{
40
- test_leak_setup (__FILE__ , __LINE__ );
41
57
const esp_websocket_client_config_t websocket_cfg = {
42
58
.uri = "INVALID" ,
43
59
};
44
60
esp_websocket_client_handle_t client = esp_websocket_client_init (& websocket_cfg );
45
61
TEST_ASSERT_NULL (client );
46
62
}
47
63
48
- TEST_CASE ( " websocket set url with invalid url" , "[websocket][leaks=0]" )
64
+ TEST ( websocket , websocket_set_invalid_url )
49
65
{
50
- test_leak_setup (__FILE__ , __LINE__ );
51
66
const esp_websocket_client_config_t websocket_cfg = {};
52
67
esp_websocket_client_handle_t client = esp_websocket_client_init (& websocket_cfg );
53
68
TEST_ASSERT_NOT_EQUAL (NULL , client );
54
69
TEST_ASSERT_NOT_EQUAL (ESP_OK , esp_websocket_client_set_uri (client , "INVALID" ));
55
70
esp_websocket_client_destroy (client );
56
71
}
72
+
73
+ TEST_GROUP_RUNNER (websocket )
74
+ {
75
+ RUN_TEST_CASE (websocket , websocket_init_deinit )
76
+ RUN_TEST_CASE (websocket , websocket_init_invalid_url )
77
+ RUN_TEST_CASE (websocket , websocket_set_invalid_url )
78
+ }
79
+
80
+ void app_main (void )
81
+ {
82
+ UNITY_MAIN (websocket );
83
+ }
0 commit comments