test.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "test.h"
  20. #include <pjlib.h>
  21. #include <pjlib-util.h>
  22. void app_perror(const char *msg, pj_status_t rc)
  23. {
  24. char errbuf[256];
  25. PJ_CHECK_STACK();
  26. pj_strerror(rc, errbuf, sizeof(errbuf));
  27. PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
  28. }
  29. #define DO_TEST(test) do { \
  30. PJ_LOG(3, ("test", "Running %s...", #test)); \
  31. rc = test; \
  32. PJ_LOG(3, ("test", \
  33. "%s(%d)", \
  34. (char*)(rc ? "..ERROR" : "..success"), rc)); \
  35. if (rc!=0) goto on_return; \
  36. } while (0)
  37. pj_pool_factory *mem;
  38. int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
  39. PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_INDENT;
  40. static int test_inner(void)
  41. {
  42. pj_caching_pool caching_pool;
  43. int rc = 0;
  44. mem = &caching_pool.factory;
  45. pj_log_set_level(3);
  46. pj_log_set_decor(param_log_decor);
  47. rc = pj_init();
  48. if (rc != 0) {
  49. app_perror("pj_init() error!!", rc);
  50. return rc;
  51. }
  52. rc = pjlib_util_init();
  53. pj_assert(rc == 0);
  54. pj_dump_config();
  55. pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
  56. #if INCLUDE_XML_TEST
  57. DO_TEST(xml_test());
  58. #endif
  59. #if INCLUDE_JSON_TEST
  60. DO_TEST(json_test());
  61. #endif
  62. #if INCLUDE_ENCRYPTION_TEST
  63. DO_TEST(encryption_test());
  64. # if WITH_BENCHMARK
  65. DO_TEST(encryption_benchmark());
  66. # endif
  67. #endif
  68. #if INCLUDE_STUN_TEST
  69. DO_TEST(stun_test());
  70. #endif
  71. #if INCLUDE_RESOLVER_TEST
  72. DO_TEST(resolver_test());
  73. #endif
  74. #if INCLUDE_HTTP_CLIENT_TEST
  75. DO_TEST(http_client_test());
  76. #endif
  77. on_return:
  78. return rc;
  79. }
  80. int test_main(void)
  81. {
  82. PJ_USE_EXCEPTION;
  83. PJ_TRY {
  84. return test_inner();
  85. }
  86. PJ_CATCH_ANY {
  87. int id = PJ_GET_EXCEPTION();
  88. PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
  89. id, pj_exception_id_name(id)));
  90. }
  91. PJ_END;
  92. return -1;
  93. }