test/buffer_tests.c

changeset 218
b20d6088795c
parent 192
1e51558b9d09
child 219
2df780a4482b
equal deleted inserted replaced
217:e056e4e0b08e 218:b20d6088795c
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "buffer_tests.h" 29 #include "buffer_tests.h"
30 #include <stdint.h>
31 30
32 UCX_TEST(test_ucx_buffer_new) { 31 UCX_TEST(test_ucx_buffer_new) {
33 UcxBuffer *b = ucx_buffer_new(NULL, 16, UCX_BUFFER_AUTOEXTEND); 32 UcxBuffer *b = ucx_buffer_new(NULL, 16, UCX_BUFFER_AUTOEXTEND);
34 UcxBuffer *b2 = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); 33 UcxBuffer *b2 = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT);
35 UCX_TEST_BEGIN 34 UCX_TEST_BEGIN
86 UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); 85 UcxBuffer *b = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT);
87 b->size = 32; 86 b->size = 32;
88 int r; 87 int r;
89 88
90 UCX_TEST_BEGIN 89 UCX_TEST_BEGIN
91 size_t bigpos = SIZE_MAX - 5000; 90 const size_t sizemax = (size_t)-1;
91 size_t bigpos = sizemax - 5000;
92 b->pos = bigpos; 92 b->pos = bigpos;
93 r = ucx_buffer_seek(b, 5016, SEEK_CUR); 93 r = ucx_buffer_seek(b, 5016, SEEK_CUR);
94 UCX_TEST_ASSERT(r != 0, "seek cur overflow"); 94 UCX_TEST_ASSERT(r != 0, "seek cur overflow");
95 UCX_TEST_ASSERT(b->pos == bigpos, 95 UCX_TEST_ASSERT(b->pos == bigpos,
96 "failed seek shall leave pos unchanged"); 96 "failed seek shall leave pos unchanged");
97 97
98 b->pos = 0; 98 b->pos = 0;
99 b->size = SIZE_MAX / 2 + 32; 99 b->size = sizemax / 2 + 32;
100 off_t bigoff = SIZE_MAX / 2 - 16; 100 off_t bigoff = sizemax / 2 - 16;
101 r = ucx_buffer_seek(b, -bigoff, SEEK_CUR); 101 r = ucx_buffer_seek(b, -bigoff, SEEK_CUR);
102 UCX_TEST_ASSERT(r != 0, "seek cur underflow"); 102 UCX_TEST_ASSERT(r != 0, "seek cur underflow");
103 UCX_TEST_ASSERT(b->pos == 0, 103 UCX_TEST_ASSERT(b->pos == 0,
104 "failed seek shall leave pos unchanged"); 104 "failed seek shall leave pos unchanged");
105 105
591 UCX_TEST_ASSERT(ucx_buffer_extend(b, 15) == 0, "shall return 0 on success"); 591 UCX_TEST_ASSERT(ucx_buffer_extend(b, 15) == 0, "shall return 0 on success");
592 UCX_TEST_ASSERT(b->capacity = 40, "wrong capacity"); 592 UCX_TEST_ASSERT(b->capacity = 40, "wrong capacity");
593 UCX_TEST_ASSERT((b->size == 0 && b->pos == 0), 593 UCX_TEST_ASSERT((b->size == 0 && b->pos == 0),
594 "pos and size shall remain unchanged"); 594 "pos and size shall remain unchanged");
595 595
596 UCX_TEST_ASSERT(ucx_buffer_extend(b, SIZE_MAX - 60) != 0, 596 UCX_TEST_ASSERT(ucx_buffer_extend(b, (size_t) - 61) != 0,
597 "shall fail and return a non-zero value on overflow"); 597 "shall fail and return a non-zero value on overflow");
598 598
599 UCX_TEST_END 599 UCX_TEST_END
600 600
601 ucx_buffer_free(b); 601 ucx_buffer_free(b);

mercurial