Added test harness for bitwriter
This commit is contained in:
parent
4c3a5c9e4e
commit
1fa209bdb7
2 changed files with 31 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "hammer.h"
|
#include "hammer.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "test_suite.h"
|
||||||
|
|
||||||
// This file provides the logical inverse of bitreader.c
|
// This file provides the logical inverse of bitreader.c
|
||||||
struct HBitWriter_ {
|
struct HBitWriter_ {
|
||||||
|
|
@ -104,3 +105,32 @@ void h_bit_writer_free(HBitWriter* w) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TESTS BELOW HERE
|
// TESTS BELOW HERE
|
||||||
|
typedef struct {
|
||||||
|
unsigned long long data;
|
||||||
|
size_t nbits;
|
||||||
|
} bitwriter_test_elem; // should end with {0,0}
|
||||||
|
|
||||||
|
void run_bitwriter_test(bitwriter_test_elem data[], char flags) {
|
||||||
|
size_t len;
|
||||||
|
const uint8_t *buf;
|
||||||
|
HBitWriter *w = h_bit_writer_new();
|
||||||
|
int i;
|
||||||
|
w->flags = flags;
|
||||||
|
for (i = 0; data[i].nbits; i++) {
|
||||||
|
h_bit_writer_put(w, data[i].data, data[i].nbits);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = h_bit_writer_get_buffer(w, &len);
|
||||||
|
HInputStream input = {
|
||||||
|
.input = buf,
|
||||||
|
.index = 0,
|
||||||
|
.length = len,
|
||||||
|
.bit_offset = (flags & BIT_BIG_ENDIAN) ? 8 : 0,
|
||||||
|
.endianness = flags,
|
||||||
|
.overrun = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i = 0; data[i].nbits; i++) {
|
||||||
|
g_check_cmpulonglong ((unsigned long long)h_read_bits(&input, data[i].nbits, FALSE), ==, data[i].data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@
|
||||||
#define g_check_cmplonglong(n1, op, n2) g_check_inttype("%lld", long long, n1, op, n2)
|
#define g_check_cmplonglong(n1, op, n2) g_check_inttype("%lld", long long, n1, op, n2)
|
||||||
#define g_check_cmpuint(n1, op, n2) g_check_inttype("%u", unsigned int, n1, op, n2)
|
#define g_check_cmpuint(n1, op, n2) g_check_inttype("%u", unsigned int, n1, op, n2)
|
||||||
#define g_check_cmpulong(n1, op, n2) g_check_inttype("%lu", unsigned long, n1, op, n2)
|
#define g_check_cmpulong(n1, op, n2) g_check_inttype("%lu", unsigned long, n1, op, n2)
|
||||||
|
#define g_check_cmpulonglong(n1, op, n2) g_check_inttype("%llu", unsigned long long, n1, op, n2)
|
||||||
#define g_check_cmpfloat(n1, op, n2) g_check_inttype("%g", float, n1, op, n2)
|
#define g_check_cmpfloat(n1, op, n2) g_check_inttype("%g", float, n1, op, n2)
|
||||||
#define g_check_cmpdouble(n1, op, n2) g_check_inttype("%g", double, n1, op, n2)
|
#define g_check_cmpdouble(n1, op, n2) g_check_inttype("%g", double, n1, op, n2)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue