|
|
#include "../../unity/unity.h" |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <stdint.h> |
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setUp(void) { |
|
|
|
|
|
|
|
|
|
|
|
obuf = NULL; |
|
|
ibuf = NULL; |
|
|
conversions_mask = 0; |
|
|
|
|
|
page_size = 4096; |
|
|
input_blocksize = 64; |
|
|
output_blocksize = 128; |
|
|
} |
|
|
|
|
|
void tearDown(void) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void test_alloc_obuf_twobufs_allocates_separate_buffer(void) { |
|
|
conversions_mask = C_TWOBUFS; |
|
|
|
|
|
page_size = 4096; |
|
|
output_blocksize = 128; |
|
|
ibuf = NULL; |
|
|
obuf = NULL; |
|
|
|
|
|
alloc_obuf(); |
|
|
|
|
|
TEST_ASSERT_NOT_NULL(obuf); |
|
|
TEST_ASSERT_NULL(ibuf); |
|
|
} |
|
|
|
|
|
|
|
|
void test_alloc_obuf_without_twobufs_uses_ibuf_buffer(void) { |
|
|
conversions_mask = 0; |
|
|
page_size = 4096; |
|
|
input_blocksize = 64; |
|
|
obuf = NULL; |
|
|
ibuf = NULL; |
|
|
|
|
|
alloc_obuf(); |
|
|
|
|
|
TEST_ASSERT_NOT_NULL(ibuf); |
|
|
TEST_ASSERT_EQUAL_PTR(ibuf, obuf); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void test_alloc_obuf_idempotent_when_already_allocated(void) { |
|
|
static char dummy_out[8]; |
|
|
|
|
|
obuf = dummy_out; |
|
|
|
|
|
conversions_mask = C_TWOBUFS; |
|
|
output_blocksize = 256; |
|
|
ibuf = NULL; |
|
|
|
|
|
alloc_obuf(); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(dummy_out, obuf); |
|
|
TEST_ASSERT_NULL(ibuf); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void test_alloc_obuf_twobufs_does_not_touch_existing_ibuf(void) { |
|
|
static char existing_ibuf[16]; |
|
|
ibuf = existing_ibuf; |
|
|
obuf = NULL; |
|
|
conversions_mask = C_TWOBUFS; |
|
|
output_blocksize = 128; |
|
|
|
|
|
alloc_obuf(); |
|
|
|
|
|
TEST_ASSERT_NOT_NULL(obuf); |
|
|
TEST_ASSERT_EQUAL_PTR(existing_ibuf, ibuf); |
|
|
TEST_ASSERT_NOT_EQUAL(obuf, ibuf); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void test_alloc_obuf_non_twobufs_uses_existing_ibuf(void) { |
|
|
static char existing_ibuf[32]; |
|
|
ibuf = existing_ibuf; |
|
|
obuf = NULL; |
|
|
conversions_mask = 0; |
|
|
|
|
|
alloc_obuf(); |
|
|
|
|
|
TEST_ASSERT_EQUAL_PTR(existing_ibuf, ibuf); |
|
|
TEST_ASSERT_EQUAL_PTR(ibuf, obuf); |
|
|
} |
|
|
|
|
|
int main(void) { |
|
|
UNITY_BEGIN(); |
|
|
RUN_TEST(test_alloc_obuf_twobufs_allocates_separate_buffer); |
|
|
RUN_TEST(test_alloc_obuf_without_twobufs_uses_ibuf_buffer); |
|
|
RUN_TEST(test_alloc_obuf_idempotent_when_already_allocated); |
|
|
RUN_TEST(test_alloc_obuf_twobufs_does_not_touch_existing_ibuf); |
|
|
RUN_TEST(test_alloc_obuf_non_twobufs_uses_existing_ibuf); |
|
|
return UNITY_END(); |
|
|
} |