fff4ed43f6cdd0945d809a6d33603c3be10db7c0
[platform/upstream/gstreamer.git] / tests / check / libs / gdp.c
1 /* GStreamer
2  *
3  * unit test for data protocol
4  *
5  * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
6  *
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.
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  * Library General Public License for more details.
16  *
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.
21  */
22
23 #include "config.h"
24
25 #include <gst/check/gstcheck.h>
26
27 #ifndef GST_REMOVE_DEPRECATED
28 #undef GST_DISABLE_DEPRECATED
29 #endif
30
31 #include <gst/dataprotocol/dataprotocol.h>
32 #include "libs/gst/dataprotocol/dp-private.h"   /* private header */
33
34 /* test our method of reading and writing headers using TO/FROM_BE */
35 GST_START_TEST (test_conversion)
36 {
37   guint8 array[9];
38   guint8 write_array[9];
39   guint16 read_two, expect_two;
40   guint32 read_four, expect_four;
41   guint64 read_eight, expect_eight;
42   int i;
43
44   for (i = 0; i < 9; ++i) {
45     array[i] = i * 0x10;
46   }
47
48   /* read 8 16 bits */
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);
54   }
55
56   /* write 8 16 bits */
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);
61   }
62
63   /* read 5 32 bits */
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);
70   }
71
72   /* read 2 64 bits */
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);
82   }
83
84   /* write 1 64 bit */
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");
88 }
89
90 GST_END_TEST;
91
92 static Suite *
93 gst_dp_suite (void)
94 {
95   Suite *s = suite_create ("data protocol");
96   TCase *tc_chain = tcase_create ("general");
97
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);
101
102   return s;
103 }
104
105 GST_CHECK_MAIN (gst_dp);