Skip to content

Commit

Permalink
Convert Constraint struct to CgreenConstraint
Browse files Browse the repository at this point in the history
The `Constraint` struct name can easily conflict with other application
that have some sort of constraint. To ensure that name collision does
not happen the struct was renamed from `Constraint` ->
`CgreenConstraint`
  • Loading branch information
joaopapereira committed Dec 10, 2018
1 parent 0fc7415 commit 895d214
Show file tree
Hide file tree
Showing 20 changed files with 296 additions and 296 deletions.
6 changes: 3 additions & 3 deletions doc/cgreen-guide-en.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ results.
Here are the standard constraints...

|=========================================================
|*Constraint* |*Passes if actual value/expression...*
|*CgreenConstraint* |*Passes if actual value/expression...*
| _Basic_ |
| `is_true` | evaluates to true, buy you can also just leave out the constraint,
e.g. `assert_that(found)` if `found` is of boolean type
Expand Down Expand Up @@ -1678,7 +1678,7 @@ There is a multitude of constraints available (actually, exactly the
same as for the assertions we saw earlier):

|==========================================================================
|*Constraint* |*Type*
|*CgreenConstraint* |*Type*
|`is_equal_to(value)` | Integers
|`is_not_equal_to(value)` | Integers
|`is_greater_than(value)` | Integers
Expand Down Expand Up @@ -1986,7 +1986,7 @@ When it comes to double typed values this has spilled over even further. For
double typed values we have

|==========================================================================
| *Constraint*
| *CgreenConstraint*
| `is_equal_to_double(value)`
| `is_not_equal_to_double(value)`
| `is_less_than_double(value)`
Expand Down
68 changes: 34 additions & 34 deletions include/cgreen/constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ typedef enum {
CALL_COUNTER
} ConstraintType;

