github.com/study-group-99/pilates@v0.2.2/libft/test_ft_memmove.cpp (about) 1 #include <gtest/gtest.h> 2 #include <string.h> 3 4 extern "C" { 5 #include "../libft.h" 6 } 7 8 TEST(TestFtMemmove, Basic) { 9 char s[] = "This is some text."; 10 char want[50] = {'0'}; 11 char got[50] = {'0'}; 12 13 memmove((void *)want, s, 19); ft_memmove((void *)got, s, 19); 14 15 EXPECT_STREQ(want, got) << "Input: char got[50] = {'0'}; ft_memmove((void *)got, \"This is some text.\", 19)"; 16 } 17 18 TEST(TestFtMemmove, Return) { 19 char s[] = "This is some text."; 20 char s1[50] = {'0'}; 21 char s2[50] = {'0'}; 22 23 void *want = memmove((void *)s1, s, 19); 24 void *got = ft_memmove((void *)s2, s, 19); 25 26 EXPECT_STREQ((char *)want, (char *)got) << "Input: char s2[50] = {'0'}; void *got = ft_memmove((void *)s2, \"This is some text.\", 19)"; 27 } 28 29 TEST(TestFtMemmove, ZeroCheck) { 30 char s[] = "This is some text."; 31 char want[50] = {'0'}; 32 char got[50] = {'0'}; 33 34 memmove((void *)want, s, 0); ft_memmove((void *)got, s, 0); 35 36 EXPECT_STREQ(want, got) << "Input: char got[50] = {'0'}; ft_memmove((void *)got, \"This is some text.\", 0);"; 37 } 38 39 TEST(TestFtMemmove, ZeroCheckReturn) { 40 char s[] = "This is some text."; 41 char s1[50] = {'0'}; 42 char s2[50] = {'0'}; 43 44 void *want = memmove((void *) s1, s, 0); 45 void *got = ft_memmove((void *) s2, s, 0); 46 47 EXPECT_STREQ((char *)want, (char *)got); 48 } 49 50 TEST(TestFtMemmove, Unsigned) { 51 char s[] = "thi\xffs i\xfas \0a g\xde\xadood \0nonono\0dog\0 !\r\n"; 52 char want[0xF0], got[0xF0]; 53 54 memmove(want, s, 33); ft_memmove(got, s, 33); 55 56 EXPECT_STREQ(want, got) << "Input: char got[0xF0]; ft_memmove(got, \"thi\\xffs i\\xfas \\0a g\\xde\\xadood \\0nonono\\0dog\\0 !\\r\\n\", 33);"; 57 } 58 59 TEST(TestFtMemmove, IntegerCopy) { 60 unsigned long s = 0xdeadbeef; 61 int size = sizeof(s); 62 unsigned long want; 63 unsigned long got; 64 65 memmove(&want, &s, size); ft_memmove(&got, &s, size); 66 67 EXPECT_TRUE(want == got) << "Input: unsigned long s = 0xdeadbeef; int size = sizeof(s); unsigned long got; ft_memmove(&got, &s, size);"; 68 } 69 70 TEST(TestFtMemmove, Overlap1) { 71 char s[] = "++++++++++"; 72 char want[240], got[240]; 73 int size = 240 - 15; 74 75 memset(want, 'A', sizeof(want)-1); 76 memcpy(want, s, strlen(s)); 77 78 memset(got, 'A', sizeof(got)-1); 79 memcpy(got, s, strlen(s)); 80 81 memmove(want + 3, want, size); ft_memmove(got + 3, got, size); 82 83 EXPECT_STREQ(want, got) << "Input: overlap"; 84 } 85 86 TEST(TestFtMemmove, Overlap2) { 87 char s[] = "thiß ß\xde\xad\xbe\xeftriñg will be øvérlapéd !\r\n"; 88 char got[0xF0], want[0xF0]; 89 int size = 0xF0 - 0xF; 90 91 memset(want, 'A', sizeof(want)-1); 92 memcpy(want, s, strlen(s)); 93 94 memset(got, 'A', sizeof(got)-1); 95 memcpy(got, s, strlen(s)); 96 97 memmove(got, got + 3, size); ft_memmove(want, want + 3, size); 98 99 EXPECT_STREQ(want, got) << "Input: overlap"; 100 } 101 102 TEST(TestFtMemmove, Overlap3) { 103 char got[] = "memmove can be very useful......"; 104 ft_memmove(got + 20, got + 15, 11); 105 EXPECT_STREQ("memmove can be very very useful.", got); 106 } 107 108 TEST(TestFtMemmove, BigSize) { 109 int size = 128 * 1024 * 1024; 110 char *got = (char *)malloc(sizeof(char) * size); 111 char *want = (char *)malloc(sizeof(char) * size); 112 memset(want, 'A', size); 113 114 ft_memmove(got, want, size); 115 116 EXPECT_STREQ(want, got) << "Input: int size = 128 * 1024 * 1024; char *got = (char *)malloc(sizeof(char) * size); char *want = (char *)malloc(sizeof(char) * size); ft_memmove(got, want, size);"; 117 }