Applied patch 13357
authorWim Taymans <wim.taymans@gmail.com>
Sun, 5 Jan 2003 16:50:35 +0000 (16:50 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Sun, 5 Jan 2003 16:50:35 +0000 (16:50 +0000)
Original commit message from CVS:
Applied patch 13357

common
tests/old/testsuite/indexers/cache1.c
testsuite/indexers/cache1.c

diff --git a/common b/common
index 2a7d1c5..86c5084 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit 2a7d1c564cbf64d94cb04fb8615afb761e89f80c
+Subproject commit 86c508421de359776c4c2cb411a78c729330a250
index 36922e5..0392a19 100644 (file)
 #include <gst/gst.h>
 
 static void
-lookup (GstCache *cache, GstCacheLookupMethod method,
+lookup (GstIndex *index, GstIndexLookupMethod method,
         GstFormat src_format, gint64 src_value,
-       GstFormat dest_format)
+       GstFormat dest_format, gint64 expecting)
 {
-  GstCacheEntry *entry;
+  GstIndexEntry *entry;
   gint64 result;
 
-  entry = gst_cache_get_assoc_entry (cache, 0, method, 
+  entry = gst_index_get_assoc_entry (index, 0, method, 0,
                                     src_format, src_value); 
   if (entry) {
-    gst_cache_entry_assoc_map (entry, dest_format, &result); 
+    gst_index_entry_assoc_map (entry, dest_format, &result); 
 
-    g_print ("%lld\n", result);
+    if (result == expecting) {
+      g_print ("OK (%lld)\n", result);
+    } else {
+      g_print ("FAIL - expecting %lld, got %lld\n", expecting, result);
+    }
   }
   else {
     const GstFormatDefinition *def = gst_format_get_details (src_format);
     
-    g_print ("no cache entry found for %lld %s\n", src_value, def->nick);
+    if (expecting == -1) 
+      g_print ("OK (not found)\n");
+    else
+      g_print ("FAIL - no index entry found for %lld %s, expecting %lld\n",
+              src_value, def->nick, expecting);
   }
 }
 
-typedef struct _GstCacheTestCase
+typedef struct _GstIndexTestCase
 {
-  GstCacheLookupMethod         method;
+  GstIndexLookupMethod         method;
   GstFormat            src_format;
   gint64               src_value;
   GstFormat            dest_format;
-} GstCacheTestCase;
+  gint64                expecting;
+} GstIndexTestCase;
 
-const static GstCacheTestCase cases[] =
+const static GstIndexTestCase cases[] =
 {
-  { GST_CACHE_LOOKUP_EXACT,    GST_FORMAT_BYTES,       3,              GST_FORMAT_TIME },
-  { GST_CACHE_LOOKUP_EXACT,    GST_FORMAT_TIME,        5000,           GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_EXACT,    GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_AFTER,    GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        -1,             GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES },
+  { GST_INDEX_LOOKUP_EXACT,    GST_FORMAT_BYTES,       3,              GST_FORMAT_TIME, 3000 },
+  { GST_INDEX_LOOKUP_EXACT,    GST_FORMAT_TIME,        5000,           GST_FORMAT_BYTES, 5 },
+  { GST_INDEX_LOOKUP_EXACT,    GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES, -1 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES, 5 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES, 6 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES, 0 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES, -1 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES, 0 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        -1,             GST_FORMAT_BYTES, -1 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES, 99999 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES, -1 },
 };
 
 gint 
 main (gint argc, gchar *argv[]) 
 {
-  GstCache *cache;
+  GstIndex *index;
   GstElement *element;
   gint i, id;
   
   gst_init (&argc, &argv);
 
-  cache = gst_cache_factory_make ("memcache");
-  g_assert (cache != NULL);
+  if (argc != 2)
+    { g_print ("usage: cache1 (memindex | fileindex)\n"); exit (0); }
+
+  index = gst_index_factory_make (argv[1]);
+  g_assert (index != NULL);
 
   element = gst_element_factory_make ("identity", "element");
   g_assert (element != NULL);
 
-  gst_cache_get_writer_id (cache, GST_OBJECT (element), &id);
+  gst_index_get_writer_id (index, GST_OBJECT (element), &id);
+
+  g_print ("Building index...\n");
 
   for (i = 0; i < 100000; i++) {
-    gst_cache_add_association (cache, 0, 0, GST_FORMAT_BYTES, (gint64)i, GST_FORMAT_TIME, 
+    gst_index_add_association (index, 0, 0, GST_FORMAT_BYTES, (gint64)i, GST_FORMAT_TIME, 
                                            (gint64) (i * 1000), 0);
   }
 
-  for (i = 0; i < (sizeof (cases) / sizeof (GstCacheTestCase)); i++) {
-    lookup (cache, cases[i].method, cases[i].src_format, cases[i].src_value, cases[i].dest_format);
+  g_print ("Testing index...\n");
+
+  for (i = 0; i < (sizeof (cases) / sizeof (GstIndexTestCase)); i++) {
+    lookup (index, cases[i].method, cases[i].src_format, cases[i].src_value, cases[i].dest_format, cases[i].expecting);
   }
   
   return 0;
index 36922e5..0392a19 100644 (file)
 #include <gst/gst.h>
 
 static void
-lookup (GstCache *cache, GstCacheLookupMethod method,
+lookup (GstIndex *index, GstIndexLookupMethod method,
         GstFormat src_format, gint64 src_value,
-       GstFormat dest_format)
+       GstFormat dest_format, gint64 expecting)
 {
-  GstCacheEntry *entry;
+  GstIndexEntry *entry;
   gint64 result;
 
-  entry = gst_cache_get_assoc_entry (cache, 0, method, 
+  entry = gst_index_get_assoc_entry (index, 0, method, 0,
                                     src_format, src_value); 
   if (entry) {
-    gst_cache_entry_assoc_map (entry, dest_format, &result); 
+    gst_index_entry_assoc_map (entry, dest_format, &result); 
 
-    g_print ("%lld\n", result);
+    if (result == expecting) {
+      g_print ("OK (%lld)\n", result);
+    } else {
+      g_print ("FAIL - expecting %lld, got %lld\n", expecting, result);
+    }
   }
   else {
     const GstFormatDefinition *def = gst_format_get_details (src_format);
     
-    g_print ("no cache entry found for %lld %s\n", src_value, def->nick);
+    if (expecting == -1) 
+      g_print ("OK (not found)\n");
+    else
+      g_print ("FAIL - no index entry found for %lld %s, expecting %lld\n",
+              src_value, def->nick, expecting);
   }
 }
 
-typedef struct _GstCacheTestCase
+typedef struct _GstIndexTestCase
 {
-  GstCacheLookupMethod         method;
+  GstIndexLookupMethod         method;
   GstFormat            src_format;
   gint64               src_value;
   GstFormat            dest_format;
-} GstCacheTestCase;
+  gint64                expecting;
+} GstIndexTestCase;
 
-const static GstCacheTestCase cases[] =
+const static GstIndexTestCase cases[] =
 {
-  { GST_CACHE_LOOKUP_EXACT,    GST_FORMAT_BYTES,       3,              GST_FORMAT_TIME },
-  { GST_CACHE_LOOKUP_EXACT,    GST_FORMAT_TIME,        5000,           GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_EXACT,    GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_AFTER,    GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        -1,             GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_BEFORE,   GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES },
-  { GST_CACHE_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES },
+  { GST_INDEX_LOOKUP_EXACT,    GST_FORMAT_BYTES,       3,              GST_FORMAT_TIME, 3000 },
+  { GST_INDEX_LOOKUP_EXACT,    GST_FORMAT_TIME,        5000,           GST_FORMAT_BYTES, 5 },
+  { GST_INDEX_LOOKUP_EXACT,    GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES, -1 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES, 5 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        5010,           GST_FORMAT_BYTES, 6 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES, 0 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES, -1 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        0,              GST_FORMAT_BYTES, 0 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        -1,             GST_FORMAT_BYTES, -1 },
+  { GST_INDEX_LOOKUP_BEFORE,   GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES, 99999 },
+  { GST_INDEX_LOOKUP_AFTER,    GST_FORMAT_TIME,        G_MAXINT64,     GST_FORMAT_BYTES, -1 },
 };
 
 gint 
 main (gint argc, gchar *argv[]) 
 {
-  GstCache *cache;
+  GstIndex *index;
   GstElement *element;
   gint i, id;
   
   gst_init (&argc, &argv);
 
-  cache = gst_cache_factory_make ("memcache");
-  g_assert (cache != NULL);
+  if (argc != 2)
+    { g_print ("usage: cache1 (memindex | fileindex)\n"); exit (0); }
+
+  index = gst_index_factory_make (argv[1]);
+  g_assert (index != NULL);
 
   element = gst_element_factory_make ("identity", "element");
   g_assert (element != NULL);
 
-  gst_cache_get_writer_id (cache, GST_OBJECT (element), &id);
+  gst_index_get_writer_id (index, GST_OBJECT (element), &id);
+
+  g_print ("Building index...\n");
 
   for (i = 0; i < 100000; i++) {
-    gst_cache_add_association (cache, 0, 0, GST_FORMAT_BYTES, (gint64)i, GST_FORMAT_TIME, 
+    gst_index_add_association (index, 0, 0, GST_FORMAT_BYTES, (gint64)i, GST_FORMAT_TIME, 
                                            (gint64) (i * 1000), 0);
   }
 
-  for (i = 0; i < (sizeof (cases) / sizeof (GstCacheTestCase)); i++) {
-    lookup (cache, cases[i].method, cases[i].src_format, cases[i].src_value, cases[i].dest_format);
+  g_print ("Testing index...\n");
+
+  for (i = 0; i < (sizeof (cases) / sizeof (GstIndexTestCase)); i++) {
+    lookup (index, cases[i].method, cases[i].src_format, cases[i].src_value, cases[i].dest_format, cases[i].expecting);
   }
   
   return 0;