From 5aea0e2e0c1fa915b7948649a6511f172e03bc32 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Wed, 28 Sep 2011 00:04:36 -0400 Subject: [PATCH] Add test to check that handle_signals resets the terminal --- cunit/test_utils.c | 40 ++++++++++++++++++++++++++++++++++++++++ cunit/test_utils.h | 1 + 2 files changed, 41 insertions(+) diff --git a/cunit/test_utils.c b/cunit/test_utils.c index 395ff4d6d..753dd890e 100644 --- a/cunit/test_utils.c +++ b/cunit/test_utils.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "test_utils.h" @@ -58,6 +59,7 @@ int add_utils_suite(void) add_test_function(wait_obj); add_test_function(args); add_test_function(passphrase_read); + add_test_function(handle_signals); return 0; } @@ -629,3 +631,41 @@ void test_passphrase_read(void) passphrase_read_prompts_to_stderr_when_no_tty(); passphrase_read_reads_from_stdin_when_no_tty(); } + +void handle_signals_resets_terminal(void) +{ + int status, masterfd; + char* slavedevice; + struct termios test_flags; + + masterfd = posix_openpt(O_RDWR|O_NOCTTY); + + if (masterfd == -1 + || grantpt (masterfd) == -1 + || unlockpt (masterfd) == -1 + || (slavedevice = ptsname (masterfd)) == NULL) + CU_FAIL_FATAL("Could not create pty"); + + terminal_fildes = open(slavedevice, O_RDWR|O_NOCTTY); + tcgetattr(terminal_fildes, &orig_flags); + new_flags = orig_flags; + new_flags.c_lflag &= ~ECHO; + tcsetattr(terminal_fildes, TCSANOW, &new_flags); + terminal_needs_reset = 1; + + if(fork() == 0) + { + freerdp_handle_signals(); + raise(SIGINT); + } + wait(&status); + tcgetattr(terminal_fildes, &test_flags); + CU_ASSERT_EQUAL(orig_flags.c_lflag, test_flags.c_lflag); + close(masterfd); + close(terminal_fildes); +} + +void test_handle_signals(void) +{ + handle_signals_resets_terminal(); +} diff --git a/cunit/test_utils.h b/cunit/test_utils.h index 39cae3920..1bc37d9ef 100644 --- a/cunit/test_utils.h +++ b/cunit/test_utils.h @@ -29,3 +29,4 @@ void test_load_plugin(void); void test_wait_obj(void); void test_args(void); void test_passphrase_read(void); +void test_handle_signals(void);