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
6 changes: 6 additions & 0 deletions .github/workflows/meson_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ on:
paths:
- "**.c"
- "**.h"
- "**.cpp"
- "**.hpp"
- "**.rs"
- "**.py"
- "**.build"
- "**.options"
pull_request:
paths:
- "**.c"
- "**.h"
- "**.cpp"
- "**.hpp"
- "**.rs"
- "**.py"
- "**.build"
- "**.options"
Expand Down
3 changes: 0 additions & 3 deletions code/logic/fossil/test/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ uint64_t fossil_test_stop_benchmark(void);
#endif

#ifdef __cplusplus
#include <iostream>
#include <string>

namespace fossil {

}
Expand Down
3 changes: 0 additions & 3 deletions code/logic/fossil/test/mockup.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ void fossil_mock_print(MockCallList *list);
#endif

#ifdef __cplusplus
#include <iostream>
#include <string>

namespace fossil {

}
Expand Down
66 changes: 47 additions & 19 deletions code/logic/fossil/test/unittest.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,27 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace);
#define _FOSSIL_TEST_ASSUME(condition, message) \
fossil_test_assert_internal((condition), (message), __FILE__, __LINE__, __func__)

// Macro for defining test data structures
#define _FOSSIL_TEST_DATA(name) \
typedef struct name

// Macro for defining a test case
#ifdef __cplusplus
#define _FOSSIL_TEST_CASE(test_name) \
void test_name##_test_func(void); \
test_case_t test_name##_test_case = { \
#test_name, \
test_name##_test_func, \
nullptr, \
nullptr, \
TEST_STATUS_PASS, \
nullptr, \
nullptr, \
0.0, \
nullptr \
}; \
void test_name##_test_func(void)
#else
#define _FOSSIL_TEST_CASE(test_name) \
void test_name##_test_func(void); \
test_case_t test_name##_test_case = { \
Expand All @@ -222,36 +242,47 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace);
.teardown_func = NULL, \
.status = TEST_STATUS_PASS, \
.failure_message = NULL, \
.execution_time = 0.0, \
.stack_trace = NULL, \
.execution_time = 0.0, \
.next = NULL \
}; \
void test_name##_test_func(void)

// Macro for defining test data structures
#define _FOSSIL_TEST_DATA(name) \
typedef struct name

// Macro for setting up a test case
#define _FOSSIL_TEST_SETUP(name) \
void name##_setup_func(void)

// Macro for tearing down a test case
#define _FOSSIL_TEST_TEARDOWN(name) \
void name##_teardown_func(void)
#endif

// Macro to create a test suite with setup and teardown hooks
#ifdef __cplusplus
#define _FOSSIL_TEST_SUITE(suite_name) \
void suite_name##_setup_func(void); \
void suite_name##_teardown_func(void); \
test_suite_t suite_name = { \
#suite_name, \
suite_name##_setup_func, \
suite_name##_teardown_func, \
0.0, \
nullptr, \
nullptr \
}
#else
#define _FOSSIL_TEST_SUITE(suite_name) \
void suite_name##_setup_func(void); \
void suite_name##_teardown_func(void); \
test_suite_t suite_name = { \
.name = #suite_name, \
.tests = NULL, \
.total_execution_time = 0.0, \
.suite_setup_func = suite_name##_setup_func, \
.suite_teardown_func = suite_name##_teardown_func, \
.total_execution_time = 0.0, \
.tests = NULL, \
.next = NULL \
}
#endif

// Macro for setting up a test case
#define _FOSSIL_TEST_SETUP(name) \
void name##_setup_func(void)

// Macro for tearing down a test case
#define _FOSSIL_TEST_TEARDOWN(name) \
void name##_teardown_func(void)

// Macro to register a suite with the test environment
#define _FOSSIL_TEST_REGISTER(suite) \
Expand Down Expand Up @@ -315,12 +346,9 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace);
#endif

#ifdef __cplusplus
#include <iostream>
#include <string>

namespace fossil {

}
} // namespace fossil
#endif

#endif
24 changes: 23 additions & 1 deletion code/tests/test_bdd.c → code/tests/cases/test_bdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,36 @@ FOSSIL_TEST_CASE(xbdd_valid_login) {
}
} // end of case

