Test Utilities

Test Utilities — Utilities to write tests more easily.

Synopsis

void *              cut_take                            (void *object,
                                                         CutDestroyFunction destroy_function);
#define             cut_take_memory                     (memory)
#define             cut_take_string                     (string)
#define             cut_take_strdup                     (string)
#define             cut_take_strndup                    (string, size)
#define             cut_take_memdup                     (memory, size)
const char *        cut_take_printf                     (const char *format,
                                                         ...);
char **             cut_take_string_array               (char **strings);
#define             cut_take_diff                       (from, to)
#define             cut_take_replace                    (target, pattern, replacement)
#define             cut_append_diff                     (message, from, to)
#define             cut_inspect_string_array            (strings)
void                cut_set_fixture_data_dir            (const char *path,
                                                         ...);
char *              cut_build_fixture_data_path         (const char *path,
                                                         ...);
#define             cut_get_fixture_data_string         (path, ...)
#define             cut_remove_path                     (path, ...)
cut_boolean         cut_equal_string                    (const char *string1,
                                                         const char *string2);
cut_boolean         cut_equal_double                    (double double1,
                                                         double double2,
                                                         double error);

Description

To write tests, you need to write codes that set up/tear down test environment, prepare expected and actual values and so on. Cutter provides test utilities to you write your tests more easily.

The utilities work without GLib support.

Details

cut_take ()

void *              cut_take                            (void *object,
                                                         CutDestroyFunction destroy_function);

Passes ownership of the object to Cutter and returns the object itself. object is destroyed by destroy_func.

object :

the object to be owned by Cutter.

destroy_function :

the destroy function for the object.

Returns :

the object owned by Cutter. Don't free it.

Since 1.0.5


cut_take_memory()

#define             cut_take_memory(memory)

Passes ownership of the memory to Cutter and returns the memory itself. memory is destroyed by free().

memory :

the memory to be owned by Cutter. (void *)

Since 1.0.5


cut_take_string()

#define             cut_take_string(string)

Passes ownership of the string to Cutter and returns the string itself.

string :

the string to be owned by Cutter.

cut_take_strdup()

#define             cut_take_strdup(string)

Duplicates the string, passes ownership of the duplicated string to Cutter and returns the duplicated string.

string :

the string to be duplicated. (const char *)

Since 1.0.5


cut_take_strndup()

#define             cut_take_strndup(string, size)

Duplicates the first size bytes of the string, passes ownership of the duplicated string to Cutter and returns the duplicated string. The duplicated string is always nul-terminated.

string :

the string to be duplicated. (const char *)

size :

the number of bytes to duplicate. (size_t)

Since 1.0.5


cut_take_memdup()

#define             cut_take_memdup(memory, size)

Duplicates size bytes of the memory, passes ownership of the duplicated memory to Cutter and returns the duplicated memory.

memory :

the memory to be duplicated. (void *)

size :

the number of bytes to duplicate. (size_t)

Since 1.0.5


cut_take_printf ()

const char *        cut_take_printf                     (const char *format,
                                                         ...);

Formats a string like printf() but the formatted string is owned by Cutter.

format :

the message format. See the printf() documentation.

... :

the parameters to insert into the format string.

Returns :

a formatted string owned by Cutter. Don't free it.

cut_take_string_array ()

char **             cut_take_string_array               (char **strings);

Passes ownership of the array of strings to Cutter and returns strings itself.

strings :

the array of strings to be owned by Cutter.

Returns :

array of strings owned by Cutter. Don't free it.

cut_take_diff()

#define             cut_take_diff(from, to)

Computes diff between from and to that is owned by Cutter.

from :

the original string.

to :

the modified string.

cut_take_replace()

#define             cut_take_replace(target, pattern, replacement)

Replaces all occurrences of the pattern with the replacement in the target string.

target :

the replace target string.

pattern :

the regular expression pattern as string.

replacement :

text to replace each match with

Since 1.0.6


cut_append_diff()

#define             cut_append_diff(message, from, to)

Computes diff between from and to and append the diff to message. Returned string is owned by Cutter.

message :

the string to be appended diff.

from :

the original string.

to :

the modified string.

Since 1.0.3


cut_inspect_string_array()

#define             cut_inspect_string_array(strings)

Formats strings as human readable string that is owned by Cutter.

strings :

the array of strings to be inspected.

cut_set_fixture_data_dir ()

void                cut_set_fixture_data_dir            (const char *path,
                                                         ...);

Set fixture data directory that is used by cut_get_fixture_data_string() and so on.

path :

a first element of the path to the fixture data directory.

... :

remaining elements in path.

Since 1.0.2


cut_build_fixture_data_path ()

char *              cut_build_fixture_data_path         (const char *path,
                                                         ...);

Builds a path to the fixture data. If path is relative path, the path is handled as a relative path from a directory that is specified by cut_set_fixture_data_dir() or the current directory.

path :

a first element of the path to the fixture data.

... :

remaining elements in path.

Returns :

a path to the fixture data. It should be freed when no longer needed.

Since 1.0.2


cut_get_fixture_data_string()

#define             cut_get_fixture_data_string(path, ...)

Reads the fixture data at "path/..." and returns it as a string that is owned by Cutter. The description of cut_build_fixture_data_path() shows how the fixture data path is determined.

path :

a first element of the path to the fixture data.

... :

remaining elements in path.

Since 1.0.2


cut_remove_path()

#define             cut_remove_path(path, ...)

Removes path and it's children recursively. It doesn't report any errors.

path :

a first element of the path to be removed.

... :

remaining elements in path. NULL-terminate.

Since 1.0.2


cut_equal_string ()

cut_boolean         cut_equal_string                    (const char *string1,
                                                         const char *string2);

Compare string1 to string2. string1 and/or string2 maybe NULL.

string1 :

a string.

string2 :

a string.

Returns :

CUT_TRUE if both string1 and string2 are NULL or have the same contents; CUT_FALSE otherwise.

Since 1.0.5


cut_equal_double ()

cut_boolean         cut_equal_double                    (double double1,
                                                         double double2,
                                                         double error);

Compare double1 to double2 with error range.

double1 :

a double value.

double2 :

a double value.

error :

a double value that specifies error range.

Returns :

CUT_TRUE if |double1 - double2| <= error; CUT_FALSE otherwise.

Since 1.0.5