1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-01-27 15:25:24 -05:00
rofi/test/textbox-test.c

162 lines
5.2 KiB
C
Raw Normal View History

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <glib.h>
#include <history.h>
#include <string.h>
2016-02-21 16:40:29 +01:00
#include <xcb/xcb.h>
#include <widgets/textbox.h>
#include <rofi.h>
#include <cairo-xlib.h>
2016-01-07 16:01:56 +01:00
#include "settings.h"
2015-09-16 21:01:40 +02:00
static int test = 0;
unsigned int normal_window_mode = 0;
2015-07-28 22:14:21 +02:00
#define TASSERT( a ) { \
assert ( a ); \
printf ( "Test %3i passed (%s)\n", ++test, # a ); \
}
2016-02-06 14:27:36 +01:00
#include "view.h"
2017-01-09 23:15:45 +01:00
void rofi_add_error_message ( GString *msg)
{
}
2016-02-06 13:06:58 +01:00
void rofi_view_queue_redraw ()
{
2016-02-28 01:21:22 +01:00
}
2017-01-03 19:35:23 +01:00
void rofi_view_get_current_monitor ( int *width, int *height )
{
2017-01-03 19:35:23 +01:00
}
2016-03-03 08:23:12 +01:00
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
2015-07-28 22:22:18 +02:00
{
fputs ( msg, stderr );
2016-03-03 08:23:12 +01:00
return FALSE;
2015-07-28 22:22:18 +02:00
}
2016-03-05 20:16:10 +01:00
int abe_test_action ( G_GNUC_UNUSED KeyBindingAction action, G_GNUC_UNUSED unsigned int mask, G_GNUC_UNUSED xkb_keysym_t key )
2016-02-28 01:21:22 +01:00
{
return FALSE;
}
int show_error_message ( const char *msg, int markup )
2015-07-28 22:22:18 +02:00
{
2016-02-08 09:03:11 +01:00
rofi_view_error_dialog ( msg, markup );
return 0;
2015-07-28 22:22:18 +02:00
}
2015-02-09 19:58:17 +01:00
int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
{
2016-02-28 15:32:53 +01:00
cairo_surface_t *surf = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, 100, 100 );
cairo_t *draw = cairo_create ( surf );
PangoContext *p = pango_cairo_create_context ( draw );
2017-01-26 17:40:46 +01:00
textbox_set_pango_context ( "default", p );
2017-01-01 16:32:01 +01:00
textbox *box = textbox_create ( "textbox", TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "test" );
2015-07-28 22:14:21 +02:00
TASSERT ( box != NULL );
textbox_keybinding ( box, MOVE_END );
2015-07-28 22:14:21 +02:00
TASSERT ( box->cursor == 4 );
textbox_cursor ( box, -1 );
2015-07-28 21:54:08 +02:00
TASSERT ( box->cursor == 0 );
textbox_cursor ( box, 8 );
2015-07-28 21:54:08 +02:00
TASSERT ( box->cursor == 4 );
textbox_cursor ( box, 2 );
2015-07-28 21:54:08 +02:00
TASSERT ( box->cursor == 2 );
textbox_insert ( box, 3, "bo", 2 );
2015-07-28 22:14:21 +02:00
TASSERT ( strcmp ( box->text, "tesbot" ) == 0 );
textbox_keybinding ( box, MOVE_END );
2015-07-28 22:14:21 +02:00
TASSERT ( box->cursor == 6 );
TASSERT ( widget_get_width ( WIDGET ( box ) ) > 0 );
2015-07-28 22:14:21 +02:00
TASSERT ( textbox_get_height ( box ) > 0 );
TASSERT ( widget_get_width ( WIDGET ( box ) ) >= textbox_get_font_width ( box ) );
2015-07-28 22:14:21 +02:00
TASSERT ( textbox_get_height ( box ) >= textbox_get_font_height ( box ) );
2015-07-28 22:14:21 +02:00
TASSERT ( textbox_get_estimated_char_width ( ) > 0 );
textbox_keybinding ( box, REMOVE_CHAR_BACK );
2015-07-28 22:14:21 +02:00
TASSERT ( strcmp ( box->text, "tesbo" ) == 0 );
TASSERT ( box->cursor == 5 );
textbox_keybinding ( box, MOVE_CHAR_BACK );
2015-07-28 22:14:21 +02:00
TASSERT ( box->cursor == 4 );
textbox_keybinding ( box, REMOVE_CHAR_FORWARD );
2015-07-28 22:14:21 +02:00
TASSERT ( strcmp ( box->text, "tesb" ) == 0 );
textbox_keybinding ( box, MOVE_CHAR_BACK );
2015-07-28 22:14:21 +02:00
TASSERT ( box->cursor == 3 );
textbox_keybinding ( box, MOVE_CHAR_FORWARD );
2015-07-28 22:14:21 +02:00
TASSERT ( box->cursor == 4 );
textbox_keybinding ( box, MOVE_CHAR_FORWARD );
2015-07-28 22:14:21 +02:00
TASSERT ( box->cursor == 4 );
// Cursor after delete section.
textbox_delete ( box, 0, 1 );
2015-07-28 22:14:21 +02:00
TASSERT ( strcmp ( box->text, "esb" ) == 0 );
TASSERT ( box->cursor == 3 );
// Cursor before delete.
2015-07-28 22:14:21 +02:00
textbox_text ( box, "aap noot mies" );
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 );
textbox_cursor ( box, 3 );
TASSERT ( box->cursor == 3 );
textbox_delete ( box, 3, 6 );
2015-07-28 22:14:21 +02:00
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
TASSERT ( box->cursor == 3 );
// Cursor within delete
2015-07-28 22:14:21 +02:00
textbox_text ( box, "aap noot mies" );
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 );
textbox_cursor ( box, 5 );
TASSERT ( box->cursor == 5 );
textbox_delete ( box, 3, 6 );
2015-07-28 22:14:21 +02:00
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
TASSERT ( box->cursor == 3 );
2015-07-28 21:54:08 +02:00
// Cursor after delete.
2015-07-28 22:14:21 +02:00
textbox_text ( box, "aap noot mies" );
TASSERT ( strcmp ( box->text, "aap noot mies" ) == 0 );
textbox_cursor ( box, 11 );
TASSERT ( box->cursor == 11 );
textbox_delete ( box, 3, 6 );
2015-07-28 22:14:21 +02:00
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
TASSERT ( box->cursor == 5 );
textbox_text ( box, "aap noot mies" );
textbox_cursor ( box, 8 );
textbox_keybinding ( box, REMOVE_WORD_BACK );
TASSERT ( box->cursor == 4 );
TASSERT ( strcmp ( box->text, "aap mies" ) == 0 );
textbox_keybinding ( box, REMOVE_TO_EOL );
TASSERT ( box->cursor == 4 );
TASSERT ( strcmp ( box->text, "aap " ) == 0 );
textbox_text ( box, "aap noot mies" );
textbox_cursor ( box, 8 );
textbox_keybinding ( box, REMOVE_WORD_FORWARD );
TASSERT ( strcmp ( box->text, "aap noot" ) == 0 );
textbox_keybinding ( box, MOVE_FRONT );
TASSERT ( box->cursor == 0 );
textbox_keybinding ( box, CLEAR_LINE );
TASSERT ( strcmp ( box->text, "" ) == 0 );
textbox_text ( box, "aap noot mies" );
textbox_keybinding ( box, MOVE_END );
textbox_keybinding ( box, MOVE_WORD_BACK );
TASSERT ( box->cursor == 9 );
textbox_keybinding ( box, MOVE_WORD_BACK );
TASSERT ( box->cursor == 4 );
textbox_keybinding ( box, REMOVE_TO_SOL );
TASSERT ( strcmp ( box->text, "noot mies" ) == 0 );
TASSERT ( box->cursor == 0 );
textbox_font ( box, HIGHLIGHT );
2016-02-28 01:21:22 +01:00
//textbox_draw ( box, draw );
2016-01-09 19:25:03 +01:00
widget_move ( WIDGET ( box ), 12, 13 );
TASSERT ( box->widget.x == 12 );
TASSERT ( box->widget.y == 13 );
widget_free ( WIDGET ( box ) );
2015-07-28 22:14:21 +02:00
textbox_cleanup ( );
}