mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-06-02 10:01:57 +00:00
add fluid_align_ptr() for aligning pointers
This commit is contained in:
parent
384f05e77c
commit
cdbd508007
3 changed files with 48 additions and 0 deletions
31
test/test_pointer_alignment.c
Normal file
31
test/test_pointer_alignment.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
#include "test.h"
|
||||
#include "utils/fluid_sys.h"
|
||||
|
||||
|
||||
// test for fluid_align_ptr()
|
||||
int main(void)
|
||||
{
|
||||
unsigned int align;
|
||||
uintptr_t ptr, aligned_ptr;
|
||||
|
||||
for(align = 32; align <= 4*1024u; align <<= 1)
|
||||
{
|
||||
for(ptr = 0; ptr <= (align<<10); ptr++)
|
||||
{
|
||||
char* tmp = fluid_align_ptr((char*)ptr, align);
|
||||
aligned_ptr = (uintptr_t)tmp;
|
||||
|
||||
// pointer must be aligned properly
|
||||
TEST_ASSERT(aligned_ptr % align == 0);
|
||||
|
||||
// aligned pointer must not be smaller than ptr
|
||||
TEST_ASSERT(aligned_ptr >= ptr);
|
||||
|
||||
// aligned pointer must not be bigger than alignment
|
||||
TEST_ASSERT(aligned_ptr < ptr + align);
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue