Exemplo n.º 1
0
END_TEST

//--------------------

START_TEST (test_simple_db)
{
    GlyrQuery q;
    setup (&q,GLYR_GET_LYRICS,10);
    glyr_opt_artist (&q,"Equi");
    glyr_opt_title (&q,"lala");

    GlyrDatabase * db = setup_db();

    GlyrMemCache * ct = glyr_cache_new();

    glyr_cache_set_data (ct,g_strdup ("test"),-1);

    glyr_db_insert (NULL,&q, (GlyrMemCache*) 0x1);
    fail_unless (count_db_items (db) == 0, NULL);
    glyr_db_insert (db,NULL, (GlyrMemCache*) 0x1);
    fail_unless (count_db_items (db) == 0, NULL);
    glyr_db_insert (db,&q,NULL);
    fail_unless (count_db_items (db) == 0, NULL);

    glyr_db_insert (db,&q,ct);
    GlyrMemCache * c = glyr_db_lookup (db,&q);
    fail_unless (c != NULL, NULL);
    fail_unless (c->data != NULL, NULL);
    fail_unless (count_db_items (db) == 1, NULL);

    glyr_db_destroy (db);
    glyr_cache_free (ct);
    glyr_query_destroy (&q);
}
Exemplo n.º 2
0
/* Our polling thread */
gpointer apollo_orbiter(gpointer gp_queue)
{
    FinishedNotify * pn = gp_queue;
    g_async_queue_ref(pn->queue);

    while(TRUE)
    {
        g_print("\n-----------\n\n");
        gpointer thread_data = g_async_queue_pop(pn->queue);

        if(thread_data == THREAD_TERMINATOR)
        {
            g_printerr("\n-- Terminating --\n");
            break;
        }
        else
        {
            GlyrQuery * q = thread_data;
            GlyrMemCache * head = glyr_get(q,NULL,NULL);
            if(head != NULL)
            {
                g_print("//////// ITEM %d ////////\n",++pn->counter);
                glyr_cache_print(head);
                glyr_free_list(head);
                g_print("/////////////////////////\n");
            }
            glyr_query_destroy(q);
        }
    }

    g_async_queue_unref(pn->queue);
    return NULL;
}
static void moose_metadata_query_finalize(GObject *gobject) {
    MooseMetadataQuery *self = MOOSE_METADATA_QUERY(gobject);
    g_assert(self);

    MooseMetadataQueryPrivate *priv = moose_metadata_query_get_instance_private(self);
    glyr_query_destroy(&priv->query);
    g_list_free_full(priv->result_caches, g_object_unref);

    G_OBJECT_CLASS(g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)))->finalize(gobject);
}
Exemplo n.º 4
0
END_TEST

//--------------------

START_TEST(test_glyr_opt_proxy)
{
    GlyrQuery q;
    setup(&q, GLYR_GET_COVERART, 1);
    glyr_opt_verbosity(&q, 0);
    glyr_opt_proxy(&q, "I can haz Existence?");

    GlyrMemCache *list = glyr_get(&q, NULL, NULL);
    fail_unless(list == NULL, NULL);

    glyr_cache_free(list);
    glyr_query_destroy(&q);
}
Exemplo n.º 5
0
END_TEST

//--------------------

