refactor: xmake in use, compiles and tests fine
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -7,6 +7,12 @@ out/
|
|||||||
out/Debug/
|
out/Debug/
|
||||||
out/Release/
|
out/Release/
|
||||||
|
|
||||||
|
# xmake
|
||||||
|
xmake/
|
||||||
|
xmake/*
|
||||||
|
.xmake
|
||||||
|
.xmake/*
|
||||||
|
|
||||||
# Cmake files
|
# Cmake files
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles/
|
CMakeFiles/
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
|
||||||
project(
|
|
||||||
arraylist
|
|
||||||
VERSION 1.0
|
|
||||||
LANGUAGES C)
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Estandard C
|
|
||||||
# ------------------------------------------------
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
||||||
set(CMAKE_C_EXTENSIONS OFF)
|
|
||||||
|
|
||||||
# Exportar compile_commands.json (clangd / IDEs)
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Is Top project?
|
|
||||||
# ------------------------------------------------
|
|
||||||
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
|
|
||||||
set(ARRAYLIST_IS_TOP_LEVEL ON)
|
|
||||||
else()
|
|
||||||
set(ARRAYLIST_IS_TOP_LEVEL OFF)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Opciones
|
|
||||||
# ------------------------------------------------
|
|
||||||
option(ARRAYLIST_BUILD_TESTS "Build tests" ${ARRAYLIST_IS_TOP_LEVEL})
|
|
||||||
option(ARRAYLIST_BUILD_EXAMPLE "Build example" ${ARRAYLIST_IS_TOP_LEVEL})
|
|
||||||
option(ARRAYLIST_ENABLE_INSTALL "Enable install" ${ARRAYLIST_IS_TOP_LEVEL})
|
|
||||||
option(ARRAYLIST_ENABLE_SANITIZERS "Enable Sanitizers for test" ON)
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Warning Flags (GCC/Clang vs MSVC)
|
|
||||||
# ------------------------------------------------
|
|
||||||
if(MSVC)
|
|
||||||
set(ARRAYLIST_WARNING_FLAGS /W4)
|
|
||||||
else()
|
|
||||||
set(ARRAYLIST_WARNING_FLAGS -Wall -Wextra -Wpedantic)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Main Library
|
|
||||||
# ------------------------------------------------
|
|
||||||
add_library(arraylist src/arraylist.c)
|
|
||||||
|
|
||||||
# Alias con namespace → los consumidores via CPM/FetchContent pueden escribir
|
|
||||||
# target_link_libraries(mi_app arraylist::arraylist)
|
|
||||||
add_library(arraylist::arraylist ALIAS arraylist)
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
arraylist PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
||||||
$<INSTALL_INTERFACE:include>)
|
|
||||||
|
|
||||||
# Flagas only for compile lib
|
|
||||||
target_compile_options(arraylist PRIVATE ${ARRAYLIST_WARNING_FLAGS})
|
|
||||||
|
|
||||||
# Propagates c11 as requirement
|
|
||||||
target_compile_features(arraylist PUBLIC c_std_11)
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Example only built when is main proyect
|
|
||||||
# ------------------------------------------------
|
|
||||||
if(ARRAYLIST_BUILD_EXAMPLE)
|
|
||||||
add_executable(arraylist_example src/main.c)
|
|
||||||
target_link_libraries(arraylist_example PRIVATE arraylist)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Tests
|
|
||||||
# ------------------------------------------------
|
|
||||||
if(ARRAYLIST_BUILD_TESTS)
|
|
||||||
enable_testing()
|
|
||||||
add_subdirectory(test)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ------------------------------------------------
|
|
||||||
# Installation rules
|
|
||||||
# ------------------------------------------------
|
|
||||||
if(ARRAYLIST_ENABLE_INSTALL)
|
|
||||||
include(GNUInstallDirs)
|
|
||||||
|
|
||||||
install(
|
|
||||||
TARGETS arraylist
|
|
||||||
EXPORT arraylistTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
||||||
|
|
||||||
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
||||||
|
|
||||||
install(
|
|
||||||
EXPORT arraylistTargets
|
|
||||||
FILE arraylistTargets.cmake
|
|
||||||
NAMESPACE arraylist::
|
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arraylist)
|
|
||||||
endif()
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#ifndef ARRAYLIST_H
|
#ifndef LAE_ARRAYLIST_H
|
||||||
#define ARRAYLIST_H
|
#define LAE_ARRAYLIST_H
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
typedef struct ArrayList ArrayList;
|
typedef struct ArrayList ArrayList;
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@ size_t arraylist_capacity(const ArrayList *arr);
|
|||||||
bool arraylist_is_empty(const ArrayList *arr);
|
bool arraylist_is_empty(const ArrayList *arr);
|
||||||
|
|
||||||
ArrayListErr arraylist_push_back(ArrayList *arr, void *data);
|
ArrayListErr arraylist_push_back(ArrayList *arr, void *data);
|
||||||
ArrayListErr arraylist_insert(ArrayList*arr, size_t index, void *data);
|
ArrayListErr arraylist_insert(ArrayList *arr, size_t index, void *data);
|
||||||
ArrayListErr arraylist_push_front(ArrayList* arr, void *data);
|
ArrayListErr arraylist_push_front(ArrayList *arr, void *data);
|
||||||
|
|
||||||
// Here out can be null for not having anything writen
|
// Here out can be null for not having anything writen
|
||||||
ArrayListErr arraylist_pop_back(ArrayList *arr, void *out);
|
ArrayListErr arraylist_pop_back(ArrayList *arr, void *out);
|
||||||
@@ -49,9 +49,13 @@ ArrayListErr arraylist_set(ArrayList *arr, size_t index, void *data);
|
|||||||
ArrayListErr arraylist_resize(ArrayList *arr, size_t new_capacity);
|
ArrayListErr arraylist_resize(ArrayList *arr, size_t new_capacity);
|
||||||
ArrayListErr arraylist_reserve(ArrayList *arr, size_t size_to_reserve);
|
ArrayListErr arraylist_reserve(ArrayList *arr, size_t size_to_reserve);
|
||||||
|
|
||||||
//Slice stuff
|
// Slice stuff
|
||||||
ArrayListErr arraylist_slice(ArraySlice **slice, ArrayList *arr, size_t start, size_t len);
|
ArrayListErr
|
||||||
ArrayListErr arraylist_slice_unsafe(ArraySlice **slice, ArrayList *arr, size_t start, size_t len);
|
arraylist_slice(ArraySlice **slice, ArrayList *arr, size_t start, size_t len);
|
||||||
|
|
||||||
|
ArrayListErr arraylist_slice_unsafe(
|
||||||
|
ArraySlice **slice, ArrayList *arr, size_t start, size_t len);
|
||||||
|
|
||||||
ArrayListErr arrayslice_destroy(ArraySlice **slice);
|
ArrayListErr arrayslice_destroy(ArraySlice **slice);
|
||||||
|
|
||||||
bool arrayslice_is_valid(const ArraySlice *slice);
|
bool arrayslice_is_valid(const ArraySlice *slice);
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "arraylist.h"
|
#include "lae_arraylist.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct ArrayList{
|
struct ArrayList {
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
size_t len;
|
size_t len;
|
||||||
@@ -26,7 +26,8 @@ struct ArraySlice {
|
|||||||
static ArrayListErr arraylist_grow(ArrayList *arr);
|
static ArrayListErr arraylist_grow(ArrayList *arr);
|
||||||
static ArrayListErr arraylist_shrink(ArrayList *arr);
|
static ArrayListErr arraylist_shrink(ArrayList *arr);
|
||||||
|
|
||||||
ArrayListErr arraylist_init(ArrayList **arr, size_t capacity, size_t elem_size) {
|
ArrayListErr
|
||||||
|
arraylist_init(ArrayList **arr, size_t capacity, size_t elem_size) {
|
||||||
if (arr == NULL) {
|
if (arr == NULL) {
|
||||||
return ARRLIST_NULL_ARG;
|
return ARRLIST_NULL_ARG;
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,7 @@ static ArrayListErr arraylist_shrink(ArrayList *arr) {
|
|||||||
return ARRLIST_ALLOC_OVERFLOW;
|
return ARRLIST_ALLOC_OVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *tmp = realloc(arr->buffer, new_capacity *arr->elem_size);
|
void *tmp = realloc(arr->buffer, new_capacity * arr->elem_size);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
return ARRLIST_BAD_ALLOC;
|
return ARRLIST_BAD_ALLOC;
|
||||||
}
|
}
|
||||||
@@ -195,13 +196,9 @@ ArrayListErr arraylist_push_front(ArrayList *arr, void *data) {
|
|||||||
memmove(
|
memmove(
|
||||||
arr->buffer + arr->elem_size,
|
arr->buffer + arr->elem_size,
|
||||||
arr->buffer,
|
arr->buffer,
|
||||||
(arr->len) * arr->elem_size
|
(arr->len) * arr->elem_size);
|
||||||
);
|
|
||||||
|
|
||||||
memcpy(
|
memcpy(arr->buffer, data, arr->elem_size);
|
||||||
arr->buffer,
|
|
||||||
data,
|
|
||||||
arr->elem_size);
|
|
||||||
|
|
||||||
arr->len++;
|
arr->len++;
|
||||||
|
|
||||||
@@ -233,9 +230,7 @@ ArrayListErr arraylist_insert(ArrayList *arr, size_t index, void *data) {
|
|||||||
arr->buffer + (index * arr->elem_size),
|
arr->buffer + (index * arr->elem_size),
|
||||||
(arr->len - index) * arr->elem_size);
|
(arr->len - index) * arr->elem_size);
|
||||||
|
|
||||||
memcpy(arr->buffer + (index * arr->elem_size),
|
memcpy(arr->buffer + (index * arr->elem_size), data, arr->elem_size);
|
||||||
data,
|
|
||||||
arr->elem_size);
|
|
||||||
|
|
||||||
arr->len++;
|
arr->len++;
|
||||||
|
|
||||||
@@ -295,11 +290,7 @@ ArrayListErr arraylist_pop_front(ArrayList *arr, void *out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (out != NULL) {
|
if (out != NULL) {
|
||||||
memcpy(
|
memcpy(out, arr->buffer, arr->elem_size);
|
||||||
out,
|
|
||||||
arr->buffer,
|
|
||||||
arr->elem_size
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove(
|
memmove(
|
||||||
@@ -330,11 +321,7 @@ ArrayListErr arraylist_remove_at(ArrayList *arr, size_t index, void *out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (out != NULL) {
|
if (out != NULL) {
|
||||||
memcpy(
|
memcpy(out, arr->buffer + (index * arr->elem_size), arr->elem_size);
|
||||||
out,
|
|
||||||
arr->buffer + (index * arr->elem_size),
|
|
||||||
arr->elem_size
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove(
|
memmove(
|
||||||
@@ -356,10 +343,7 @@ ArrayListErr arraylist_get(const ArrayList *arr, size_t index, void *out) {
|
|||||||
return ARRLIST_OUT_OF_BOUNDS;
|
return ARRLIST_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(
|
memcpy(out, arr->buffer + (index * arr->elem_size), arr->elem_size);
|
||||||
out,
|
|
||||||
arr->buffer + (index * arr->elem_size),
|
|
||||||
arr->elem_size);
|
|
||||||
|
|
||||||
return ARRLIST_OK;
|
return ARRLIST_OK;
|
||||||
}
|
}
|
||||||
@@ -373,10 +357,7 @@ ArrayListErr arraylist_set(ArrayList *arr, size_t index, void *data) {
|
|||||||
return ARRLIST_OUT_OF_BOUNDS;
|
return ARRLIST_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(
|
memcpy(arr->buffer + (index * arr->elem_size), data, arr->elem_size);
|
||||||
arr->buffer + (index * arr->elem_size),
|
|
||||||
data,
|
|
||||||
arr->elem_size);
|
|
||||||
|
|
||||||
return ARRLIST_OK;
|
return ARRLIST_OK;
|
||||||
}
|
}
|
||||||
@@ -436,7 +417,8 @@ ArrayListErr arraylist_reserve(ArrayList *arr, size_t size_to_reserve) {
|
|||||||
return ARRLIST_OK;
|
return ARRLIST_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayListErr arraylist_slice(ArraySlice **slice, ArrayList *arr, size_t start, size_t len) {
|
ArrayListErr
|
||||||
|
arraylist_slice(ArraySlice **slice, ArrayList *arr, size_t start, size_t len) {
|
||||||
if (arr == NULL || slice == NULL) {
|
if (arr == NULL || slice == NULL) {
|
||||||
return ARRLIST_NULL_ARG;
|
return ARRLIST_NULL_ARG;
|
||||||
}
|
}
|
||||||
@@ -469,7 +451,8 @@ ArrayListErr arraylist_slice(ArraySlice **slice, ArrayList *arr, size_t start, s
|
|||||||
return ARRLIST_OK;
|
return ARRLIST_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayListErr arraylist_slice_unsafe(ArraySlice **slice, ArrayList *arr, size_t start, size_t len) {
|
ArrayListErr arraylist_slice_unsafe(
|
||||||
|
ArraySlice **slice, ArrayList *arr, size_t start, size_t len) {
|
||||||
if (arr == NULL || slice == NULL) {
|
if (arr == NULL || slice == NULL) {
|
||||||
return ARRLIST_NULL_ARG;
|
return ARRLIST_NULL_ARG;
|
||||||
}
|
}
|
||||||
@@ -606,8 +589,7 @@ ArrayListErr arrayslice_to_arraylist(ArrayList **arr, const ArraySlice *slice) {
|
|||||||
ArrayListErr init_err = arraylist_init(
|
ArrayListErr init_err = arraylist_init(
|
||||||
&new_arr,
|
&new_arr,
|
||||||
arraylist_capacity(slice->arr),
|
arraylist_capacity(slice->arr),
|
||||||
slice->arr->elem_size
|
slice->arr->elem_size);
|
||||||
);
|
|
||||||
|
|
||||||
if (init_err != ARRLIST_OK) {
|
if (init_err != ARRLIST_OK) {
|
||||||
return init_err;
|
return init_err;
|
||||||
@@ -616,8 +598,7 @@ ArrayListErr arrayslice_to_arraylist(ArrayList **arr, const ArraySlice *slice) {
|
|||||||
memcpy(
|
memcpy(
|
||||||
new_arr->buffer,
|
new_arr->buffer,
|
||||||
slice->arr->buffer + (slice->start * slice->arr->elem_size),
|
slice->arr->buffer + (slice->start * slice->arr->elem_size),
|
||||||
slice->arr->elem_size * len
|
slice->arr->elem_size * len);
|
||||||
);
|
|
||||||
|
|
||||||
new_arr->len = len;
|
new_arr->len = len;
|
||||||
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
# ---------------------------------------------------------------
|
|
||||||
# First search cmocka and automatically download if necessary
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
find_package(cmocka QUIET)
|
|
||||||
|
|
||||||
if(NOT cmocka_FOUND)
|
|
||||||
message(
|
|
||||||
STATUS
|
|
||||||
"[arraylist] cmocka was not fount in the system — downloading with FetchContent..."
|
|
||||||
)
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
cmocka
|
|
||||||
GIT_REPOSITORY https://git.cryptomilk.org/projects/cmocka.git
|
|
||||||
GIT_TAG cmocka-1.1.7
|
|
||||||
GIT_SHALLOW TRUE)
|
|
||||||
|
|
||||||
set(WITH_STATIC_LIB
|
|
||||||
ON
|
|
||||||
CACHE BOOL "" FORCE)
|
|
||||||
set(WITH_SHARED_LIB
|
|
||||||
OFF
|
|
||||||
CACHE BOOL "" FORCE)
|
|
||||||
set(WITH_CMOCKERY_SUPPORT
|
|
||||||
OFF
|
|
||||||
CACHE BOOL "" FORCE)
|
|
||||||
set(WITH_EXAMPLES
|
|
||||||
OFF
|
|
||||||
CACHE BOOL "" FORCE)
|
|
||||||
set(UNIT_TESTING
|
|
||||||
OFF
|
|
||||||
CACHE BOOL "" FORCE)
|
|
||||||
set(PICKY_DEVELOPER
|
|
||||||
OFF
|
|
||||||
CACHE BOOL "" FORCE)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(cmocka)
|
|
||||||
|
|
||||||
# cmocka can export its target as "cmocka" or "cmocka-static" create alias if
|
|
||||||
# it doesnt exist
|
|
||||||
if(NOT TARGET cmocka::cmocka)
|
|
||||||
if(TARGET cmocka-static)
|
|
||||||
add_library(cmocka::cmocka ALIAS cmocka-static)
|
|
||||||
elseif(TARGET cmocka)
|
|
||||||
add_library(cmocka::cmocka ALIAS cmocka)
|
|
||||||
else()
|
|
||||||
message(
|
|
||||||
WARNING
|
|
||||||
"[arraylist] cmocka::cmocka target could not be tested — skipping tests"
|
|
||||||
)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
# Verifiy ASAN support
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
set(ARRAYLIST_USE_ASAN OFF)
|
|
||||||
|
|
||||||
if(ARRAYLIST_ENABLE_SANITIZERS)
|
|
||||||
if(MSVC)
|
|
||||||
if(MSVC_VERSION GREATER_EQUAL 1928)
|
|
||||||
set(ARRAYLIST_USE_ASAN ON)
|
|
||||||
else()
|
|
||||||
message(
|
|
||||||
STATUS
|
|
||||||
"[arraylist] MSVC < 16.9 doesnt support ASAN — sanitizers deactivated."
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" AND NOT WIN32)
|
|
||||||
include(CheckCCompilerFlag)
|
|
||||||
check_c_compiler_flag(-fsanitize=address ARRAYLIST_COMPILER_HAS_ASAN)
|
|
||||||
if(ARRAYLIST_COMPILER_HAS_ASAN)
|
|
||||||
set(ARRAYLIST_USE_ASAN ON)
|
|
||||||
else()
|
|
||||||
message(
|
|
||||||
STATUS
|
|
||||||
"[arraylist] Compiler doesnt support -fsanitize=address — sanitizers deactivated."
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(
|
|
||||||
STATUS
|
|
||||||
"[arraylist] Platform/compiler doesnt support ASAN — sanitizers deactivated."
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(ARRAYLIST_USE_ASAN)
|
|
||||||
message(STATUS "[arraylist] ASAN Enabled for tests")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
# Test execuatable
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
add_executable(test_arraylist test_arraylist.c)
|
|
||||||
|
|
||||||
target_link_libraries(test_arraylist PRIVATE arraylist cmocka::cmocka)
|
|
||||||
|
|
||||||
# Same as lib
|
|
||||||
target_compile_features(test_arraylist PRIVATE c_std_11)
|
|
||||||
|
|
||||||
# Apply asan
|
|
||||||
if(ARRAYLIST_USE_ASAN)
|
|
||||||
if(MSVC)
|
|
||||||
target_compile_options(test_arraylist PRIVATE /fsanitize=address)
|
|
||||||
else()
|
|
||||||
target_compile_options(test_arraylist PRIVATE -fsanitize=address
|
|
||||||
-fno-omit-frame-pointer)
|
|
||||||
target_link_options(test_arraylist PRIVATE -fsanitize=address)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
# Register with CTests
|
|
||||||
# ---------------------------------------------------------------
|
|
||||||
add_test(NAME arraylist_tests COMMAND test_arraylist)
|
|
||||||
|
|
||||||
set_tests_properties(arraylist_tests PROPERTIES TIMEOUT 30)
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "arraylist.h"
|
#include "lae_arraylist.h"
|
||||||
|
|
||||||
// INIT
|
// INIT
|
||||||
|
|
||||||
@@ -23,7 +23,8 @@ static void test_init_zero_capacity(void **state) {
|
|||||||
(void)state;
|
(void)state;
|
||||||
|
|
||||||
ArrayList *arr;
|
ArrayList *arr;
|
||||||
assert_uint_equal(arraylist_init(&arr, 0, sizeof(int)),
|
assert_uint_equal(
|
||||||
|
arraylist_init(&arr, 0, sizeof(int)),
|
||||||
ARRLIST_INVALID_CAPACITY);
|
ARRLIST_INVALID_CAPACITY);
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
}
|
}
|
||||||
@@ -40,7 +41,8 @@ static void test_init_large_capacity(void **state) {
|
|||||||
(void)state;
|
(void)state;
|
||||||
|
|
||||||
ArrayList *arr;
|
ArrayList *arr;
|
||||||
assert_uint_equal(arraylist_init(&arr, SIZE_MAX, sizeof(int)),
|
assert_uint_equal(
|
||||||
|
arraylist_init(&arr, SIZE_MAX, sizeof(int)),
|
||||||
ARRLIST_INVALID_CAPACITY);
|
ARRLIST_INVALID_CAPACITY);
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
}
|
}
|
||||||
@@ -92,7 +94,8 @@ static void test_destroy_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arraylist_destroy(&arr), ARRLIST_IS_BORROWED);
|
assert_uint_equal(arraylist_destroy(&arr), ARRLIST_IS_BORROWED);
|
||||||
@@ -287,7 +290,8 @@ static void test_push_back_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int n = 8;
|
int n = 8;
|
||||||
@@ -365,7 +369,8 @@ static void test_push_front_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int n = 8;
|
int n = 8;
|
||||||
@@ -482,7 +487,8 @@ static void test_insert_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int n = 8;
|
int n = 8;
|
||||||
@@ -598,7 +604,8 @@ static void test_pop_back_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int n = 8;
|
int n = 8;
|
||||||
@@ -716,7 +723,8 @@ static void test_pop_front_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
assert_non_null(slice);
|
assert_non_null(slice);
|
||||||
|
|
||||||
@@ -831,7 +839,8 @@ static void test_remove_at_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int n = 8;
|
int n = 8;
|
||||||
@@ -944,7 +953,8 @@ static void test_get_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int n = 8;
|
int n = 8;
|
||||||
@@ -1059,7 +1069,8 @@ static void test_set_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int n = 8;
|
int n = 8;
|
||||||
@@ -1117,7 +1128,8 @@ static void test_clear_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arraylist_clear(arr), ARRLIST_IS_BORROWED);
|
assert_uint_equal(arraylist_clear(arr), ARRLIST_IS_BORROWED);
|
||||||
@@ -1194,7 +1206,8 @@ static void test_resize_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arraylist_resize(arr, 128), ARRLIST_IS_BORROWED);
|
assert_uint_equal(arraylist_resize(arr, 128), ARRLIST_IS_BORROWED);
|
||||||
@@ -1251,7 +1264,8 @@ static void test_reserve_while_borrowed(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arraylist_reserve(arr, 128), ARRLIST_IS_BORROWED);
|
assert_uint_equal(arraylist_reserve(arr, 128), ARRLIST_IS_BORROWED);
|
||||||
@@ -1289,7 +1303,8 @@ static void test_slice_invalid_index(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 32, 10),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 32, 10),
|
||||||
ARRLIST_INVALID_START);
|
ARRLIST_INVALID_START);
|
||||||
|
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
@@ -1306,7 +1321,8 @@ static void test_slice_invalid_len(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, 300),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, 300),
|
||||||
ARRLIST_INVALID_START);
|
ARRLIST_INVALID_START);
|
||||||
|
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
@@ -1323,7 +1339,9 @@ static void test_slice_len_zero(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, 0), ARRLIST_INVALID_START);
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, 0),
|
||||||
|
ARRLIST_INVALID_START);
|
||||||
|
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
}
|
}
|
||||||
@@ -1378,7 +1396,8 @@ static void test_slice_unsafe_invalid_index(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice_unsafe(&slice, arr, 32, 10),
|
assert_uint_equal(
|
||||||
|
arraylist_slice_unsafe(&slice, arr, 32, 10),
|
||||||
ARRLIST_INVALID_START);
|
ARRLIST_INVALID_START);
|
||||||
|
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
@@ -1395,7 +1414,8 @@ static void test_slice_unsafe_invalid_len(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice_unsafe(&slice, arr, 0, 300),
|
assert_uint_equal(
|
||||||
|
arraylist_slice_unsafe(&slice, arr, 0, 300),
|
||||||
ARRLIST_INVALID_START);
|
ARRLIST_INVALID_START);
|
||||||
|
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
@@ -1412,7 +1432,8 @@ static void test_slice_unsafe_len_zero(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice_unsafe(&slice, arr, 0, 0),
|
assert_uint_equal(
|
||||||
|
arraylist_slice_unsafe(&slice, arr, 0, 0),
|
||||||
ARRLIST_INVALID_START);
|
ARRLIST_INVALID_START);
|
||||||
|
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
@@ -1425,7 +1446,8 @@ static void test_slice_unsafe_empty_array(void **state) {
|
|||||||
assert_int_equal(arraylist_init(&arr, 64, sizeof(int)), ARRLIST_OK);
|
assert_int_equal(arraylist_init(&arr, 64, sizeof(int)), ARRLIST_OK);
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice_unsafe(&slice, arr, 0, 10),
|
assert_uint_equal(
|
||||||
|
arraylist_slice_unsafe(&slice, arr, 0, 10),
|
||||||
ARRLIST_INVALID_ARR);
|
ARRLIST_INVALID_ARR);
|
||||||
|
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
@@ -1437,7 +1459,8 @@ static void test_slice_unsafe_null_arr(void **state) {
|
|||||||
ArrayList *arr = NULL;
|
ArrayList *arr = NULL;
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice_unsafe(&slice, arr, 0, 10),
|
assert_uint_equal(
|
||||||
|
arraylist_slice_unsafe(&slice, arr, 0, 10),
|
||||||
ARRLIST_NULL_ARG);
|
ARRLIST_NULL_ARG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1453,7 +1476,8 @@ static void test_slice_destroy_valid(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arrayslice_destroy(&slice), ARRLIST_OK);
|
assert_uint_equal(arrayslice_destroy(&slice), ARRLIST_OK);
|
||||||
@@ -1486,7 +1510,8 @@ static void test_slice_double_destroy(void **state) {
|
|||||||
assert_uint_equal(arraylist_push_back(arr, &i), ARRLIST_OK);
|
assert_uint_equal(arraylist_push_back(arr, &i), ARRLIST_OK);
|
||||||
}
|
}
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arrayslice_destroy(&slice), ARRLIST_OK);
|
assert_uint_equal(arrayslice_destroy(&slice), ARRLIST_OK);
|
||||||
@@ -1505,7 +1530,8 @@ static void test_slice_peek_valid_array(void **state) {
|
|||||||
assert_uint_equal(arraylist_push_back(arr, &i), ARRLIST_OK);
|
assert_uint_equal(arraylist_push_back(arr, &i), ARRLIST_OK);
|
||||||
}
|
}
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
@@ -1527,7 +1553,8 @@ static void test_slice_peek_invalid_array(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arrayslice_advance(slice, 10), ARRLIST_OK);
|
assert_uint_equal(arrayslice_advance(slice, 10), ARRLIST_OK);
|
||||||
@@ -1550,7 +1577,8 @@ static void test_slice_peek_null_out(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arrayslice_peek(slice, NULL), ARRLIST_NULL_ARG);
|
assert_uint_equal(arrayslice_peek(slice, NULL), ARRLIST_NULL_ARG);
|
||||||
@@ -1580,7 +1608,8 @@ static void test_slice_next_valid_array(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
@@ -1602,7 +1631,8 @@ static void test_slice_next_invalid_array(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arrayslice_advance(slice, 10), ARRLIST_OK);
|
assert_uint_equal(arrayslice_advance(slice, 10), ARRLIST_OK);
|
||||||
@@ -1625,7 +1655,8 @@ static void test_slice_next_null_out(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
assert_uint_equal(arrayslice_next(slice, NULL), ARRLIST_OK);
|
assert_uint_equal(arrayslice_next(slice, NULL), ARRLIST_OK);
|
||||||
@@ -1654,7 +1685,8 @@ static void test_slice_next_until_invalid(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
@@ -1680,7 +1712,8 @@ static void test_slice_reset_valid_slice(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
@@ -1722,7 +1755,8 @@ static void test_slice_advance_valid_slice(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
@@ -1748,7 +1782,8 @@ static void test_slice_advance_out_of_bounds(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
@@ -1774,7 +1809,8 @@ static void test_slice_advance_size_max(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
int m;
|
int m;
|
||||||
@@ -1783,7 +1819,9 @@ static void test_slice_advance_size_max(void **state) {
|
|||||||
assert_uint_equal(m, i);
|
assert_uint_equal(m, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_uint_equal(arrayslice_advance(slice, SIZE_MAX), ARRLIST_OUT_OF_BOUNDS);
|
assert_uint_equal(
|
||||||
|
arrayslice_advance(slice, SIZE_MAX),
|
||||||
|
ARRLIST_OUT_OF_BOUNDS);
|
||||||
|
|
||||||
arrayslice_destroy(&slice);
|
arrayslice_destroy(&slice);
|
||||||
arraylist_destroy(&arr);
|
arraylist_destroy(&arr);
|
||||||
@@ -1809,7 +1847,8 @@ static void test_slice_to_array_valid(void **state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArraySlice *slice;
|
ArraySlice *slice;
|
||||||
assert_uint_equal(arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
assert_uint_equal(
|
||||||
|
arraylist_slice(&slice, arr, 0, arraylist_size(arr)),
|
||||||
ARRLIST_OK);
|
ARRLIST_OK);
|
||||||
|
|
||||||
ArrayList *arr2;
|
ArrayList *arr2;
|
||||||
|
|||||||
94
xmake.lua
Normal file
94
xmake.lua
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
set_project("lae_arraylist")
|
||||||
|
set_version("1.0.0")
|
||||||
|
|
||||||
|
set_languages("c11")
|
||||||
|
|
||||||
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
-- clang compile commands
|
||||||
|
add_rules("plugin.compile_commands.autoupdate")
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- Options
|
||||||
|
-- =========================================================
|
||||||
|
|
||||||
|
option("tests")
|
||||||
|
set_default(false)
|
||||||
|
set_showmenu(true)
|
||||||
|
option_end()
|
||||||
|
|
||||||
|
option("example")
|
||||||
|
set_default(false)
|
||||||
|
set_showmenu(true)
|
||||||
|
option_end()
|
||||||
|
|
||||||
|
option("asan")
|
||||||
|
set_default(false)
|
||||||
|
set_showmenu(true)
|
||||||
|
option_end()
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- Packages
|
||||||
|
-- =========================================================
|
||||||
|
|
||||||
|
-- Run xmake repo --add lae-repo https://laentropia-homelab.tail7368da.ts.net/laentropia/xmake-repo.git
|
||||||
|
-- to add my repo :)
|
||||||
|
|
||||||
|
add_requires("cmocka", { optional = true }) -- For tests
|
||||||
|
add_requires("lae_allocator")
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- Library
|
||||||
|
-- =========================================================
|
||||||
|
|
||||||
|
target("lae_arraylist")
|
||||||
|
set_kind("static")
|
||||||
|
|
||||||
|
add_packages("lae_allocator", { public = true })
|
||||||
|
|
||||||
|
add_files("src/lae_arraylist.c")
|
||||||
|
|
||||||
|
add_headerfiles("include/*.h")
|
||||||
|
|
||||||
|
add_includedirs("include", { public = true })
|
||||||
|
|
||||||
|
if is_mode("debug") then
|
||||||
|
add_cflags("-Wall", "-Wextra", "-Wpedantic")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- Example executable
|
||||||
|
-- =========================================================
|
||||||
|
|
||||||
|
if has_config("example") then
|
||||||
|
target("example")
|
||||||
|
set_kind("binary")
|
||||||
|
|
||||||
|
add_deps("lae_arraylist")
|
||||||
|
add_packages("lae_allocator")
|
||||||
|
|
||||||
|
add_files("src/main.c")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- =========================================================
|
||||||
|
-- Tests
|
||||||
|
-- =========================================================
|
||||||
|
|
||||||
|
if has_config("tests") then
|
||||||
|
target("test_arena")
|
||||||
|
set_kind("binary")
|
||||||
|
|
||||||
|
add_files("test/test_arraylist.c")
|
||||||
|
|
||||||
|
add_deps("lae_arraylist")
|
||||||
|
|
||||||
|
add_packages("cmocka")
|
||||||
|
|
||||||
|
add_tests("default")
|
||||||
|
|
||||||
|
if has_config("asan") then
|
||||||
|
add_cflags("-fsanitize=address", "-fno-omit-frame-pointer", { force = true })
|
||||||
|
|
||||||
|
add_ldflags("-fsanitize=address", { force = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user