utest.h File Reference

#include <stddef.h>

Go to the source code of this file.

Defines

#define ASSERT(expr)
#define UTEST_MAIN(name, tfun)

Functions

void utest_setname (char *name)
void fail (char *fmt,...)
size_t utest_strtobin (void *dst, char *src)
int utest_byteequal (void *d1, void *d2, size_t len)
void utest_printarray (void *src, size_t len)
void utest_success (void)
const void * utest_nist_data (unsigned blen)

Detailed Description

Functions for unit tests.

==========================(LICENSE BEGIN)============================

Copyright (c) 2007-2010 Projet RNRT SAPHIR

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

===========================(LICENSE END)=============================

Author:
Thomas Pornin <thomas.pornin@cryptolog.com>

Define Documentation

#define ASSERT ( expr   ) 

Assert an expression to be true. If the expression does not evaluate to a boolean "true" value, then the test fails with an explicit message which contains the string representation of the expression (the program is exited).

Parameters:
expr the expression to test
#define UTEST_MAIN ( name,
tfun   ) 

This macro defines a main() function which runs the provided tfun() function (no parameter) and then reports test success. The current test name is set to name, which must evaluate to a string pointer (a literal string is fine).

Parameters:
name the current test name (string)
tfun the test function

Function Documentation

void utest_setname ( char *  name  ) 

Set the current name (used for success and failure reports). The provided pointer is recorded as-is; the pointed-to string must not be modified afterwards, until a new name is set.

Parameters:
name the current name
void fail ( char *  fmt,
  ... 
)

Fail with an explicit message. Message format and argument use the same conventions than printf(). This function does not return.

Parameters:
fmt the explicit message (format)
size_t utest_strtobin ( void *  dst,
char *  src 
)

Convert an hexadecimal string into bytes. The string characters are read in sequence; non-hex digits are skipped silently. And hexadecimal digit is either a decimal digit or a letter between A and F, inclusive (both uppercase and lowercase letters are accepted). If the number of hexadecimal digits in the string is odd, then the function fails: the program exists with an explicit message. The destination buffer MUST be wide enough to accomodate the resulting byte stream.

Parameters:
dst the destination buffer
src the source string
Returns:
the message length (in bytes)
int utest_byteequal ( void *  d1,
void *  d2,
size_t  len 
)

Compare to arrays of bytes for equality. Returned value is 1 if the two arrays are equal, 0 otherwise.

Parameters:
d1 the first array
d2 the second array
len the common array length (in bytes)
Returns:
1 on equality, 0 otherwise
void utest_printarray ( void *  src,
size_t  len 
)

Print out some bytes in hexadecimal. Uppercase letters are used, with no leading, trailing or separating extra character.

Parameters:
src the buffer address
len the buffer length (in bytes)
void utest_success ( void   ) 

Report success. A message is printed, which contains the current test name.

const void* utest_nist_data ( unsigned  blen  ) 

Get a pointer to one of the NIST short messages, defined for the SHA-3 test vectors. Those messages are indexed by bit length, from 0 to 2047, inclusive.

Parameters:
blen the message length (in bits)
Returns:
the test message
Generated on Mon Jun 21 17:48:04 2010 for sphlib by  doxygen 1.6.3