test_librws_socket_get_set.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2014 - 2019 Oleh Kulykov <info@resident.name>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. #include <stdlib.h>
  23. #include <assert.h>
  24. #include <string.h>
  25. #if defined(CMAKE_BUILD)
  26. #undef CMAKE_BUILD
  27. #endif
  28. #if defined(XCODE)
  29. #include "librws.h"
  30. #else
  31. #include <librws.h>
  32. #endif
  33. #if defined(CMAKE_BUILD)
  34. #undef CMAKE_BUILD
  35. #endif
  36. int main(int argc, char* argv[]) {
  37. const char * scheme = "ws";
  38. const char * host = "echo.websocket.org";
  39. const char * path = "/";
  40. rws_socket socket = rws_socket_create();
  41. assert(socket);
  42. rws_socket_set_scheme(socket, scheme); printf("%i\n", (int)__LINE__);
  43. assert(strcmp(rws_socket_get_scheme(socket), scheme) == 0); printf("%i\n", (int)__LINE__);
  44. rws_socket_set_host(socket, host); printf("%i\n", (int)__LINE__);
  45. assert(strcmp(rws_socket_get_host(socket), host) == 0); printf("%i\n", (int)__LINE__);
  46. rws_socket_set_path(socket, path); printf("%i\n", (int)__LINE__);
  47. assert(strcmp(rws_socket_get_path(socket), path) == 0); printf("%i\n", (int)__LINE__);
  48. rws_socket_set_port(socket, 80); printf("%i\n", (int)__LINE__);
  49. assert(rws_socket_get_port(socket) == 80); printf("%i\n", (int)__LINE__);
  50. rws_socket_set_port(socket, 443); printf("%i\n", (int)__LINE__);
  51. assert(rws_socket_get_port(socket) == 443); printf("%i\n", (int)__LINE__);
  52. rws_socket_set_scheme(socket, NULL); printf("%i\n", (int)__LINE__);
  53. assert(rws_socket_get_scheme(socket) == NULL); printf("%i\n", (int)__LINE__);
  54. rws_socket_set_host(socket, NULL); printf("%i\n", (int)__LINE__);
  55. assert(rws_socket_get_host(socket) == NULL); printf("%i\n", (int)__LINE__);
  56. rws_socket_set_path(socket, NULL); printf("%i\n", (int)__LINE__);
  57. assert(rws_socket_get_path(socket) == NULL); printf("%i\n", (int)__LINE__);
  58. rws_socket_disconnect_and_release(socket);
  59. return 0;
  60. }