Back to home page

Enduro/X

 
 

    


0001 #ifndef CGREEN_CPP_CONSTRAINT
0002 #define CGREEN_CPP_CONSTRAINT
0003 
0004 
0005 #include <cgreen/constraint.h>
0006 #include <string>
0007 
0008 namespace cgreen {
0009 
0010 template<typename T>
0011 class CppConstraint : public Constraint {
0012  public:
0013     T expected_real_value;
0014     bool (*compare)(CppConstraint *, T);
0015 };
0016 
0017 Constraint *create_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
0018 Constraint *create_not_equal_to_string_constraint(const std::string& expected_value, const char *expected_value_name);
0019 Constraint *create_contains_string_constraint(const std::string& expected_value, const char *expected_value_name);
0020 Constraint *create_does_not_contain_string_constraint(const std::string& expected_value, const char *expected_value_name);
0021 Constraint *create_equal_to_string_constraint(const std::string* expected_value, const char *expected_value_name);
0022 Constraint *create_not_equal_to_string_constraint(const std::string* expected_value, const char *expected_value_name);
0023 Constraint *create_contains_string_constraint(const std::string* expected_value, const char *expected_value_name);
0024 Constraint *create_does_not_contain_string_constraint(const std::string* expected_value, const char *expected_value_name);
0025 
0026 template<typename T>
0027 bool compare_want_value(CppConstraint<T> *constraint, T actual) {
0028     return constraint->expected_real_value == actual;
0029 }
0030 
0031 template<typename T>
0032 bool compare_do_not_want_value(CppConstraint<T> *constraint, T actual) {
0033     return !compare_want_value(constraint, actual);
0034 }
0035 
0036 template<typename T>
0037 void test_want_value(CppConstraint<T> *constraint, const char *function, T actual, const char *test_file, int test_line, TestReporter *reporter) {
0038 }
0039 
0040 #include <stdlib.h>
0041 // TODO: add create_equal_to_constraint_<T> where operator<< output is used for expected_value name
0042 template<typename T>
0043 CppConstraint<T> *create_equal_to_value_constraint(T expected_value, const char *expected_value_name) {
0044     CppConstraint<T> *constraint;// = create_cpp_constraint<T>();
0045     constraint = new CppConstraint<T>();
0046     constraint->type = VALUE_COMPARER;
0047 
0048     constraint->Constraint::compare = &compare_want_value;
0049     constraint->execute = &test_want;
0050     constraint->name = "equal";
0051     constraint->expected_value = expected_value;
0052     constraint->expected_value_name = expected_value_name;
0053     constraint->size_of_expected_value = sizeof(intptr_t);
0054     constraint->expected_real_value = expected_value;
0055     return constraint;
0056 }
0057 
0058 
0059 }
0060 
0061 #endif