Skip to content

Commit 790d057

Browse files
Merge pull request #2 from dreamer-coding/main
Pull Request to update test
2 parents 8e5ac24 + e76ffb9 commit 790d057

File tree

12 files changed

+399
-260
lines changed

12 files changed

+399
-260
lines changed

.github/workflows/meson_ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ on:
55
paths:
66
- "**.c"
77
- "**.h"
8-
- "**.kt"
8+
- "**.cpp"
9+
- "**.hpp"
910
- "**.py"
10-
- "meson.**"
11+
- "**.build"
12+
- "**.options"
1113
pull_request:
1214
paths:
1315
- "**.c"
1416
- "**.h"
15-
- "**.kt"
17+
- "**.cpp"
18+
- "**.hpp"
1619
- "**.py"
17-
- "meson.**"
20+
- "**.build"
21+
- "**.options"
1822

1923
jobs:
2024
build_msvc:

code/logic/fossil/io/framework.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef FOSSIL_IO_FRAMEWORK_H
1515
#define FOSSIL_IO_FRAMEWORK_H
1616

17+
// Include the necessary headers
1718
#include "output.h"
1819
#include "input.h"
1920
#include "error.h"

code/logic/soap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void replace_substring_case_insensitive(char *str, const char *old_substr
106106
}
107107

