1 /* vi:set ts=8 sts=4 sw=4 noet: 2 * 3 * VIM - Vi IMproved by Bram Moolenaar 4 * 5 * Do ":help uganda" in Vim to read copying and usage conditions. 6 * Do ":help credits" in Vim to see a list of people who contributed. 7 * See README.txt for an overview of the Vim source code. 8 */ 9 10 /* 11 * message_test.c: Unittests for message.c 12 */ 13 14 #undef NDEBUG 15 #include <assert.h> 16 17 /* Must include main.c because it contains much more than just main() */ 18 #define NO_VIM_MAIN 19 #include "main.c" 20 21 /* This file has to be included because some of the tested functions are 22 * static. */ 23 #include "message.c" 24 25 /* 26 * Test trunc_string(). 27 */ 28 static void 29 test_trunc_string(void) 30 { 31 char_u *buf; /*allocated every time to find uninit errors */ 32 char_u *s; 33 34 /* in place */ 35 buf = alloc(40); 36 STRCPY(buf, "text"); 37 trunc_string(buf, buf, 20, 40); 38 assert(STRCMP(buf, "text") == 0); 39 vim_free(buf); 40 41 buf = alloc(40); 42 STRCPY(buf, "a short text"); 43 trunc_string(buf, buf, 20, 40); 44 assert(STRCMP(buf, "a short text") == 0); 45 vim_free(buf); 46 47 buf = alloc(40); 48 STRCPY(buf, "a text tha just fits"); 49 trunc_string(buf, buf, 20, 40); 50 assert(STRCMP(buf, "a text tha just fits") == 0); 51 vim_free(buf); 52 53 buf = alloc(40); 54 STRCPY(buf, "a text that nott fits"); 55 trunc_string(buf, buf, 20, 40); 56 assert(STRCMP(buf, "a text t...nott fits") == 0); 57 vim_free(buf); 58 59 /* copy from string to buf */ 60 buf = alloc(40); 61 s = vim_strsave((char_u *)"text"); 62 trunc_string(s, buf, 20, 40); 63 assert(STRCMP(buf, "text") == 0); 64 vim_free(buf); 65 vim_free(s); 66 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); 77 assert(STRCMP(buf, "a short text") == 0); 78 vim_free(buf); 79 vim_free(s); 80 81 buf = alloc(40); 82 s = vim_strsave((char_u *)"a text tha just fits"); 83 trunc_string(s, buf, 20, 40); 84 assert(STRCMP(buf, "a text tha just fits") == 0); 85 vim_free(buf); 86 vim_free(s); 87 88 buf = alloc(40); 89 s = vim_strsave((char_u *)"a text that nott fits"); 90 trunc_string(s, buf, 20, 40); 91 assert(STRCMP(buf, "a text t...nott fits") == 0); 92 vim_free(buf); 93 vim_free(s); 94 } 95 96 int 97 main(int argc, char **argv) 98 { 99 vim_memset(¶ms, 0, sizeof(params)); 100 params.argc = argc; 101 params.argv = argv; 102 common_init(¶ms); 103 init_chartab(); 104 105 test_trunc_string(); 106 return 0; 107 } 108