|
| 1 | +/* |
| 2 | + * ----------------------------------------------------------------------------- |
| 3 | + * Project: Fossil Logic |
| 4 | + * |
| 5 | + * This file is part of the Fossil Logic project, which aims to develop high- |
| 6 | + * performance, cross-platform applications and libraries. The code contained |
| 7 | + * herein is subject to the terms and conditions defined in the project license. |
| 8 | + * |
| 9 | + * Author: Michael Gene Brockus (Dreamer) |
| 10 | + * Date: 07/01/2024 |
| 11 | + * |
| 12 | + * Copyright (C) 2024 Fossil Logic. All rights reserved. |
| 13 | + * ----------------------------------------------------------------------------- |
| 14 | + */ |
| 15 | +#include <fossil/test/framework.h> |
| 16 | + |
| 17 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 18 | +// * Fossil Logic Test Utilites |
| 19 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 20 | +// Setup steps for things like test fixtures and |
| 21 | +// mock objects are set here. |
| 22 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 23 | + |
| 24 | +// Define the test suite and add test cases |
| 25 | +FOSSIL_TEST_SUITE(cpp_bdd_suite); |
| 26 | + |
| 27 | +// Setup function for the test suite |
| 28 | +FOSSIL_SETUP(cpp_bdd_suite) { |
| 29 | + // Setup code here |
| 30 | +} |
| 31 | + |
| 32 | +// Teardown function for the test suite |
| 33 | +FOSSIL_TEARDOWN(cpp_bdd_suite) { |
| 34 | + // Teardown code here |
| 35 | +} |
| 36 | + |
| 37 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 38 | +// * Fossil Logic Test Cases |
| 39 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 40 | +// The test cases below are provided as samples, inspired |
| 41 | +// by the Meson build system's approach of using test cases |
| 42 | +// as samples for library usage. |
| 43 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 44 | + |
| 45 | +FOSSIL_TEST_CASE(cpp_xbdd_logic_test) { |
| 46 | + GIVEN("a valid statement is passed") { |
| 47 | + // Set up the context |
| 48 | + bool givenExecuted = true; |
| 49 | + |
| 50 | + WHEN("a statement is true") { |
| 51 | + // Perform the login action |
| 52 | + bool whenExecuted = true; |
| 53 | + |
| 54 | + THEN("we validate everything was worked") { |
| 55 | + // Check the expected outcome |
| 56 | + bool thenExecuted = true; |
| 57 | + |
| 58 | + FOSSIL_TEST_ASSUME(givenExecuted, "Given statement should have executed"); |
| 59 | + FOSSIL_TEST_ASSUME(whenExecuted, "When statement should have executed"); |
| 60 | + FOSSIL_TEST_ASSUME(thenExecuted, "Then statement should have executed"); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} // end of case |
| 65 | + |
| 66 | +FOSSIL_TEST_CASE(cpp_xbdd_user_account) { |
| 67 | + GIVEN("a user's account with sufficient balance") { |
| 68 | + // Set up the context |
| 69 | + float accountBalance = 500.0; |
| 70 | + float withdrawalAmount = 200.0; |
| 71 | + |
| 72 | + WHEN("the user requests a withdrawal of $200") { |
| 73 | + // Perform the withdrawal action |
| 74 | + if (accountBalance >= withdrawalAmount) { |
| 75 | + accountBalance -= withdrawalAmount; |
| 76 | + } // end if |
| 77 | + THEN("the withdrawal amount should be deducted from the account balance") { |
| 78 | + // Check the expected outcome |
| 79 | + |
| 80 | + // Simulate the scenario |
| 81 | + float compareBalance = 500.0; |
| 82 | + FOSSIL_TEST_ASSUME(accountBalance == (compareBalance - withdrawalAmount), "Account balance should have been deducted by $200"); |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | +} // end of case |
| 87 | + |
| 88 | +FOSSIL_TEST_CASE(cpp_xbdd_empty_cart) { |
| 89 | + GIVEN("a user with an empty shopping cart") { |
| 90 | + // Set up the context |
| 91 | + int cartItemCount = 0; |
| 92 | + |
| 93 | + WHEN("the user adds a product to the cart") { |
| 94 | + // Perform the action of adding a product |
| 95 | + |
| 96 | + THEN("the cart item count should increase by 1") { |
| 97 | + // Check the expected outcome |
| 98 | + cartItemCount++; |
| 99 | + |
| 100 | + FOSSIL_TEST_ASSUME(cartItemCount == 1, "Cart item count should have increased by 1"); |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +} // end of case |
| 105 | + |
| 106 | +FOSSIL_TEST_CASE(cpp_xbdd_valid_login) { |
| 107 | + GIVEN("a registered user with valid credentials") { |
| 108 | + // Set up the context |
| 109 | + const char* validUsername = "user123"; |
| 110 | + const char* validPassword = "pass456"; |
| 111 | + |
| 112 | + WHEN("the user provides correct username and password") { |
| 113 | + // Perform the action of user login |
| 114 | + const char* inputUsername = "user123"; |
| 115 | + const char* inputPassword = "pass456"; |
| 116 | + |
| 117 | + THEN("the login should be successful") { |
| 118 | + // Check the expected outcome |
| 119 | + // Simulate login validation |
| 120 | + FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) == 0, "Username should match"); |
| 121 | + FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) == 0, "Password should match"); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + WHEN("the user provides incorrect password") { |
| 126 | + // Perform the action of user login |
| 127 | + const char* inputUsername = "user123"; |
| 128 | + const char* inputPassword = "wrongpass"; |
| 129 | + |
| 130 | + THEN("the login should fail with an error message") { |
| 131 | + // Check the expected outcome |
| 132 | + // Simulate login validation |
| 133 | + FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) == 0, "Username should match"); |
| 134 | + FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) != 0, "Password should not match"); |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | +} // end of case |
| 139 | + |
| 140 | +FOSSIL_TEST_CASE(cpp_xbdd_invalid_login) { |
| 141 | + GIVEN("a registered user with valid credentials") { |
| 142 | + // Set up the context |
| 143 | + const char* validUsername = "user123"; |
| 144 | + const char* validPassword = "pass456"; |
| 145 | + |
| 146 | + WHEN("the user provides incorrect username") { |
| 147 | + // Perform the action of user login |
| 148 | + const char* inputUsername = "wronguser"; |
| 149 | + const char* inputPassword = "pass456"; |
| 150 | + |
| 151 | + THEN("the login should fail with an error message") { |
| 152 | + // Check the expected outcome |
| 153 | + // Simulate login validation |
| 154 | + FOSSIL_TEST_ASSUME(strcmp(inputUsername, validUsername) != 0, "Username should not match"); |
| 155 | + FOSSIL_TEST_ASSUME(strcmp(inputPassword, validPassword) == 0, "Password should match"); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | +} // end of case |
| 160 | + |
| 161 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 162 | +// * Fossil Logic Test Pool |
| 163 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 164 | +FOSSIL_TEST_GROUP(cpp_bdd_test_cases) { |
| 165 | + FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_logic_test); |
| 166 | + FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_user_account); |
| 167 | + FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_empty_cart); |
| 168 | + FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_valid_login); |
| 169 | + FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_invalid_login); |
| 170 | + |
| 171 | + FOSSIL_TEST_REGISTER(cpp_bdd_suite); |
| 172 | +} // end of group |
0 commit comments