| 1 |
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|---|
| 2 |
|
|---|
| 3 |
/* test-packet.c - FlowPacket test. |
|---|
| 4 |
* |
|---|
| 5 |
* Copyright (C) 2006 Hans Petter Jansson |
|---|
| 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 library; if not, write to the |
|---|
| 19 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 20 |
* Boston, MA 02111-1307, USA. |
|---|
| 21 |
* |
|---|
| 22 |
* Authors: Hans Petter Jansson <hpj@copyleft.no> |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
#define TEST_UNIT_NAME "FlowPacket" |
|---|
| 26 |
#define TEST_TIMEOUT_S 20 |
|---|
| 27 |
|
|---|
| 28 |
#include "test-common.c" |
|---|
| 29 |
|
|---|
| 30 |
#define BUFFER_SIZE (1 << 19) /* 1 Mi */ |
|---|
| 31 |
#define ITERATIONS 500 |
|---|
| 32 |
|
|---|
| 33 |
static void |
|---|
| 34 |
test_run (void) |
|---|
| 35 |
{ |
|---|
| 36 |
FlowPacket *packet; |
|---|
| 37 |
guchar *buffer; |
|---|
| 38 |
guint len; |
|---|
| 39 |
gint i; |
|---|
| 40 |
|
|---|
| 41 |
buffer = g_malloc (BUFFER_SIZE); |
|---|
| 42 |
|
|---|
| 43 |
for (i = 0; i < ITERATIONS; i++) |
|---|
| 44 |
{ |
|---|
| 45 |
/* Test buffer */ |
|---|
| 46 |
|
|---|
| 47 |
len = g_random_int_range (1, BUFFER_SIZE); |
|---|
| 48 |
memset (buffer, 0xaa, len); |
|---|
| 49 |
|
|---|
| 50 |
packet = flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buffer, len); |
|---|
| 51 |
|
|---|
| 52 |
if (flow_packet_get_format (packet) != FLOW_PACKET_FORMAT_BUFFER) |
|---|
| 53 |
test_end (TEST_RESULT_FAILED, "wrong format for buffer"); |
|---|
| 54 |
if (flow_packet_get_size (packet) != len) |
|---|
| 55 |
test_end (TEST_RESULT_FAILED, "wrong size for buffer"); |
|---|
| 56 |
if (memcmp (flow_packet_get_data (packet), buffer, len)) |
|---|
| 57 |
test_end (TEST_RESULT_FAILED, "bad data in buffer"); |
|---|
| 58 |
|
|---|
| 59 |
flow_packet_free (packet); |
|---|
| 60 |
|
|---|
| 61 |
/* TODO: Test object */ |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
g_free (buffer); |
|---|
| 65 |
} |
|---|