Advertisement
Guest User

memmove_test1

a guest
Jul 28th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void * my_memmove(void* dest, void* source, size_t n)
  6. {
  7. /*** TYPE YOUR CODE HERE ***/
  8.  
  9. /*** END MEMMOVE IMPLEMENTATION ***/
  10. }
  11.  
  12.  
  13.  
  14. void memmove_test(char*pre, char*d, char*a, char*b, int c, char* note) {
  15. char aeq[512]="", beq[512]="", *ares, *bres;
  16.  
  17. strcpy(d, pre);
  18. ares = my_memmove(a, b, c);
  19. strcpy(aeq, d);
  20.  
  21. strcpy(d, pre);
  22. bres = memmove(a, b, c);
  23. strcpy (beq, d);
  24.  
  25. if ((bres && !ares) || (ares && !bres)) {
  26. fprintf(stderr, "Test Failed: Return code disagrees!!\n");
  27. abort();
  28. }
  29.  
  30. if ( ares != bres ) {
  31. fprintf(stderr, "Test Failed: Return code disagrees!!\n");
  32. abort();
  33. }
  34.  
  35. if (memcmp(aeq,beq, c)) {
  36. fprintf(stderr, "Test Failed: Answers were not equal!\n");
  37. abort();
  38. }
  39. }
  40.  
  41.  
  42.  
  43. int main(){
  44. FILE* fp = fopen("/dev/urandom", "r");
  45. char pre[512]="";
  46. char buf[512]="";
  47. int m,n,o;
  48.  
  49. if (!fp) {
  50. perror("Test fails: No functional random device");
  51. abort();
  52. }
  53.  
  54. strcpy(pre, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghhijklmnopqrstuvwxyz!@#$%^&*()_-=+=\\|__________________________");
  55. if ( fread(pre + 100, 10, 20, fp) < 20 ) {
  56. perror("Test fails: No functional random device");
  57. abort();
  58. }
  59. fclose(fp);
  60.  
  61. for(m = 0; m < 200; m++) {
  62. for(n = 0 ; n < 200 ; n++) {
  63. for(o = 1; o < 256; o++) {
  64. memmove_test(pre,buf,buf+m, buf+n, o, "");
  65. }
  66. }
  67. }
  68. puts("Congratulations.");
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement