rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 66a6f8e56c8c606ed6dd0f1b91103a9d460430d4
parent 959c8dd6c600c1654c452edebfef9fc5db111454
Author: vaplv <vaplv@free.fr>
Date:   Sun, 20 May 2018 19:21:18 +0200

Remove the no more use "big buffer" test

Diffstat:
Dsrc/test_big_buffer.c | 369-------------------------------------------------------------------------------
1 file changed, 0 insertions(+), 369 deletions(-)

diff --git a/src/test_big_buffer.c b/src/test_big_buffer.c @@ -1,369 +0,0 @@ -/* Copyright (C) 2013-2018 Vincent Forest (vaplv@free.fr) - * - * The RSys library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The RSys library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ - -#include "big_buffer.h" -#include "test_utils.h" - -#include <stdlib.h> - -#define BIGBUF_NAME byte -#define BIGBUF_DATA char -#include "big_buffer.h" - -#define BIGBUF_NAME integer -#define BIGBUF_DATA int -#define BIGBUF_ALIGNMENT 64 -#include "big_buffer.h" - -#define BIGBUF_NAME real -#define BIGBUF_DATA double -#include "big_buffer.h" - -static INLINE double -rand_canonic(void) -{ - return (double)rand()/(double)(RAND_MAX-1); -} - -static void -test_byte(struct mem_allocator* allocator) -{ - struct bigbuf_byte bytes; - size_t i; - char byte; - - CHECK(bigbuf_byte_init(allocator, 4, NULL, BIGBUF_LOAD_STREAM, &bytes), RES_BAD_ARG); - CHECK(bigbuf_byte_init(allocator, 0, NULL, 0, &bytes), RES_BAD_ARG); - CHECK(bigbuf_byte_init(allocator, 4, NULL, 0, &bytes), RES_OK); - CHECK(bigbuf_byte_size_get(&bytes), 0); - - FOR_EACH(i, 0, 32) { - byte = (char)i; - CHECK(bigbuf_byte_push_back(&bytes, &byte), RES_OK); - } - - CHECK(bigbuf_byte_size_get(&bytes), 32); - - FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { - byte = *bigbuf_byte_at(&bytes, i); - CHECK((size_t)byte, i); - } - - FOR_EACH(i, 0, 16) { - size_t id = (size_t)(rand_canonic() * (double)bigbuf_byte_size_get(&bytes)); - byte = *bigbuf_byte_at(&bytes, id); - CHECK((size_t)byte, id); - } - - FOR_EACH(i, 0, 32) { - byte = (char)(i + 32); - CHECK(bigbuf_byte_push_back(&bytes, &byte), RES_OK); - } - - FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { - byte = *bigbuf_byte_at(&bytes, i); - CHECK((size_t)byte, i); - } - - CHECK(bigbuf_byte_size_get(&bytes), 64); - byte = *bigbuf_byte_at(&bytes, 61); - - CHECK(bigbuf_byte_resize(&bytes, 63), RES_OK); - CHECK(bigbuf_byte_size_get(&bytes), 63); - byte = *bigbuf_byte_at(&bytes, 62); - CHECK(byte, 62); - - byte = 63; - CHECK(bigbuf_byte_push_back(&bytes, &byte), RES_OK); - CHECK(bigbuf_byte_size_get(&bytes), 64); - FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { - byte = *bigbuf_byte_at(&bytes, i); - CHECK((size_t)byte, i); - } - - CHECK(bigbuf_byte_resize(&bytes, 32), RES_OK); - CHECK(bigbuf_byte_resize(&bytes, 32), RES_OK); - - byte = *bigbuf_byte_at(&bytes, 31); - CHECK(byte, 31); - FOR_EACH(i, 0, 32) { - byte = (char)(i + 32); - CHECK(bigbuf_byte_push_back(&bytes, &byte), RES_OK); - } - FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { - byte = *bigbuf_byte_at(&bytes, i); - CHECK((size_t)byte, i); - } - - CHECK(bigbuf_byte_resize(&bytes, 128), RES_OK); - CHECK(bigbuf_byte_size_get(&bytes), 128); - FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { - byte = *bigbuf_byte_at(&bytes, i); - if(i < 64) { - CHECK((size_t)byte, i); - } else { - CHECK(byte, 0); - } - } - - CHECK(bigbuf_byte_set(&bytes, 128, &byte), RES_BAD_ARG); - FOR_EACH(i, 0, 64) { - byte = (char)(i+64); - CHECK(bigbuf_byte_set(&bytes, (size_t)byte, &byte), RES_OK); - byte = *bigbuf_byte_at(&bytes, (size_t)byte - 1); - CHECK((size_t)byte, i+63); - } - FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { - byte = *bigbuf_byte_at(&bytes, i); - CHECK((size_t)byte, i); - } - - CHECK(bigbuf_byte_clear(&bytes), RES_OK); - CHECK(bigbuf_byte_size_get(&bytes), 0); - CHECK(bigbuf_byte_set(&bytes, 0, &byte), RES_BAD_ARG); - FOR_EACH(i, 0, 16) { - byte = (char)i; - CHECK(bigbuf_byte_push_back(&bytes, &byte), RES_OK); - } - CHECK(bigbuf_byte_size_get(&bytes), 16); - FOR_EACH(i, 0, bigbuf_byte_size_get(&bytes)) { - byte = *bigbuf_byte_at(&bytes, i); - CHECK((size_t)byte, i); - } - - bigbuf_byte_release(&bytes); -} - -static void -test_integer(struct mem_allocator* allocator) -{ - struct bigbuf_integer ints; - struct bigbuf_integer ints2; - FILE* stream; - size_t i; - int integer; - - NCHECK(stream = tmpfile(), NULL); - - CHECK(bigbuf_integer_init(NULL, 1, stream, 0, &ints), RES_OK); - - FOR_EACH(i, 0, 999) { - integer = (int)i; - CHECK(bigbuf_integer_push_back(&ints, &integer), RES_OK); - } - - FOR_EACH(i, 0, 666) { - size_t id = (size_t)(rand_canonic() * (double)bigbuf_integer_size_get(&ints)); - integer = *bigbuf_integer_at(&ints, id); - CHECK((size_t)integer, id); - } - - FOR_EACH(i, 0, 666) { - integer = (int)i + 999; - CHECK(bigbuf_integer_push_back(&ints, &integer), RES_OK); - } - - CHECK(bigbuf_integer_size_get(&ints), 1665); - FOR_EACH(i, 0, bigbuf_integer_size_get(&ints)) { - integer = *bigbuf_integer_at(&ints, i); - CHECK((size_t)integer, i); - } - - bigbuf_integer_release(&ints); - - rewind(stream); - CHECK(bigbuf_integer_init(allocator, 1, stream, BIGBUF_LOAD_STREAM, &ints), RES_OK); - CHECK(bigbuf_integer_size_get(&ints), 1665); - - FOR_EACH(i, 0, 666) { - size_t id = (size_t)(rand_canonic() * (double)bigbuf_integer_size_get(&ints)); - integer = *bigbuf_integer_at(&ints, id); - CHECK((size_t)integer, id); - } - - FOR_EACH(i, 0, 1024) { - integer = (int)i + 1665; - CHECK(bigbuf_integer_push_back(&ints, &integer), RES_OK); - } - CHECK(bigbuf_integer_size_get(&ints), 2689); - bigbuf_integer_release(&ints); - - rewind(stream); - CHECK(bigbuf_integer_init(NULL, 1, stream, BIGBUF_LOAD_STREAM, &ints2), RES_OK); - CHECK(bigbuf_integer_size_get(&ints2), bigbuf_integer_size_get(&ints)); - CHECK(bigbuf_integer_size_get(&ints2), 2689); - - FOR_EACH(i, 0, bigbuf_integer_size_get(&ints2)) { - integer = *bigbuf_integer_at(&ints2, i); - CHECK((size_t)integer, i); - } - - CHECK(bigbuf_integer_resize(&ints2, 999), RES_OK); - CHECK(bigbuf_integer_size_get(&ints2), 999); - FOR_EACH(i, 0, bigbuf_integer_size_get(&ints2)) { - integer = *bigbuf_integer_at(&ints2, i); - integer = -integer; - CHECK(bigbuf_integer_set(&ints2, i, &integer), RES_OK); - if(i) { - integer = *bigbuf_integer_at(&ints2, i-1); - CHECK(integer, 1 - (int)i); - } - } - - FOR_EACH(i, 0, bigbuf_integer_size_get(&ints2)) { - integer = *bigbuf_integer_at(&ints2, i); - CHECK(integer, -(int)i); - } - - CHECK(bigbuf_integer_clear(&ints2), RES_OK); - CHECK(bigbuf_integer_size_get(&ints2), 0); - CHECK(bigbuf_integer_set(&ints2, 0, &integer), RES_BAD_ARG); - FOR_EACH(i, 0, 64) { - integer = (int)i; - CHECK(bigbuf_integer_push_back(&ints2, &integer), RES_OK); - } - CHECK(bigbuf_integer_size_get(&ints2), 64); - FOR_EACH(i, 0, bigbuf_integer_size_get(&ints2)) { - integer = *bigbuf_integer_at(&ints2, i); - CHECK(integer, (int)i); - } - - bigbuf_integer_release(&ints2); - fclose(stream); -} - -static void -test_real(struct mem_allocator* allocator) -{ - struct bigbuf_real reals; - struct bigbuf_real reals2; - FILE* stream; - double real; - size_t ids[32]; - size_t i; - - NCHECK(stream = tmpfile(), NULL); - CHECK(bigbuf_real_init(allocator, 45, stream, BIGBUF_LOAD_STREAM, &reals), RES_IO_ERR); - CHECK(bigbuf_real_init(allocator, 45, stream, 0, &reals), RES_OK); - - FOR_EACH(i, 0, 4000) { - real = (double)i / 100.0; - CHECK(bigbuf_real_push_back(&reals, &real), RES_OK); - } - - CHECK(bigbuf_real_size_get(&reals), 4000); - - FOR_EACH(i, 0, 10) { - size_t id = (size_t)(rand_canonic() * (double)bigbuf_real_size_get(&reals)); - real = *bigbuf_real_at(&reals, id); - CHECK(real, (double)id/100.0); - } - - rewind(stream); - - FOR_EACH(i, 0, 2000) { - real = (double)(i+4000) / 100.0; - CHECK(bigbuf_real_push_back(&reals, &real), RES_OK); - } - - bigbuf_real_flush(&reals); - - rewind(stream); - bigbuf_real_init(allocator, 45, stream, BIGBUF_LOAD_STREAM, &reals2); - - CHECK(bigbuf_real_size_get(&reals), 6000); - CHECK(bigbuf_real_size_get(&reals2), 6000); - - FOR_EACH(i, 0, bigbuf_real_size_get(&reals)) { - real = *bigbuf_real_at(&reals, i); - CHECK(real, (double)i/100.0); - } - - FOR_EACH(i, 0, 300) { - size_t id = (size_t)(rand_canonic() * (double)bigbuf_real_size_get(&reals2)); - real = *bigbuf_real_at(&reals2, id); - CHECK(real, (double)id/100.0); - } - - real = *bigbuf_real_at(&reals2, 5990); - CHECK(real, 59.90); - CHECK(bigbuf_real_resize(&reals2, 5992), RES_OK); - real = *bigbuf_real_at(&reals2, 5990); - CHECK(real, 59.90); - CHECK(bigbuf_real_resize(&reals2, 5990), RES_OK); - real = *bigbuf_real_at(&reals2, 5989); - CHECK(real, 59.89); - CHECK(bigbuf_real_resize(&reals2, 5985), RES_OK); - real = *bigbuf_real_at(&reals2, 5984); - CHECK(real, 59.84); - - FOR_EACH(i, 0, sizeof(ids)/sizeof(size_t)) { - ids[i] = (size_t)(rand_canonic() * (double)bigbuf_real_size_get(&reals2)); - real = (double)ids[i]; - CHECK(bigbuf_real_set(&reals2, ids[i], &real), RES_OK); - } - - CHECK(bigbuf_real_size_get(&reals2), 5985); - FOR_EACH(i, 0, bigbuf_real_size_get(&reals2)) { - size_t j; - real = *bigbuf_real_at(&reals2, i); - - FOR_EACH(j, 0, sizeof(ids)/sizeof(size_t)) { - if(i == ids[j]) break; - } - - if(j == sizeof(ids)/sizeof(size_t)) { - CHECK(real, (double)i/100.0); - } else { - CHECK(real, (double)i); - } - } - - CHECK(bigbuf_real_clear(&reals2), RES_OK); - CHECK(bigbuf_real_size_get(&reals2), 0); - CHECK(bigbuf_real_set(&reals2, 0, &real), RES_BAD_ARG); - FOR_EACH(i, 0, 64) { - real = (double)i; - CHECK(bigbuf_real_push_back(&reals2, &real), RES_OK); - } - CHECK(bigbuf_real_size_get(&reals2), 64); - FOR_EACH(i, 0, bigbuf_real_size_get(&reals2)) { - real = *bigbuf_real_at(&reals2, i); - CHECK(real, (double)i); - } - - bigbuf_real_release(&reals); - bigbuf_real_release(&reals2); - fclose(stream); -} - -int -main(int argc, char** argv) -{ - struct mem_allocator allocator_proxy; - (void)argc, (void)argv; - - mem_init_proxy_allocator(&allocator_proxy, &mem_default_allocator); - - test_byte(&allocator_proxy); - test_integer(&allocator_proxy); - test_real(&allocator_proxy); - - check_memory_allocator(&allocator_proxy); - mem_shutdown_proxy_allocator(&allocator_proxy); - CHECK(mem_allocated_size(), 0); - return 0; -} -