| 1 |
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|---|
| 2 |
|
|---|
| 3 |
/* test-demux.c - Tests for the demultiplexer. |
|---|
| 4 |
* |
|---|
| 5 |
* Copyright (C) 2007 Andreas Rottmann |
|---|
| 6 |
* |
|---|
| 7 |
* This library is free software; you can redistribute it and/or |
|---|
| 8 |
* modify it under the terms of the GNU Lesser General Public |
|---|
| 9 |
* License as published by the Free Software Foundation; either |
|---|
| 10 |
* version 2 of the License, or (at your option) any later version. |
|---|
| 11 |
* |
|---|
| 12 |
* This library is distributed in the hope that it will be useful, |
|---|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 15 |
* Lesser General Public License for more details. |
|---|
| 16 |
* |
|---|
| 17 |
* You should have received a copy of the GNU Lesser General Public |
|---|
| 18 |
* License along with this program. If not, see |
|---|
| 19 |
* <http://www.gnu.org/licenses/>. |
|---|
| 20 |
* |
|---|
| 21 |
* Authors: Andreas Rottmann <a.rottmann@gmx.at> |
|---|
| 22 |
*/ |
|---|
| 23 |
|
|---|
| 24 |
#define TEST_UNIT_NAME "FlowDemux" |
|---|
| 25 |
#define TEST_TIMEOUT_S 20 |
|---|
| 26 |
|
|---|
| 27 |
#include "test-common.c" |
|---|
| 28 |
#include "test-mux-common.c" |
|---|
| 29 |
|
|---|
| 30 |
#define N_PADS 5 |
|---|
| 31 |
#define BUFFER_SIZE 4096 |
|---|
| 32 |
#define ITERATIONS 500 |
|---|
| 33 |
|
|---|
| 34 |
static void |
|---|
| 35 |
test_run (void) |
|---|
| 36 |
{ |
|---|
| 37 |
FlowDemux *demux; |
|---|
| 38 |
FlowOutputPad *o_pads[N_PADS]; |
|---|
| 39 |
FlowInputPad *input_pad; |
|---|
| 40 |
FlowUserAdapter *adapters[N_PADS]; |
|---|
| 41 |
GList *expected_packets[N_PADS]; |
|---|
| 42 |
gint last_channel_id = -1; |
|---|
| 43 |
int i, k, len; |
|---|
| 44 |
guchar *buffer; |
|---|
| 45 |
FlowPacket *packet; |
|---|
| 46 |
|
|---|
| 47 |
buffer = g_malloc (BUFFER_SIZE); |
|---|
| 48 |
|
|---|
| 49 |
demux = flow_demux_new (); |
|---|
| 50 |
for (i = 0; i < N_PADS; i++) |
|---|
| 51 |
{ |
|---|
| 52 |
expected_packets[i] = NULL; |
|---|
| 53 |
o_pads[i] = flow_demux_add_channel (demux, i); |
|---|
| 54 |
adapters[i] = flow_user_adapter_new (); |
|---|
| 55 |
flow_pad_connect (FLOW_PAD (o_pads[i]), |
|---|
| 56 |
FLOW_PAD (flow_simplex_element_get_input_pad ( |
|---|
| 57 |
FLOW_SIMPLEX_ELEMENT (adapters[i])))); |
|---|
| 58 |
} |
|---|
| 59 |
input_pad = flow_splitter_get_input_pad (FLOW_SPLITTER (demux)); |
|---|
| 60 |
for (i = 0; i < ITERATIONS; i++) |
|---|
| 61 |
{ |
|---|
| 62 |
len = g_random_int_range (1, BUFFER_SIZE); |
|---|
| 63 |
memset (buffer, 0xaa, len); |
|---|
| 64 |
|
|---|
| 65 |
k = g_random_int_range (0, N_PADS); |
|---|
| 66 |
|
|---|
| 67 |
if (g_random_int () % 2 == 0) |
|---|
| 68 |
packet = flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buffer, len); |
|---|
| 69 |
else |
|---|
| 70 |
{ |
|---|
| 71 |
int j; |
|---|
| 72 |
packet = flow_create_simple_event_packet (FLOW_STREAM_DOMAIN, FLOW_STREAM_ERROR); |
|---|
| 73 |
for (j = 0; j < N_PADS; j++) |
|---|
| 74 |
{ |
|---|
| 75 |
if (j != k) |
|---|
| 76 |
expected_packets[j] = g_list_prepend (expected_packets[j], flow_packet_copy (packet)); |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
if (last_channel_id != k) |
|---|
| 81 |
{ |
|---|
| 82 |
flow_pad_push (FLOW_PAD (input_pad), |
|---|
| 83 |
flow_packet_new_take_object (flow_mux_event_new (k), 0)); |
|---|
| 84 |
last_channel_id = k; |
|---|
| 85 |
} |
|---|
| 86 |
flow_pad_push (FLOW_PAD (input_pad), packet); |
|---|
| 87 |
expected_packets[k] = g_list_prepend (expected_packets[k], flow_packet_copy (packet)); |
|---|
| 88 |
} |
|---|
| 89 |
flow_pad_push (FLOW_PAD (input_pad), |
|---|
| 90 |
flow_create_simple_event_packet (FLOW_STREAM_DOMAIN, FLOW_STREAM_END)); |
|---|
| 91 |
for (i = 0; i < N_PADS; i++) |
|---|
| 92 |
expected_packets[i] = g_list_prepend (expected_packets[i], |
|---|
| 93 |
flow_create_simple_event_packet (FLOW_STREAM_DOMAIN, |
|---|
| 94 |
FLOW_STREAM_END)); |
|---|
| 95 |
for (i = 0; i < N_PADS; i++) |
|---|
| 96 |
{ |
|---|
| 97 |
expected_packets[i] = g_list_reverse (expected_packets[i]); |
|---|
| 98 |
check_user_adapter_packets (adapters[i], expected_packets[i]); |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|