Changeset 510

Show
Ignore:
Timestamp:
09/20/07 16:41:41
Author:
rachel
Message:

Improved framework for testing larger files

Files:

Legend:

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

    r509 r510  
    11#include "CUnit/Basic.h" 
    2  
     2  
    33#include <openpgpsdk/types.h> 
    44#include "openpgpsdk/packet.h" 
     
    132132static void test_literal_data_packet_text() 
    133133    { 
     134    char* testtext=NULL; 
    134135    ops_create_info_t *cinfo; 
    135136    ops_parse_info_t *pinfo; 
    136137    ops_memory_t *mem; 
    137138 
    138     char *in=ops_mallocz(MAXBUF); 
     139    //    char *in=ops_mallocz(MAXBUF); 
    139140    int rtn=0; 
    140141 
    141142    // create test string 
    142     create_testtext("literal data packet text", &in[0], MAXBUF); 
     143    testtext=create_testtext("literal data packet text"); 
    143144 
    144145    /* 
     
    146147     */ 
    147148 
    148     ops_setup_memory_write(&cinfo,&mem,strlen(in)); 
     149    ops_setup_memory_write(&cinfo,&mem,strlen(testtext)); 
    149150 
    150151    /* 
    151152     * create literal data packet 
    152153     */ 
    153     ops_write_literal_data((unsigned char *)in,strlen(in),OPS_LDT_TEXT,cinfo); 
     154    ops_write_literal_data((unsigned char *)testtext,strlen(testtext),OPS_LDT_TEXT,cinfo); 
    154155 
    155156    /* 
     
    169170     */ 
    170171 
    171     CU_ASSERT(strncmp((char *)literal_data,in,MAXBUF)==0); 
     172    CU_ASSERT(strncmp((char *)literal_data,testtext,MAXBUF)==0); 
    172173 
    173174    // cleanup 
    174175    local_cleanup(); 
    175176    ops_teardown_memory_read(pinfo,mem); 
    176     free (in); 
     177    free (testtext); 
    177178    } 
    178179 
  • openpgpsdk/trunk/tests/test_rsa_decrypt.c

    r505 r510  
    207207    { 
    208208    char encfile[MAXBUF+1]; 
    209     char testtext[MAXBUF+1]
     209    char* testtext
    210210    char *suffix= has_armour ? "asc" : "gpg"; 
    211211    int fd=0; 
     
    249249     
    250250    // File contents should match 
    251     create_testtext(filename,&testtext[0],MAXBUF); 
     251    testtext=create_testtext(filename); 
     252    CU_ASSERT(strlen(testtext)==sz_literal_data); 
    252253    CU_ASSERT(memcmp(literal_data,testtext,sz_literal_data)==0); 
    253254    } 
  • openpgpsdk/trunk/tests/test_rsa_encrypt.c

    r509 r510  
    148148static void old_test_rsa_encrypt(const int has_armour, const ops_key_data_t *pub_key, const char *filename) 
    149149    { 
     150    char* testtext=NULL; 
    150151    ops_memory_t *mem_ldt; 
    151152    ops_create_info_t *cinfo_ldt; 
     
    241242    // File contents should match - checking with OPS 
    242243 
    243     char buffer[MAXBUF+1]; 
    244     create_testtext(filename,&buffer[0],MAXBUF); 
    245     test_rsa_decrypt(encrypted_file,buffer); 
     244    testtext=create_testtext(filename); 
     245    test_rsa_decrypt(encrypted_file,testtext); 
    246246 
    247247    // File contents should match - check with GPG 
     
    341341    // File contents should match - checking with OPS 
    342342 
    343     char buffer[MAXBUF+1]
    344     create_testtext(filename,&buffer[0],MAXBUF); 
    345     test_rsa_decrypt(encrypted_file,buffer); 
     343    char* testtext=NULL
     344    testtext=create_testtext(filename); 
     345    test_rsa_decrypt(encrypted_file,testtext); 
    346346 
    347347    // File contents should match - check with GPG 
  • openpgpsdk/trunk/tests/tests.c

    r509 r510  
    220220    } 
    221221 
    222 void create_testtext(const char *text, char *buf, const int maxlen) 
    223     { 
    224     buf[maxlen]='\0'; 
    225     snprintf(buf,maxlen,"%s : Test Text\n", text); 
     222char* create_testtext(const char *text) 
     223    { 
     224    const unsigned int repeats=2; 
     225    unsigned int i=0; 
     226 
     227    const unsigned int maxbuf=1024; 
     228    char buf[maxbuf+1]; 
     229    buf[maxbuf]='\0'; 
     230    snprintf(buf,maxbuf,"%s : Test Text\n", text); 
     231 
     232    const unsigned int sz_one=strlen(buf); 
     233    const unsigned int sz_big=sz_one*repeats+1; 
     234 
     235    char* bigbuf=ops_mallocz(sz_big);  
     236   for (i=0; i<repeats; i++) 
     237        { 
     238        char* ptr=bigbuf+ (i*(sz_one-1)); 
     239        snprintf(ptr,sz_one,buf); 
     240        } 
     241 
     242   return bigbuf; 
    226243    } 
    227244 
     
    241258void create_testfile(const char *name) 
    242259    { 
    243     unsigned int i=0; 
    244     const unsigned int limit=1; 
    245260    char filename[MAXBUF+1]; 
    246     char buffer[MAXBUF+1]
     261    char* testtext=NULL
    247262 
    248263    int fd=0; 
     
    251266        return; 
    252267 
    253     create_testtext(name,&buffer[0],MAXBUF); 
    254     for (i=0; i<limit; i++) 
    255         write(fd,buffer,strlen(buffer)); 
     268    testtext=create_testtext(name); 
     269    write(fd,testtext,strlen(testtext)); 
    256270    close(fd); 
     271    free(testtext); 
    257272    } 
    258273 
  • openpgpsdk/trunk/tests/tests.h

    r507 r510  
    2929int mktmpdir(); 
    3030extern char dir[]; 
    31 void create_testtext(const char *text, char *buf, const int maxlen); 
     31char* create_testtext(const char *text); 
    3232void create_testdata(const char *text, unsigned char *buf, const int maxlen); 
    3333void create_testfile(const char *name);