Esempio n. 1
0
void checkChunkResponse(ds3_client* client, uint32_t num_files, ds3_get_available_chunks_response* chunk_response, checksum_result* results) {
    uint64_t max_file_index = 0;
    int64_t file_index = 0;
    ds3_request* request = NULL;
    ds3_error* error = NULL;

    for (uint64_t object_list_index = 0; object_list_index < chunk_response->object_list->list_size; object_list_index++) {
        ds3_bulk_object_list* chunk_object_list = chunk_response->object_list->list[object_list_index];
        for (uint64_t chunk_object_index = 0; chunk_object_index < chunk_object_list->size; chunk_object_index++) {
            FILE* w_file;
            ds3_bulk_object current_obj = chunk_object_list->list[chunk_object_index];
            file_index = getFileIndexForChunk(&max_file_index, current_obj.name, results);
            
            request = ds3_init_get_object_for_job(chunk_response->object_list->bucket_name->value, current_obj.name->value, current_obj.offset, chunk_response->object_list->job_id->value);
            
            w_file = fopen(results[file_index].tmp_name, "a+");
            fseek(w_file, current_obj.offset, SEEK_SET);
            
            error = ds3_get_object(client, request, w_file, ds3_write_to_file);
            ds3_free_request(request);
            fclose(w_file);
            handle_error(error);
        }
    }

    for (uint64_t current_file_index = 0; current_file_index < max_file_index; current_file_index++) {
        printf("------Performing Data Integrity Test-------\n");
        results[current_file_index].passed = compare_hash(results[current_file_index].original_name, results[current_file_index].tmp_name);
        unlink(results[current_file_index].tmp_name);
    }
}
//FUNCTION: The 'match' function carries out pairwise PocketMatch scoring.
//It reads 2 <cabbage unit files> and directly prints a character string of results.
int match(char *file1_const, char *file2_const,
          FILE *OP_file1, FILE *OP_file2, 
          int FILE_address1, int FILE_address2)
{
/* Variable explanations:
  *file1: pointer for <cabbage unit file-1>. NOT a file-pointer
  *file1-const: input pointer, used to to keep track of the beginning of *file1
  *file2: pointer for <cabbage unit file-2>. NOT a file-pointer
  *file2-const: input pointer, used to to keep track of the beginning of *file2
  i, j: loop variables
  SUM_file1/valsum1: Total number of <distance-elements> in <cabbage unit file-1>
  SUM_file2/valsum2: Total number of <distance-elements> in <cabbage unit file-2>
  counter: counts the number of matching <distance-elements> between <cabbage unit files-1/2>

  frac1: P-min (PocketMatch minimum) score
  frac2: P-max (PocketMatch maximum) score
  bin_counter1: array[1x90] of no. of <pairwise distances> per <point-type-comparison> in <cabbage unit file-1>
  bin_counter2: array[1x90] of no. of <pairwise distances> per <point-type-comparison> in <cabbage unit file-2>
  num1end: Number of <pairwise distances> in a given <point-type-comparison> in <cabbage unit file-1>
           Extracted from val1 array[1x90]
  num2end: Number of <pairwise distances> in a given <point-type-comparison> in <cabbage unit file-2>
           Extracted from val1 array[1x90]
  num1: Incremental counter, counts from 0 to num1end
  num2: Incremental counter, counts from 0 to num2end
  name1: User-given file-name of <cabbage unit file-1>
  name2: User-given file-name of <cabbage unit file-2>
*/

int i, j;
int bin_counter1[90], bin_counter2[90];
char *file1=file1_const, *file2=file2_const;
char name1[OP_NAME_SIZE], name2[OP_NAME_SIZE];
UNION_int temp_intUNION;

//Read filename of <cabbage unit files-1/2>
for(i=0;i<OP_NAME_SIZE;++i)  {
  name1[i] = *(file1 +i +sizeof(int));
  name2[i] = *(file2 +i +sizeof(int));
  }

//Shift 'file-pointers' to appropriate location:
file1 = file1 +OP_NAME_SIZE +sizeof(int);
file2 = file2 +OP_NAME_SIZE +sizeof(int);

//Read number of <distance-elements>:
//Calculate total number of <distance-elements> for 'file1/2':
int SUM_file1=0, SUM_file2=0;
for(i=0;i<90;++i)  {
  bin_counter1[i] = *((int*)file1+i);
  SUM_file1 += bin_counter1[i];
  bin_counter2[i] = *((int*)file2+i);
  SUM_file2 += bin_counter2[i];
  }
//Shift 'file-pointers' to appropriate location:
file1 = file1+sizeof(int)*90;
file2 = file2+sizeof(int)*90;
//Declare 'element' file-pointers at start of <distance-elements> block:
element *file1_element=(element*)file1, *file1_element_const=(element*)file1;
element *file2_element=(element*)file2, *file2_element_const=(element*)file2;

//Initialise hash-table to store residues of <distance-elements> that pass CUTOFF threshold:
twin_int *hash_table1, *hash_table2;
int hash_size;
if(SUMA_TOGGLE==1)  {
  if(SUM_file1>SUM_file2) hash_size=SUM_file1;
  else hash_size=SUM_file2;
  hash_size = ((int)((sqrt(8*hash_size+1)+1)/2))+1;
  //Since 2-residue numbers accompany 1 <distance-element> the hash-table
  //size has to be a function of the largest number of <distance-elements>
  hash_table1 = make_hash(hash_size);
  hash_table2 = make_hash(hash_size);
  }

/*===================================\
|      PocketMatch Calculation       |
\===================================*/
int valsum1=0, valsum2=0, counter=0, num1end, num2end;
double frac1, frac2;
element num1, num2;
int IP_value1[3], IP_value2[3];

for(i=0;i<90;++i)  {
  valsum1 = valsum1+bin_counter1[i];
  valsum2 = valsum2+bin_counter2[i];
  if((bin_counter1[i]!=0)&&(bin_counter2[i]!=0))  {
    num1end = bin_counter1[i];
    num2end = bin_counter2[i];
    //Read <distance-elements> values, Increment file-pointers:
    num1 = *file1_element; ++file1_element;
    num2 = *file2_element; ++file2_element;

    while(1)  {
      //Count number of <distance-elements> that pass CUTOFF threshold:
      if(num1.distance.d-num2.distance.d<0.5 && num1.distance.d-num2.distance.d>-0.5)  {
        if(SUMA_TOGGLE==1)  {
          //Store 'residue-numbers' in 'hash_table1':
          IP_value1[0] = num1.residue1.i;
          IP_value1[1] = num2.residue1.i;
          IP_value1[2] = num2.residue2.i;
          IP_hash(hash_table1, IP_value1);

          IP_value1[0] = num1.residue2.i;
          IP_hash(hash_table1, IP_value1);

          //Store 'residue-numbers' in 'hash_table2':
          IP_value2[0] = num2.residue1.i;
          IP_value2[1] = num1.residue1.i;
          IP_value2[2] = num1.residue2.i;
          IP_hash(hash_table2, IP_value2);

          IP_value2[0] = num2.residue2.i;
          IP_hash(hash_table2, IP_value2);
          }
        ++counter;
        --num1end;
        --num2end;

        //Read <distance-elementse> values, Increment file-pointers:
        num1 = *file1_element; ++file1_element;
        num2 = *file2_element; ++file2_element;
        }
      else  {
        if(num1.distance.d<num2.distance.d)  {
          --num1end;
          //Read <distance-elements> value, Increment file-pointer:
          num1 = *file1_element; ++file1_element;
          }
        else  {
          --num2end;
          //Read <distance-elements> value, Increment file-pointer:
          num2 = *file2_element; ++file2_element;
          }
        }
      if(num1end<=0) break;
      if(num2end<=0) break;
      }
    }
  //Move onto another set of <point-type-comparisons>
  file1_element = file1_element_const+valsum1;
  file2_element = file2_element_const+valsum2;
  }

//Assign values to frac1 (P-min) and frac2 (P-max) based on 
//total number of <distance-elements> in <cabbage unit files-1/2>
if(valsum1<valsum2)  {
  frac1 = (double)counter/(double)valsum1;
  frac2 = (double)counter/(double)valsum2;
  }
else  {
  frac1 = (double)counter/(double)valsum2;
  frac2 = (double)counter/(double)valsum1;
  }

/*===================================\
|      SUMA-SCORE: Calculations      |
\===================================*/
int SUMA_score=0;
char SUMA_block[BLOCK_SIZE];

if(SUMA_TOGGLE==1)  {
  strncpy(SUMA_block, name1, 32);
  strncpy(SUMA_block+32, name2, 32);
  compare_hash(hash_table1, hash_table2, &SUMA_score, SUMA_block);
  }

/*===================================\
|           Output results           |
\===================================*/
//Print output string (1 line only):
//If one or more input pockets has no matches:
char *OP_string=malloc(LINE_LENGTH*sizeof(char));

if(valsum1==0||valsum2==0)  {
  if(SUMA_TOGGLE==1)  {
    sprintf(OP_string, "%.32s %.32s NULL____ NULL____ ________ ________ ________ ________\n", name1, name2);
    }
  else  {
    sprintf(OP_string, "%.32s %.32s NULL____ NULL____ ________ ________ ________\n", name1, name2);
    }
  }
//Standard output:
else  {
  if(SUMA_TOGGLE==1)  {
  sprintf(OP_string, "%.32s %.32s %8.6f %8.6f %8d %8d %8d %8d\n", name1, name2, frac1, frac2, valsum1, valsum2, counter, SUMA_score);
    }
  else  {
  sprintf(OP_string, "%.32s %.32s %8.6f %8.6f %8d %8d %8d\n", name1, name2, frac1, frac2, valsum1, valsum2, counter); 
    }
  }

//Write outputs to PM-score file, 'OP_file1':
fseek(OP_file1, FILE_address1, SEEK_SET);
for(i=0;i<LINE_LENGTH;++i) fputc(*(OP_string+i), OP_file1);

//Write outputs to SUMA-score file, 'OP_file2':
fseek(OP_file2, FILE_address2, SEEK_SET);
for(i=0;i<BLOCK_SIZE;++i) fputc(SUMA_block[i], OP_file2);

if(SUMA_TOGGLE==1)  {
  //Free the 2 hash-tables' allocated memory:
  free(hash_table1);
  free(hash_table2);
  }

//Free all allocated memory:
free(OP_string);
return 0;
}
Esempio n. 3
0
File: dib.c Progetto: aragaer/wine
static void draw_graphics(HDC hdc, BITMAPINFO *bmi, BYTE *bits, const char ***sha1)
{
    DWORD dib_size = get_dib_size(bmi);
    HPEN solid_pen, dashed_pen, orig_pen;
    HBRUSH solid_brush, dib_brush, hatch_brush, orig_brush;
    INT i, y, hatch_style;
    HRGN hrgn, hrgn2;
    BYTE dib_brush_buf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD) + 16 * 16 * sizeof(DWORD)]; /* Enough for 16 x 16 at 32 bpp */
    BITMAPINFO *brush_bi = (BITMAPINFO*)dib_brush_buf;
    BYTE *brush_bits;
    BOOL dib_is_1bpp = (bmi->bmiHeader.biBitCount == 1);

    memset(bits, 0xcc, dib_size);
    compare_hash(bmi, bits, sha1, "empty");

    solid_pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0xff));
    orig_pen = SelectObject(hdc, solid_pen);
    SetBrushOrgEx(hdc, 0, 0, NULL);

    /* horizontal and vertical lines */
    for(i = 1; i <= 16; i++)
    {
        SetROP2(hdc, i);
        MoveToEx(hdc, 10, i * 3, NULL);
        LineTo(hdc, 100, i * 3); /* l -> r */
        MoveToEx(hdc, 100, 50 + i * 3, NULL);
        LineTo(hdc, 10, 50 + i * 3); /* r -> l */
        MoveToEx(hdc, 120 + i * 3, 10, NULL);
        LineTo(hdc, 120 + i * 3, 100); /* t -> b */
        MoveToEx(hdc, 170 + i * 3, 100, NULL);
        LineTo(hdc, 170 + i * 3, 10); /* b -> t */
    }
    compare_hash(bmi, bits, sha1, "h and v solid lines");
    memset(bits, 0xcc, dib_size);

    /* diagonal lines */
    SetROP2(hdc, R2_COPYPEN);
    for(i = 0; i < 16; i++)
    {
        double s = sin(M_PI * i / 8.0);
        double c = cos(M_PI * i / 8.0);

        MoveToEx(hdc, 200.5 + 10 * c, 200.5 + 10 * s, NULL);
        LineTo(hdc, 200.5 + 100 * c, 200.5 + 100 * s);
    }
    compare_hash(bmi, bits, sha1, "diagonal solid lines");
    memset(bits, 0xcc, dib_size);

    for(i = 0; i < sizeof(bias_check) / sizeof(bias_check[0]); i++)
    {
        MoveToEx(hdc, bias_check[i].left, bias_check[i].top, NULL);
        LineTo(hdc, bias_check[i].right, bias_check[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "more diagonal solid lines");
    memset(bits, 0xcc, dib_size);

    /* solid brush PatBlt */
    solid_brush = CreateSolidBrush(RGB(0x33, 0xaa, 0xff));
    orig_brush = SelectObject(hdc, solid_brush);

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        ret = PatBlt(hdc, 10, y, 100, 10, rop3[i]);

        if(rop_uses_src(rop3[i]))
            ok(ret == FALSE, "got TRUE for %x\n", rop3[i]);
        else
        {
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 20;
        }

    }
    compare_hash(bmi, bits, sha1, "solid patblt");
    memset(bits, 0xcc, dib_size);

    /* clipped lines */
    hrgn = CreateRectRgn(10, 10, 200, 20);
    hrgn2 = CreateRectRgn(100, 100, 200, 200);
    CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
    SetRectRgn(hrgn2, 290, 100, 300, 200);
    CombineRgn(hrgn, hrgn, hrgn2, RGN_OR);
    ExtSelectClipRgn(hdc, hrgn, RGN_COPY);
    DeleteObject(hrgn2);

    for(i = 0; i < sizeof(hline_clips)/sizeof(hline_clips[0]); i++)
    {
        MoveToEx(hdc, hline_clips[i].left, hline_clips[i].top, NULL);
        LineTo(hdc, hline_clips[i].right, hline_clips[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "clipped solid hlines");
    memset(bits, 0xcc, dib_size);

    for(i = 0; i < sizeof(vline_clips)/sizeof(vline_clips[0]); i++)
    {
        MoveToEx(hdc, vline_clips[i].left, vline_clips[i].top, NULL);
        LineTo(hdc, vline_clips[i].right, vline_clips[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "clipped solid vlines");
    memset(bits, 0xcc, dib_size);

    for(i = 0; i < sizeof(line_clips)/sizeof(line_clips[0]); i++)
    {
        MoveToEx(hdc, line_clips[i].left, line_clips[i].top, NULL);
        LineTo(hdc, line_clips[i].right, line_clips[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "clipped solid diagonal lines");
    memset(bits, 0xcc, dib_size);

    /* clipped PatBlt */
    for(i = 0; i < sizeof(patblt_clips) / sizeof(patblt_clips[0]); i++)
    {
        PatBlt(hdc, patblt_clips[i].left, patblt_clips[i].top,
               patblt_clips[i].right - patblt_clips[i].left,
               patblt_clips[i].bottom - patblt_clips[i].top, PATCOPY);
    }
    compare_hash(bmi, bits, sha1, "clipped patblt");
    memset(bits, 0xcc, dib_size);

    /* clipped dashed lines */
    dashed_pen = CreatePen(PS_DASH, 1, RGB(0xff, 0, 0));
    SelectObject(hdc, dashed_pen);
    SetBkMode(hdc, TRANSPARENT);
    SetBkColor(hdc, RGB(0, 0xff, 0));

    for(i = 0; i < sizeof(hline_clips)/sizeof(hline_clips[0]); i++)
    {
        MoveToEx(hdc, hline_clips[i].left, hline_clips[i].top, NULL);
        LineTo(hdc, hline_clips[i].right, hline_clips[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "clipped dashed hlines");
    memset(bits, 0xcc, dib_size);

    for(i = 0; i < sizeof(hline_clips)/sizeof(hline_clips[0]); i++)
    {
        MoveToEx(hdc, hline_clips[i].right - 1, hline_clips[i].bottom, NULL);
        LineTo(hdc, hline_clips[i].left - 1, hline_clips[i].top);
    }
    compare_hash(bmi, bits, sha1, "clipped dashed hlines r -> l");
    memset(bits, 0xcc, dib_size);

    for(i = 0; i < sizeof(vline_clips)/sizeof(vline_clips[0]); i++)
    {
        MoveToEx(hdc, vline_clips[i].left, vline_clips[i].top, NULL);
        LineTo(hdc, vline_clips[i].right, vline_clips[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "clipped dashed vlines");
    memset(bits, 0xcc, dib_size);

    for(i = 0; i < sizeof(vline_clips)/sizeof(vline_clips[0]); i++)
    {
        MoveToEx(hdc, vline_clips[i].right, vline_clips[i].bottom - 1, NULL);
        LineTo(hdc, vline_clips[i].left, vline_clips[i].top - 1);
    }
    compare_hash(bmi, bits, sha1, "clipped dashed vlines b -> t");
    memset(bits, 0xcc, dib_size);

    for(i = 0; i < sizeof(line_clips)/sizeof(line_clips[0]); i++)
    {
        MoveToEx(hdc, line_clips[i].left, line_clips[i].top, NULL);
        LineTo(hdc, line_clips[i].right, line_clips[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "clipped dashed diagonal lines");
    memset(bits, 0xcc, dib_size);

    SetBkMode(hdc, OPAQUE);

    for(i = 0; i < sizeof(line_clips)/sizeof(line_clips[0]); i++)
    {
        MoveToEx(hdc, line_clips[i].left, line_clips[i].top, NULL);
        LineTo(hdc, line_clips[i].right, line_clips[i].bottom);
    }
    compare_hash(bmi, bits, sha1, "clipped opaque dashed diagonal lines");
    memset(bits, 0xcc, dib_size);

    ExtSelectClipRgn(hdc, NULL, RGN_COPY);

    /* 8888 DIB pattern brush */

    brush_bi->bmiHeader = dib_brush_header_8888;
    brush_bits = (BYTE*)brush_bi + sizeof(BITMAPINFOHEADER);
    memset(brush_bits, 0, 16 * 16 * sizeof(DWORD));
    brush_bits[2] = 0xff;
    brush_bits[6] = 0xff;
    brush_bits[14] = 0xff;
    brush_bits[65] = 0xff;
    brush_bits[69] = 0xff;
    brush_bits[72] = 0xff;

    dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);

    SelectObject(hdc, dib_brush);
    SetBrushOrgEx(hdc, 1, 1, NULL);

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 25;
        }
    }
    compare_hash_broken_todo(bmi, bits, sha1, "top-down 8888 dib brush patblt", dib_is_1bpp ? 2 : 0, dib_is_1bpp);
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    DeleteObject(dib_brush);

    /* 8888 bottom-up DIB pattern brush */

    brush_bi->bmiHeader.biHeight = -brush_bi->bmiHeader.biHeight;

    dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);

    SelectObject(hdc, dib_brush);

    /* This used to set the x origin to 100 as well, but
       there's a Windows bug for 24 bpp where the brush's x offset
       is incorrectly calculated for rops that involve both D and P */
    SetBrushOrgEx(hdc, 4, 100, NULL);

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 25;
        }
    }
    compare_hash_broken_todo(bmi, bits, sha1, "bottom-up 8888 dib brush patblt", dib_is_1bpp ? 2 : 0, dib_is_1bpp);
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    DeleteObject(dib_brush);

    /* 24 bpp dib pattern brush */

    brush_bi->bmiHeader = dib_brush_header_24;
    brush_bits = (BYTE*)brush_bi + sizeof(BITMAPINFOHEADER);
    memset(brush_bits, 0, 16 * 16 * 3);
    brush_bits[0] = brush_bits[3] = brush_bits[6] = brush_bits[8] = 0xff;
    brush_bits[49] = brush_bits[52] = 0xff;

    dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);

    SelectObject(hdc, dib_brush);
    SetBrushOrgEx(hdc, 1, 1, NULL);

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 25;
        }
    }
    compare_hash_broken_todo(bmi, bits, sha1, "top-down 24 bpp brush patblt", dib_is_1bpp ? 2 : 0, dib_is_1bpp);
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    DeleteObject(dib_brush);

    /* 555 dib pattern brush */

    brush_bi->bmiHeader = dib_brush_header_555;
    brush_bits = (BYTE*)brush_bi + sizeof(BITMAPINFOHEADER);
    memset(brush_bits, 0, 16 * 16 * sizeof(WORD));
    brush_bits[0] = brush_bits[1] = 0xff;
    brush_bits[32] = brush_bits[34] = 0x7c;

    dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);

    SelectObject(hdc, dib_brush);
    SetBrushOrgEx(hdc, 1, 1, NULL);

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 25;
        }
    }
    compare_hash_broken_todo(bmi, bits, sha1, "top-down 555 dib brush patblt", dib_is_1bpp ? 1 : 0, dib_is_1bpp);
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    DeleteObject(dib_brush);

    SetBrushOrgEx(hdc, 0, 0, NULL);

    /* 8 bpp dib pattern brush */

    brush_bi->bmiHeader = dib_brush_header_8;
    brush_bi->bmiHeader.biClrUsed = 3;
    memset(brush_bi->bmiColors, 0, brush_bi->bmiHeader.biClrUsed * sizeof(RGBQUAD));
    brush_bi->bmiColors[0].rgbRed = 0xff;
    brush_bi->bmiColors[1].rgbRed = 0xff;
    brush_bi->bmiColors[1].rgbGreen = 0xff;
    brush_bi->bmiColors[1].rgbBlue = 0xff;

    brush_bits = (BYTE*)brush_bi + sizeof(BITMAPINFOHEADER) + brush_bi->bmiHeader.biClrUsed * sizeof(RGBQUAD);
    memset(brush_bits, 0, 16 * 16 * sizeof(BYTE));
    brush_bits[0] = brush_bits[1] = 1;
    brush_bits[16] = brush_bits[17] = 2;
    brush_bits[32] = brush_bits[33] = 6;

    dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);

    SelectObject(hdc, dib_brush);
    SetBrushOrgEx(hdc, 1, 1, NULL);

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 25;
        }
    }
    compare_hash_broken_todo(bmi, bits, sha1, "top-down 8 bpp dib brush patblt", dib_is_1bpp ? 2 : 0, dib_is_1bpp);
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    DeleteObject(dib_brush);

    /* 4 bpp dib pattern brush */

    brush_bi->bmiHeader = dib_brush_header_4;
    dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);

    SelectObject(hdc, dib_brush);
    SetBrushOrgEx(hdc, 1, 1, NULL);

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 25;
        }
    }
    compare_hash_broken_todo(bmi, bits, sha1, "top-down 4 bpp dib brush patblt", dib_is_1bpp ? 2 : 0, dib_is_1bpp);
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    DeleteObject(dib_brush);

    /* 1 bpp dib pattern brush */

    brush_bi->bmiHeader = dib_brush_header_1;
    brush_bi->bmiHeader.biClrUsed = 2;
    memset(brush_bits, 0, 16 * 4);
    brush_bits[0] = 0xf0;
    brush_bits[4] = 0xf0;
    brush_bits[8] = 0xf0;

    dib_brush = CreateDIBPatternBrushPt(brush_bi, DIB_RGB_COLORS);
    SelectObject(hdc, dib_brush);
    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            ret = PatBlt(hdc, 10 + i, y, 100, 20, rop3[i]);
            ok(ret, "got FALSE for %x\n", rop3[i]);
            y += 25;
        }
    }

    compare_hash_broken_todo(bmi, bits, sha1, "top-down 1 bpp dib brush patblt", dib_is_1bpp ? 2 : 0, dib_is_1bpp);
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    SetBrushOrgEx(hdc, 0, 0, NULL);

    /* Rectangle */

    SelectObject(hdc, solid_pen);
    SelectObject(hdc, solid_brush);

    for(i = 0; i < sizeof(rectangles)/sizeof(rectangles[0]); i++)
    {
        Rectangle(hdc, rectangles[i].left, rectangles[i].top, rectangles[i].right, rectangles[i].bottom);
    }

    SelectObject(hdc, dashed_pen);
    for(i = 0; i < sizeof(rectangles)/sizeof(rectangles[0]); i++)
    {
        Rectangle(hdc, rectangles[i].left, rectangles[i].top + 150, rectangles[i].right, rectangles[i].bottom + 150);
    }

    compare_hash(bmi, bits, sha1, "rectangles");
    memset(bits, 0xcc, dib_size);
    SelectObject(hdc, solid_pen);

    /* PaintRgn */

    PaintRgn(hdc, hrgn);
    compare_hash(bmi, bits, sha1, "PaintRgn");
    memset(bits, 0xcc, dib_size);

    /* RTL rectangles */

    if( !pSetLayout )
    {
        win_skip("Don't have SetLayout\n");
        (*sha1)++;
    }
    else
    {
        pSetLayout(hdc, LAYOUT_RTL);
        PaintRgn(hdc, hrgn);
        PatBlt(hdc, 10, 250, 10, 10, PATCOPY);
        Rectangle(hdc, 100, 250, 110, 260);
        compare_hash(bmi, bits, sha1, "rtl");
        memset(bits, 0xcc, dib_size);

        pSetLayout(hdc, LAYOUT_LTR);
    }

    for(i = 0, y = 10; i < 256; i++)
    {
        BOOL ret;

        if(!rop_uses_src(rop3[i]))
        {
            for(hatch_style = HS_HORIZONTAL; hatch_style <= HS_DIAGCROSS; hatch_style++)
            {
                hatch_brush = CreateHatchBrush(hatch_style, RGB(0xff, 0, 0));
                SelectObject(hdc, hatch_brush);
                ret = PatBlt(hdc, 10 + i + 30 * hatch_style, y, 20, 20, rop3[i]);
                ok(ret, "got FALSE for %x\n", rop3[i]);
                SelectObject(hdc, orig_brush);
                DeleteObject(hatch_brush);
            }
            y += 25;
        }
    }

    compare_hash_broken_todo(bmi, bits, sha1, "hatch brushes", 1, FALSE); /* nt4 is different */
    memset(bits, 0xcc, dib_size);

    SelectObject(hdc, orig_brush);
    SelectObject(hdc, orig_pen);
    DeleteObject(hrgn);
    DeleteObject(dib_brush);
    DeleteObject(dashed_pen);
    DeleteObject(solid_brush);
    DeleteObject(solid_pen);
}
Esempio n. 4
0
int main (int argc, char **argv)
{
  // establish necessary variables here
  int sockfd, n;		// socket and received buffer length

  if (argc != 4)
    {
      printf ("Incorrect Arguments!\n");
      printf ("usage: client <host> <port> <filename>\n");
      exit (1);
    }

  if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
    {
      printf ("Error creating socket\n");
      exit (1);
    }

  // to convert host name (returns original IP or hostname converted to IP)
  char *host = hostname_to_ip (argv[1]);

  // set up all the network stuff
  struct sockaddr_in servaddr, cliaddr;
  bzero (&servaddr, sizeof (servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr (host);
  servaddr.sin_port = htons (atoi (argv[2]));

  if (connect (sockfd, (struct sockaddr *) &servaddr, sizeof (servaddr)) ==
      -1)
    {
      printf ("Error creating a connection with the server\n");
      exit (1);
    }

  /* send the message to the server */
  short int length = htons (strlen (argv[3]));
  n = write (sockfd, &length, sizeof (length));
  n = write (sockfd, argv[3], strlen (argv[3]));

  int file_size;
  n = read (sockfd, &file_size, sizeof (file_size));
  if (n < 0)
    error ("ERROR reading from socket");
  file_size = ntohl (file_size);
  //printf("Response read from the server: %d\n", file_size);

  if (file_size == 0)
    {
      printf ("File does not exist on the server\n");
      exit (1);
    }

  unsigned char server_hash[16];
  n = read (sockfd, &server_hash, sizeof (server_hash));
  if (n < 0)
    error ("ERROR reading from socket");

  int i;
	/*
  printf ("Server Hash: ");
  for (i = 0; i < mhash_get_block_size (MHASH_MD5); i++)
    {
      printf ("%.2x", server_hash[i]);
    }
  printf ("\n");
	 */

  FILE *file;
  file = fopen (argv[3], "w+");
  if (file == NULL)
    {
      printf ("Could not open file\n");
      exit (1);
    }

  char output[BUF_LEN];
  bzero (output, BUF_LEN);
  int downloaded = 0;
  int buffer_size;
  struct timeval start;
  struct timeval finish;
  gettimeofday(&start,NULL);
  while (downloaded < file_size)
    {
	  if ((file_size-downloaded)>=BUF_LEN)
	  {
		  buffer_size=BUF_LEN;
	  }else{
		  buffer_size=(file_size-downloaded);
	  }
      n = read (sockfd, output, buffer_size);
      fwrite (output, sizeof (char), buffer_size, file);
      bzero (output, buffer_size);
      downloaded += buffer_size;
    }
  gettimeofday(&finish,NULL);
	long microsecs_elapsed = ((finish.tv_sec - start.tv_sec)*1000000L
						  +finish.tv_usec) - start.tv_usec;
	float time_elapsed = (float)microsecs_elapsed/1000000;

  rewind (file);

	MHASH td;
	unsigned char buffer;
	unsigned char client_hash[16];
	
	td = mhash_init (MHASH_MD5);
	
	while (fread (&buffer, 1, 1, file) == 1)
    {
		mhash (td, &buffer, 1);
    }
	mhash_deinit (td, client_hash);

	/*
  printf ("Client Hash: ");
  for (i = 0; i < mhash_get_block_size (MHASH_MD5); i++)
    {
      printf ("%.2x", client_hash[i]);
    }
  printf ("\n");
	 */
	 
  fclose (file);

  if (compare_hash (server_hash, client_hash) == 0)
    {
      printf ("File transfer was unsuccessful\n");
      remove (argv[3]);
      exit (1);
    }
	
  printf("%d bytes transferred in %.6f seconds: %.6f MB/sec\n",file_size,time_elapsed,
		 (float)(file_size/1048576)/time_elapsed);
	printf("File MD5sum: ");
	for (i = 0; i < mhash_get_block_size (MHASH_MD5); i++)
    {
		printf ("%.2x", client_hash[i]);
    }
	printf ("\n");

  close (sockfd);
  return 0;
}