Changeset 510
- Timestamp:
- 09/20/07 16:41:41
- Files:
-
- openpgpsdk/trunk/tests/test_packet_types.c (modified) (4 diffs)
- openpgpsdk/trunk/tests/test_rsa_decrypt.c (modified) (2 diffs)
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (3 diffs)
- openpgpsdk/trunk/tests/tests.c (modified) (3 diffs)
- openpgpsdk/trunk/tests/tests.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/tests/test_packet_types.c
r509 r510 1 1 #include "CUnit/Basic.h" 2 2 3 3 #include <openpgpsdk/types.h> 4 4 #include "openpgpsdk/packet.h" … … 132 132 static void test_literal_data_packet_text() 133 133 { 134 char* testtext=NULL; 134 135 ops_create_info_t *cinfo; 135 136 ops_parse_info_t *pinfo; 136 137 ops_memory_t *mem; 137 138 138 char *in=ops_mallocz(MAXBUF);139 // char *in=ops_mallocz(MAXBUF); 139 140 int rtn=0; 140 141 141 142 // create test string 142 create_testtext("literal data packet text", &in[0], MAXBUF);143 testtext=create_testtext("literal data packet text"); 143 144 144 145 /* … … 146 147 */ 147 148 148 ops_setup_memory_write(&cinfo,&mem,strlen( in));149 ops_setup_memory_write(&cinfo,&mem,strlen(testtext)); 149 150 150 151 /* 151 152 * create literal data packet 152 153 */ 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); 154 155 155 156 /* … … 169 170 */ 170 171 171 CU_ASSERT(strncmp((char *)literal_data, in,MAXBUF)==0);172 CU_ASSERT(strncmp((char *)literal_data,testtext,MAXBUF)==0); 172 173 173 174 // cleanup 174 175 local_cleanup(); 175 176 ops_teardown_memory_read(pinfo,mem); 176 free ( in);177 free (testtext); 177 178 } 178 179 openpgpsdk/trunk/tests/test_rsa_decrypt.c
r505 r510 207 207 { 208 208 char encfile[MAXBUF+1]; 209 char testtext[MAXBUF+1];209 char* testtext; 210 210 char *suffix= has_armour ? "asc" : "gpg"; 211 211 int fd=0; … … 249 249 250 250 // File contents should match 251 create_testtext(filename,&testtext[0],MAXBUF); 251 testtext=create_testtext(filename); 252 CU_ASSERT(strlen(testtext)==sz_literal_data); 252 253 CU_ASSERT(memcmp(literal_data,testtext,sz_literal_data)==0); 253 254 } openpgpsdk/trunk/tests/test_rsa_encrypt.c
r509 r510 148 148 static void old_test_rsa_encrypt(const int has_armour, const ops_key_data_t *pub_key, const char *filename) 149 149 { 150 char* testtext=NULL; 150 151 ops_memory_t *mem_ldt; 151 152 ops_create_info_t *cinfo_ldt; … … 241 242 // File contents should match - checking with OPS 242 243 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); 246 246 247 247 // File contents should match - check with GPG … … 341 341 // File contents should match - checking with OPS 342 342 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); 346 346 347 347 // File contents should match - check with GPG openpgpsdk/trunk/tests/tests.c
r509 r510 220 220 } 221 221 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); 222 char* 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; 226 243 } 227 244 … … 241 258 void create_testfile(const char *name) 242 259 { 243 unsigned int i=0;244 const unsigned int limit=1;245 260 char filename[MAXBUF+1]; 246 char buffer[MAXBUF+1];261 char* testtext=NULL; 247 262 248 263 int fd=0; … … 251 266 return; 252 267 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)); 256 270 close(fd); 271 free(testtext); 257 272 } 258 273 openpgpsdk/trunk/tests/tests.h
r507 r510 29 29 int mktmpdir(); 30 30 extern char dir[]; 31 void create_testtext(const char *text, char *buf, const int maxlen);31 char* create_testtext(const char *text); 32 32 void create_testdata(const char *text, unsigned char *buf, const int maxlen); 33 33 void create_testfile(const char *name);
