comparison src/message_test.c @ 9581:716382aaa0c0 v7.4.2068

commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jul 19 12:33:44 2016 +0200 patch 7.4.2068 Problem: Not all arguments of trunc_string() are tested. Memory access error when running the message tests. Solution: Add another test case. (Yegappan Lakshmanan) Make it easy to run unittests with valgrind. Fix the access error.
author Christian Brabandt <cb@256bit.org>
date Tue, 19 Jul 2016 12:45:05 +0200
parents 00ee8d8c2e0c
children 4aead6a9b7a9
comparison
equal deleted inserted replaced
9580:624a90bf4f05 9581:716382aaa0c0
26 * Test trunc_string(). 26 * Test trunc_string().
27 */ 27 */
28 static void 28 static void
29 test_trunc_string(void) 29 test_trunc_string(void)
30 { 30 {
31 char_u buf[40]; 31 char_u *buf; /*allocated every time to find uninit errors */
32 char_u *s;
32 33
33 /* in place */ 34 /* in place */
35 buf = alloc(40);
34 STRCPY(buf, "text"); 36 STRCPY(buf, "text");
35 trunc_string(buf, buf, 20, 40); 37 trunc_string(buf, buf, 20, 40);
36 assert(STRCMP(buf, "text") == 0); 38 assert(STRCMP(buf, "text") == 0);
39 vim_free(buf);
37 40
41 buf = alloc(40);
38 STRCPY(buf, "a short text"); 42 STRCPY(buf, "a short text");
39 trunc_string(buf, buf, 20, 40); 43 trunc_string(buf, buf, 20, 40);
40 assert(STRCMP(buf, "a short text") == 0); 44 assert(STRCMP(buf, "a short text") == 0);
45 vim_free(buf);
41 46
47 buf = alloc(40);
42 STRCPY(buf, "a text tha just fits"); 48 STRCPY(buf, "a text tha just fits");
43 trunc_string(buf, buf, 20, 40); 49 trunc_string(buf, buf, 20, 40);
44 assert(STRCMP(buf, "a text tha just fits") == 0); 50 assert(STRCMP(buf, "a text tha just fits") == 0);
51 vim_free(buf);
45 52
53 buf = alloc(40);
46 STRCPY(buf, "a text that nott fits"); 54 STRCPY(buf, "a text that nott fits");
47 trunc_string(buf, buf, 20, 40); 55 trunc_string(buf, buf, 20, 40);
48 assert(STRCMP(buf, "a text t...nott fits") == 0); 56 assert(STRCMP(buf, "a text t...nott fits") == 0);
57 vim_free(buf);
49 58
50 /* copy from string to buf */ 59 /* copy from string to buf */
51 trunc_string((char_u *)"text", buf, 20, 40); 60 buf = alloc(40);
61 s = vim_strsave((char_u *)"text");
62 trunc_string(s, buf, 20, 40);
52 assert(STRCMP(buf, "text") == 0); 63 assert(STRCMP(buf, "text") == 0);
64 vim_free(buf);
65 vim_free(s);
53 66
54 trunc_string((char_u *)"a short text", buf, 20, 40); 67 buf = alloc(40);
68 s = vim_strsave((char_u *)"a text that fits");
69 trunc_string(s, buf, 34, 40);
70 assert(STRCMP(buf, "a text that fits") == 0);
71 vim_free(buf);
72 vim_free(s);
73
74 buf = alloc(40);
75 s = vim_strsave((char_u *)"a short text");
76 trunc_string(s, buf, 20, 40);
55 assert(STRCMP(buf, "a short text") == 0); 77 assert(STRCMP(buf, "a short text") == 0);
78 vim_free(buf);
79 vim_free(s);
56 80
57 trunc_string((char_u *)"a text tha just fits", buf, 20, 40); 81 buf = alloc(40);
82 s = vim_strsave((char_u *)"a text tha just fits");
83 trunc_string(s, buf, 20, 40);
58 assert(STRCMP(buf, "a text tha just fits") == 0); 84 assert(STRCMP(buf, "a text tha just fits") == 0);
85 vim_free(buf);
86 vim_free(s);
59 87
60 trunc_string((char_u *)"a text that nott fits", buf, 20, 40); 88 buf = alloc(40);
89 s = vim_strsave((char_u *)"a text that nott fits");
90 trunc_string(s, buf, 20, 40);
61 assert(STRCMP(buf, "a text t...nott fits") == 0); 91 assert(STRCMP(buf, "a text t...nott fits") == 0);
92 vim_free(buf);
93 vim_free(s);
62 } 94 }
63 95
64 int 96 int
65 main(int argc, char **argv) 97 main(int argc, char **argv)
66 { 98 {