"Fossies" - the Fresh Open Source Software Archive

Member "burp-2.3.6/utest/protocol2/test_blk.c" (28 Apr 2019, 2085 Bytes) of package /linux/privat/burp-2.3.6.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "test_blk.c" see the Fossies "Dox" file reference documentation.

    1 #include "../test.h"
    2 #include "../../src/alloc.h"
    3 #include "../../src/hexmap.h"
    4 #include "../../src/iobuf.h"
    5 #include "../../src/protocol2/blk.h"
    6 #include "../../src/protocol2/rabin/rabin.h"
    7 
    8 struct bdata
    9 {
   10     int unchar;
   11     uint64_t fingerprint;
   12     const char *md5str;
   13     int expected_result;
   14 };
   15 
   16 static struct bdata b[] = {
   17     { 243, 0x00000000000000F3, "6334c2ae05c2421c687f516772b817da", 1 },
   18     { 243, 0x00000000000000F2, "6334c2ae05c2421c687f516772b817da", 0 },
   19     { 243, 0x00000000000000F3, "6334c2ae05c2421c686f516772b817da", 0 },
   20 };
   21 
   22 START_TEST(test_protocol2_blk)
   23 {
   24     struct blk *blk;
   25     alloc_check_init();
   26     hexmap_init();
   27     blks_generate_init();
   28     fail_unless((blk=blk_alloc_with_data(1))!=NULL);
   29     FOREACH(b)
   30     {
   31         char x=(unsigned char)b[i].unchar;
   32         blk->fingerprint=b[i].fingerprint;
   33         md5str_to_bytes(b[i].md5str, blk->md5sum);
   34         blk->length=1;
   35         memcpy(blk->data, &x, blk->length);
   36         fail_unless(blk_verify(blk->fingerprint, blk->md5sum,
   37             blk->data, blk->length)==b[i].expected_result);
   38     }
   39     blk_free(&blk);
   40     blks_generate_free();
   41     alloc_check();
   42 }
   43 END_TEST
   44 
   45 START_TEST(test_protocol2_blk_length_errors)
   46 {
   47     struct iobuf iobuf;
   48     struct blk blk;
   49     alloc_check_init();
   50     iobuf.len=0;
   51     fail_unless(blk_set_from_iobuf_sig_and_savepath(&blk, &iobuf)==-1);
   52     fail_unless(blk_set_from_iobuf_fingerprint(&blk, &iobuf)==-1);
   53     fail_unless(blk_set_from_iobuf_savepath(&blk, &iobuf)==-1);
   54     fail_unless(blk_set_from_iobuf_wrap_up(&blk, &iobuf)==-1);
   55     fail_unless(blk_set_from_iobuf_index_and_savepath(&blk, &iobuf)==-1);
   56     alloc_check();
   57 }
   58 END_TEST
   59 
   60 START_TEST(test_protocol2_blk_alloc_error)
   61 {
   62     alloc_check_init();
   63     alloc_errors=1;
   64     fail_unless(blk_alloc_with_data(1)==NULL);
   65     alloc_errors=2;
   66     fail_unless(blk_alloc_with_data(1)==NULL);
   67     alloc_check();
   68 }
   69 END_TEST
   70 
   71 Suite *suite_protocol2_blk(void)
   72 {
   73     Suite *s;
   74     TCase *tc_core;
   75 
   76     s=suite_create("protocol2_blk");
   77 
   78     tc_core=tcase_create("Core");
   79 
   80     tcase_add_test(tc_core, test_protocol2_blk);
   81     tcase_add_test(tc_core, test_protocol2_blk_length_errors);
   82     tcase_add_test(tc_core, test_protocol2_blk_alloc_error);
   83     suite_add_tcase(s, tc_core);
   84 
   85     return s;
   86 }