source: trunk/third/gstreamer/testsuite/indexers/cache1.c @ 21005

Revision 21005, 3.5 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
1/* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#include <gst/gst.h>
21
22static void
23lookup (GstIndex * index, GstIndexLookupMethod method,
24    GstFormat src_format, gint64 src_value,
25    GstFormat dest_format, gint64 expecting)
26{
27  GstIndexEntry *entry;
28  gint64 result;
29
30  entry = gst_index_get_assoc_entry (index, 0, method, 0,
31      src_format, src_value);
32  if (entry) {
33    gst_index_entry_assoc_map (entry, dest_format, &result);
34
35    if (result == expecting) {
36      g_print ("OK (%lld)\n", result);
37    } else {
38      g_print ("FAIL - expecting %lld, got %lld\n", expecting, result);
39    }
40  } else {
41    const GstFormatDefinition *def = gst_format_get_details (src_format);
42
43    if (expecting == -1)
44      g_print ("OK (not found)\n");
45    else
46      g_print ("FAIL - no index entry found for %lld %s, expecting %lld\n",
47          src_value, def->nick, expecting);
48  }
49}
50
51typedef struct _GstIndexTestCase
52{
53  GstIndexLookupMethod method;
54  GstFormat src_format;
55  gint64 src_value;
56  GstFormat dest_format;
57  gint64 expecting;
58} GstIndexTestCase;
59
60const static GstIndexTestCase cases[] = {
61  {GST_INDEX_LOOKUP_EXACT, GST_FORMAT_BYTES, 3, GST_FORMAT_TIME, 3000},
62  {GST_INDEX_LOOKUP_EXACT, GST_FORMAT_TIME, 5000, GST_FORMAT_BYTES, 5},
63  {GST_INDEX_LOOKUP_EXACT, GST_FORMAT_TIME, 5010, GST_FORMAT_BYTES, -1},
64  {GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, 5010, GST_FORMAT_BYTES, 5},
65  {GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, 5010, GST_FORMAT_BYTES, 6},
66  {GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, 0, GST_FORMAT_BYTES, 0},
67  {GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, G_MAXINT64, GST_FORMAT_BYTES, -1},
68  {GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, 0, GST_FORMAT_BYTES, 0},
69  {GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, -1, GST_FORMAT_BYTES, -1},
70  {GST_INDEX_LOOKUP_BEFORE, GST_FORMAT_TIME, G_MAXINT64, GST_FORMAT_BYTES,
71      99999},
72  {GST_INDEX_LOOKUP_AFTER, GST_FORMAT_TIME, G_MAXINT64, GST_FORMAT_BYTES, -1},
73};
74
75gint
76main (gint argc, gchar * argv[])
77{
78  GstIndex *index;
79  GstElement *element;
80  gint i, id;
81
82  gst_init (&argc, &argv);
83
84  if (argc != 2) {
85    g_print ("usage: cache1 (memindex | fileindex)\n");
86    exit (0);
87  }
88
89  index = gst_index_factory_make (argv[1]);
90  g_assert (index != NULL);
91
92  element = gst_element_factory_make ("identity", "element");
93  g_assert (element != NULL);
94
95  gst_index_get_writer_id (index, GST_OBJECT (element), &id);
96
97  g_print ("Building index...\n");
98
99  for (i = 0; i < 100000; i++) {
100    gst_index_add_association (index, 0, 0, GST_FORMAT_BYTES, (gint64) i,
101        GST_FORMAT_TIME, (gint64) (i * 1000), 0);
102  }
103
104  g_print ("Testing index...\n");
105
106  for (i = 0; i < (sizeof (cases) / sizeof (GstIndexTestCase)); i++) {
107    lookup (index, cases[i].method, cases[i].src_format, cases[i].src_value,
108        cases[i].dest_format, cases[i].expecting);
109  }
110
111  return 0;
112}
Note: See TracBrowser for help on using the repository browser.