FOSSIL_TEST_CASE(xbdd_invalid_login) {
GIVEN("a registered user with valid credentials") {
// Set up the context
const char* validUsername = "user123";
const char* validPassword = "pass456";

WHEN("the user provides incorrect username") {
// Perform the action of user login
const char* inputUsername = "wronguser";
const char* 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");
}
}
}
} // end of case

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
FOSSIL_TEST_GROUP(bdd_test_group) {
FOSSIL_TEST_GROUP(c_bdd_test_cases) {
FOSSIL_TEST_ADD(bdd_suite, xbdd_logic_test);
FOSSIL_TEST_ADD(bdd_suite, xbdd_user_account);
FOSSIL_TEST_ADD(bdd_suite, xbdd_empty_cart);
FOSSIL_TEST_ADD(bdd_suite, xbdd_valid_login);
FOSSIL_TEST_ADD(bdd_suite, xbdd_invalid_login);

FOSSIL_TEST_REGISTER(bdd_suite);
} // end of group
172 changes: 172 additions & 0 deletions code/tests/cases/test_bdd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* -----------------------------------------------------------------------------
* Project: Fossil Logic
*
* This file is part of the Fossil Logic project, which aims to develop high-
* performance, cross-platform applications and libraries. The code contained
* herein is subject to the terms and conditions defined in the project license.
*
* Author: Michael Gene Brockus (Dreamer)
* Date: 07/01/2024
*
* Copyright (C) 2024 Fossil Logic. All rights reserved.
* -----------------------------------------------------------------------------
*/
#include <fossil/test/framework.h>

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Utilites
// * * * * * * * * * * * * * * * * * * * * * * * *
// Setup steps for things like test fixtures and
// mock objects are set here.
// * * * * * * * * * * * * * * * * * * * * * * * *

// Define the test suite and add test cases
FOSSIL_TEST_SUITE(cpp_bdd_suite);

// Setup function for the test suite
FOSSIL_SETUP(cpp_bdd_suite) {
// Setup code here
}

// Teardown function for the test suite
FOSSIL_TEARDOWN(cpp_bdd_suite) {
// Teardown code here
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Cases
// * * * * * * * * * * * * * * * * * * * * * * * *
// The test cases below are provided as samples, inspired
// by the Meson build system's approach of using test cases
// as samples for library usage.
// * * * * * * * * * * * * * * * * * * * * * * * *

FOSSIL_TEST_CASE(cpp_xbdd_logic_test) {
GIVEN("a valid statement is passed") {
// Set up the context
bool givenExecuted = true;

WHEN("a statement is true") {
// Perform the login action
bool whenExecuted = true;

THEN("we validate everything was worked") {
// Check the expected outcome
bool thenExecuted = true;

FOSSIL_TEST_ASSUME(givenExecuted, "Given statement should have executed");
FOSSIL_TEST_ASSUME(whenExecuted, "When statement should have executed");
FOSSIL_TEST_ASSUME(thenExecuted, "Then statement should have executed");
}
}
}
} // end of case

FOSSIL_TEST_CASE(cpp_xbdd_user_account) {
GIVEN("a user's account with sufficient balance") {
// Set up the context
float accountBalance = 500.0;
float withdrawalAmount = 200.0;

WHEN("the user requests a withdrawal of $200") {
// Perform the withdrawal action
if (accountBalance >= withdrawalAmount) {
accountBalance -= withdrawalAmount;
} // end if
THEN("the withdrawal amount should be deducted from the account balance") {
// Check the expected outcome

// Simulate the scenario
float compareBalance = 500.0;
FOSSIL_TEST_ASSUME(accountBalance == (compareBalance - withdrawalAmount), "Account balance should have been deducted by $200");
}
}
}
} // end of case

FOSSIL_TEST_CASE(cpp_xbdd_empty_cart) {
GIVEN("a user with an empty shopping cart") {
// Set up the context
int cartItemCount = 0;

WHEN("the user adds a product to the cart") {
// Perform the action of adding a product

THEN("the cart item count should increase by 1") {
// Check the expected outcome
cartItemCount++;

FOSSIL_TEST_ASSUME(cartItemCount == 1, "Cart item count should have increased by 1");
}
}
}
} // end of case

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";

WHEN("the user provides correct username and password") {
// Perform the action of user login
const char* inputUsername = "user123";
const char* 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");
}
}

WHEN("the user provides incorrect password") {
// Perform the action of user login
const char* inputUsername = "user123";
const char* 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");
}
}
}
} // end of case

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";

WHEN("the user provides incorrect username") {
// Perform the action of user login
const char* inputUsername = "wronguser";
const char* 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");
}
}
}
} // end of case

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
FOSSIL_TEST_GROUP(cpp_bdd_test_cases) {
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_logic_test);
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_user_account);
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_empty_cart);
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_valid_login);
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_invalid_login);

FOSSIL_TEST_REGISTER(cpp_bdd_suite);
} // end of group
Loading