Path: blob/main/contrib/arm-optimized-routines/string/test/stringtest.h
39530 views
/*1* Common string test code.2*3* Copyright (c) 2020, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include <ctype.h>8#include <stdio.h>910/* Accounting errors for a test case. */11static int err_count;12#define ERR_LIMIT 1013#define ERR(...) (err_count++, printf (__VA_ARGS__))1415static inline void16quotechar (unsigned char c)17{18if (isprint (c))19putchar (c);20else21printf ("\\x%02x", c);22}2324/* quoted print around at or the entire string if at < 0. */25static void26quoteat (const char *prefix, const void *p, int len, int at)27{28static const int CTXLEN = 15;29int i;30const char *pre = "\"";31const char *post = "\"";32const char *s = p;33if (at > CTXLEN)34{35s += at - CTXLEN;36len -= at - CTXLEN;37pre = "...\"";38}39if (at >= 0 && len > 2 * CTXLEN + 1)40{41len = 2 * CTXLEN + 1;42post = "\"...";43}44printf ("%4s: %s", prefix, pre);45for (i = 0; i < len; i++)46quotechar (s[i]);47printf ("%s\n", post);48}4950static inline void51quote (const char *prefix, const void *p, int len)52{53quoteat (prefix, p, len, -1);54}555657