test_endpoints.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \file \brief Test endpoints.
  20. *
  21. * \author\verbatim David M. Lee, II <dlee@digium.com> \endverbatim
  22. *
  23. * \ingroup tests
  24. */
  25. /*** MODULEINFO
  26. <depend>TEST_FRAMEWORK</depend>
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include "asterisk/astobj2.h"
  32. #include "asterisk/endpoints.h"
  33. #include "asterisk/module.h"
  34. #include "asterisk/stasis_endpoints.h"
  35. #include "asterisk/test.h"
  36. static const char *test_category = "/core/endpoints/";
  37. AST_TEST_DEFINE(create)
  38. {
  39. RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
  40. switch (cmd) {
  41. case TEST_INIT:
  42. info->name = __func__;
  43. info->category = test_category;
  44. info->summary = "Test endpoint creation";
  45. info->description = "Test endpoint creation";
  46. return AST_TEST_NOT_RUN;
  47. case TEST_EXECUTE:
  48. break;
  49. }
  50. ast_test_validate(test, NULL == ast_endpoint_create(NULL, NULL));
  51. ast_test_validate(test, NULL == ast_endpoint_create("", ""));
  52. ast_test_validate(test, NULL == ast_endpoint_create("TEST", ""));
  53. ast_test_validate(test, NULL == ast_endpoint_create("", "test_res"));
  54. uut = ast_endpoint_create("TEST", "test_res");
  55. ast_test_validate(test, NULL != uut);
  56. ast_test_validate(test,
  57. 0 == strcmp("TEST", ast_endpoint_get_tech(uut)));
  58. ast_test_validate(test,
  59. 0 == strcmp("test_res", ast_endpoint_get_resource(uut)));
  60. return AST_TEST_PASS;
  61. }
  62. AST_TEST_DEFINE(defaults)
  63. {
  64. RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
  65. RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
  66. switch (cmd) {
  67. case TEST_INIT:
  68. info->name = __func__;
  69. info->category = test_category;
  70. info->summary = "Test defaults for new endpoints";
  71. info->description = "Test defaults for new endpoints";
  72. return AST_TEST_NOT_RUN;
  73. case TEST_EXECUTE:
  74. break;
  75. }
  76. uut = ast_endpoint_create("TEST", "test_res");
  77. ast_test_validate(test, NULL != uut);
  78. snapshot = ast_endpoint_snapshot_create(uut);
  79. ast_test_validate(test, NULL != snapshot);
  80. ast_test_validate(test, 0 == strcmp("TEST/test_res", snapshot->id));
  81. ast_test_validate(test, 0 == strcmp("TEST", snapshot->tech));
  82. ast_test_validate(test, 0 == strcmp("test_res", snapshot->resource));
  83. ast_test_validate(test, AST_ENDPOINT_UNKNOWN == snapshot->state);
  84. ast_test_validate(test, -1 == snapshot->max_channels);
  85. ast_test_validate(test, 0 == snapshot->num_channels);
  86. return AST_TEST_PASS;
  87. }
  88. AST_TEST_DEFINE(setters)
  89. {
  90. RAII_VAR(struct ast_endpoint *, uut, NULL, ast_endpoint_shutdown);
  91. RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
  92. switch (cmd) {
  93. case TEST_INIT:
  94. info->name = __func__;
  95. info->category = test_category;
  96. info->summary = "Test endpoint setters";
  97. info->description = "Test endpoint setters";
  98. return AST_TEST_NOT_RUN;
  99. case TEST_EXECUTE:
  100. break;
  101. }
  102. uut = ast_endpoint_create("TEST", "test_res");
  103. ast_test_validate(test, NULL != uut);
  104. ast_endpoint_set_state(uut, AST_ENDPOINT_ONLINE);
  105. ast_endpoint_set_max_channels(uut, 314159);
  106. snapshot = ast_endpoint_snapshot_create(uut);
  107. ast_test_validate(test, NULL != snapshot);
  108. ast_test_validate(test, AST_ENDPOINT_ONLINE == snapshot->state);
  109. ast_test_validate(test, 314159 == snapshot->max_channels);
  110. return AST_TEST_PASS;
  111. }
  112. static int unload_module(void)
  113. {
  114. AST_TEST_UNREGISTER(create);
  115. AST_TEST_UNREGISTER(defaults);
  116. AST_TEST_UNREGISTER(setters);
  117. return 0;
  118. }
  119. static int load_module(void)
  120. {
  121. AST_TEST_REGISTER(create);
  122. AST_TEST_REGISTER(defaults);
  123. AST_TEST_REGISTER(setters);
  124. return AST_MODULE_LOAD_SUCCESS;
  125. }
  126. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Endpoint testing",
  127. .support_level = AST_MODULE_SUPPORT_CORE,
  128. .load = load_module,
  129. .unload = unload_module,
  130. );