Skip to content

Commit 735c382

Browse files
Merge pull request #25 from dreamer-coding/mixed_lang_testbed
Mixed lang testbed
2 parents 145c18f + fdeefe4 commit 735c382

File tree

13 files changed

+644
-66
lines changed

13 files changed

+644
-66
lines changed

.github/workflows/meson_ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ on:
55
paths:
66
- "**.c"
77
- "**.h"
8+
- "**.cpp"
9+
- "**.hpp"
10+
- "**.rs"
811
- "**.py"
912
- "**.build"
1013
- "**.options"
1114
pull_request:
1215
paths:
1316
- "**.c"
1417
- "**.h"
18+
- "**.cpp"
19+
- "**.hpp"
20+
- "**.rs"
1521
- "**.py"
1622
- "**.build"
1723
- "**.options"

code/logic/fossil/test/benchmark.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@ uint64_t fossil_test_stop_benchmark(void);
137137
#endif
138138

139139
#ifdef __cplusplus
140-
#include <iostream>
141-
#include <string>
142-
143140
namespace fossil {
144141

145142
}

code/logic/fossil/test/mockup.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ void fossil_mock_print(MockCallList *list);
159159
#endif
160160

161161
#ifdef __cplusplus
162-
#include <iostream>
163-
#include <string>
164-
165162
namespace fossil {
166163

167164
}

code/logic/fossil/test/unittest.h

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,27 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace);
212212
#define _FOSSIL_TEST_ASSUME(condition, message) \
213213
fossil_test_assert_internal((condition), (message), __FILE__, __LINE__, __func__)
214214

215+
// Macro for defining test data structures
216+
#define _FOSSIL_TEST_DATA(name) \
217+
typedef struct name
218+
215219
// Macro for defining a test case
220+
#ifdef __cplusplus
221+
#define _FOSSIL_TEST_CASE(test_name) \
222+
void test_name##_test_func(void); \
223+
test_case_t test_name##_test_case = { \
224+
#test_name, \
225+
test_name##_test_func, \
226+
nullptr, \
227+
nullptr, \
228+
TEST_STATUS_PASS, \
229+
nullptr, \
230+
nullptr, \
231+
0.0, \
232+
nullptr \
233+
}; \
234+
void test_name##_test_func(void)
235+
#else
216236
#define _FOSSIL_TEST_CASE(test_name) \
217237
void test_name##_test_func(void); \
218238
test_case_t test_name##_test_case = { \
@@ -222,36 +242,47 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace);
222242
.teardown_func = NULL, \
223243
.status = TEST_STATUS_PASS, \
224244
.failure_message = NULL, \
225-
.execution_time = 0.0, \
226245
.stack_trace = NULL, \
246+
.execution_time = 0.0, \
227247
.next = NULL \
228248
}; \
229249
void test_name##_test_func(void)
230-
231-
// Macro for defining test data structures
232-
#define _FOSSIL_TEST_DATA(name) \
233-
typedef struct name
234-
235-
// Macro for setting up a test case
236-
#define _FOSSIL_TEST_SETUP(name) \
237-
void name##_setup_func(void)
238-
239-
// Macro for tearing down a test case
240-
#define _FOSSIL_TEST_TEARDOWN(name) \
241-
void name##_teardown_func(void)
250+
#endif
242251

243252
// Macro to create a test suite with setup and teardown hooks
253+
#ifdef __cplusplus
254+
#define _FOSSIL_TEST_SUITE(suite_name) \
255+
void suite_name##_setup_func(void); \
256+
void suite_name##_teardown_func(void); \
257+
test_suite_t suite_name = { \
258+
#suite_name, \
259+
suite_name##_setup_func, \
260+
suite_name##_teardown_func, \
261+
0.0, \
262+
nullptr, \
263+
nullptr \
264+
}
265+
#else
244266
#define _FOSSIL_TEST_SUITE(suite_name) \
245267
void suite_name##_setup_func(void); \
246268
void suite_name##_teardown_func(void); \
247269
test_suite_t suite_name = { \
248270
.name = #suite_name, \
249-
.tests = NULL, \
250-
.total_execution_time = 0.0, \
251271
.suite_setup_func = suite_name##_setup_func, \
252272
.suite_teardown_func = suite_name##_teardown_func, \
273+
.total_execution_time = 0.0, \
274+
.tests = NULL, \
253275
.next = NULL \
254276
}
277+
#endif
278+
279+
// Macro for setting up a test case
280+
#define _FOSSIL_TEST_SETUP(name) \
281+
void name##_setup_func(void)
282+
283+
// Macro for tearing down a test case
284+
#define _FOSSIL_TEST_TEARDOWN(name) \
285+
void name##_teardown_func(void)
255286

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

317348
#ifdef __cplusplus
318-
#include <iostream>
319-
#include <string>
320-
321349
namespace fossil {
322350

323-
}
351+
} // namespace fossil
324352
#endif
325353

326354
#endif

code/tests/test_bdd.c renamed to code/tests/cases/test_bdd.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,36 @@ FOSSIL_TEST_CASE(xbdd_valid_login) {
137137
}
138138
} // end of case
139139

140+
FOSSIL_TEST_CASE(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+
140161
// * * * * * * * * * * * * * * * * * * * * * * * *
141162
// * Fossil Logic Test Pool
142163
// * * * * * * * * * * * * * * * * * * * * * * * *
143-
FOSSIL_TEST_GROUP(bdd_test_group) {
164+
FOSSIL_TEST_GROUP(c_bdd_test_cases) {
144165
FOSSIL_TEST_ADD(bdd_suite, xbdd_logic_test);
145166
FOSSIL_TEST_ADD(bdd_suite, xbdd_user_account);
146167
FOSSIL_TEST_ADD(bdd_suite, xbdd_empty_cart);
147168
FOSSIL_TEST_ADD(bdd_suite, xbdd_valid_login);
169+
FOSSIL_TEST_ADD(bdd_suite, xbdd_invalid_login);
148170

149171
FOSSIL_TEST_REGISTER(bdd_suite);
150172
} // end of group

code/tests/cases/test_bdd.cpp

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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

Comments
 (0)