3 * unit test for data protocol
5 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library 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.
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 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library 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.
25 #include <gst/check/gstcheck.h>
27 #ifndef GST_REMOVE_DEPRECATED
28 #undef GST_DISABLE_DEPRECATED
31 #include <gst/dataprotocol/dataprotocol.h>
32 #include "libs/gst/dataprotocol/dp-private.h" /* private header */
34 /* test our method of reading and writing headers using TO/FROM_BE */
35 GST_START_TEST (test_conversion)
38 guint8 write_array[9];
39 guint16 read_two, expect_two;
40 guint32 read_four, expect_four;
41 guint64 read_eight, expect_eight;
44 for (i = 0; i < 9; ++i) {
49 for (i = 0; i < 8; ++i) {
50 read_two = GST_READ_UINT16_BE (array + i);
51 expect_two = array[i] * (1 << 8) + array[i + 1];
52 fail_unless (read_two == expect_two,
53 "GST_READ_UINT16_BE %d: read %d != %d", i, read_two, expect_two);
57 for (i = 0; i < 8; ++i) {
58 GST_WRITE_UINT16_BE (&write_array[i], read_two);
59 fail_unless (memcmp (array + 7, write_array + i, 2) == 0,
60 "GST_WRITE_UINT16_BE %d: memcmp failed", i);
64 for (i = 0; i < 5; ++i) {
65 read_four = GST_READ_UINT32_BE (array + i);
66 expect_four = array[i] * (1 << 24) + array[i + 1] * (1 << 16)
67 + array[i + 2] * (1 << 8) + array[i + 3];
68 fail_unless (read_four == expect_four,
69 "GST_READ_UINT32_BE %d: read %d != %d", i, read_four, expect_four);
73 for (i = 0; i < 2; ++i) {
74 read_eight = GST_READ_UINT64_BE (array + i);
75 expect_eight = array[i] * (1LL << 56) + array[i + 1] * (1LL << 48)
76 + array[i + 2] * (1LL << 40) + array[i + 3] * (1LL << 32)
77 + array[i + 4] * (1 << 24) + array[i + 5] * (1 << 16)
78 + array[i + 6] * (1 << 8) + array[i + 7];
79 fail_unless (read_eight == expect_eight,
80 "GST_READ_UINT64_BE %d: read %" G_GUINT64_FORMAT
81 " != %" G_GUINT64_FORMAT, i, read_eight, expect_eight);
85 GST_WRITE_UINT64_BE (&write_array[0], read_eight);
86 fail_unless (memcmp (array + 1, write_array, 8) == 0,
87 "GST_WRITE_UINT64_BE: memcmp failed");
95 Suite *s = suite_create ("data protocol");
96 TCase *tc_chain = tcase_create ("general");
98 suite_add_tcase (s, tc_chain);
99 tcase_add_checked_fixture (tc_chain, gst_dp_init, NULL);
100 tcase_add_test (tc_chain, test_conversion);
105 GST_CHECK_MAIN (gst_dp);