summaryrefslogtreecommitdiff
path: root/src/message_test.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-07-19 12:33:44 +0200
committerBram Moolenaar <Bram@vim.org>2016-07-19 12:33:44 +0200
commitb9644433d2728e99fab874e5e33147ad95d23a31 (patch)
treee54ad05240a3009af2bf30c811ab5314ef4268d0 /src/message_test.c
parent16ec3c9be3fcdc38530bddb12978bc5a7b98c0f6 (diff)
downloadvim-git-b9644433d2728e99fab874e5e33147ad95d23a31.tar.gz
patch 7.4.2068v7.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.
Diffstat (limited to 'src/message_test.c')
-rw-r--r--src/message_test.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/message_test.c b/src/message_test.c
index 41b887579..ec231e8ef 100644
--- a/src/message_test.c
+++ b/src/message_test.c
@@ -28,37 +28,69 @@
static void
test_trunc_string(void)
{
- char_u buf[40];
+ char_u *buf; /*allocated every time to find uninit errors */
+ char_u *s;
/* in place */
+ buf = alloc(40);
STRCPY(buf, "text");
trunc_string(buf, buf, 20, 40);
assert(STRCMP(buf, "text") == 0);
+ vim_free(buf);
+ buf = alloc(40);
STRCPY(buf, "a short text");
trunc_string(buf, buf, 20, 40);
assert(STRCMP(buf, "a short text") == 0);
+ vim_free(buf);
+ buf = alloc(40);
STRCPY(buf, "a text tha just fits");
trunc_string(buf, buf, 20, 40);
assert(STRCMP(buf, "a text tha just fits") == 0);
+ vim_free(buf);
+ buf = alloc(40);
STRCPY(buf, "a text that nott fits");
trunc_string(buf, buf, 20, 40);
assert(STRCMP(buf, "a text t...nott fits") == 0);
+ vim_free(buf);
/* copy from string to buf */
- trunc_string((char_u *)"text", buf, 20, 40);
+ buf = alloc(40);
+ s = vim_strsave((char_u *)"text");
+ trunc_string(s, buf, 20, 40);
assert(STRCMP(buf, "text") == 0);
-
- trunc_string((char_u *)"a short text", buf, 20, 40);
+ vim_free(buf);
+ vim_free(s);
+
+ buf = alloc(40);
+ s = vim_strsave((char_u *)"a text that fits");
+ trunc_string(s, buf, 34, 40);
+ assert(STRCMP(buf, "a text that fits") == 0);
+ vim_free(buf);
+ vim_free(s);
+
+ buf = alloc(40);
+ s = vim_strsave((char_u *)"a short text");
+ trunc_string(s, buf, 20, 40);
assert(STRCMP(buf, "a short text") == 0);
+ vim_free(buf);
+ vim_free(s);
- trunc_string((char_u *)"a text tha just fits", buf, 20, 40);
+ buf = alloc(40);
+ s = vim_strsave((char_u *)"a text tha just fits");
+ trunc_string(s, buf, 20, 40);
assert(STRCMP(buf, "a text tha just fits") == 0);
+ vim_free(buf);
+ vim_free(s);
- trunc_string((char_u *)"a text that nott fits", buf, 20, 40);
+ buf = alloc(40);
+ s = vim_strsave((char_u *)"a text that nott fits");
+ trunc_string(s, buf, 20, 40);
assert(STRCMP(buf, "a text t...nott fits") == 0);
+ vim_free(buf);
+ vim_free(s);
}
int