test_websocket_client.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2021 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <stdlib.h>
  15. #include <stdbool.h>
  16. #include <esp_websocket_client.h>
  17. #include "unity.h"
  18. #include "test_utils.h"
  19. static void test_leak_setup(const char * file, long line)
  20. {
  21. printf("%s:%ld\n", file, line);
  22. unity_reset_leak_checks();
  23. }
  24. TEST_CASE("websocket init and deinit", "[websocket][leaks=0]")
  25. {
  26. test_leak_setup(__FILE__, __LINE__);
  27. const esp_websocket_client_config_t websocket_cfg = {
  28. // no connection takes place, but the uri has to be valid for init() to succeed
  29. .uri = "ws://echo.websocket.org",
  30. };
  31. esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
  32. TEST_ASSERT_NOT_EQUAL(NULL, client);
  33. esp_websocket_client_destroy(client);
  34. }
  35. TEST_CASE("websocket init with invalid url", "[websocket][leaks=0]")
  36. {
  37. test_leak_setup(__FILE__, __LINE__);
  38. const esp_websocket_client_config_t websocket_cfg = {
  39. .uri = "INVALID",
  40. };
  41. esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
  42. TEST_ASSERT_NULL(client);
  43. }
  44. TEST_CASE("websocket set url with invalid url", "[websocket][leaks=0]")
  45. {
  46. test_leak_setup(__FILE__, __LINE__);
  47. const esp_websocket_client_config_t websocket_cfg = {};
  48. esp_websocket_client_handle_t client = esp_websocket_client_init(&websocket_cfg);
  49. TEST_ASSERT_NOT_EQUAL(NULL, client);
  50. TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_websocket_client_set_uri(client, "INVALID"));
  51. esp_websocket_client_destroy(client);
  52. }