]>
Commit | Line | Data |
---|---|---|
3818e5c8 JH |
1 | /** |
2 | * @file packet_test.c | |
3 | * | |
ed37dee6 | 4 | * @brief Tests for the packet_t class. |
3818e5c8 JH |
5 | * |
6 | */ | |
7 | ||
8 | /* | |
9 | * Copyright (C) 2005 Jan Hutter, Martin Willi | |
10 | * Hochschule fuer Technik Rapperswil | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License as published by the | |
14 | * Free Software Foundation; either version 2 of the License, or (at your | |
15 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, but | |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
19 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
20 | * for more details. | |
21 | */ | |
22 | ||
23 | #include <string.h> | |
88878242 | 24 | |
3818e5c8 | 25 | #include "packet_test.h" |
88878242 | 26 | |
0e96f7d8 | 27 | #include <daemon.h> |
716abc9f | 28 | #include <network/packet.h> |
94852e75 | 29 | #include <utils/logger_manager.h> |
3818e5c8 JH |
30 | |
31 | ||
32 | /* | |
33 | * Described in Header | |
34 | */ | |
51d56047 | 35 | void test_packet(protected_tester_t *tester) |
3818e5c8 | 36 | { |
66e379a2 | 37 | packet_t *packet = packet_create(); |
3818e5c8 | 38 | packet_t *packet2; |
2b547481 MW |
39 | chunk_t data; |
40 | char *string_to_copy = "aha, soso"; | |
3818e5c8 | 41 | |
2b547481 | 42 | data.len = strlen(string_to_copy) + 1; |
5113680f | 43 | data.ptr = malloc(data.len); |
2b547481 | 44 | memcpy(data.ptr, string_to_copy, data.len); |
66e379a2 | 45 | |
2b547481 | 46 | packet->set_data(packet, data); |
df3c59d0 | 47 | packet2 = packet->clone(packet); |
2b547481 | 48 | data = packet2->get_data(packet2); |
3818e5c8 | 49 | |
2b547481 MW |
50 | tester->assert_true(tester,(data.len == (strlen(string_to_copy) + 1)),"value length check"); |
51 | tester->assert_true(tester,(memcmp(data.ptr,string_to_copy,data.len) == 0),"cloned value check"); | |
3818e5c8 JH |
52 | |
53 | packet2->destroy(packet2); | |
54 | packet->destroy(packet); | |
3818e5c8 | 55 | } |