summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaulet2008-02-27 16:44:39 +0000
committernaulet2008-02-27 16:44:39 +0000
commit314f5225099186a51298f799d7d6fffdd538b1a5 (patch)
treee37b9b01012403009309513a5f31aa29310e185c
parentc593bd90832ea38bc218b91d9d2ef9c9e9c23f7d (diff)
Added bitstream_memcpy unit test
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1481 017c9cb6-072f-447c-8318-d5b54f68fe89
-rw-r--r--lib/src/bitstream.c22
-rw-r--r--lib/test/bitstream/src/test_bit.c11
2 files changed, 19 insertions, 14 deletions
diff --git a/lib/src/bitstream.c b/lib/src/bitstream.c
index a2287cf2df..949a2ed17b 100644
--- a/lib/src/bitstream.c
+++ b/lib/src/bitstream.c
@@ -338,22 +338,20 @@ bitstream_direct_write_large (u8 *data, uint bit_offset, u64 value,
void*
bitstream_memcpy (void *dest, void *src, size_t len)
{
- u32 tmp;
- u32 len32 = len >> 1; /* len div 4 */
- u32 left = len & 0x01; /* len mod 4 */
- u32 *dest32 = (u32*)dest, *src32 = (u32*)src;
+ u32 tmp, x = 0;
+ bitstream_t ctx_r, ctx_w;
- while(len32--)
- {
- tmp = bitstream_direct_read (src32++, 0, 32);
- bitstream_direct_write (dest32++, 0, tmp, 32);
- }
+ bitstream_init (&ctx_r, src, len, BITSTREAM_READ);
+ bitstream_init (&ctx_w, dest, len, BITSTREAM_WRITE);
- if(left)
+ for(len *= 8; len; len -= x)
{
- tmp = bitstream_direct_read (src32++, 0, left * 8);
- bitstream_direct_write (dest32++, 0, tmp, left * 8);
+ x = MIN (bitsizeof (u32), len);
+ bitstream_access (&ctx_r, &tmp, x);
+ bitstream_access (&ctx_w, &tmp, x);
}
+ bitstream_finalise (&ctx_r);
+ bitstream_finalise (&ctx_w);
return dest;
}
diff --git a/lib/test/bitstream/src/test_bit.c b/lib/test/bitstream/src/test_bit.c
index 8ecc4f3d64..4c3def84f6 100644
--- a/lib/test/bitstream/src/test_bit.c
+++ b/lib/test/bitstream/src/test_bit.c
@@ -165,8 +165,8 @@ bitstream_basic_test_case (test_t t)
test_begin (t, "read_unaligned")
{
+ u32 bit32 = 0;
bitstream_t bsr;
- u8 bit8 = 0; u16 bit16 = 0; u32 bit32 = 0;
static const u32 s[] = { 0x76543210, 0xfedcba98, 0x12345678 };
bitstream_init (&bsr, (void*)((u8*)s+1), sizeof (s), BITSTREAM_READ);
@@ -177,8 +177,8 @@ bitstream_basic_test_case (test_t t)
} test_end;
test_begin (t, "write_unaligned")
{
+ u16 bit16;
bitstream_t bsw;
- u8 bit8; u16 bit16; u32 bit32;
u32 s[4] = { [0] = 0x55000088, [1] = 0xabba5555 };
bitstream_init (&bsw, (void*)((u8*)s+1),
sizeof(s) - 4, BITSTREAM_WRITE);
@@ -193,6 +193,13 @@ bitstream_basic_test_case (test_t t)
test_fail_unless (s[0] == 0x55667788
&& s[1] == 0xabba5566);
} test_end;
+ test_begin (t, "memcpy")
+ {
+ u8 data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00 };
+ u8 copy[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff };
+ bitstream_memcpy (copy, data, sizeof(data) - 1);
+ test_fail_unless (data[6] == copy[6] && copy[7] == 0xff);
+ } test_end;
/* TODO: -- add a random number based test here --. */
}