Revision 1845 trunk/tests/test_download_queue.c

test_download_queue.c (revision 1845)
434 434
}
435 435

                
436 436
static void
437
test_download_queue_get_next_part_to_download_one_server_all_available(void *data, gconstpointer user_data)
437
test_download_queue_get_next_part_to_download_one_server_generic(gboolean all_available)
438 438
{
439
    /* There should be 10 files with 4 parts each in the download queue now
440
     * Assume for this testcase that all parts are available on the server */
439
    /* There should be 10 files with 4 parts each in the download queue now */
441 440
    int i, j;
442 441

                
443 442
    NNTPCollection *prev_collection = NULL;
... ...
450 449

                
451 450
    GList *list, *files = NULL;
452 451

                
453
    for (i = 0; i < 10; i++) {
452
    for (i = 1; i <= 10; i++) {
454 453
        prev_file = NULL;
455 454

                
456
        for (j = 0; j < 4; j++) {
455
        for (j = 1; j <= 4; j++) {
457 456
            /* There 1 server configured at the moment, so a request for the next part for server_id 0
458 457
             * should return TRUE and nothing_do_download should_or_active be FALSE */
459 458
            if (!download_queue_get_next_part_to_download(&collection, &file, &part, 0, ¬hing_to_download_or_active)) {
... ...
461 460
                FAIL_TEST("download_queue_get_next_part_to_download returned FALSE while it isn't expected");
462 461
                return;
463 462
            } else {
463
                char *expected_subject = g_strdup_printf("file %i", i);
464

                
464 465
                g_assert_cmpint(nothing_to_download_or_active, ==, FALSE);
465 466
                g_assert(collection != NULL);
466 467
                g_assert(file != NULL);
467 468
                g_assert(part != NULL);
468 469

                
470
                g_assert_cmpint(part->part_num, ==, j);
471
                g_assert_cmpstr(file->subject, ==, expected_subject);
472

                
473
                g_free(expected_subject);
474

                
469 475
                if (prev_collection == NULL) {
470 476
                    prev_collection = collection;
471 477
                } else {
... ...
480 486
                }
481 487
            }
482 488

                
483
            /* Update the status of the part so that everything got completed succesfully */
484
            download_queue_update_part_status("server1", 0, collection, file, part, 0, TRUE, FALSE, FALSE);
489
            /* Update the status of the part */
490
            if (!all_available && j % 2 == 0) {
491
                /* Indicate the every second part isn't available on the server and it shouldn't be retried again */
492
                download_queue_update_part_status("server1", 0, collection, file, part, 0, FALSE, FALSE, TRUE);
493
            } else {
494
                /* Indicate that the file was downloaded succesfully */
495
                download_queue_update_part_status("server1", 0, collection, file, part, 0, TRUE, FALSE, FALSE);
496
            }
485 497

                
486 498
            collection = NULL;
487 499
            file = NULL;
... ...
507 519
    while (list) {
508 520
        file = (NNTPFile*) list->data;
509 521

                
510
        file->file_is_downloaded = TRUE;
511
        file->now_decoding = FALSE;
512
        file->status = TASK_STATE_FINISHED_COMPLETE;
522
        if (!all_available && g_list_index(files, file) % 2 == 0) {
523
            /* Indicate that not all parts were available */
524
            download_queue_mark_file_as_decoded_and_unref(prev_collection, file, "somefilename", TASK_STATE_FINISHED_INCOMPLETE);
525
        } else {
526
            /* Indicate that all parts were decoded succesfully */
527
            download_queue_mark_file_as_decoded_and_unref(prev_collection, file, "somefilename", TASK_STATE_FINISHED_COMPLETE);
528
        }
513 529

                
514 530
        list = g_list_next(list);
515 531
    }
... ...
528 544
    }
529 545
}
530 546

                
547
static void
548
test_download_queue_get_next_part_to_download_one_server_all_available(void *data, gconstpointer user_data)
549
{
550
    /* Assume for this testcase that all parts are available on the server */
551
    test_download_queue_get_next_part_to_download_one_server_generic(TRUE);
552
}
553

                
554
static void
555
test_download_queue_get_next_part_to_download_one_server_some_available(void *data, gconstpointer user_data)
556
{
557
    /* Assume for this testcase that some parts are available on the server */
558
    test_download_queue_get_next_part_to_download_one_server_generic(FALSE);
559
}
560

                
531 561
int
532 562
main(int argc, char **argv)
533 563
{
... ...
565 595
               test_download_queue_get_next_part_to_download_setup_one_server_after,
566 596
               test_download_queue_get_next_part_to_download_one_server_all_available,
567 597
               test_download_queue_get_next_part_to_download_teardown_one_server);
598
    g_test_add("/download_queue/get_next_part_to_download/one_server/before/some_available", void, NULL,
599
               test_download_queue_get_next_part_to_download_setup_one_server_before,
600
               test_download_queue_get_next_part_to_download_one_server_some_available,
601
               test_download_queue_get_next_part_to_download_teardown_one_server);
602
    g_test_add("/download_queue/get_next_part_to_download/one_server/after/some_available", void, NULL,
603
               test_download_queue_get_next_part_to_download_setup_one_server_after,
604
               test_download_queue_get_next_part_to_download_one_server_all_available,
605
               test_download_queue_get_next_part_to_download_teardown_one_server);
568 606

                
569 607
    /* Perform the tests */
570 608
    ret = g_test_run();

Also available in: Unified diff