cunit: cleanup old test suites

This commit is contained in:
Marc-André Moreau
2012-09-30 16:33:42 -04:00
parent 7de10e2092
commit 440a4e23f2
15 changed files with 8 additions and 1266 deletions

View File

@@ -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

View File

@@ -1,96 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Basic Encoding Rules (BER) Unit Tests
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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 <freerdp/freerdp.h>
#include <freerdp/utils/hexdump.h>
#include <freerdp/utils/stream.h>
#include "test_ber.h"
#include <freerdp/crypto/ber.h>
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);
}

View File

@@ -1,28 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Basic Encoding Rules (BER) Unit Tests
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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);

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <freerdp/freerdp.h>
#include <freerdp/constants.h>
#include <freerdp/channels/channels.h>
#include <freerdp/utils/event.h>
#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);
}

View File

@@ -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);

View File

@@ -19,21 +19,15 @@
#include <CUnit/Basic.h>
#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])

View File

@@ -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);

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <freerdp/freerdp.h>
#include <freerdp/utils/list.h>
#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);
}

View File

@@ -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);

View File

@@ -1,64 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Packed Encoding Rules (PER) Unit Tests
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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 <freerdp/freerdp.h>
#include <freerdp/utils/hexdump.h>
#include <freerdp/utils/stream.h>
#include "test_per.h"
#include <freerdp/crypto/per.h>
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));
}

View File

@@ -1,27 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Packed Encoding Rules (PER) Unit Tests
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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);

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <freerdp/freerdp.h>
#include <freerdp/utils/hexdump.h>
#include <freerdp/utils/stream.h>
#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);
}

View File

@@ -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);

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
#include <freerdp/freerdp.h>
#include <freerdp/utils/load_plugin.h>
#include <freerdp/utils/wait_obj.h>
#include <freerdp/utils/args.h>
#include <freerdp/utils/passphrase.h>
#include <freerdp/utils/signal.h>
#include <freerdp/utils/memory.h>
#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();
}

View File

@@ -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);