gstreamer_core/tsrc/check/libs/typefindhelper/src/typefindhelper.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
child 29 567bb019e3e3
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer
       
     2  *
       
     3  * unit test for typefind helper
       
     4  *
       
     5  * Copyright (C) 2006 Tim-Philipp Müller  <tim centricular net>
       
     6  *
       
     7  * This library is free software; you can redistribute it and/or
       
     8  * modify it under the terms of the GNU Library General Public
       
     9  * License as published by the Free Software Foundation; either
       
    10  * version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  * This library is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  * Library General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU Library General Public
       
    18  * License along with this library; if not, write to the
       
    19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    20  * Boston, MA 02111-1307, USA.
       
    21  */
       
    22 #include <gst/gst_global.h>
       
    23 #ifdef HAVE_CONFIG_H
       
    24 #include "config.h"
       
    25 #endif
       
    26 
       
    27 #include "libgstreamer_wsd_solution.h" 
       
    28 
       
    29 #if EMULATOR
       
    30 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean)
       
    31 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)())
       
    32 #else 
       
    33 extern gboolean _gst_check_raised_critical ;
       
    34 #endif
       
    35 //gboolean _gst_check_raised_warning = FALSE;
       
    36 #if EMULATOR
       
    37 static GET_GLOBAL_VAR_FROM_TLS(raised_warning,gstcheck,gboolean)
       
    38 #define _gst_check_raised_warning (*GET_GSTREAMER_WSD_VAR_NAME(raised_warning,gstcheck,g)())
       
    39 #else 
       
    40 extern gboolean _gst_check_raised_warning ;
       
    41 #endif
       
    42 //gboolean _gst_check_expecting_log = FALSE;
       
    43 #if EMULATOR
       
    44 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean)
       
    45 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)())
       
    46 #else 
       
    47 extern gboolean _gst_check_expecting_log ;
       
    48 #endif
       
    49 
       
    50 //gboolean _gst_check_expecting_log = FALSE;
       
    51 #if EMULATOR
       
    52 static GET_GLOBAL_VAR_FROM_TLS(threads_running,gstcheck,gboolean)
       
    53 #define _gst_check_threads_running (*GET_GSTREAMER_WSD_VAR_NAME(threads_running,gstcheck,g)())
       
    54 #else 
       
    55 extern gboolean _gst_check_threads_running ;
       
    56 #endif
       
    57 
       
    58 
       
    59 #if EMULATOR
       
    60 GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*)
       
    61 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)())
       
    62 #else 
       
    63 extern GList *buffers;
       
    64 #endif
       
    65 
       
    66 
       
    67 #if EMULATOR
       
    68 GET_GLOBAL_VAR_FROM_TLS(thread_list,gstcheck,GList*)
       
    69 #define thread_list (*GET_GSTREAMER_WSD_VAR_NAME(thread_list,gstcheck,g)())
       
    70 #else 
       
    71 extern GList *thread_list;
       
    72 #endif
       
    73 
       
    74 //GMutex *mutex;
       
    75 #if EMULATOR
       
    76 GET_GLOBAL_VAR_FROM_TLS(mutex,gstcheck,GMutex*)
       
    77 #define mutex (*GET_GSTREAMER_WSD_VAR_NAME(mutex,gstcheck,g)())
       
    78 #else 
       
    79 extern GMutex *mutex;
       
    80 #endif
       
    81 
       
    82 //GCond *start_cond;              /* used to notify main thread of thread startups */
       
    83 #if EMULATOR
       
    84 GET_GLOBAL_VAR_FROM_TLS(start_cond,gstcheck,GCond*)
       
    85 #define start_cond (*GET_GSTREAMER_WSD_VAR_NAME(start_cond,gstcheck,g)())
       
    86 #else 
       
    87 extern GCond *start_cond;
       
    88 #endif
       
    89 
       
    90 //GCond *sync_cond;               /* used to synchronize all threads and main thread */
       
    91 #if EMULATOR
       
    92 GET_GLOBAL_VAR_FROM_TLS(sync_cond,gstcheck,GCond*)
       
    93 #define sync_cond (*GET_GSTREAMER_WSD_VAR_NAME(sync_cond,gstcheck,g)())
       
    94 #else 
       
    95 extern GCond *sync_cond;
       
    96 #endif
       
    97 
       
    98 #define LOG_FILE "c:\\logs\\typefindhelper_logs.txt" 
       
    99 #include "std_log_result.h" 
       
   100 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
   101 
       
   102 #include <gst/check/gstcheck.h>
       
   103 
       
   104 #include <gst/base/gsttypefindhelper.h>
       
   105 
       
   106 static const guint8 vorbisid[30] = { 0x01, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73,
       
   107   0x00, 0x00, 0x00, 0x00, 0x02, 0x44, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00,
       
   108   0x00, 0x03, 0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x01
       
   109 };
       
   110 
       
   111 
       
   112 
       
   113 static GstStaticCaps foobar_caps = GST_STATIC_CAPS ("foo/x-bar");
       
   114 
       
   115 #define FOOBAR_CAPS (gst_static_caps_get (&foobar_caps))
       
   116 
       
   117 static void
       
   118 foobar_typefind (GstTypeFind * tf, gpointer unused)
       
   119 {
       
   120   guint8 *data;
       
   121 
       
   122   data = gst_type_find_peek (tf, 0, 10);
       
   123   fail_unless (data != NULL);
       
   124   fail_unless (memcmp (data, vorbisid, 10) == 0);
       
   125 
       
   126   data = gst_type_find_peek (tf, 0, 20);
       
   127   fail_unless (data != NULL);
       
   128   fail_unless (memcmp (data, vorbisid, 20) == 0);
       
   129 
       
   130   data = gst_type_find_peek (tf, 0, 30);
       
   131   fail_unless (data != NULL);
       
   132   fail_unless (memcmp (data, vorbisid, 30) == 0);
       
   133 
       
   134   fail_unless (gst_type_find_peek (tf, 0, 31) == NULL);
       
   135   fail_unless (gst_type_find_peek (tf, 1, 30) == NULL);
       
   136   fail_unless (gst_type_find_peek (tf, 25, 6) == NULL);
       
   137 
       
   138   data = gst_type_find_peek (tf, 1, 29);
       
   139   fail_unless (data != NULL);
       
   140   fail_unless (memcmp (data, vorbisid + 1, 29) == 0);
       
   141 
       
   142   data = gst_type_find_peek (tf, 25, 4);
       
   143   fail_unless (data != NULL);
       
   144   fail_unless (memcmp (data, vorbisid + 25, 4) == 0);
       
   145 
       
   146   fail_unless (gst_type_find_peek (tf, -1, 29) == NULL);
       
   147   fail_unless (gst_type_find_peek (tf, -1, 1) == NULL);
       
   148   fail_unless (gst_type_find_peek (tf, -1, 0) == NULL);
       
   149 
       
   150   gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FOOBAR_CAPS);
       
   151 }
       
   152 
       
   153 
       
   154 //char* xmlfile = "typefindhelper";
       
   155 
       
   156 void create_xml(int result)
       
   157 {
       
   158     if(result)
       
   159         assert_failed = 1;
       
   160     
       
   161     testResultXml(xmlfile);
       
   162     close_log_file();
       
   163 }
       
   164 
       
   165 /* make sure the entire data in the buffer is available for peeking */
       
   166 void test_buffer_range()
       
   167 {
       
   168   static gchar *foobar_exts[] = { "foobar", NULL };
       
   169 
       
   170   GstStructure *s;
       
   171   GstBuffer *buf;
       
   172   GstCaps *caps;
       
   173 	
       
   174 	xmlfile = "test_buffer_range";
       
   175   std_log(LOG_FILENAME_LINE, "Test Started test_buffer_range");
       
   176   
       
   177   fail_unless (gst_type_find_register (NULL, "foo/x-bar",
       
   178           GST_RANK_PRIMARY + 50, foobar_typefind, foobar_exts, FOOBAR_CAPS,
       
   179           NULL, NULL));
       
   180 
       
   181   buf = gst_buffer_new ();
       
   182   fail_unless (buf != NULL);
       
   183   GST_BUFFER_DATA (buf) = (guint8 *) vorbisid;
       
   184   GST_BUFFER_SIZE (buf) = 30;
       
   185   GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
       
   186 
       
   187   caps = gst_type_find_helper_for_buffer (NULL, buf, NULL);
       
   188   fail_unless (caps != NULL);
       
   189   fail_unless (GST_CAPS_IS_SIMPLE (caps));
       
   190   fail_unless (gst_caps_is_fixed (caps));
       
   191 
       
   192   s = gst_caps_get_structure (caps, 0);
       
   193   fail_unless (s != NULL);
       
   194   fail_unless (gst_structure_has_name (s, "foo/x-bar"));
       
   195 
       
   196   gst_caps_unref (caps);
       
   197   gst_buffer_unref (buf);
       
   198   
       
   199   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   200   create_xml(0); 
       
   201   
       
   202 }
       
   203 
       
   204 
       
   205 
       
   206 void
       
   207 gst_typefindhelper_suite (void)
       
   208 {
       
   209 test_buffer_range();
       
   210 }
       
   211 
       
   212 void (*fn[]) (void) = {
       
   213 test_buffer_range
       
   214 };
       
   215 
       
   216 char *args[] = {
       
   217 "test_buffer_range"
       
   218 };
       
   219 
       
   220 GST_CHECK_MAIN (gst_typefindhelper);
       
   221 #if 0
       
   222 int main(int argc,char** argv)
       
   223 {
       
   224 		int i;
       
   225 		gst_check_init(&argc,&argv);
       
   226 		for(i=0;i<1;i++)
       
   227 			fn[i]();
       
   228 			
       
   229 } 
       
   230 #endif