Benny Prijono | e91bf77 | 2005-11-08 11:31:55 +0000 | [diff] [blame] | 1 | #include "test.h"
|
| 2 | #include <pjlib.h>
|
| 3 |
|
| 4 | void app_perror(const char *msg, pj_status_t rc)
|
| 5 | {
|
| 6 | char errbuf[256];
|
| 7 |
|
| 8 | PJ_CHECK_STACK();
|
| 9 |
|
| 10 | pj_strerror(rc, errbuf, sizeof(errbuf));
|
| 11 | PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
|
| 12 | }
|
| 13 |
|
| 14 | #define DO_TEST(test) do { \
|
| 15 | PJ_LOG(3, ("test", "Running %s...", #test)); \
|
| 16 | rc = test; \
|
| 17 | PJ_LOG(3, ("test", \
|
| 18 | "%s(%d)", \
|
| 19 | (char*)(rc ? "..ERROR" : "..success"), rc)); \
|
| 20 | if (rc!=0) goto on_return; \
|
| 21 | } while (0)
|
| 22 |
|
| 23 |
|
| 24 | pj_pool_factory *mem;
|
| 25 |
|
| 26 |
|
| 27 | static int test_inner(void)
|
| 28 | {
|
| 29 | pj_caching_pool caching_pool;
|
| 30 | int rc = 0;
|
| 31 |
|
| 32 | mem = &caching_pool.factory;
|
| 33 |
|
| 34 | pj_log_set_level(3);
|
| 35 | pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
|
| 36 | PJ_LOG_HAS_MICRO_SEC);
|
| 37 |
|
| 38 | rc = pj_init();
|
| 39 | if (rc != 0) {
|
| 40 | app_perror("pj_init() error!!", rc);
|
| 41 | return rc;
|
| 42 | }
|
| 43 |
|
| 44 | pj_dump_config();
|
| 45 | pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
|
| 46 | DO_TEST(xml_test());
|
| 47 |
|
| 48 | on_return:
|
| 49 | return rc;
|
| 50 | }
|
| 51 |
|
| 52 | int test_main(void)
|
| 53 | {
|
| 54 | PJ_USE_EXCEPTION;
|
| 55 |
|
| 56 | PJ_TRY {
|
| 57 | return test_inner();
|
| 58 | }
|
| 59 | PJ_DEFAULT {
|
| 60 | int id = PJ_GET_EXCEPTION();
|
| 61 | PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
|
| 62 | id, pj_exception_id_name(id)));
|
| 63 | }
|
| 64 | PJ_END;
|
| 65 |
|
| 66 | return -1;
|
| 67 | }
|
| 68 |
|