Changeset 550

Show
Ignore:
Timestamp:
03/03/08 14:09:02
Author:
rachel
Message:

Add test for generating compressed literal data packets.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/tests/test_common.c

    r547 r550  
    270270        { 
    271271    case OPS_PARSER_PTAG: 
     272    case OPS_PTAG_CT_COMPRESSED:  
    272273        // ignore 
    273274        break; 
  • openpgpsdk/trunk/tests/test_packet_types.c

    r547 r550  
    88#include "openpgpsdk/util.h" 
    99#include "openpgpsdk/crypto.h" 
     10#include "openpgpsdk/compress.h" 
    1011#include "openpgpsdk/readerwriter.h" 
    1112#include "openpgpsdk/random.h" 
     
    171172     */ 
    172173 
    173     CU_ASSERT(strncmp((char *)ops_memory_get_data(mem_literal_data),testtext,MAXBUF)==0); 
     174    CU_ASSERT(strlen(testtext)==ops_memory_get_length(mem_literal_data)); 
     175    CU_ASSERT(strncmp((char *)ops_memory_get_data(mem_literal_data),testtext,strlen(testtext))==0); 
    174176 
    175177    // cleanup 
     
    225227    ops_teardown_memory_read(pinfo,mem); 
    226228    free (in); 
     229    } 
     230 
     231static void test_compressed_literal_data_packet_text() 
     232    { 
     233    int debug=0; 
     234    char* testtext=NULL; 
     235 
     236    ops_create_info_t *cinfo_uncompress; 
     237    ops_memory_t        *mem_uncompress; 
     238 
     239    ops_create_info_t *cinfo_compress; 
     240    ops_memory_t        *mem_compress; 
     241 
     242    ops_parse_info_t *pinfo; 
     243 
     244    int rtn=0; 
     245    unsigned int i; 
     246    ops_memory_t* mem; 
     247    unsigned char* data; 
     248    unsigned int len; 
     249 
     250    // create test string 
     251    testtext=create_testtext("compressed literal data packet text - "); 
     252 
     253    /* 
     254     * initialise needed structures for writing into memory 
     255     */ 
     256 
     257    ops_setup_memory_write(&cinfo_uncompress,&mem_uncompress,strlen(testtext)); 
     258    ops_setup_memory_write(&cinfo_compress,&mem_compress,strlen(testtext)); 
     259 
     260    /* 
     261     * create literal data packet 
     262     */ 
     263    ops_write_literal_data_from_buf((unsigned char *)testtext,strlen(testtext),OPS_LDT_TEXT,cinfo_uncompress); 
     264 
     265    // mem_uncompress now contains a LDT packet containing the text 
     266 
     267    if (debug) 
     268        { 
     269        mem=mem_uncompress; 
     270        data=ops_memory_get_data(mem); 
     271        len=ops_memory_get_length(mem); 
     272        fprintf(stderr,"\nuncompressed: (%d)\n", len); 
     273        for (i=0; i<len; i++) 
     274            { 
     275            fprintf(stderr," 0x%02x", data[i]); 
     276            } 
     277        fprintf(stderr,"\n"); 
     278        } 
     279 
     280    ops_write_compressed(ops_memory_get_data(mem_uncompress), ops_memory_get_length(mem_uncompress), cinfo_compress); 
     281 
     282    // mem_compress should now contain a COMPRESSION packet containing the LDT 
     283 
     284    /* 
     285     * initialise needed structures for reading from memory 
     286     */ 
     287 
     288    if (debug) 
     289        { 
     290        mem=mem_compress; 
     291        data=ops_memory_get_data(mem); 
     292        len=ops_memory_get_length(mem); 
     293        fprintf(stderr,"\ncompressed: (%d)\n",len); 
     294        for (i=0; i<len; i++) 
     295            { 
     296            fprintf(stderr," 0x%02x", data[i]); 
     297            } 
     298        fprintf(stderr,"\n"); 
     299        } 
     300 
     301    ops_setup_memory_read(&pinfo,mem_compress,callback_literal_data); 
     302 
     303    // and parse it 
     304 
     305    ops_memory_init(mem_literal_data,128); 
     306    ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 
     307    rtn=ops_parse(pinfo); 
     308    CU_ASSERT(rtn==1); 
     309 
     310    if (debug) 
     311        { 
     312        mem=mem_literal_data; 
     313        data=ops_memory_get_data(mem); 
     314        len=ops_memory_get_length(mem); 
     315        fprintf(stderr,"\nliteral_data: (%d)\n",len); 
     316        for (i=0; i<len; i++) 
     317            { 
     318            fprintf(stderr," 0x%02x", data[i]); 
     319            } 
     320        fprintf(stderr,"\n"); 
     321        } 
     322 
     323    /* 
     324     * test it's the same 
     325     */ 
     326 
     327 
     328    CU_ASSERT(strlen(testtext)==ops_memory_get_length(mem_literal_data)); 
     329    CU_ASSERT(strncmp((char *)ops_memory_get_data(mem_literal_data),testtext,strlen(testtext))==0); 
     330 
     331    // cleanup 
     332    local_cleanup(); 
     333    ops_teardown_memory_read(pinfo,mem_compress); 
     334    //    ops_teardown_memory_read(pinfo,mem); 
     335    free (testtext); 
    227336    } 
    228337 
     
    445554            return NULL; 
    446555     
     556    if (NULL == CU_add_test(suite, "Tag 8 and 11: Compressed Literal Data packet in Text mode", test_compressed_literal_data_packet_text)) 
     557            return NULL; 
     558     
    447559    if (NULL == CU_add_test(suite, "Tag 19: Modification Detection Code packet", test_ops_mdc)) 
    448560            return NULL;