diff --git a/cunit/CMakeLists.txt b/cunit/CMakeLists.txt index 18f7c1216..dd902d674 100644 --- a/cunit/CMakeLists.txt +++ b/cunit/CMakeLists.txt @@ -26,10 +26,6 @@ include_directories(../libfreerdp/cache) include_directories(../libfreerdp/codec) add_executable(test_freerdp - test_per.c - test_per.h - test_ber.c - test_ber.h test_gcc.c test_gcc.h test_mcs.c @@ -40,8 +36,6 @@ add_executable(test_freerdp test_bitmap.h test_gdi.c test_gdi.h - test_list.c - test_list.h test_orders.c test_orders.h test_pcap.c @@ -50,12 +44,6 @@ add_executable(test_freerdp test_ntlm.h test_license.c test_license.h - test_stream.c - test_stream.h - test_utils.c - test_utils.h - test_channels.c - test_channels.h test_cliprdr.c test_cliprdr.h test_drdynvc.c diff --git a/cunit/test_ber.c b/cunit/test_ber.c deleted file mode 100644 index cb555f0e3..000000000 --- a/cunit/test_ber.c +++ /dev/null @@ -1,96 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Basic Encoding Rules (BER) Unit Tests - * - * Copyright 2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "test_ber.h" -#include - -int init_ber_suite(void) -{ - return 0; -} - -int clean_ber_suite(void) -{ - return 0; -} - -int add_ber_suite(void) -{ - add_test_suite(ber); - - add_test_function(ber_write_length); - add_test_function(ber_write_universal_tag); - add_test_function(ber_write_application_tag); - - return 0; -} - -uint8 ber_length_expected_1[1] = "\x40"; /* 64 */ -uint8 ber_length_expected_2[3] = "\x82\x01\x94"; /* 404 */ - -void test_ber_write_length(void) -{ - STREAM *s1, *s2; - - s1 = stream_new(sizeof(ber_length_expected_1)); - s2 = stream_new(sizeof(ber_length_expected_2)); - - ber_write_length(s1, 64); - ASSERT_STREAM(s1, (uint8*) ber_length_expected_1, sizeof(ber_length_expected_1)); - - ber_write_length(s2, 404); - ASSERT_STREAM(s2, (uint8*) ber_length_expected_2, sizeof(ber_length_expected_2)); - - stream_free(s1); - stream_free(s2); -} - -/* BOOLEAN, length 1, without value */ -uint8 ber_universal_tag_expected[1] = "\x01"; - -void test_ber_write_universal_tag(void) -{ - STREAM* s; - - s = stream_new(sizeof(ber_universal_tag_expected)); - ber_write_universal_tag(s, 1, false); - - ASSERT_STREAM(s, (uint8*) ber_universal_tag_expected, sizeof(ber_universal_tag_expected)); - - stream_free(s); -} - -/* T.125 MCS Application 101 (Connect-Initial), length 404 */ -uint8 ber_application_tag_expected[5] = "\x7F\x65\x82\x01\x94"; - -void test_ber_write_application_tag(void) -{ - STREAM* s; - - s = stream_new(sizeof(ber_application_tag_expected)); - ber_write_application_tag(s, 101, 404); - - ASSERT_STREAM(s, (uint8*) ber_application_tag_expected, sizeof(ber_application_tag_expected)); - - stream_free(s); -} diff --git a/cunit/test_ber.h b/cunit/test_ber.h deleted file mode 100644 index 0cc922885..000000000 --- a/cunit/test_ber.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Basic Encoding Rules (BER) Unit Tests - * - * Copyright 2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_freerdp.h" - -int init_ber_suite(void); -int clean_ber_suite(void); -int add_ber_suite(void); - -void test_ber_write_length(void); -void test_ber_write_universal_tag(void); -void test_ber_write_application_tag(void); diff --git a/cunit/test_channels.c b/cunit/test_channels.c deleted file mode 100644 index 6ef97cda2..000000000 --- a/cunit/test_channels.c +++ /dev/null @@ -1,91 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Channel Manager Unit Tests - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "test_channels.h" - -int init_channels_suite(void) -{ - freerdp_channels_global_init(); - return 0; -} - -int clean_channels_suite(void) -{ - freerdp_channels_global_uninit(); - return 0; -} - -int add_channels_suite(void) -{ - add_test_suite(channels); - - add_test_function(channels); - - return 0; -} - -static int test_rdp_channel_data(freerdp* instance, int chan_id, uint8* data, int data_size) -{ - printf("chan_id %d data_size %d\n", chan_id, data_size); - return 0; -} - -void test_channels(void) -{ - rdpChannels* chan_man; - rdpSettings settings = { 0 }; - freerdp instance = { 0 }; - RDP_EVENT* event; - - settings.hostname = "testhost"; - instance.settings = &settings; - instance.SendChannelData = test_rdp_channel_data; - - chan_man = freerdp_channels_new(); - - freerdp_channels_load_plugin(chan_man, &settings, "../channels/rdpdbg/rdpdbg.so", NULL); - freerdp_channels_pre_connect(chan_man, &instance); - freerdp_channels_post_connect(chan_man, &instance); - - freerdp_channels_data(&instance, 0, "testdata", 8, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, 8); - freerdp_channels_data(&instance, 0, "testdata1", 9, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, 9); - freerdp_channels_data(&instance, 0, "testdata11", 10, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, 10); - freerdp_channels_data(&instance, 0, "testdata111", 11, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, 11); - - event = freerdp_event_new(RDP_EVENT_CLASS_DEBUG, 0, NULL, NULL); - freerdp_channels_send_event(chan_man, event); - - while ((event = freerdp_channels_pop_event(chan_man)) == NULL) - { - freerdp_channels_check_fds(chan_man, &instance); - } - printf("responded event_type %d\n", event->event_type); - freerdp_event_free(event); - - freerdp_channels_close(chan_man, &instance); - freerdp_channels_free(chan_man); -} diff --git a/cunit/test_channels.h b/cunit/test_channels.h deleted file mode 100644 index 678a5c08d..000000000 --- a/cunit/test_channels.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Channel Manager Unit Tests - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_freerdp.h" - -int init_channels_suite(void); -int clean_channels_suite(void); -int add_channels_suite(void); - -void test_channels(void); diff --git a/cunit/test_freerdp.c b/cunit/test_freerdp.c index a7223de83..077550054 100644 --- a/cunit/test_freerdp.c +++ b/cunit/test_freerdp.c @@ -19,21 +19,15 @@ #include -#include "test_per.h" -#include "test_ber.h" #include "test_gcc.h" #include "test_mcs.h" #include "test_color.h" #include "test_bitmap.h" #include "test_gdi.h" -#include "test_list.h" #include "test_sspi.h" -#include "test_stream.h" -#include "test_utils.h" #include "test_orders.h" #include "test_ntlm.h" #include "test_license.h" -#include "test_channels.h" #include "test_cliprdr.h" #include "test_drdynvc.h" #include "test_rfx.h" @@ -122,29 +116,23 @@ typedef struct _test_suite test_suite; const static test_suite suites[] = { - { "ber", add_ber_suite }, { "bitmap", add_bitmap_suite }, - { "channels", add_channels_suite }, - { "cliprdr", add_cliprdr_suite }, + //{ "cliprdr", add_cliprdr_suite }, { "color", add_color_suite }, - { "drdynvc", add_drdynvc_suite }, + //{ "drdynvc", add_drdynvc_suite }, { "gcc", add_gcc_suite }, { "gdi", add_gdi_suite }, { "license", add_license_suite }, - { "list", add_list_suite }, { "mcs", add_mcs_suite }, { "mppc", add_mppc_suite }, { "mppc_enc", add_mppc_enc_suite }, { "ntlm", add_ntlm_suite }, { "orders", add_orders_suite }, { "pcap", add_pcap_suite }, - { "per", add_per_suite }, - { "rail", add_rail_suite }, + //{ "rail", add_rail_suite }, { "rfx", add_rfx_suite }, { "nsc", add_nsc_suite }, - { "sspi", add_sspi_suite }, - { "stream", add_stream_suite }, - { "utils", add_utils_suite } + { "sspi", add_sspi_suite } }; #define N_SUITES (sizeof suites / sizeof suites[0]) diff --git a/cunit/test_license.c b/cunit/test_license.c index 49e7e0457..997ad6c63 100644 --- a/cunit/test_license.c +++ b/cunit/test_license.c @@ -426,8 +426,8 @@ void test_license_generate_keys(void) memcpy(license->server_random, test_server_random, sizeof(test_server_random)); memcpy(license->premaster_secret, premaster_secret, sizeof(premaster_secret)); memcpy(license->certificate->cert_info.exponent, test_exponent, sizeof(test_exponent)); - memcpy(license->certificate->cert_info.modulus.data, test_modulus, sizeof(test_modulus)); - license->certificate->cert_info.modulus.length = sizeof(test_modulus); + memcpy(license->certificate->cert_info.Modulus, test_modulus, sizeof(test_modulus)); + license->certificate->cert_info.ModulusLength = sizeof(test_modulus); license_generate_keys(license); license_encrypt_premaster_secret(license); @@ -460,8 +460,8 @@ void test_license_encrypt_premaster_secret(void) s = &_s; memcpy(license->premaster_secret, premaster_secret, sizeof(premaster_secret)); memcpy(license->certificate->cert_info.exponent, test_exponent, sizeof(test_exponent)); - memcpy(license->certificate->cert_info.modulus.data, test_modulus, sizeof(test_modulus)); - license->certificate->cert_info.modulus.length = sizeof(test_modulus); + memcpy(license->certificate->cert_info.Modulus, test_modulus, sizeof(test_modulus)); + license->certificate->cert_info.ModulusLength = sizeof(test_modulus); s->data = license->encrypted_premaster_secret->data; s->p = s->data + sizeof(test_encrypted_premaster_secret); diff --git a/cunit/test_list.c b/cunit/test_list.c deleted file mode 100644 index c5ef963f9..000000000 --- a/cunit/test_list.c +++ /dev/null @@ -1,94 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * List Unit Tests - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -#include "test_list.h" - -int init_list_suite(void) -{ - return 0; -} - -int clean_list_suite(void) -{ - return 0; -} - -int add_list_suite(void) -{ - add_test_suite(list); - - add_test_function(list); - - return 0; -} - -struct _my_list_item -{ - uint32 a; - uint32 b; -}; -typedef struct _my_list_item my_list_item; - -void test_list(void) -{ - LIST* list; - LIST_ITEM* list_item; - my_list_item* item; - my_list_item* item1; - my_list_item* item2; - int i; - - list = list_new(); - - for (i = 0; i < 10; i++) - { - item = xnew(my_list_item); - item->a = i; - item->b = i * i; - list_enqueue(list, item); - } - - for (i = 0, list_item = list->head; list_item; i++, list_item = list_item->next) - { - CU_ASSERT(((my_list_item*)list_item->data)->a == i); - CU_ASSERT(((my_list_item*)list_item->data)->b == i * i); - /*printf("%d %d\n", item->a, item->b);*/ - } - - item1 = xnew(my_list_item); - list_add(list, item1); - item2 = xnew(my_list_item); - list_add(list, item2); - - CU_ASSERT(list_remove(list, item1) == item1); - xfree(item1); - CU_ASSERT(list_remove(list, item2) == item2); - CU_ASSERT(list_remove(list, item2) == NULL); - xfree(item2); - - while ((item = list_dequeue(list)) != NULL) - xfree(item); - list_free(list); -} diff --git a/cunit/test_list.h b/cunit/test_list.h deleted file mode 100644 index 01afbb02d..000000000 --- a/cunit/test_list.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * List Unit Tests - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_freerdp.h" - -int init_list_suite(void); -int clean_list_suite(void); -int add_list_suite(void); - -void test_list(void); diff --git a/cunit/test_per.c b/cunit/test_per.c deleted file mode 100644 index 3d872849f..000000000 --- a/cunit/test_per.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Packed Encoding Rules (PER) Unit Tests - * - * Copyright 2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "test_per.h" -#include - -int init_per_suite(void) -{ - return 0; -} - -int clean_per_suite(void) -{ - return 0; -} - -int add_per_suite(void) -{ - add_test_suite(per); - - add_test_function(per_write_length); - add_test_function(per_write_object_identifier); - - return 0; -} - -uint8 per_length_expected[2] = "\x81\x2A"; - -void test_per_write_length(void) -{ - STREAM* s = stream_new(2); - per_write_length(s, 298); - ASSERT_STREAM(s, (uint8*) per_length_expected, sizeof(per_length_expected)); -} - -uint8 per_oid[6] = { 0, 0, 20, 124, 0, 1 }; -uint8 per_oid_expected[6] = "\x05\x00\x14\x7C\x00\x01"; - -void test_per_write_object_identifier(void) -{ - STREAM* s = stream_new(6); - per_write_object_identifier(s, per_oid); - ASSERT_STREAM(s, (uint8*) per_oid_expected, sizeof(per_oid_expected)); -} diff --git a/cunit/test_per.h b/cunit/test_per.h deleted file mode 100644 index 30f8d6fe6..000000000 --- a/cunit/test_per.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Packed Encoding Rules (PER) Unit Tests - * - * Copyright 2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_freerdp.h" - -int init_per_suite(void); -int clean_per_suite(void); -int add_per_suite(void); - -void test_per_write_length(void); -void test_per_write_object_identifier(void); diff --git a/cunit/test_stream.c b/cunit/test_stream.c deleted file mode 100644 index ae1a9e256..000000000 --- a/cunit/test_stream.c +++ /dev/null @@ -1,76 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Stream Unit Tests - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -#include "test_stream.h" - -int init_stream_suite(void) -{ - return 0; -} - -int clean_stream_suite(void) -{ - return 0; -} - -int add_stream_suite(void) -{ - add_test_suite(stream); - - add_test_function(stream); - - return 0; -} - -void test_stream(void) -{ - STREAM * stream; - int pos; - uint32 n; - uint64 n64; - - stream = stream_new(1); - pos = stream_get_pos(stream); - - stream_write_uint8(stream, 0xFE); - - stream_check_size(stream, 14); - stream_write_uint16(stream, 0x0102); - stream_write_uint32(stream, 0x03040506); - stream_write_uint64(stream, 0x0708091011121314LL); - - /* freerdp_hexdump(stream->buffer, 15); */ - - stream_set_pos(stream, pos); - stream_seek(stream, 3); - stream_read_uint32(stream, n); - stream_read_uint64(stream, n64); - - CU_ASSERT(n == 0x03040506); - CU_ASSERT(n64 == 0x0708091011121314LL); - - stream_free(stream); -} diff --git a/cunit/test_stream.h b/cunit/test_stream.h deleted file mode 100644 index 32080edb5..000000000 --- a/cunit/test_stream.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Stream Unit Tests - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_freerdp.h" - -int init_stream_suite(void); -int clean_stream_suite(void); -int add_stream_suite(void); - -void test_stream(void); diff --git a/cunit/test_utils.c b/cunit/test_utils.c deleted file mode 100644 index 673da5163..000000000 --- a/cunit/test_utils.c +++ /dev/null @@ -1,650 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Utils Unit Tests - * - * Copyright 2011 Vic Lee, 2011 Shea Levy - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define _XOPEN_SOURCE 700 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "test_utils.h" - -int init_utils_suite(void) -{ - return 0; -} - -int clean_utils_suite(void) -{ - return 0; -} - -int add_utils_suite(void) -{ - add_test_suite(utils); - - add_test_function(load_plugin); - add_test_function(wait_obj); - add_test_function(args); - add_test_function(passphrase_read); - add_test_function(handle_signals); - - return 0; -} - -void test_load_plugin(void) -{ - void* entry; - -#ifdef _WIN32 - /* untested */ - entry = freerdp_load_plugin("..\\channels\\cliprdr\\cliprdr", "VirtualChannelEntry"); -#else - entry = freerdp_load_plugin("../channels/cliprdr/cliprdr.so", "VirtualChannelEntry"); -#endif - CU_ASSERT(entry != NULL); -} - -void test_wait_obj(void) -{ - struct wait_obj* wo; - int set; - - wo = wait_obj_new(); - - set = wait_obj_is_set(wo); - CU_ASSERT(set == 0); - - wait_obj_set(wo); - set = wait_obj_is_set(wo); - CU_ASSERT(set == 1); - - wait_obj_clear(wo); - set = wait_obj_is_set(wo); - CU_ASSERT(set == 0); - - wait_obj_select(&wo, 1, 1000); - - wait_obj_free(wo); -} - -static int process_plugin_args(rdpSettings* settings, const char* name, - RDP_PLUGIN_DATA* plugin_data, void* user_data) -{ - /*printf("load plugin: %s\n", name);*/ - return 1; -} - -static int process_ui_args(rdpSettings* settings, const char* opt, - const char* val, void* user_data) -{ - /*printf("ui arg: %s %s\n", opt, val);*/ - return 1; -} - -void test_args(void) -{ - char* argv_c[] = - { - "freerdp", "-a", "8", "-u", "testuser", "-d", "testdomain", "-g", "640x480", "address1:3389", - "freerdp", "-a", "16", "-u", "testuser", "-d", "testdomain", "-g", "1280x960", "address2:3390" - }; - char** argv = argv_c; - int argc = ARRAY_SIZE(argv_c); - int i; - int c; - rdpSettings* settings; - - i = 0; - while (argc > 0) - { - settings = settings_new(NULL); - - i++; - c = freerdp_parse_args(settings, argc, argv, process_plugin_args, NULL, process_ui_args, NULL); - CU_ASSERT(c > 0); - if (c == 0) - { - settings_free(settings); - break; - } - CU_ASSERT(settings->color_depth == i * 8); - CU_ASSERT(settings->width == i * 640); - CU_ASSERT(settings->height == i * 480); - CU_ASSERT(settings->port == i + 3388); - - settings_free(settings); - argc -= c; - argv += c; - } - CU_ASSERT(i == 2); -} - -void passphrase_read_prompts_to_tty() -{ - static const int read_nbyte = 11; - int masterfd; - char* slavedevice = NULL; - char read_buf[read_nbyte]; - fd_set fd_set_write; - - 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"); - - switch (fork()) - { - case -1: - CU_FAIL_FATAL("Could not fork"); - case 0: - { - static const int password_size = 512; - char buffer[password_size]; - int slavefd; - if (setsid() == (pid_t) -1) - CU_FAIL_FATAL("Could not create new session"); - - if ((slavefd = open(slavedevice, O_RDWR)) == 0) - CU_FAIL_FATAL("Could not open slave end of pty"); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - close(masterfd); - freerdp_passphrase_read("Password: ", buffer, password_size, 0); - close(slavefd); - exit(EXIT_SUCCESS); - } - } - - read_buf[read_nbyte - 1] = '\0'; - - FD_ZERO(&fd_set_write); - FD_SET(masterfd, &fd_set_write); - if (select(masterfd + 1, NULL, &fd_set_write, NULL, NULL) == -1) - CU_FAIL_FATAL("Master end of pty not writeable"); - if (read(masterfd, read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to slave end of pty"); - CU_ASSERT_STRING_EQUAL(read_buf, "Password: "); - - write(masterfd, "\n", (size_t) 2); - close(masterfd); - return; -} - -void passphrase_read_reads_from_tty() -{ - static const int read_nbyte = 11; - int masterfd; - int pipe_ends[2]; - char* slavedevice = NULL; - char read_buf[read_nbyte]; - fd_set fd_set_write; - - 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"); - - if (pipe(pipe_ends) != 0) - CU_FAIL_FATAL("Could not create pipe"); - - switch (fork()) - { - case -1: - CU_FAIL_FATAL("Could not fork"); - case 0: - { - static const int password_size = 512; - char buffer[password_size]; - int slavefd; - if (setsid() == (pid_t) -1) - CU_FAIL_FATAL("Could not create new session"); - - if ((slavefd = open(slavedevice, O_RDWR)) == 0) - CU_FAIL_FATAL("Could not open slave end of pty"); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - close(masterfd); - close(pipe_ends[0]); - freerdp_passphrase_read("Password: ", buffer, password_size, 0); - write(pipe_ends[1], buffer, password_size); - close(slavefd); - close(pipe_ends[1]); - exit(EXIT_SUCCESS); - } - } - - close(pipe_ends[1]); - read_buf[read_nbyte - 1] = '\0'; - - FD_ZERO(&fd_set_write); - FD_SET(masterfd, &fd_set_write); - if (select(masterfd + 1, NULL, &fd_set_write, NULL, NULL) == -1) - CU_FAIL_FATAL("Master end of pty not writeable"); - if (read(masterfd, read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to slave end of pty"); - - write(masterfd, "passw0rd\n", sizeof "passw0rd\n"); - if (read(pipe_ends[0], read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to pipe"); - CU_ASSERT_STRING_EQUAL(read_buf, "passw0rd"); - close(masterfd); - close(pipe_ends[0]); - return; -} - -void passphrase_read_turns_off_echo_during_read() -{ - static const int read_nbyte = 11; - int masterfd, slavefd; - char* slavedevice = NULL; - char read_buf[read_nbyte]; - fd_set fd_set_write; - struct termios term_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"); - - slavefd = open(slavedevice, O_RDWR|O_NOCTTY); - if (slavefd == -1) - CU_FAIL_FATAL("Could not open slave end of pty"); - - if (tcgetattr(slavefd, &term_flags) != 0) - CU_FAIL_FATAL("Could not get slave pty attributes"); - if (!(term_flags.c_lflag & ECHO)) - { - term_flags.c_lflag |= ECHO; - if (tcsetattr(slavefd, TCSANOW, &term_flags) != 0) - CU_FAIL_FATAL("Could not turn ECHO on on slave pty"); - } - - switch (fork()) - { - case -1: - CU_FAIL_FATAL("Could not fork"); - case 0: - { - static const int password_size = 512; - int child_slavefd; - char buffer[password_size]; - if (setsid() == (pid_t) -1) - CU_FAIL_FATAL("Could not create new session"); - - if ((child_slavefd = open(slavedevice, O_RDWR)) == 0) - CU_FAIL_FATAL("Could not open slave end of pty"); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - close(masterfd); - close(slavefd); - freerdp_passphrase_read("Password: ", buffer, password_size, 0); - close(child_slavefd); - exit(EXIT_SUCCESS); - } - } - - read_buf[read_nbyte - 1] = '\0'; - - FD_ZERO(&fd_set_write); - FD_SET(masterfd, &fd_set_write); - if (select(masterfd + 1, NULL, &fd_set_write, NULL, NULL) == -1) - CU_FAIL_FATAL("Master end of pty not writeable"); - if (read(masterfd, read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to slave end of pty"); - - if (tcgetattr(slavefd, &term_flags) != 0) - CU_FAIL_FATAL("Could not get slave pty attributes"); - CU_ASSERT(!(term_flags.c_lflag & ECHO)) - write(masterfd, "\n", (size_t) 2); - close(masterfd); - close(slavefd); - return; -} - -void passphrase_read_resets_terminal_after_read() -{ - static const int read_nbyte = 11; - int masterfd, slavefd, status; - char* slavedevice = NULL; - char read_buf[read_nbyte]; - fd_set fd_set_write; - struct termios term_flags; - pid_t child; - - 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"); - - slavefd = open(slavedevice, O_RDWR|O_NOCTTY); - if (slavefd == -1) - CU_FAIL_FATAL("Could not open slave end of pty"); - - if (tcgetattr(slavefd, &term_flags) != 0) - CU_FAIL_FATAL("Could not get slave pty attributes"); - if (!(term_flags.c_lflag & ECHO)) - { - term_flags.c_lflag |= ECHO; - if (tcsetattr(slavefd, TCSANOW, &term_flags) != 0) - CU_FAIL_FATAL("Could not turn ECHO on on slave pty"); - } - - switch (child = fork()) - { - case -1: - CU_FAIL_FATAL("Could not fork"); - case 0: - { - static const int password_size = 512; - int child_slavefd; - char buffer[password_size]; - if (setsid() == (pid_t) -1) - CU_FAIL_FATAL("Could not create new session"); - - if ((child_slavefd = open(slavedevice, O_RDWR)) == 0) - CU_FAIL_FATAL("Could not open slave end of pty"); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - close(masterfd); - close(slavefd); - freerdp_passphrase_read("Password: ", buffer, password_size, 0); - close(child_slavefd); - exit(EXIT_SUCCESS); - } - } - - read_buf[read_nbyte - 1] = '\0'; - - FD_ZERO(&fd_set_write); - FD_SET(masterfd, &fd_set_write); - if (select(masterfd + 1, NULL, &fd_set_write, NULL, NULL) == -1) - CU_FAIL_FATAL("Master end of pty not writeable"); - if (read(masterfd, read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to slave end of pty"); - - write(masterfd, "\n", (size_t) 2); - waitpid(child, &status, WUNTRACED); - if (tcgetattr(slavefd, &term_flags) != 0) - CU_FAIL_FATAL("Could not get slave pty attributes"); - CU_ASSERT(term_flags.c_lflag & ECHO) - close(masterfd); - close(slavefd); - return; -} - -void passphrase_read_turns_on_newline_echo_during_read() -{ - static const int read_nbyte = 11; - int masterfd, slavefd; - char* slavedevice = NULL; - char read_buf[read_nbyte]; - fd_set fd_set_write; - struct termios term_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"); - - slavefd = open(slavedevice, O_RDWR|O_NOCTTY); - if (slavefd == -1) - CU_FAIL_FATAL("Could not open slave end of pty"); - - if (tcgetattr(slavefd, &term_flags) != 0) - CU_FAIL_FATAL("Could not get slave pty attributes"); - if (term_flags.c_lflag & ECHONL) - { - term_flags.c_lflag &= ~ECHONL; - if (tcsetattr(slavefd, TCSANOW, &term_flags) != 0) - CU_FAIL_FATAL("Could not turn ECHO on on slave pty"); - } - - switch (fork()) - { - case -1: - CU_FAIL_FATAL("Could not fork"); - case 0: - { - static const int password_size = 512; - int child_slavefd; - char buffer[password_size]; - if (setsid() == (pid_t) -1) - CU_FAIL_FATAL("Could not create new session"); - - if ((child_slavefd = open(slavedevice, O_RDWR)) == 0) - CU_FAIL_FATAL("Could not open slave end of pty"); - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - close(masterfd); - close(slavefd); - freerdp_passphrase_read("Password: ", buffer, password_size, 0); - close(child_slavefd); - exit(EXIT_SUCCESS); - } - } - - read_buf[read_nbyte - 1] = '\0'; - - FD_ZERO(&fd_set_write); - FD_SET(masterfd, &fd_set_write); - if (select(masterfd + 1, NULL, &fd_set_write, NULL, NULL) == -1) - CU_FAIL_FATAL("Master end of pty not writeable"); - if (read(masterfd, read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to slave end of pty"); - - if (tcgetattr(slavefd, &term_flags) != 0) - CU_FAIL_FATAL("Could not get slave pty attributes"); - CU_ASSERT(term_flags.c_lflag & ECHONL) - write(masterfd, "\n", (size_t) 2); - close(masterfd); - close(slavefd); - return; -} - -void passphrase_read_prompts_to_stderr_when_no_tty() -{ - static const int read_nbyte = 11; - int stdin_pipe[2], stderr_pipe[2]; - char read_buf[read_nbyte]; - struct sigaction ignore, orig; - - ignore.sa_handler = SIG_IGN; - sigemptyset(&ignore.sa_mask); - - if (pipe(stdin_pipe) != 0 || pipe(stderr_pipe) != 0) - CU_FAIL_FATAL("Could not create pipe"); - - switch (fork()) - { - case -1: - CU_FAIL_FATAL("Could not fork"); - case 0: - { - static const int password_size = 512; - char buffer[password_size]; - close(stderr_pipe[0]); - close(stdin_pipe[1]); - if (setsid() == (pid_t) -1) - CU_FAIL_FATAL("Could not create new session"); - - dup2(stdin_pipe[0], STDIN_FILENO); - dup2(stderr_pipe[1], STDERR_FILENO); - freerdp_passphrase_read("Password: ", buffer, password_size, 0); - exit(EXIT_SUCCESS); - } - } - close(stderr_pipe[1]); - close(stdin_pipe[0]); - - read_buf[read_nbyte - 1] = '\0'; - - if (read(stderr_pipe[0], read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to pipe"); - CU_ASSERT_STRING_EQUAL(read_buf, "Password: "); - - sigaction(SIGPIPE, &ignore, &orig); - write(stdin_pipe[1], "\n", (size_t) 2); - sigaction(SIGPIPE, &orig, NULL); - close(stderr_pipe[0]); - close(stdin_pipe[1]); - return; -} - -void passphrase_read_reads_from_stdin_when_no_tty() -{ - static const int read_nbyte = 11; - int stdin_pipe[2], stderr_pipe[2], result_pipe[2]; - char read_buf[read_nbyte]; - struct sigaction ignore, orig; - - ignore.sa_handler = SIG_IGN; - sigemptyset(&ignore.sa_mask); - - if (pipe(stdin_pipe) != 0 - || pipe(stderr_pipe) != 0 - || pipe(result_pipe) !=0) - CU_FAIL_FATAL("Could not create pipe"); - - switch (fork()) - { - case -1: - CU_FAIL_FATAL("Could not fork"); - case 0: - { - static const int password_size = 512; - char buffer[password_size]; - close(stderr_pipe[0]); - close(result_pipe[0]); - close(stdin_pipe[1]); - if (setsid() == (pid_t) -1) - CU_FAIL_FATAL("Could not create new session"); - - dup2(stdin_pipe[0], STDIN_FILENO); - dup2(stderr_pipe[1], STDERR_FILENO); - freerdp_passphrase_read("Password: ", buffer, password_size, 0); - write(result_pipe[1], buffer, strlen(buffer) + (size_t) 1); - exit(EXIT_SUCCESS); - } - } - close(stderr_pipe[1]); - close(result_pipe[1]); - close(stdin_pipe[0]); - - read_buf[read_nbyte - 1] = '\0'; - - if (read(stderr_pipe[0], read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to pipe"); - - sigaction(SIGPIPE, &ignore, &orig); - write(stdin_pipe[1], "passw0rd\n", sizeof "passw0rd\n"); - sigaction(SIGPIPE, &orig, NULL); - - if (read(result_pipe[0], read_buf, read_nbyte) == (ssize_t) -1) - CU_FAIL_FATAL("Nothing written to pipe"); - CU_ASSERT_STRING_EQUAL(read_buf, "passw0rd"); - - close(stderr_pipe[0]); - close(stdin_pipe[1]); - return; -} - -void test_passphrase_read(void) -{ - passphrase_read_prompts_to_tty(); - passphrase_read_reads_from_tty(); - passphrase_read_turns_off_echo_during_read(); - passphrase_read_resets_terminal_after_read(); - passphrase_read_turns_on_newline_echo_during_read(); - 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 = NULL; - struct termios test_flags; - pid_t child_pid; - - 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((child_pid = fork()) == 0) - { - freerdp_handle_signals(); - raise(SIGINT); - } - while(wait(&status) != -1); - 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 deleted file mode 100644 index 6f7567603..000000000 --- a/cunit/test_utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Utils Unit Tests - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "test_freerdp.h" - -int init_utils_suite(void); -int clean_utils_suite(void); -int add_utils_suite(void); - -void test_load_plugin(void); -void test_wait_obj(void); -void test_args(void); -void test_passphrase_read(void); -void test_handle_signals(void);