108108
void fossil_soap_sanitize(char *input) {
109-
if (input == NULL) return;
109+
if (input == NULL || *input == '\0') return;
110110

111111
// Perform single-threaded sanitization
112112
for (size_t i = 0; i < sizeof(offensive_words) / sizeof(offensive_words[0]); ++i) {
@@ -118,7 +118,7 @@ void fossil_soap_sanitize(char *input) {
118118

119119
// Function to check if a word is an offensive word or phrase
120120
int32_t fossil_soap_is_offensive(const char *word) {
121-
if (word == NULL) return EXIT_SUCCESS;
121+
if (word == NULL || *word == '\0') return EXIT_SUCCESS;
122122

123123
for (size_t i = 0; i < sizeof(offensive_words) / sizeof(offensive_words[0]); ++i) {
124124
if (strcasecmp(word, offensive_words[i]) == 0) {
@@ -130,7 +130,7 @@ int32_t fossil_soap_is_offensive(const char *word) {
130130

131131
// Function to get the number of offensive words found in a string
132132
int32_t fossil_soap_count_offensive(const char *input) {
133-
if (input == NULL) return 0;
133+
if (input == NULL || *input == '\0') return 0;
134134

135135
int count = 0;
136136
char *copy = _custom_fossil_strdup(input);

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,39 @@
1111
* Copyright (C) 2024 Fossil Logic. All rights reserved.
1212
* -----------------------------------------------------------------------------
1313
*/
14-
#include <fossil/unittest/framework.h>
15-
#include <fossil/mockup/framework.h>
16-
#include <fossil/unittest/assume.h>
14+
#include <fossil/test/framework.h>
1715

1816
#include "fossil/io/framework.h"
1917

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_TEST_SUITE(c_soap_suite);
27+
28+
// Setup function for the test suite
29+
FOSSIL_SETUP(c_soap_suite) {
30+
// Setup code here
31+
}
32+
33+
// Teardown function for the test suite
34+
FOSSIL_TEARDOWN(c_soap_suite) {
35+
// Teardown code here
36+
}
2037

2138
// * * * * * * * * * * * * * * * * * * * * * * * *
22-
// * Fossil Logic Test
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.
2344
// * * * * * * * * * * * * * * * * * * * * * * * *
2445

25-
FOSSIL_TEST(test_fossil_soap_sanitize) {
46+
FOSSIL_TEST_CASE(c_test_soap_sanitize) {
2647
char input[] = "This is a test with curse1 and racist_phrase1.";
2748
char expected[] = "This is a test with *** and ***.";
2849

@@ -31,13 +52,13 @@ FOSSIL_TEST(test_fossil_soap_sanitize) {
3152
ASSUME_ITS_EQUAL_CSTR(expected, input);
3253
}
3354

34-
FOSSIL_TEST(test_fossil_soap_is_offensive) {
55+
FOSSIL_TEST_CASE(c_test_soap_is_offensive) {
3556
ASSUME_ITS_TRUE(fossil_soap_is_offensive("curse1"));
3657
ASSUME_ITS_TRUE(fossil_soap_is_offensive("racist_phrase2"));
3758
ASSUME_ITS_FALSE(fossil_soap_is_offensive("non_offensive_word"));
3859
}
3960

40-
FOSSIL_TEST(test_fossil_soap_count_offensive) {
61+
FOSSIL_TEST_CASE(c_test_soap_count_offensive) {
4162
char input[] = "This is a test with curse1 and racist_phrase1";
4263
ASSUME_ITS_EQUAL_I32(2, fossil_soap_count_offensive(input));
4364
}
@@ -47,7 +68,9 @@ FOSSIL_TEST(test_fossil_soap_count_offensive) {
4768
// * * * * * * * * * * * * * * * * * * * * * * * *
4869

4970
FOSSIL_TEST_GROUP(c_soap_tests) {
50-
ADD_TEST(test_fossil_soap_sanitize);
51-
ADD_TEST(test_fossil_soap_is_offensive);
52-
ADD_TEST(test_fossil_soap_count_offensive);
71+
FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_sanitize);
72+
FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_is_offensive);
73+
FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_count_offensive);
74+
75+
FOSSIL_TEST_REGISTER(c_soap_suite);
5376
}

code/tests/cases/test_soap.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
*
11+
* Copyright (C) 2024 Fossil Logic. All rights reserved.
12+
* -----------------------------------------------------------------------------
13+
*/
14+
#include <fossil/test/framework.h>
15+
16+
#include "fossil/io/framework.h"
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_TEST_SUITE(cpp_soap_suite);
27+
28+
// Setup function for the test suite
29+
FOSSIL_SETUP(cpp_soap_suite) {
30+
// Setup code here
31+
}
32+
33+
// Teardown function for the test suite
34+
FOSSIL_TEARDOWN(cpp_soap_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_CASE(cpp_test_soap_sanitize) {
47+
char input[] = "This is a test with curse1 and racist_phrase1.";
48+
char expected[] = "This is a test with *** and ***.";
49+
50+
fossil_soap_sanitize(input);
51+
52+
ASSUME_ITS_EQUAL_CSTR(expected, input);
53+
}
54+
55+
FOSSIL_TEST_CASE(cpp_test_soap_is_offensive) {
56+
ASSUME_ITS_TRUE(fossil_soap_is_offensive("curse1"));
57+
ASSUME_ITS_TRUE(fossil_soap_is_offensive("racist_phrase2"));
58+
ASSUME_ITS_FALSE(fossil_soap_is_offensive("non_offensive_word"));
59+
}
60+
61+
FOSSIL_TEST_CASE(cpp_test_soap_count_offensive) {
62+
char input[] = "This is a test with curse1 and racist_phrase1";
63+
ASSUME_ITS_EQUAL_I32(2, fossil_soap_count_offensive(input));
64+
}
65+
66+
// * * * * * * * * * * * * * * * * * * * * * * * *
67+
// * Fossil Logic Test Pool
68+
// * * * * * * * * * * * * * * * * * * * * * * * *
69+
70+
FOSSIL_TEST_GROUP(cpp_soap_tests) {
71+
FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_sanitize);
72+
FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_is_offensive);
73+
FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_count_offensive);
74+
75+
FOSSIL_TEST_REGISTER(cpp_soap_suite);
76+
}

code/tests/cases/test_stream.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
*
11+
* Copyright (C) 2024 Fossil Logic. All rights reserved.
12+
* -----------------------------------------------------------------------------
13+
*/
14+
#include <fossil/test/framework.h>
15+
16+
#include "fossil/io/framework.h"
17+
18+
19+
// * * * * * * * * * * * * * * * * * * * * * * * *
20+
// * Fossil Logic Test Utilites
21+
// * * * * * * * * * * * * * * * * * * * * * * * *
22+
// Setup steps for things like test fixtures and
23+
// mock objects are set here.
24+
// * * * * * * * * * * * * * * * * * * * * * * * *
25+
26+
// Define the test suite and add test cases
27+
FOSSIL_TEST_SUITE(c_stream_suite);
28+
fossil_fstream_t c_stream;
29+
30+
// Setup function for the test suite
31+
FOSSIL_SETUP(c_stream_suite) {
32+
// Setup code here
33+
}
34+
35+
// Teardown function for the test suite
36+
FOSSIL_TEARDOWN(c_stream_suite) {
37+
// Teardown code here
38+
}
39+
40+
// * * * * * * * * * * * * * * * * * * * * * * * *
41+
// * Fossil Logic Test Cases
42+
// * * * * * * * * * * * * * * * * * * * * * * * *
43+
// The test cases below are provided as samples, inspired
44+
// by the Meson build system's approach of using test cases
45+
// as samples for library usage.
46+
// * * * * * * * * * * * * * * * * * * * * * * * *
47+
48+
FOSSIL_TEST_CASE(c_test_stream_let_write_and_read_file) {
49+
const char *filename = "testfile.txt";
50+
const char *content = "This is a test.";
51+
52+
// Write data to the file
53+
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w"));
54+
fossil_fstream_write(&c_stream, content, strlen(content), 1);
55+
fossil_fstream_close(&c_stream);
56+
57+
// Read data from the file
58+
char buffer[1024];
59+
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "r"));
60+
fossil_fstream_read(&c_stream, buffer, sizeof(buffer), 1);
61+
fossil_fstream_close(&c_stream);
62+
}
63+
64+
FOSSIL_TEST_CASE(c_test_stream_let_open_and_close_file) {
65+
const char *filename = "testfile.txt";
66+
67+
// Open the file
68+
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w"));
69+
fossil_fstream_close(&c_stream);
70+
}
71+
72+
FOSSIL_TEST_CASE(c_test_stream_multiple_files) {
73+
const char *filename1 = "testfile1.txt";
74+
const char *filename2 = "testfile2.txt";
75+
76+
// Open the first file
77+
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename1, "w"));
78+
fossil_fstream_close(&c_stream);
79+
80+
// Open the second file
81+
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename2, "w"));
82+
fossil_fstream_close(&c_stream);
83+
}
84+
85+
FOSSIL_TEST_CASE(c_test_stream_seek_and_tell) {
86+
const char *filename = "testfile.txt";
87+
const char *content = "This is a test.";
88+
89+
// Write data to the file
90+
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w"));
91+
fossil_fstream_write(&c_stream, content, strlen(content), 1);
92+
fossil_fstream_close(&c_stream);
93+
94+
// Open the file
95+
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "r"));
96+
97+
// Seek to the end of the file
98+
fossil_fstream_seek(&c_stream, 0, SEEK_END);
99+
100+
// Get the current position
101+
long position = fossil_fstream_tell(&c_stream);
102+
103+
ASSUME_ITS_TRUE(position > 0);
104+
105+
// Close the file
106+
fossil_fstream_close(&c_stream);
107+
}
108+
109+
// * * * * * * * * * * * * * * * * * * * * * * * *
110+
// * Fossil Logic Test Pool
111+
// * * * * * * * * * * * * * * * * * * * * * * * *
112+
113+
FOSSIL_TEST_GROUP(c_file_tests) {
114+
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_write_and_read_file);
115+
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_open_and_close_file);
116+
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_multiple_files);
117+
118+
FOSSIL_TEST_REGISTER(c_stream_suite);
119+
}

0 commit comments

Comments
 (0)