blob: 8f6194cec020e491249fd74296491b7ce2300bcd [file] [log] [blame]
Benny Prijono4ea0bf12006-02-02 19:16:07 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono4ea0bf12006-02-02 19:16:07 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include "test.h"
21
Sauw Ming21bd3fd2011-04-06 11:30:18 +000022#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0
23# include <CoreFoundation/CFRunLoop.h>
24#endif
25
Benny Prijono4ea0bf12006-02-02 19:16:07 +000026#define THIS_FILE "test.c"
27
28#define DO_TEST(test) do { \
29 PJ_LOG(3, (THIS_FILE, "Running %s...", #test)); \
30 rc = test; \
31 PJ_LOG(3, (THIS_FILE, \
32 "%s(%d)", \
33 (rc ? "..ERROR" : "..success"), rc)); \
34 if (rc!=0) goto on_return; \
35 } while (0)
36
37
38pj_pool_factory *mem;
Sauw Ming21bd3fd2011-04-06 11:30:18 +000039pj_bool_t is_quit = PJ_FALSE;
40pj_thread_t *thread;
41pj_caching_pool caching_pool;
42pj_pool_t *pool;
Benny Prijono4ea0bf12006-02-02 19:16:07 +000043
44void app_perror(pj_status_t status, const char *msg)
45{
Benny Prijonocf5c06d2008-03-26 16:18:17 +000046 char errbuf[PJ_ERR_MSG_SIZE];
Benny Prijono4ea0bf12006-02-02 19:16:07 +000047
48 pjmedia_strerror(status, errbuf, sizeof(errbuf));
49
50 PJ_LOG(3,(THIS_FILE, "%s: %s", msg, errbuf));
51}
52
Sauw Ming21bd3fd2011-04-06 11:30:18 +000053static int test_func(void *data)
Benny Prijono4ea0bf12006-02-02 19:16:07 +000054{
Benny Prijonocf5c06d2008-03-26 16:18:17 +000055 int rc = 0;
Sauw Ming6e6c2152010-12-14 13:03:10 +000056
Benny Prijonoc45d9512010-12-10 11:04:30 +000057#if HAS_VID_DEV_TEST
58 DO_TEST(vid_dev_test());
59#endif
Sauw Ming21bd3fd2011-04-06 11:30:18 +000060
Benny Prijonoc45d9512010-12-10 11:04:30 +000061#if HAS_VID_CODEC_TEST
62 DO_TEST(vid_codec_test());
63#endif
Sauw Ming21bd3fd2011-04-06 11:30:18 +000064
Benny Prijono41a14512009-08-15 10:05:36 +000065#if HAS_SDP_NEG_TEST
Benny Prijono1dc0da72009-04-18 00:12:13 +000066 DO_TEST(sdp_neg_test());
Benny Prijono41a14512009-08-15 10:05:36 +000067#endif
Benny Prijono1dc0da72009-04-18 00:12:13 +000068 //DO_TEST(sdp_test (&caching_pool.factory));
69 //DO_TEST(rtp_test(&caching_pool.factory));
70 //DO_TEST(session_test (&caching_pool.factory));
Benny Prijono41a14512009-08-15 10:05:36 +000071#if HAS_JBUF_TEST
Nanang Izzuddinad4bb0a2009-04-06 17:13:33 +000072 DO_TEST(jbuf_main());
Benny Prijono41a14512009-08-15 10:05:36 +000073#endif
74#if HAS_MIPS_TEST
Benny Prijono1dc0da72009-04-18 00:12:13 +000075 DO_TEST(mips_test());
Benny Prijono41a14512009-08-15 10:05:36 +000076#endif
77#if HAS_CODEC_VECTOR_TEST
Benny Prijono1dc0da72009-04-18 00:12:13 +000078 DO_TEST(codec_test_vectors());
Benny Prijono41a14512009-08-15 10:05:36 +000079#endif
Sauw Ming21bd3fd2011-04-06 11:30:18 +000080
Benny Prijono4ea0bf12006-02-02 19:16:07 +000081 PJ_LOG(3,(THIS_FILE," "));
Sauw Ming21bd3fd2011-04-06 11:30:18 +000082
Nanang Izzuddinad4bb0a2009-04-06 17:13:33 +000083on_return:
Benny Prijono4ea0bf12006-02-02 19:16:07 +000084 if (rc != 0) {
85 PJ_LOG(3,(THIS_FILE,"Test completed with error(s)!"));
86 } else {
87 PJ_LOG(3,(THIS_FILE,"Looks like everything is okay!"));
88 }
Sauw Ming21bd3fd2011-04-06 11:30:18 +000089
90 is_quit = PJ_TRUE;
91 return rc;
92}
93
94int test_main(void)
95{
96 int rc = 0;
97
98 pj_init();
99 pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
100 pool = pj_pool_create(&caching_pool.factory, "test", 1000, 512, NULL);
101
102 pj_log_set_decor(PJ_LOG_HAS_NEWLINE);
103 pj_log_set_level(3);
104
105 mem = &caching_pool.factory;
106
107 pjmedia_video_format_mgr_create(pool, 64, 0, NULL);
108 pjmedia_converter_mgr_create(pool, NULL);
109 pjmedia_vid_codec_mgr_create(pool, NULL);
110
111#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0
112 {
113 if (pj_thread_create(pool, "test_func", test_func, NULL, 0, 0,
114 &thread) == PJ_SUCCESS) {
115 while (!is_quit) {
116 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);
117 }
118 }
119 return 0;
120 }
121#else
122 rc = test_func(NULL);
123#endif
Benny Prijono4ea0bf12006-02-02 19:16:07 +0000124
Sauw Ming6e6c2152010-12-14 13:03:10 +0000125 pjmedia_video_format_mgr_destroy(pjmedia_video_format_mgr_instance());
126 pjmedia_converter_mgr_destroy(pjmedia_converter_mgr_instance());
127 pjmedia_vid_codec_mgr_destroy(pjmedia_vid_codec_mgr_instance());
128
129 pj_pool_release(pool);
Benny Prijono4ea0bf12006-02-02 19:16:07 +0000130 pj_caching_pool_destroy(&caching_pool);
Nanang Izzuddinad4bb0a2009-04-06 17:13:33 +0000131
Benny Prijono4ea0bf12006-02-02 19:16:07 +0000132 return rc;
133}