|
| 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/unittest/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 | +FOSSIL_TEST_DATA(sample_data) { |
| 25 | + int x; |
| 26 | + int y; |
| 27 | +} sample_data; |
| 28 | + |
| 29 | +// Fixture setup and teardown procedures |
| 30 | +FOSSIL_FEATURE(sample_feature); |
| 31 | + |
| 32 | +FOSSIL_SETUP(sample_fixture) { |
| 33 | + sample_data.x = 42; |
| 34 | + sample_data.y = 20; |
| 35 | +} // end of setup |
| 36 | + |
| 37 | +FOSSIL_TEARDOWN(sample_fixture) { |
| 38 | + // Teardown code goes here |
| 39 | +} // end of teardown |
| 40 | + |
| 41 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 42 | +// * Fossil Logic Test Cases |
| 43 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 44 | +// The test cases below are provided as samples, inspired |
| 45 | +// by the Meson build system's approach of using test cases |
| 46 | +// as samples for library usage. |
| 47 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 48 | + |
| 49 | +FOSSIL_SONIREO(xbdd_logic_within_feature_test) { |
| 50 | + GIVEN("a valid statement is passed") { |
| 51 | + // Set up the context |
| 52 | + bool givenExecuted = true; |
| 53 | + |
| 54 | + WHEN("a statement is true") { |
| 55 | + // Perform the login action |
| 56 | + bool whenExecuted = true; |
| 57 | + |
| 58 | + THEN("we validate everything was worked") { |
| 59 | + // Check the expected outcome |
| 60 | + bool thenExecuted = true; |
| 61 | + |
| 62 | + TEST_EXPECT(givenExecuted, "Given statement should have executed"); |
| 63 | + TEST_EXPECT(whenExecuted, "When statement should have executed"); |
| 64 | + TEST_EXPECT(thenExecuted, "Then statement should have executed"); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +} // end of case |
| 69 | + |
| 70 | +FOSSIL_SONIREO(xbdd_user_account_within_feature) { |
| 71 | + GIVEN("a user's account with sufficient balance") { |
| 72 | + // Set up the context |
| 73 | + float accountBalance = 500.0; |
| 74 | + float withdrawalAmount = 200.0; |
| 75 | + |
| 76 | + WHEN("the user requests a withdrawal of $200") { |
| 77 | + // Perform the withdrawal action |
| 78 | + if (accountBalance >= withdrawalAmount) { |
| 79 | + accountBalance -= withdrawalAmount; |
| 80 | + } // end if |
| 81 | + THEN("the withdrawal amount should be deducted from the account balance") { |
| 82 | + // Check the expected outcome |
| 83 | + |
| 84 | + // Simulate the scenario |
| 85 | + float compareBalance = 500.0; |
| 86 | + TEST_EXPECT(accountBalance == (compareBalance - withdrawalAmount), "Account balance should have been deducted by $200"); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | +} // end of case |
| 91 | + |
| 92 | +FOSSIL_SONIREO(xbdd_empty_cart_within_feature) { |
| 93 | + GIVEN("a user with an empty shopping cart") { |
| 94 | + // Set up the context |
| 95 | + int cartItemCount = 0; |
| 96 | + |
| 97 | + WHEN("the user adds a product to the cart") { |
| 98 | + // Perform the action of adding a product |
| 99 | + |
| 100 | + THEN("the cart item count should increase by 1") { |
| 101 | + // Check the expected outcome |
| 102 | + cartItemCount++; |
| 103 | + |
| 104 | + TEST_EXPECT(cartItemCount == 1, "Cart item count should have increased by 1"); |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | +} // end of case |
| 109 | + |
| 110 | +FOSSIL_SONIREO(xbdd_valid_login_within_feature) { |
| 111 | + GIVEN("a registered user with valid credentials") { |
| 112 | + // Set up the context |
| 113 | + const char* validUsername = "user123"; |
| 114 | + const char* validPassword = "pass456"; |
| 115 | + |
| 116 | + WHEN("the user provides correct username and password") { |
| 117 | + // Perform the action of user login |
| 118 | + const char* inputUsername = "user123"; |
| 119 | + const char* inputPassword = "pass456"; |
| 120 | + |
| 121 | + THEN("the login should be successful") { |
| 122 | + // Check the expected outcome |
| 123 | + // Simulate login validation |
| 124 | + TEST_EXPECT(strcmp(inputUsername, validUsername) == 0, "Username should match"); |
| 125 | + TEST_EXPECT(strcmp(inputPassword, validPassword) == 0, "Password should match"); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + WHEN("the user provides incorrect password") { |
| 130 | + // Perform the action of user login |
| 131 | + const char* inputUsername = "user123"; |
| 132 | + const char* inputPassword = "wrongpass"; |
| 133 | + |
| 134 | + THEN("the login should fail with an error message") { |
| 135 | + // Check the expected outcome |
| 136 | + // Simulate login validation |
| 137 | + TEST_EXPECT(strcmp(inputUsername, validUsername) == 0, "Username should match"); |
| 138 | + TEST_EXPECT(strcmp(inputPassword, validPassword) != 0, "Password should not match"); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | +} // end of case |
| 143 | + |
| 144 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 145 | +// * Fossil Logic Test Pool |
| 146 | +// * * * * * * * * * * * * * * * * * * * * * * * * |
| 147 | +FOSSIL_TEST_GROUP(feature_test_group) { |
| 148 | + ADD_TESTF(xbdd_logic_within_feature_test, sample_feature); |
| 149 | + ADD_TESTF(xbdd_user_account_within_feature, sample_feature); |
| 150 | + ADD_TESTF(xbdd_empty_cart_within_feature, sample_feature); |
| 151 | + ADD_TESTF(xbdd_valid_login_within_feature, sample_feature); |
| 152 | +} // end of group |
0 commit comments