/* Write artist|album|title, select only artist|title */
START_TEST (test_intelligent_lookup)
{
    GlyrDatabase * db = setup_db();

    GlyrQuery alt;
    glyr_query_init (&alt);

    gchar * artist = "Аркона";
    gchar * album  = "Ot Serdca k Nebu";
    gchar * title  = "Pokrovy Nebesnogo Startsa (Shrouds Of Celestial Sage)";

    glyr_opt_artist (&alt,artist);
    glyr_opt_album (&alt,album );
    glyr_opt_title (&alt,title );
    glyr_opt_type  (&alt,GLYR_GET_LYRICS);

    GlyrMemCache * subject = glyr_cache_new();
    glyr_cache_set_data (subject,g_strdup ("These are lyrics. Really."),-1);

    glyr_db_insert (db,&alt,subject);

    GlyrMemCache * one = glyr_db_lookup (db,&alt);
    fail_if (one == NULL,NULL);
    fail_if (memcmp (one->md5sum,subject->md5sum,16) != 0, NULL);
    glyr_cache_free (one);

    alt.album = NULL;
    GlyrMemCache * two = glyr_db_lookup (db,&alt);
    fail_if (two == NULL,NULL);
    fail_if (memcmp (two->md5sum,subject->md5sum,16) != 0, NULL);
    glyr_cache_free (two);

    fail_unless (count_db_items (db) == 1,NULL);
    int deleted = glyr_db_delete (db,&alt);
    fail_unless (deleted == 1,NULL);
    fail_unless (count_db_items (db) == 0,NULL);

    glyr_query_destroy (&alt);
    glyr_db_destroy (db);
}
Exemplo n.º 6
0
Arquivo: simple.c Projeto: sahib/glyr
int main (void)
{
    /* Init this thing, the only two methods not being threadsafe */
    glyr_init();
    /* Also clear ressources on exit */
    atexit (glyr_cleanup);

    /* This struct is used to store all settings you do via glyr_opt_* */
    GlyrQuery q;
    /* We also should set it to standard values */
    glyr_query_init (&q);

    /* We want lyrics, well, I want. */
    glyr_opt_type (&q,GLYR_GET_LYRICS);

    /* Set random artist/title -  you could also omit the album line */
    glyr_opt_artist (&q, (char*) "Die Ärzte");
    glyr_opt_album (&q, (char*) "Die Bestie in Menschengestalt");
    glyr_opt_title (&q, (char*) "FaFaFa");

    /* If any error occured it will be saved here, or GLYRE_OK */
    /* You could have also passed a NULL pointer to glyr_get() if you're not interested in this */
    GLYR_ERROR err;

    /* Now get the job done! The 3rd  */
    GlyrMemCache * head = glyr_get (&q,&err,NULL);

    /* The results are stored in the GlyrMemCache struct -
       you are most likely only interested in the fields data, size and type*/
    if (head != NULL)
    {
        /* head contains also a pointer to the next element, you can use it therefore as linkedlist */
        //        puts(head->data);
        glyr_cache_print (head);

        /* We have to free it again also, you can pass ANY pointer of the list, it works in both directions */
        glyr_free_list (head);
    }

    /* glyr_query_init  may allocate memory - free it. */
    glyr_query_destroy (&q);
    return err;
}
static gboolean
glyr_finished_thread_update (gpointer data)
{
	PraghaApplication *pragha;
	GtkWidget *window;

	glyr_struct *glyr_info = data;

	pragha = pragha_songinfo_plugin_get_application (glyr_info->plugin);
	window = pragha_application_get_window (pragha);
	remove_watch_cursor (window);

	if(glyr_info->head != NULL)
		glyr_finished_successfully (glyr_info);
	else
		glyr_finished_incorrectly (glyr_info);

	glyr_query_destroy (&glyr_info->query);
	g_slice_free (glyr_struct, glyr_info);

	return FALSE;
}
Exemplo n.º 8
0
END_TEST

//--------------------

