File: test_pointer_alignment.c

package info (click to toggle)
fluidsynth 2.4.4%2Bdfsg-1%2Bdeb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,328 kB
  • sloc: ansic: 43,529; cpp: 1,434; xml: 1,020; makefile: 71; sh: 46
file content (31 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}