test_websocket_client.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Unlicense OR CC0-1.0
  5. *
  6. * This test code is in the Public Domain (or CC0 licensed, at your option.)
  7. *
  8. * Unless required by applicable law or agreed to in writing, this
  9. * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  10. * CONDITIONS OF ANY KIND, either express or implied.
  11. */
  12. #include <stdlib.h>
  13. #include <stdbool.h>
  14. #include <esp_websocket_client.h>
  15. #include "unity.h"
  16. #include "memory_checks.h"
  17. static void test_leak_setup(const char * file, long line)
  18. {
  19. printf("%s:%ld\n", file, line);
  20. test_utils_record_free_mem();
  21. }
  22. TEST_CASE("websocket init and deinit", "[websocket][leaks=0]")
  23. {
  24. test_leak_setup(__FILE__, __LINE__);
  25. const esp_websocket_client_config_t websocket_cfg = {
  26. // no connection takes place, but the uri has to be valid for init() to succeed
  27. .uri = "ws://echo.websocket.org",
  28. };
  29. esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
  30. TEST_ASSERT_NOT_EQUAL(NULL, client);
  31. esp_websocket_client_destroy(client);
  32. }
  33. TEST_CASE("websocket init with invalid url", "[websocket][leaks=0]")
  34. {
  35. test_leak_setup(__FILE__, __LINE__);
  36. const esp_websocket_client_config_t websocket_cfg = {
  37. .uri = "INVALID",
  38. };
  39. esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
  40. TEST_ASSERT_NULL(client);
  41. }
  42. TEST_CASE("websocket set url with invalid url", "[websocket][leaks=0]")
  43. {
  44. test_leak_setup(__FILE__, __LINE__);
  45. const esp_websocket_client_config_t websocket_cfg = {};
  46. esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
  47. TEST_ASSERT_NOT_EQUAL(NULL, client);
  48. TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_websocket_client_set_uri(client, "INVALID"));
  49. esp_websocket_client_destroy(client);
  50. }