![]() |
![]() |
![]() |
Cutter Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
void cut_assert (cut_boolean expression
,...
); void cut_assert_true (cut_boolean expression
,...
); void cut_assert_false (cut_boolean expression
,...
); void cut_assert_null (const void *expression
,...
); void cut_assert_null_string (const char *string
,...
); void cut_assert_not_null (const void *expression
,...
); void cut_assert_equal_int (int expected
,int actual
,...
); void cut_assert_equal_uint (unsigned int expected
,unsigned int actual
,...
); void cut_assert_equal_double (double expected
,double error
,double actual
,...
); void cut_assert_equal_string (const char *expected
,const char *actual
,...
); void cut_assert_equal_string_with_free (const char *expected
,const char *actual
,...
); void cut_assert_equal_string_or_null (const char *expected
,const char *actual
,...
); void cut_assert_equal_memory (const void *expected
,size_t expected_size
,const void *actual
,size_t actual_size
,...
); void cut_assert_equal_string_array (char **expected
,char **actual
,...
); void cut_assert_equal_string_array_with_free (char **expected
,char **actual
,...
); #define cut_assert_operator (lhs, operator, rhs, ...) #define cut_assert_operator_int (lhs, operator, rhs, ...) #define cut_assert_operator_uint (lhs, operator, rhs, ...) #define cut_assert_operator_double (lhs, operator, rhs, ...) #define cut_assert_equal (function, expected, actual, ...) void cut_assert_errno (...
); void cut_assert_file_exist (const char *path
,...
); void cut_assert_path_exist (const char *path
,...
); void cut_assert_path_not_exist (const char *path
,...
); void cut_assert_match (const char *pattern
,const char *actual
,...
); void cut_assert_match_with_free (const char *pattern
,const char *actual
,...
); void cut_assert_equal_pointer (const void *expected
,const void *actual
,...
); void cut_assert_equal_fixture_data_string (const char *expected
,const void *path
,...
); void cut_error (const char *format
,...
); void cut_error_errno (...
); void cut_fail (const char *format
,...
); void cut_pend (const char *format
,...
); void cut_pending (const char *format
,...
); void cut_notify (const char *format
,...
); void cut_omit (const char *format
,...
);
To check that your program works as you expect, you use
cut_assert_XXX()
where you want to check expected value
is got.
e.g.:
1 |
cut_assert_equal_int(3, 1 + 2); |
void cut_assert (cut_boolean expression
,...
);
Passes if expression
is not 0 or NULL
.
e.g.:
1 2 3 |
char *string; string = malloc(16); cut_assert(string); |
1 2 3 |
MyObject *object; object = my_object_new(); cut_assert(object, cut_message("my_object_new() should not be failed")); |
|
the expression to be checked. |
|
optional message. See cut_message() for details.
|
void cut_assert_true (cut_boolean expression
,...
);
Passes if expression
is CUT_TRUE
value (not 0 or NULL
).
|
the expression to be checked. |
|
optional message. See cut_message() for details.
|
Since 0.9
void cut_assert_false (cut_boolean expression
,...
);
Passes if expression
is 0 or NULL
.
|
the expression to be checked. |
|
optional message. See cut_message() for details.
|
Since 0.9
void cut_assert_null (const void *expression
,...
);
Passes if expression
is NULL
.
|
the expression to be checked. |
|
optional message. See cut_message() for details.
|
void cut_assert_null_string (const char *string
,...
);
Passes if string
is NULL
.
|
the string to be checked. |
|
optional message. See cut_message() for details.
|
Since 0.3
void cut_assert_not_null (const void *expression
,...
);
Passes if expression
is not NULL
.
|
the expression to be checked. |
|
optional message. See cut_message() for details.
|
void cut_assert_equal_int (int expected
,int actual
,...
);
Passes if expected
== actual
.
|
an expected integer value. |
|
an actual integer value. |
|
optional message. See cut_message() for details.
|
void cut_assert_equal_uint (unsigned int expected
,unsigned int actual
,...
);
Passes if expected
== actual
.
|
an expected unsigned integer value. |
|
an actual unsigned integer value. |
|
optional message. See cut_message() for details.
|
void cut_assert_equal_double (double expected
,double error
,double actual
,...
);
Passes if (expected
- error
) <= actual
<= (expected
+ error
).
|
an expected float value. |
|
a float value that specifies error range. |
|
an actual float value. |
|
optional message. See cut_message() for details.
|
void cut_assert_equal_string (const char *expected
,const char *actual
,...
);
Passes if both expected
and actual
are NULL
or
strcmp(expected
, actual
) == 0.
e.g.:
1 2 3 4 5 |
cut_assert_equal_string("abc", "abc"); -> Pass cut_assert_equal_string(NULL, NULL); -> Pass cut_assert_equal_string("abc", "ABC"); -> Fail cut_assert_equal_string("abc", NULL); -> Fail cut_assert_equal_string(NULL, "abc"); -> Fail |
|
an expected string value. |
|
an actual string value. |
|
optional message. See cut_message() for details.
|
void cut_assert_equal_string_with_free (const char *expected
,const char *actual
,...
);
Passes if both expected
and actual
are NULL
or
strcmp(expected
, actual
) == 0.
See also cut_assert_equal_string()
for examples.
|
an expected string value. |
|
an actual string value that is freed. |
|
optional message. See cut_message() for details.
|
Since 0.3
void cut_assert_equal_string_or_null (const char *expected
,const char *actual
,...
);
cut_assert_equal_string_or_null
has been deprecated since version 0.3 and should not be used in newly-written code. Use cut_assert_equal_string()
instead.
|
an expected string value. |
|
an actual string value. |
|
optional message. See cut_message() for details.
|
void cut_assert_equal_memory (const void *expected
,size_t expected_size
,const void *actual
,size_t actual_size
,...
);
Passes if expected_size
== actual_size
and
memcmp(expected
, actual
, expected_size
) == 0.
|
an expected data. |
|
a size of expected .
|
|
an actual data. |
|
a size of actual .
|
|
optional message. See cut_message() for details.
|
void cut_assert_equal_string_array (char **expected
,char **actual
,...
);
Passes if both expected
and actual
are not NULL
and
have same content (strcmp()
== 0) strings.
|
an expected NULL -terminated array of strings.
|
|
an actual NULL -terminated array of strings.
|
|
optional message. See cut_message() for details.
|
void cut_assert_equal_string_array_with_free (char **expected
,char **actual
,...
);
Passes if both expected
and actual
are not NULL
and
have same content (strcmp()
== 0) strings.
|
an expected NULL -terminated array of strings.
|
|
an actual NULL -terminated array of strings that are freed.
|
|
optional message. See cut_message() for details.
|
Since 0.9
#define cut_assert_operator(lhs, operator, rhs, ...)
Passes if (lhs
operator
rhs
) is TRUE.
e.g.:
1 |
cut_assert_operator(1, <, 2) -> (1 < 2); |
|
a left hand side value. |
|
a binary operator. |
|
a right hand side value. |
|
optional message. See cut_message() for details.
|
#define cut_assert_operator_int(lhs, operator, rhs, ...)
Passes if (lhs
operator
rhs
) is TRUE.
e.g.:
1 |
cut_assert_operator_int(1, <, 2) -> (1 < 2); |
|
a left hand side integer value. |
|
a binary operator. |
|
a right hand side integer value. |
|
optional message. See cut_message() for details.
|
#define cut_assert_operator_uint(lhs, operator, rhs, ...)
Passes if (lhs
operator
rhs
) is TRUE.
e.g.:
1 |
cut_assert_operator_uint(1, <, 2) -> (1 < 2); |
|
a left hand side unsigned integer value. |
|
a binary operator. |
|
a right hand side unsigned integer value. |
|
optional message. See cut_message() for details.
|
Since 1.0.5
#define cut_assert_operator_double(lhs, operator, rhs, ...)
Passes if (lhs
operator
rhs
) is TRUE.
e.g.:
1 |
cut_assert_operator_double(1.1, <, 2.2) -> (1.1 < 2.2); |
|
a left hand side double value. |
|
a binary operator. |
|
a right hand side double value. |
|
optional message. See cut_message() for details.
|
Since 1.0.5
#define cut_assert_equal(function, expected, actual, ...)
Passes if function
(expected
, actual
) returns CUT_TRUE
.
e.g.:
1 |
cut_assert_equal(!strcmp, "abc", "abc"); -> Pass |
|
a function that compares actual with expected .
|
|
an expected value. |
|
an actual value. |
|
optional message. See cut_message() for details.
|
void cut_assert_errno (...
);
Passes if errno is 0.
e.g.:
1 2 |
count = write(stdout, buffer, strlen(buffer)); cut_assert_errno("Failed to write"); -> Pass when count != -1 |
|
optional message. See cut_message() for details.
|
Since 0.8
void cut_assert_file_exist (const char *path
,...
);
cut_assert_file_exist
has been deprecated since version 1.0.2 and should not be used in newly-written code. Use cut_assert_path_exist()
instead.
Passes if path
exists. It may or may not be a regular file.
e.g.:
1 2 |
cut_assert_file_exist("/tmp"); -> Pass on many environment cut_assert_file_exist("/non-existent"); -> Fail |
|
the path to test. |
|
optional message. See cut_message() for details.
|
Since 0.9
void cut_assert_path_exist (const char *path
,...
);
Passes if path
exists. It may or may not be a regular file.
e.g.:
1 2 |
cut_assert_path_exist("/tmp"); -> Pass on many environment cut_assert_path_exist("/non-existent"); -> Fail |
|
the path to test. |
|
optional message. See cut_message() for details.
|
Since 1.0.2
void cut_assert_path_not_exist (const char *path
,...
);
Passes if path
doesn't exist.
e.g.:
1 2 |
cut_assert_path_not_exist("/non-existent"); -> Pass on many environment cut_assert_path_not_exist("/tmp"); -> Fail |
|
the path to test. |
|
optional message. See cut_message() for details.
|
Since 1.0.2
void cut_assert_match (const char *pattern
,const char *actual
,...
);
Passes if pattern
matches string
.
e.g.:
1 2 |
cut_assert_match("^abc", "abc"); -> Pass cut_assert_match("^abc", " abc"); -> Fail |
|
the regular expression pattern. |
|
the string to be matched. |
|
optional message. See cut_message() for details.
|
Since 1.0
void cut_assert_match_with_free (const char *pattern
,const char *actual
,...
);
Passes if pattern
matches string
. See cut_assert_match()
for detail.
|
the regular expression as string. |
|
the string to be matched that is freed. |
|
optional message. See cut_message() for details.
|
Since 1.0
void cut_assert_equal_pointer (const void *expected
,const void *actual
,...
);
Passes if expected
== actual
.
|
an expected pointer. |
|
an actual pointer. |
|
optional message. See cut_message() for details.
|
Since 1.0
void cut_assert_equal_fixture_data_string (const char *expected
,const void *path
,...
);
Passes if expected
== cut_get_fixture_data_string(path
, ...).
|
an expected string. |
|
a first element of the path to the fixture data. |
|
remaining elements in path. NULL terminated.
|
Since 1.0.2
void cut_error (const char *format
,...
);
Raises an error with message.
|
the message format. See the printf() documentation.
|
|
the parameters to insert into the format string. |
void cut_error_errno (...
);
e.g.:
1 2 3 4 5 6 7 |
void setup (void) { mkdir("tmp", 0700); cut_error_errno("Failed to make tmp directory"); -> Error when tmp directory isn't made successfully. } |
|
optional message. See cut_message() for details.
|
Since 1.0.2
void cut_fail (const char *format
,...
);
Raises a failure with message.
|
the message format. See the printf() documentation.
|
|
the parameters to insert into the format string. |
void cut_pend (const char *format
,...
);
Marks the test is pending with message. The test is stopped.
|
the message format. See the printf() documentation.
|
|
the parameters to insert into the format string. |
void cut_pending (const char *format
,...
);
cut_pending
has been deprecated since version 0.4 and should not be used in newly-written code. Use cut_pend()
instead.
Marks the test is pending with message. The test is stopped.
|
the message format. See the printf() documentation.
|
|
the parameters to insert into the format string. |
void cut_notify (const char *format
,...
);
Leaves a notification message. The test is continued.
|
the message format. See the printf() documentation.
|
|
the parameters to insert into the format string. |
void cut_omit (const char *format
,...
);
Omit the test.
e.g.:
1 2 |
if (version < 2.0) cut_omit("Require >= 2.0"); |
|
the message format. See the printf() documentation.
|
|
the parameters to insert into the format string. |
Since 0.8