File: test_snprintf.c

package info (click to toggle)
fluidsynth 2.5.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,292 kB
  • sloc: ansic: 45,503; cpp: 4,974; xml: 877; sh: 200; makefile: 74
file content (23 lines) | stat: -rw-r--r-- 484 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

#include "test.h"
#include "utils/fluid_sys.h"

// this test makes sure FLUID_SNPRINTF uses a proper C99 compliant implementation

int main(void)
{
    char buf[2 + 1];

    int ret = FLUID_SNPRINTF(buf, sizeof(buf), "99");
    TEST_ASSERT(ret == 2);

    TEST_ASSERT(buf[2] == '\0');

    ret = FLUID_SNPRINTF(buf, sizeof(buf), "999");
    TEST_ASSERT(ret == 3);

    // output truncated, buffer must be NULL terminated!
    TEST_ASSERT(buf[2] == '\0');

    return EXIT_SUCCESS;
}