typedef struct Constraint_ Constraint;
struct Constraint_ {
typedef struct CgreenConstraint_ CgreenConstraint;
struct CgreenConstraint_ {
ConstraintType type;
const char *name;
void (*destroy)(Constraint *);
bool (*compare)(Constraint *, CgreenValue);
void (*execute)(Constraint *, const char *, CgreenValue, const char *, int, TestReporter *);
char *(*failure_message)(Constraint *, const char *, intptr_t);
void (*destroy)(CgreenConstraint *);
bool (*compare)(CgreenConstraint *, CgreenValue);
void (*execute)(CgreenConstraint *, const char *, CgreenValue, const char *, int, TestReporter *);
char *(*failure_message)(CgreenConstraint *, const char *, intptr_t);
const char *actual_value_message;
const char *expected_value_message;
CgreenValue expected_value;
Expand All @@ -43,38 +43,38 @@ namespace cgreen {
extern "C" {
#endif

Constraint *create_constraint(void);
Constraint *create_parameter_constraint_for(const char *parameter_name);
CgreenConstraint *create_constraint(void);
CgreenConstraint *create_parameter_constraint_for(const char *parameter_name);

bool compare_want_value(Constraint *constraint, CgreenValue actual);
bool compare_do_not_want_value(Constraint *constraint, CgreenValue actual);
void test_want(Constraint *constraint, const char *function, CgreenValue actual, const char *test_file, int test_line, TestReporter *reporter);
bool compare_want_value(CgreenConstraint *constraint, CgreenValue actual);
bool compare_do_not_want_value(CgreenConstraint *constraint, CgreenValue actual);
void test_want(CgreenConstraint *constraint, const char *function, CgreenValue actual, const char *test_file, int test_line, TestReporter *reporter);

void test_constraint(Constraint *constraint, const char *function, intptr_t actual, const char *test_file, int test_line, TestReporter *reporter);
void test_constraint(CgreenConstraint *constraint, const char *function, intptr_t actual, const char *test_file, int test_line, TestReporter *reporter);

Constraint *create_equal_to_value_constraint(intptr_t expected_value, const char *expected_value_name);
Constraint *create_equal_to_hexvalue_constraint(intptr_t expected_value, const char *expected_value_name);
Constraint *create_not_equal_to_value_constraint(intptr_t expected_value, const char *expected_value_name);
Constraint *create_greater_than_value_constraint(intptr_t expected_value, const char *expected_value_name);
Constraint *create_less_than_value_constraint(intptr_t expected_value, const char *expected_value_name);
Constraint *create_equal_to_contents_constraint(void *pointer_to_compare, size_t size_to_compare, const char *compared_pointer_name);
Constraint *create_not_equal_to_contents_constraint(void *pointer_to_compare, size_t size_to_compare, const char *compared_pointer_name);
Constraint *create_equal_to_string_constraint(const char* expected_value, const char *expected_value_name);
Constraint *create_not_equal_to_string_constraint(const char* expected_value, const char *expected_value_name);
Constraint *create_contains_string_constraint(const char* expected_value, const char *expected_value_name);
Constraint *create_does_not_contain_string_constraint(const char* expected_value, const char *expected_value_name);
Constraint *create_begins_with_string_constraint(const char* expected_value, const char *expected_value_name);
Constraint *create_does_not_begin_with_string_constraint(const char* expected_value, const char *expected_value_name);
Constraint *create_ends_with_string_constraint(const char* expected_value, const char *expected_value_name);
Constraint *create_does_not_end_with_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_equal_to_value_constraint(intptr_t expected_value, const char *expected_value_name);
CgreenConstraint *create_equal_to_hexvalue_constraint(intptr_t expected_value, const char *expected_value_name);
CgreenConstraint *create_not_equal_to_value_constraint(intptr_t expected_value, const char *expected_value_name);
CgreenConstraint *create_greater_than_value_constraint(intptr_t expected_value, const char *expected_value_name);
CgreenConstraint *create_less_than_value_constraint(intptr_t expected_value, const char *expected_value_name);
CgreenConstraint *create_equal_to_contents_constraint(void *pointer_to_compare, size_t size_to_compare, const char *compared_pointer_name);
CgreenConstraint *create_not_equal_to_contents_constraint(void *pointer_to_compare, size_t size_to_compare, const char *compared_pointer_name);
CgreenConstraint *create_equal_to_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_not_equal_to_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_contains_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_does_not_contain_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_begins_with_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_does_not_begin_with_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_ends_with_string_constraint(const char* expected_value, const char *expected_value_name);
CgreenConstraint *create_does_not_end_with_string_constraint(const char* expected_value, const char *expected_value_name);

Constraint *create_equal_to_double_constraint(double expected_value, const char *expected_value_name);
Constraint *create_not_equal_to_double_constraint(double expected_value, const char *expected_value_name);
Constraint *create_less_than_double_constraint(double expected_value, const char *expected_value_name);
Constraint *create_greater_than_double_constraint(double expected_value, const char *expected_value_name);
Constraint *create_return_value_constraint(intptr_t value_to_return);
Constraint *create_return_double_value_constraint(double value_to_return);
Constraint *create_set_parameter_value_constraint(const char *parameter_name, intptr_t value_to_set, size_t size_to_set);
CgreenConstraint *create_equal_to_double_constraint(double expected_value, const char *expected_value_name);
CgreenConstraint *create_not_equal_to_double_constraint(double expected_value, const char *expected_value_name);
CgreenConstraint *create_less_than_double_constraint(double expected_value, const char *expected_value_name);
CgreenConstraint *create_greater_than_double_constraint(double expected_value, const char *expected_value_name);
CgreenConstraint *create_return_value_constraint(intptr_t value_to_return);
CgreenConstraint *create_return_double_value_constraint(double value_to_return);
CgreenConstraint *create_set_parameter_value_constraint(const char *parameter_name, intptr_t value_to_set, size_t size_to_set);

/* Utility: */
int get_significant_figures(void);
Expand Down
16 changes: 8 additions & 8 deletions include/cgreen/constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ extern "C" {
* macros when practical, for the namespacing and confusing symbol
* collision issues, so we use singleton instances.
*/
extern Constraint static_non_null_constraint;
extern Constraint *is_non_null;
extern CgreenConstraint static_non_null_constraint;
extern CgreenConstraint *is_non_null;
#define is_not_null (is_non_null)

extern Constraint static_null_constraint;
extern Constraint *is_null;
extern CgreenConstraint static_null_constraint;
extern CgreenConstraint *is_null;

extern Constraint static_false_constraint;
extern Constraint *is_false;
extern CgreenConstraint static_false_constraint;
extern CgreenConstraint *is_false;

extern Constraint static_true_constraint;
extern Constraint *is_true;
extern CgreenConstraint static_true_constraint;
extern CgreenConstraint *is_true;

#ifdef __cplusplus
}
Expand Down
24 changes: 12 additions & 12 deletions include/cgreen/cpp_constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
namespace cgreen {

template<typename T>
class CppConstraint : public Constraint {
class CppConstraint : public CgreenConstraint {
public:
T expected_real_value;
bool (*compare)(CppConstraint *, T);
};

Constraint *create_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
Constraint *create_equal_to_string_constraint(const std::string* expected_value, const char *expected_value_name);
Constraint *create_not_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
Constraint *create_not_equal_to_string_constraint(const std::string* expected_value, const char *expected_value_name);
Constraint *create_contains_string_constraint(const std::string& expected_value, const char *expected_value_name);
Constraint *create_contains_string_constraint(const std::string* expected_value, const char *expected_value_name);
Constraint *create_does_not_contain_string_constraint(const std::string& expected_value, const char *expected_value_name);
Constraint *create_does_not_contain_string_constraint(const std::string* expected_value, const char *expected_value_name);
Constraint *create_begins_with_string_constraint(const std::string& expected_value, const char *expected_value_name);
Constraint *create_begins_with_string_constraint(const std::string* expected_value, const char *expected_value_name);
CgreenConstraint *create_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
CgreenConstraint *create_equal_to_string_constraint(const std::string* expected_value, const char *expected_value_name);
CgreenConstraint *create_not_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
CgreenConstraint *create_not_equal_to_string_constraint(const std::string* expected_value, const char *expected_value_name);
CgreenConstraint *create_contains_string_constraint(const std::string& expected_value, const char *expected_value_name);
CgreenConstraint *create_contains_string_constraint(const std::string* expected_value, const char *expected_value_name);
CgreenConstraint *create_does_not_contain_string_constraint(const std::string& expected_value, const char *expected_value_name);
CgreenConstraint *create_does_not_contain_string_constraint(const std::string* expected_value, const char *expected_value_name);
CgreenConstraint *create_begins_with_string_constraint(const std::string& expected_value, const char *expected_value_name);
CgreenConstraint *create_begins_with_string_constraint(const std::string* expected_value, const char *expected_value_name);


template<typename T>
Expand Down Expand Up @@ -56,7 +56,7 @@ CppConstraint<T> *create_equal_to_value_constraint(CgreenValue cgreen_value, T e

(void)cgreen_value; /* Avoid warnings for UNUSED, which it is for now */

constraint->Constraint::compare = &compare_want_value;
constraint->CgreenConstraint::compare = &compare_want_value;
constraint->execute = &test_want;
constraint->name = "equal";
constraint->expected_value = expected_value;
Expand Down
2 changes: 1 addition & 1 deletion include/cgreen/internal/assertions_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void assert_double_equal_(const char *file, int line, const char *expression, do
void assert_double_not_equal_(const char *file, int line, const char *expression, double tried, double expected);
void assert_string_equal_(const char *file, int line, const char *expression, const char *tried, const char *expected);
void assert_string_not_equal_(const char *file, int line, const char *expression, const char *tried, const char *expected);
void assert_that_double_(const char *file, int line, const char *actual_string, double actual, Constraint *constraint);
void assert_that_double_(const char *file, int line, const char *actual_string, double actual, CgreenConstraint *constraint);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions include/cgreen/internal/c_assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
extern "C" {
#endif

void assert_core_(const char *file, int line, const char *actual_string, intptr_t actual, Constraint *constraint);
void assert_that_double_(const char *file, int line, const char *expression, double actual, Constraint* constraint);
void assert_core_(const char *file, int line, const char *actual_string, intptr_t actual, CgreenConstraint *constraint);
void assert_that_double_(const char *file, int line, const char *expression, double actual, CgreenConstraint* constraint);

#ifdef __cplusplus
}
Expand Down
10 changes: 5 additions & 5 deletions include/cgreen/internal/cpp_assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace cgreen {

#define assert_that_constraint(actual, constraint) assert_that_(__FILE__, __LINE__, STRINGIFY_TOKEN(actual), actual, constraint)

void assert_that_(const char *file, int line, const char *actual_string, const std::string& actual, Constraint *constraint);
void assert_that_(const char *file, int line, const char *actual_string, const std::string *actual, Constraint *constraint);
void assert_that_(const char *file, int line, const char *actual_string, double actual, Constraint *constraint);
void assert_that_(const char *file, int line, const char *actual_string, const std::string& actual, CgreenConstraint *constraint);
void assert_that_(const char *file, int line, const char *actual_string, const std::string *actual, CgreenConstraint *constraint);
void assert_that_(const char *file, int line, const char *actual_string, double actual, CgreenConstraint *constraint);

// this isn't declared in assertions.h because you can't have overloads for an extern "C"-declared function, so it seems
void assert_that_(const char *file, int line, const char *actual_string, intptr_t actual, Constraint *constraint);
void assert_that_(const char *file, int line, const char *actual_string, intptr_t actual, CgreenConstraint *constraint);

template <typename T> void assert_that_(const char *file, int line, const char *actual_string, T actual, Constraint *constraint) {
template <typename T> void assert_that_(const char *file, int line, const char *actual_string, T actual, CgreenConstraint *constraint) {

if (typeid(actual) == typeid(std::string&) ||
typeid(actual) == typeid(const std::string&) ||
Expand Down
2 changes: 1 addition & 1 deletion include/cgreen/internal/mocks_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern intptr_t mock_(TestReporter *test_reporter, const char *function, const c
passes the test case. /@awilke
*/
extern Constraint *when_(const char *parameter, Constraint *constraint) WARN_UNUSED_RESULT;
extern CgreenConstraint *when_(const char *parameter, CgreenConstraint *constraint) WARN_UNUSED_RESULT;

extern Constraint *times_(int number_times_called);

Expand Down
6 changes: 3 additions & 3 deletions include/cgreen/message_formatting.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace cgreen {
extern "C" {
#endif

char *failure_message_for(Constraint *constraint, const char *actual_string, intptr_t actual);
char *validation_failure_message_for(Constraint *constraint, intptr_t actual);
bool parameters_are_not_valid_for(Constraint *constraint, intptr_t actual);
char *failure_message_for(CgreenConstraint *constraint, const char *actual_string, intptr_t actual);
char *validation_failure_message_for(CgreenConstraint *constraint, intptr_t actual);
bool parameters_are_not_valid_for(CgreenConstraint *constraint, intptr_t actual);

#ifdef __cplusplus
}
Expand Down
6 changes: 3 additions & 3 deletions include/cgreen/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace cgreen {
expect(<function>, when(<parameter>, <constraint>), will_return(<value>));
*/
#define expect(f, ...) expect_(get_test_reporter(), STRINGIFY_TOKEN(f), __FILE__, __LINE__, \
(Constraint *)__VA_ARGS__ +0, (Constraint *)0)
(CgreenConstraint *)__VA_ARGS__ +0, (CgreenConstraint *)0)
#define always_expect(f, ...) always_expect_(get_test_reporter(), STRINGIFY_TOKEN(f), __FILE__, __LINE__, \
(Constraint *)__VA_ARGS__ +0, (Constraint *)0)
(CgreenConstraint *)__VA_ARGS__ +0, (CgreenConstraint *)0)
#define never_expect(f, ...) never_expect_(get_test_reporter(), STRINGIFY_TOKEN(f), __FILE__, __LINE__, \
(Constraint *)__VA_ARGS__ +0, (Constraint *)0)
(CgreenConstraint *)__VA_ARGS__ +0, (CgreenConstraint *)0)


#ifdef _MSC_VER
Expand Down
4 changes: 2 additions & 2 deletions src/assertions.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const char *show_null_as_the_string_null(const char *string);


void assert_core_(const char *file, int line, const char *actual_string, intptr_t actual,
Constraint* constraint) {
CgreenConstraint* constraint) {

char *failure_message;

Expand Down Expand Up @@ -80,7 +80,7 @@ void assert_core_(const char *file, int line, const char *actual_string, intptr_
free(failure_message);
}

void assert_that_double_(const char *file, int line, const char *expression, double actual, Constraint* constraint) {
void assert_that_double_(const char *file, int line, const char *expression, double actual, CgreenConstraint* constraint) {
BoxedDouble* boxed_actual;

if (NULL != constraint && is_not_comparing(constraint)) {
Expand Down
Loading

0 comments on commit 895d214

Please sign in to comment.