src/test/util.h
author Tero Marttila <terom@fixme.fi>
Mon, 04 May 2009 20:55:04 +0300
branchnew-transport
changeset 168 a58ad50911fc
permissions -rw-r--r--
refactor test.c into tests/*
168
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef TEST_UTIL_H
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define TEST_UTIL_H
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
 * @file
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
 *
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
 * General utility functions for tests
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
#include <sys/types.h>
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
#define DUMP_STR_BUF 1024
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
#define DUMP_STR_COUNT 8
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
 * This re-formats the given string to escape values, and returns a pointer to an internal static buffer.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
 *
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
 * If len is given as >= 0, only the given number of chars will be dumped from str.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
 *
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
 * The buffer cycles a bit, so the returned pointers remain valid across DUMP_STR_COUNT calls.
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
 *
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
 * The resulting string is truncated to DUMP_STR_BUF bytes, including the ending "...'\0".
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
 *
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
 * @param str the string to dump, should be NUL-terminated unless len is given
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
 * @param len if negative, ignored, otherwise, only this many bytes are dumped from str
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
 * @param return a pointer to a static buffer that remains valid across DUMP_STR_COUNT calls to this function
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
 */
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
const char *dump_strn (const char *str, ssize_t len);
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
/**
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
 * As dump_strn(), with str as a NUL-terminated string
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
 */
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
const char *dump_str (const char *str); 
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
a58ad50911fc refactor test.c into tests/*
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
#endif