Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions code/logic/fossil/test/assume.h
Original file line number Diff line number Diff line change
Expand Up @@ -2177,53 +2177,83 @@ 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.
*
* @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.
*
* @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.
*
* @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.
*
* @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.
*
* @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
}
Expand Down
33 changes: 17 additions & 16 deletions code/tests/cases/test_bdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/test/framework.h>
#include <string>

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Utilites
Expand Down Expand Up @@ -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");
}
}
}
Expand All @@ -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");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/tests/cases/test_mark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
Expand Down
13 changes: 7 additions & 6 deletions code/tests/cases/test_tdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/test/framework.h>
#include <string>

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Utilites
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down