1 /*
2 * test case not really written for gtest, but wrapped so it'll cooperate.
3 */
4
5 //#define LOG_NDEBUG 0
6 #define LOG_TAG "Utils_test"
7
8 #include <gtest/gtest.h>
9
10 #include <string.h>
11 #define REF_COUNT 1
12 #define DECODE_PACKET 1
13
14 extern "C" {
15 #include <Tremolo/codec_internal.h>
16
17 int _vorbis_unpack_books(vorbis_info *vi, oggpack_buffer *opb);
18 int _vorbis_unpack_info(vorbis_info *vi, oggpack_buffer *opb);
19 int _vorbis_unpack_comment(vorbis_comment *vc, oggpack_buffer *opb);
20 }
21
22 const uint8_t packInfoData[] = { 0x00, 0x00, 0x00, 0x00, 0x02, 0x80, 0xBB, 0x00,
23 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 0x00, 0xBB, 0x01, 0xFF, 0xFF, 0xFF, 0xFF };
25
26 unsigned char unpackBookData[] = { 0x00, 0x42, 0x43, 0x56, 0x1E, 0x00, 0x10,
27 0x00, 0x00, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x10, 0x0A, 0xFF, 0x00, 0x00,
28 0x00, 0x06, 0xD0, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x1D, 0x00, 0x00, 0x00,
29 0x2C, 0x00, 0x03, 0x3C, 0x51, 0x04, 0x34, 0x4F, 0x04, 0x00, 0x40, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0xCB, 0x00, 0x40, 0x00, 0x00, 0x01, 0x4F, 0xF4,
31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xFF, 0xFF, 0xFF, 0xFF };
35
36 unsigned char bufData[] = { 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xE7,
37 0x00, 0x00, 0xE9, 0x00 };
38
makeBitReader(const void * data,size_t size,ogg_buffer * buf,ogg_reference * ref,oggpack_buffer * bits)39 static void makeBitReader(const void *data, size_t size, ogg_buffer *buf,
40 ogg_reference *ref, oggpack_buffer *bits) {
41 buf->data = (uint8_t *) data;
42 buf->size = size;
43 buf->refcount = REF_COUNT;
44
45 ref->buffer = buf;
46 ref->length = size;
47 oggpack_readinit(bits, ref);
48 }
49
50 // below here is where we're trying to bridge the gtest and non-gtest world
51
52 namespace android {
53
54 class Floor0Test : public ::testing::Test {
55 };
56
57 //
58 // the test, since it compiles with ubsan, should fault and die if the patch
59 // is not in place. at least that's the idea.
TEST_F(Floor0Test,Test1)60 TEST_F(Floor0Test, Test1) {
61
62 ogg_buffer buf;
63 ogg_reference ref;
64 oggpack_buffer bits;
65
66 memset(&buf, 0, sizeof(ogg_buffer));
67 memset(&ref, 0, sizeof(ogg_reference));
68 memset(&bits, 0, sizeof(oggpack_buffer));
69
70 makeBitReader(packInfoData, sizeof(packInfoData), &buf, &ref, &bits);
71
72 vorbis_info *mVi = new vorbis_info;
73 vorbis_info_init(mVi);
74
75 int ret = _vorbis_unpack_info(mVi, &bits);
76 if (!ret) {
77 memset(&buf, 0, sizeof(ogg_buffer));
78 memset(&ref, 0, sizeof(ogg_reference));
79 memset(&bits, 0, sizeof(oggpack_buffer));
80
81 makeBitReader(unpackBookData, sizeof(unpackBookData), &buf, &ref,
82 &bits);
83
84 ret = _vorbis_unpack_books(mVi, &bits);
85 if (!ret) {
86 ogg_packet pack;
87 memset(&pack, 0, sizeof(ogg_packet));
88 memset(&buf, 0, sizeof(ogg_buffer));
89 memset(&ref, 0, sizeof(ogg_reference));
90
91 vorbis_dsp_state *mState = new vorbis_dsp_state;
92 vorbis_dsp_init(mState, mVi);
93
94 buf.data = bufData;
95 buf.size = sizeof(bufData);
96 buf.refcount = REF_COUNT;
97
98 ref.buffer = &buf;
99 ref.length = buf.size;
100
101 pack.packet = &ref;
102 pack.bytes = ref.length;
103
104 vorbis_dsp_synthesis(mState, &pack, DECODE_PACKET);
105 }
106 }
107 }
108
109 } // namespace android
110