BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
basictest.h File Reference
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  basictest_str
 A string value: bytes, any value, not 0-terminated. More...
struct  basictest_entry
 One entry. Only the members of its kind count: begin version block block, name (BASICTEST_BLOCK_CASE) check k, ok, expected, actual checkq k, ok, expected, actual (the quicks' bits) checkflt k, ok, expected, actual, delta (the floats' FFP bits) checkstr k, ok, expected_str, expected_length, expected_crc, actual_str, actual_length, actual_crc, cut require k (always broken) expect-error k broken reason run k runend k, ok (1: the return code is known), actual (it). More...
struct  basictest_error
 The reader's error: line, reason, field (1 = the entry name) and the entry name as it stands in the line (valid while the line is). More...

Macros

#define BASICTEST_VERSION   1
 The format version the codec writes and reads (begin).

Enumerations

enum  basictest_kind {
  BASICTEST_BEGIN , BASICTEST_BLOCK , BASICTEST_CHECK , BASICTEST_CHECKSTR ,
  BASICTEST_REQUIRE , BASICTEST_EXPECT_ERROR , BASICTEST_BLOCKEND , BASICTEST_BROKEN ,
  BASICTEST_INCOMPLETE , BASICTEST_END , BASICTEST_CHECKQ , BASICTEST_CHECKFLT ,
  BASICTEST_RUN , BASICTEST_RUNEND
}
 The entry kinds. More...
enum  basictest_block { BASICTEST_BLOCK_INIT , BASICTEST_BLOCK_CASE , BASICTEST_BLOCK_FINAL }
 The blocks of a block entry. More...
enum  basictest_err {
  BASICTEST_OK , BASICTEST_E_KIND , BASICTEST_E_FIELDS , BASICTEST_E_VALUE ,
  BASICTEST_E_VERSION
}
 Why the reader refused a line (BASICTEST_OK = 0). More...

Functions

size_t basictest_write (const struct basictest_entry *e, uint8_t *buf, size_t size)
 Writes the line of an entry, with its LF, to buf.
size_t basictest_decimal (uint32_t v, uint8_t *buf)
 Writes v in decimal (no sign, no leading zero) to buf, which has room for 10 bytes; the writer's and the error text's helper.
uint32_t basictest_crc32 (const uint8_t *data, size_t length)
 The CRC32 of a string value: the standard CRC-32 of IEEE 802.3 (zlib, PNG; the polynomial $EDB88320 reflected, $FFFFFFFF at the start and XORed at the end); $CBF43926 for "123456789", 0 for none.
int basictest_read (uint8_t *line, size_t length, uint32_t line_number, struct basictest_entry *e, struct basictest_error *err)
 Reads one line of the result file (without its LF) into e.
size_t basictest_error_text (const struct basictest_error *err, char *buf, size_t size)
 Writes the text of a reader error ("line 3: check: malformed value in field 5"), 0-terminated, cut to fit size bytes (size > 0). The entry name is written as a string value.

Macro Definition Documentation

◆ BASICTEST_VERSION

#define BASICTEST_VERSION   1

The format version the codec writes and reads (begin).

Enumeration Type Documentation

◆ basictest_block

The blocks of a block entry.

Enumerator
BASICTEST_BLOCK_INIT 
BASICTEST_BLOCK_CASE 
BASICTEST_BLOCK_FINAL 

◆ basictest_err

Why the reader refused a line (BASICTEST_OK = 0).

Enumerator
BASICTEST_OK 
BASICTEST_E_KIND 
BASICTEST_E_FIELDS 
BASICTEST_E_VALUE 
BASICTEST_E_VERSION 

◆ basictest_kind

The entry kinds.

Enumerator
BASICTEST_BEGIN 
BASICTEST_BLOCK 
BASICTEST_CHECK 
BASICTEST_CHECKSTR 
BASICTEST_REQUIRE 
BASICTEST_EXPECT_ERROR 
BASICTEST_BLOCKEND 
BASICTEST_BROKEN 
BASICTEST_INCOMPLETE 
BASICTEST_END 
BASICTEST_CHECKQ 
BASICTEST_CHECKFLT 
BASICTEST_RUN 
BASICTEST_RUNEND 

Function Documentation

◆ basictest_crc32()

uint32_t basictest_crc32 ( const uint8_t * data,
size_t length )

The CRC32 of a string value: the standard CRC-32 of IEEE 802.3 (zlib, PNG; the polynomial $EDB88320 reflected, $FFFFFFFF at the start and XORed at the end); $CBF43926 for "123456789", 0 for none.

◆ basictest_decimal()

size_t basictest_decimal ( uint32_t v,
uint8_t * buf )

Writes v in decimal (no sign, no leading zero) to buf, which has room for 10 bytes; the writer's and the error text's helper.

Returns
the number of digits.

◆ basictest_error_text()

size_t basictest_error_text ( const struct basictest_error * err,
char * buf,
size_t size )

Writes the text of a reader error ("line 3: check: malformed value in field 5"), 0-terminated, cut to fit size bytes (size > 0). The entry name is written as a string value.

Returns
the length of the text without the 0.

◆ basictest_read()

int basictest_read ( uint8_t * line,
size_t length,
uint32_t line_number,
struct basictest_entry * e,
struct basictest_error * err )

Reads one line of the result file (without its LF) into e.

The string values are decoded in place: e's strings point into line, which the call changes. line_number is the number of the line in the file, for the error.

Returns
BASICTEST_OK, or the reason; err (if not NULL) then names line, reason and field.

◆ basictest_write()

size_t basictest_write ( const struct basictest_entry * e,
uint8_t * buf,
size_t size )

Writes the line of an entry, with its LF, to buf.

Returns
the number of bytes written, 0 if the line does not fit into size bytes or the entry is not one of the kinds above, or a case without a name (buf then holds no complete line).