55 #define KEYS(...) { __VA_ARGS__ } 58 #define EDITSTRING_TEST( name, START, EXPECTED, KEYS ) \ 59 static const int name ## _keys[] = KEYS; \ 60 static struct editstring_test name = { \ 62 .keys = name ## _keys, \ 63 .count = ( sizeof ( name ## _keys ) / \ 64 sizeof ( name ## _keys[0] ) ), \ 65 .expected = EXPECTED, \ 70 KEYS (
'h',
'e',
'l',
'l',
'o',
' ',
'w',
'o',
'r',
'l',
75 KEYS (
'h',
'i',
' ',
't',
'h',
'e',
'r',
'e' ) );
136 unsigned int line ) {
143 memset ( &
string, 0,
sizeof (
string ) );
149 okx ( actual !=
NULL, file, line );
152 DBGC (
test,
"Initial string: \"%s\"\n", actual );
155 for ( i = 0 ; i <
test->count ; i++ ) {
158 okx ( actual !=
NULL, file, line );
160 DBGC (
test,
"After key %#02x (%c): \"%s\"\n",
170 #define editstring_ok( test ) editstring_okx ( test, __FILE__, __LINE__ ) 196 .
name =
"editstring",
static void editstring_test_exec(void)
Perform editable string self-tests.
static void editstring_okx(struct editstring_test *test, const char *file, unsigned int line)
Report an editable string test result.
int replace_string(struct edit_string *string, const char *replacement)
Replace editable string.
unsigned int cursor
Cursor position.
Self-test infrastructure.
const char * name
Test set name.
struct self_test editstring_test __self_test
Editable string self-test.
const char * expected
Expected result.
static int isprint(int character)
Check if character is printable.
#define okx(success, file, line)
Report test result.
static __nonnull void init_editstring(struct edit_string *string, char **buf)
Initialise editable string.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned int count
Length of key sequence.
static void(* free)(struct refcnt *refcnt))
size_t strlen(const char *src)
Get length of string.
const int * keys
Key sequence.
int strcmp(const char *first, const char *second)
Compare strings.
#define KEY_RIGHT
Right arrow.
#define EDITSTRING_TEST(name, START, EXPECTED, KEYS)
Define an editable string test.
const char * start
Initial string, or NULL.
#define NULL
NULL pointer (VOID *)
#define KEY_LEFT
Left arrow.
#define editstring_ok(test)
#define KEYS(...)
Define an inline key sequence.
void * memset(void *dest, int character, size_t len) __nonnull