diff --git a/code/logic/fossil/test/assume.h b/code/logic/fossil/test/assume.h index a30bea53..3c2d7a57 100644 --- a/code/logic/fossil/test/assume.h +++ b/code/logic/fossil/test/assume.h @@ -2177,8 +2177,13 @@ extern "C" { * @param actual The actual byte string. * @param expected The expected byte string. */ +#ifdef __cplusplus +#define ASSUME_ITS_EQUAL_BSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((actual.c_str()), (expected.c_str())) == 0, "Expected byte string " #actual " to be equal to " #expected) +#else #define ASSUME_ITS_EQUAL_BSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) == 0, "Expected byte string " #actual " to be equal to " #expected) +#endif /** * @brief Assumes that the given byte strings are not equal. @@ -2186,8 +2191,13 @@ extern "C" { * @param actual The actual byte string. * @param expected The expected byte string. */ +#ifdef __cplusplus +#define ASSUME_NOT_EQUAL_BSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((actual.c_str()), (expected.c_str())) != 0, "Expected byte string " #actual " to not be equal to " #expected) +#else #define ASSUME_NOT_EQUAL_BSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((const char*)(actual), (const char*)(expected)) != 0, "Expected byte string " #actual " to not be equal to " #expected) +#endif /** * @brief Assumes that the length of the given byte string is equal to the expected length. @@ -2195,8 +2205,13 @@ extern "C" { * @param actual The actual byte string. * @param expected_len The expected length of the byte string. */ +#ifdef __cplusplus +#define ASSUME_ITS_LENGTH_EQUAL_BSTR(actual, expected_len) \ + FOSSIL_TEST_ASSUME(strlen((actual.c_str())) == (expected_len), "Expected length of byte string " #actual " to be equal to " #expected_len) +#else #define ASSUME_ITS_LENGTH_EQUAL_BSTR(actual, expected_len) \ FOSSIL_TEST_ASSUME(strlen((const char*)(actual)) == (expected_len), "Expected length of byte string " #actual " to be equal to " #expected_len) +#endif /** * @brief Assumes that the given C strings are equal. @@ -2204,8 +2219,13 @@ extern "C" { * @param actual The actual C string. * @param expected The expected C string. */ +#ifdef __cplusplus +#define ASSUME_ITS_EQUAL_CSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((actual.c_str()), (expected.c_str())) == 0, "Expected C string " #actual " to be equal to " #expected) +#else #define ASSUME_ITS_EQUAL_CSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) == 0, "Expected C string " #actual " to be equal to " #expected) +#endif /** * @brief Assumes that the given C strings are not equal. @@ -2213,8 +2233,13 @@ extern "C" { * @param actual The actual C string. * @param expected The expected C string. */ +#ifdef __cplusplus +#define ASSUME_NOT_EQUAL_CSTR(actual, expected) \ + FOSSIL_TEST_ASSUME(strcmp((actual.c_str()), (expected.c_str())) != 0, "Expected C string " #actual " to not be equal to " #expected) +#else #define ASSUME_NOT_EQUAL_CSTR(actual, expected) \ FOSSIL_TEST_ASSUME(strcmp((actual), (expected)) != 0, "Expected C string " #actual " to not be equal to " #expected) +#endif /** * @brief Assumes that the length of the given C string is equal to the expected length. @@ -2222,8 +2247,13 @@ extern "C" { * @param actual The actual C string. * @param expected_len The expected length of the C string. */ +#ifdef __cplusplus +#define ASSUME_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \ + FOSSIL_TEST_ASSUME(strlen((actual.c_str())) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len) +#else #define ASSUME_ITS_LENGTH_EQUAL_CSTR(actual, expected_len) \ FOSSIL_TEST_ASSUME(strlen((actual)) == (expected_len), "Expected length of C string " #actual " to be equal to " #expected_len) +#endif #ifdef __cplusplus } diff --git a/code/tests/cases/test_bdd.cpp b/code/tests/cases/test_bdd.cpp index 0c365317..2681db75 100644 --- a/code/tests/cases/test_bdd.cpp +++ b/code/tests/cases/test_bdd.cpp @@ -13,6 +13,7 @@ * ----------------------------------------------------------------------------- */ #include +#include // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Utilites @@ -106,32 +107,32 @@ FOSSIL_TEST_CASE(cpp_xbdd_empty_cart) { FOSSIL_TEST_CASE(cpp_xbdd_valid_login) { GIVEN("a registered user with valid credentials") { // Set up the context - const char* validUsername = "user123"; - const char* validPassword = "pass456"; + std::string validUsername = "user123"; + std::string validPassword = "pass456"; WHEN("the user provides correct username and password") { // Perform the action of user login - const char* inputUsername = "user123"; - const char* inputPassword = "pass456"; + std::string inputUsername = "user123"; + std::string inputPassword = "pass456"; THEN("the login should be successful") { // Check the expected outcome // Simulate login validation - FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) == 0, "Username should match"); - FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) == 0, "Password should match"); + FOSSIL_TEST_ASSUME(inputUsername == validUsername, "Username should match"); + FOSSIL_TEST_ASSUME(inputPassword == validPassword, "Password should match"); } } WHEN("the user provides incorrect password") { // Perform the action of user login - const char* inputUsername = "user123"; - const char* inputPassword = "wrongpass"; + std::string inputUsername = "user123"; + std::string inputPassword = "wrongpass"; THEN("the login should fail with an error message") { // Check the expected outcome // Simulate login validation - FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) == 0, "Username should match"); - FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) != 0, "Password should not match"); + FOSSIL_TEST_ASSUME(inputUsername == validUsername, "Username should match"); + FOSSIL_TEST_ASSUME(inputPassword != validPassword, "Password should not match"); } } } @@ -140,19 +141,19 @@ FOSSIL_TEST_CASE(cpp_xbdd_valid_login) { FOSSIL_TEST_CASE(cpp_xbdd_invalid_login) { GIVEN("a registered user with valid credentials") { // Set up the context - const char* validUsername = "user123"; - const char* validPassword = "pass456"; + std::string validUsername = "user123"; + std::string validPassword = "pass456"; WHEN("the user provides incorrect username") { // Perform the action of user login - const char* inputUsername = "wronguser"; - const char* inputPassword = "pass456"; + std::string inputUsername = "wronguser"; + std::string inputPassword = "pass456"; THEN("the login should fail with an error message") { // Check the expected outcome // Simulate login validation - FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) != 0, "Username should not match"); - FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) == 0, "Password should match"); + FOSSIL_TEST_ASSUME(inputUsername != validUsername, "Username should not match"); + FOSSIL_TEST_ASSUME(inputPassword == validPassword, "Password should match"); } } } diff --git a/code/tests/cases/test_mark.cpp b/code/tests/cases/test_mark.cpp index 941fd41c..a3b6f192 100644 --- a/code/tests/cases/test_mark.cpp +++ b/code/tests/cases/test_mark.cpp @@ -50,7 +50,7 @@ FOSSIL_TEST_CASE(cpp_mark_start_and_stop) { MARK_BENCHMARK(stop_test); MARK_START(stop_test); MARK_STOP(stop_test); - ASSUME_ITS_EQUAL_CSTR(benchmark_stop_test.name, benchmark_stop_test_name.c_str()); + ASSUME_ITS_EQUAL_CSTR(std::string(benchmark_stop_test.name), benchmark_stop_test_name); } // * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/code/tests/cases/test_tdd.cpp b/code/tests/cases/test_tdd.cpp index 44c3a451..b01ba3cb 100644 --- a/code/tests/cases/test_tdd.cpp +++ b/code/tests/cases/test_tdd.cpp @@ -13,6 +13,7 @@ * ----------------------------------------------------------------------------- */ #include +#include // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Utilites @@ -686,9 +687,9 @@ FOSSIL_TEST_CASE(cpp_assume_run_of_wstr) { } // end case FOSSIL_TEST_CASE(cpp_assume_run_of_bstr) { - const char *str1 = (const char *)"Hello"; - const char *str2 = (const char *)"Hello"; - const char *str3 = (const char *)"World"; + std::string str1 = "Hello"; + std::string str2 = "Hello"; + std::string str3 = "World"; // Test cases ASSUME_ITS_EQUAL_BSTR(str1, str2); @@ -697,9 +698,9 @@ FOSSIL_TEST_CASE(cpp_assume_run_of_bstr) { } // end case FOSSIL_TEST_CASE(cpp_assume_run_of_cstr) { - const char *str1 = "Hello"; - const char *str2 = "Hello"; - const char *str3 = "World"; + std::string str1 = "Hello"; + std::string str2 = "Hello"; + std::string str3 = "World"; // Test cases ASSUME_ITS_EQUAL_CSTR(str1, str2);