Skip to content

Commit b676172

Browse files
add test cases for objc and objcpp side
1 parent 9a2d16a commit b676172

File tree

15 files changed

+4523
-3
lines changed

15 files changed

+4523
-3
lines changed

code/tests/cases/test_bdd.m

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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: 04/05/2014
11+
*
12+
* Copyright (C) 2014-2025 Fossil Logic. All rights reserved.
13+
* -----------------------------------------------------------------------------
14+
*/
15+
#include <fossil/pizza/framework.h>
16+
#include <string>
17+
18+
// * * * * * * * * * * * * * * * * * * * * * * * *
19+
// * Fossil Logic Test Utilites
20+
// * * * * * * * * * * * * * * * * * * * * * * * *
21+
// Setup steps for things like test fixtures and
22+
// mock objects are set here.
23+
// * * * * * * * * * * * * * * * * * * * * * * * *
24+
25+
// Define the test suite and add test cases
26+
FOSSIL_SUITE(objc_bdd_suite);
27+
28+
// Setup function for the test suite
29+
FOSSIL_SETUP(objc_bdd_suite) {
30+
// Setup code here
31+
}
32+
33+
// Teardown function for the test suite
34+
FOSSIL_TEARDOWN(objc_bdd_suite) {
35+
// Teardown code here
36+
}
37+
38+
// * * * * * * * * * * * * * * * * * * * * * * * *
39+
// * Fossil Logic Test Cases
40+
// * * * * * * * * * * * * * * * * * * * * * * * *
41+
// The test cases below are provided as samples, inspired
42+
// by the Meson build system's approach of using test cases
43+
// as samples for library usage.
44+
// * * * * * * * * * * * * * * * * * * * * * * * *
45+
46+
FOSSIL_TEST(objc_xbdd_logic_test) {
47+
GIVEN("a valid statement is passed") {
48+
// Set up the context
49+
bool givenExecuted = true;
50+
51+
WHEN("a statement is true") {
52+
// Perform the login action
53+
bool whenExecuted = true;
54+
55+
THEN("we validate everything was worked") {
56+
// Check the expected outcome
57+
bool thenExecuted = true;
58+
59+
FOSSIL_TEST_ASSUME(givenExecuted, "Given statement should have executed");
60+
FOSSIL_TEST_ASSUME(whenExecuted, "When statement should have executed");
61+
FOSSIL_TEST_ASSUME(thenExecuted, "Then statement should have executed");
62+
}
63+
}
64+
}
65+
} // end of case
66+
67+
FOSSIL_TEST(objc_xbdd_user_account) {
68+
GIVEN("a user's account with sufficient balance") {
69+
// Set up the context
70+
float accountBalance = 500.0;
71+
float withdrawalAmount = 200.0;
72+
73+
WHEN("the user requests a withdrawal of $200") {
74+
// Perform the withdrawal action
75+
if (accountBalance >= withdrawalAmount) {
76+
accountBalance -= withdrawalAmount;
77+
} // end if
78+
THEN("the withdrawal amount should be deducted from the account balance") {
79+
// Check the expected outcome
80+
81+
// Simulate the scenario
82+
float compareBalance = 500.0;
83+
FOSSIL_TEST_ASSUME(accountBalance == (compareBalance - withdrawalAmount), "Account balance should have been deducted by $200");
84+
}
85+
}
86+
}
87+
} // end of case
88+
89+
FOSSIL_TEST(objc_xbdd_empty_cart) {
90+
GIVEN("a user with an empty shopping cart") {
91+
// Set up the context
92+
int cartItemCount = 0;
93+
94+
WHEN("the user adds a product to the cart") {
95+
// Perform the action of adding a product
96+
97+
THEN("the cart item count should increase by 1") {
98+
// Check the expected outcome
99+
cartItemCount++;
100+
101+
FOSSIL_TEST_ASSUME(cartItemCount == 1, "Cart item count should have increased by 1");
102+
}
103+
}
104+
}
105+
} // end of case
106+
107+
FOSSIL_TEST(objc_xbdd_valid_login) {
108+
GIVEN("a registered user with valid credentials") {
109+
// Set up the context
110+
std::string validUsername = "user123";
111+
std::string validPassword = "pass456";
112+
113+
WHEN("the user provides correct username and password") {
114+
// Perform the action of user login
115+
std::string inputUsername = "user123";
116+
std::string inputPassword = "pass456";
117+
118+
THEN("the login should be successful") {
119+
// Check the expected outcome
120+
// Simulate login validation
121+
FOSSIL_TEST_ASSUME(inputUsername == validUsername, "Username should match");
122+
FOSSIL_TEST_ASSUME(inputPassword == validPassword, "Password should match");
123+
}
124+
}
125+
126+
WHEN("the user provides incorrect password") {
127+
// Perform the action of user login
128+
std::string inputUsername = "user123";
129+
std::string inputPassword = "wrongpass";
130+
131+
THEN("the login should fail with an error message") {
132+
// Check the expected outcome
133+
// Simulate login validation
134+
FOSSIL_TEST_ASSUME(inputUsername == validUsername, "Username should match");
135+
FOSSIL_TEST_ASSUME(inputPassword != validPassword, "Password should not match");
136+
}
137+
}
138+
}
139+
} // end of case
140+
141+
FOSSIL_TEST(objc_xbdd_invalid_login) {
142+
GIVEN("a registered user with valid credentials") {
143+
// Set up the context
144+
std::string validUsername = "user123";
145+
std::string validPassword = "pass456";
146+
147+
WHEN("the user provides incorrect username") {
148+
// Perform the action of user login
149+
std::string inputUsername = "wronguser";
150+
std::string inputPassword = "pass456";
151+
152+
THEN("the login should fail with an error message") {
153+
// Check the expected outcome
154+
// Simulate login validation
155+
FOSSIL_TEST_ASSUME(inputUsername != validUsername, "Username should not match");
156+
FOSSIL_TEST_ASSUME(inputPassword == validPassword, "Password should match");
157+
}
158+
}
159+
}
160+
} // end of case
161+
162+
FOSSIL_TEST(objc_xbdd_insufficient_balance) {
163+
GIVEN("a user's account with insufficient balance") {
164+
// Set up the context
165+
float accountBalance = 100.0;
166+
float withdrawalAmount = 200.0;
167+
168+
WHEN("the user requests a withdrawal of $200") {
169+
// Perform the withdrawal action
170+
bool withdrawalSuccess = false;
171+
if (accountBalance >= withdrawalAmount) {
172+
accountBalance -= withdrawalAmount;
173+
withdrawalSuccess = true;
174+
}
175+
176+
THEN("the withdrawal should fail and balance should remain unchanged") {
177+
// Check the expected outcome
178+
FOSSIL_TEST_ASSUME(!withdrawalSuccess, "Withdrawal should not succeed");
179+
FOSSIL_TEST_ASSUME(accountBalance == 100.0, "Account balance should remain unchanged");
180+
}
181+
}
182+
}
183+
} // end of case
184+
185+
FOSSIL_TEST(objc_xbdd_add_multiple_items_to_cart) {
186+
GIVEN("a user with an empty shopping cart") {
187+
// Set up the context
188+
int cartItemCount = 0;
189+
190+
WHEN("the user adds three products to the cart") {
191+
// Perform the action of adding products
192+
cartItemCount += 3;
193+
194+
THEN("the cart item count should increase by 3") {
195+
// Check the expected outcome
196+
FOSSIL_TEST_ASSUME(cartItemCount == 3, "Cart item count should have increased by 3");
197+
}
198+
}
199+
}
200+
} // end of case
201+
202+
FOSSIL_TEST(objc_xbdd_remove_item_from_cart) {
203+
GIVEN("a user with a shopping cart containing 2 items") {
204+
// Set up the context
205+
int cartItemCount = 2;
206+
207+
WHEN("the user removes one product from the cart") {
208+
// Perform the action of removing a product
209+
cartItemCount--;
210+
211+
THEN("the cart item count should decrease by 1") {
212+
// Check the expected outcome
213+
FOSSIL_TEST_ASSUME(cartItemCount == 1, "Cart item count should have decreased by 1");
214+
}
215+
}
216+
}
217+
} // end of case
218+
219+
// * * * * * * * * * * * * * * * * * * * * * * * *
220+
// * Fossil Logic Test Pool
221+
// * * * * * * * * * * * * * * * * * * * * * * * *
222+
FOSSIL_TEST_GROUP(objc_bdd_test_cases) {
223+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_logic_test);
224+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_user_account);
225+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_empty_cart);
226+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_valid_login);
227+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_invalid_login);
228+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_insufficient_balance);
229+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_add_multiple_items_to_cart);
230+
FOSSIL_TEST_ADD(objc_bdd_suite, objc_xbdd_remove_item_from_cart);
231+
232+
FOSSIL_TEST_REGISTER(objc_bdd_suite);
233+
} // end of group

0 commit comments

Comments
 (0)