START_TEST (test_iter_db)
{
    GlyrQuery q;
    setup (&q,GLYR_GET_LYRICS,10);
    glyr_opt_artist (&q,"Equi");
    glyr_opt_title (&q,"lala");

    GlyrDatabase * db = setup_db();

    GlyrQuery nugget;
    setup (&nugget,GLYR_GET_COVERART,40);
    glyr_opt_artist (&nugget,"A very special artist");
    glyr_opt_album (&nugget,"A very special album");

    GTimer * insert_time = g_timer_new();

    const int N = 5000;
    for (int i = 0; i < N; i++)
    {
        GlyrMemCache * ct = glyr_cache_new();
        glyr_cache_set_data (ct,g_strdup_printf ("test# %d",i+1),-1);
        ct->dsrc = g_strdup_printf ("Dummy url %d",i+1);

        if (i % 2)
            ct->rating = N ;
        else
            ct->rating = N ;

        if (i % 23)
            glyr_db_insert (db,&q,ct);
        else
            glyr_db_insert (db,&nugget,ct);

        glyr_cache_free (ct);
    }

    g_timer_stop (insert_time);
    g_message ("Used %.5f seconds to insert..",g_timer_elapsed (insert_time,NULL) );

    /* Check if N items are in DB */
    int cdb = count_db_items (db);
    g_message ("Counted %d items",cdb);
    fail_unless (cdb == N, NULL);

    /* Test if case-insensitivity works */
    glyr_opt_artist (&q,"eQuI");
    glyr_opt_title (&q,"LALA");

    float fine_grained = 0.0;
    GTimer * grain_time = g_timer_new();

    g_timer_start (insert_time);

    GlyrMemCache * c, * ptr;
    for (int i = 1; i <= N/10; i++)
    {
        g_timer_start (grain_time);
        /* Get a list of the caches */
        if (i % 10)
            c = glyr_db_lookup (db,&q);
        else
            c = glyr_db_lookup (db,&nugget);

        g_timer_stop (grain_time);
        fine_grained += g_timer_elapsed (grain_time,NULL);

        ptr = c;
        fail_if (ptr == NULL);

        int last_rating = INT_MAX;
        int ctr = 0;
        while (ptr)
        {
            ctr++;
            fail_unless (last_rating >= ptr->rating);
            last_rating = ptr->rating;
            ptr = ptr->next;
        }
        glyr_free_list (c);

        /* Test if we got exactly 10 or 42 items, (honoring number setting) */

        if (i % 10)
            fail_unless (ctr == 10);
        else
            fail_unless (ctr == 40);
    }


    g_timer_stop (insert_time);
    g_message ("Used %.5f seconds to lookup..",g_timer_elapsed (insert_time,NULL) );
    g_message ("Used %.5f for actual lookup..",fine_grained);

    glyr_db_destroy (db);
    glyr_query_destroy (&q);
    glyr_query_destroy (&nugget);

    g_timer_destroy (insert_time);
    g_timer_destroy (grain_time);
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
    /* You need to call this before anything happens */
    glyr_init();
    atexit(glyr_cleanup);

    /* Initialize a new query (this may allocate memory) */
    GlyrQuery q;
    glyr_query_init(&q);

    /* Say we want a Songtext */
    GLYR_GET_TYPE type = GLYR_GET_LYRICS;
    glyr_opt_type(&q, type);

    /* Set at least the required fields to your needs        *
     * For lyrics those are 'artist' and 'title', ('album')  *
     * is strictly optional and may be used by a few plugins */
    glyr_opt_artist(&q, (char *) "Die Apokalyptischen Reiter");
    glyr_opt_album(&q, (char *) "Riders on the Storm");
    glyr_opt_title(&q, (char *) "Friede sei mit dir");

    /* Execute a func when getting one item */
    int this_be_my_counter = 0;
    glyr_opt_dlcallback(&q, funny_callback, &this_be_my_counter);

    /* For the start: Enable verbosity */
    glyr_opt_verbosity(&q, 2);

    /* Download 5 (or less) items */
    glyr_opt_number(&q, 5);

    /* Just search, without downloading items */
    glyr_opt_download(&q, 0);

    /* Call the most important command: GET!
     * This returned a list of (GlyrMemCache *)s
     * Each containing ONE item. (i.e. a songtext)
     */
    GLYR_ERROR err;
    GlyrMemCache *it = glyr_get(&q, &err, NULL);

    if(err != GLYRE_OK) {
        fprintf(stderr, "E:%s\n", glyr_strerror(err));
    }

    /* Now iterate through it... */
    if(it != NULL) {
        GlyrMemCache *start = it;

        int counter = 0;
        while(it != NULL) {
            /* This has the same effect as in the callback,
             * Just that it's executed just once after all DL is done.
             * Commented out, as this would print it twice
             * */
            print_item(it, counter);

            /* Every cache has a link to the next and prev one (or NULL respectively) */
            it = it->next;
            ++counter;
        }

        /* The contents of it are dynamically allocated. */
        /* So better free them if you're not keen on memoryleaks */
        glyr_free_list(start);
    }
    /* Destroy query (reset to default values and free dyn memory) */
    /* You could start right off to use this query in another glyr_get */
    glyr_query_destroy(&q);
    return EXIT_SUCCESS;
}