Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/meson_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ on:
paths:
- "**.c"
- "**.h"
- "**.kt"
- "**.cpp"
- "**.hpp"
- "**.py"
- "meson.**"
- "**.build"
- "**.options"
pull_request:
paths:
- "**.c"
- "**.h"
- "**.kt"
- "**.cpp"
- "**.hpp"
- "**.py"
- "meson.**"
- "**.build"
- "**.options"

jobs:
build_msvc:
Expand Down
1 change: 1 addition & 0 deletions code/logic/fossil/io/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef FOSSIL_IO_FRAMEWORK_H
#define FOSSIL_IO_FRAMEWORK_H

// Include the necessary headers
#include "output.h"
#include "input.h"
#include "error.h"
Expand Down
6 changes: 3 additions & 3 deletions code/logic/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void replace_substring_case_insensitive(char *str, const char *old_substr
}

void fossil_soap_sanitize(char *input) {
if (input == NULL) return;
if (input == NULL || *input == '\0') return;

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

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

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

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

int count = 0;
char *copy = _custom_fossil_strdup(input);
Expand Down
43 changes: 33 additions & 10 deletions code/tests/test_soap.c → code/tests/cases/test_soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,39 @@
* Copyright (C) 2024 Fossil Logic. All rights reserved.
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/mockup/framework.h>
#include <fossil/unittest/assume.h>
#include <fossil/test/framework.h>

#include "fossil/io/framework.h"

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Utilites
// * * * * * * * * * * * * * * * * * * * * * * * *
// Setup steps for things like test fixtures and
// mock objects are set here.
// * * * * * * * * * * * * * * * * * * * * * * * *

// Define the test suite and add test cases
FOSSIL_TEST_SUITE(c_soap_suite);

// Setup function for the test suite
FOSSIL_SETUP(c_soap_suite) {
// Setup code here
}

// Teardown function for the test suite
FOSSIL_TEARDOWN(c_soap_suite) {
// Teardown code here
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test
// * Fossil Logic Test Cases
// * * * * * * * * * * * * * * * * * * * * * * * *
// The test cases below are provided as samples, inspired
// by the Meson build system's approach of using test cases
// as samples for library usage.
// * * * * * * * * * * * * * * * * * * * * * * * *

FOSSIL_TEST(test_fossil_soap_sanitize) {
FOSSIL_TEST_CASE(c_test_soap_sanitize) {
char input[] = "This is a test with curse1 and racist_phrase1.";
char expected[] = "This is a test with *** and ***.";

Expand All @@ -31,13 +52,13 @@ FOSSIL_TEST(test_fossil_soap_sanitize) {
ASSUME_ITS_EQUAL_CSTR(expected, input);
}

FOSSIL_TEST(test_fossil_soap_is_offensive) {
FOSSIL_TEST_CASE(c_test_soap_is_offensive) {
ASSUME_ITS_TRUE(fossil_soap_is_offensive("curse1"));
ASSUME_ITS_TRUE(fossil_soap_is_offensive("racist_phrase2"));
ASSUME_ITS_FALSE(fossil_soap_is_offensive("non_offensive_word"));
}

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

FOSSIL_TEST_GROUP(c_soap_tests) {
ADD_TEST(test_fossil_soap_sanitize);
ADD_TEST(test_fossil_soap_is_offensive);
ADD_TEST(test_fossil_soap_count_offensive);
FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_sanitize);
FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_is_offensive);
FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_count_offensive);

FOSSIL_TEST_REGISTER(c_soap_suite);
}
76 changes: 76 additions & 0 deletions code/tests/cases/test_soap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* -----------------------------------------------------------------------------
* Project: Fossil Logic
*
* This file is part of the Fossil Logic project, which aims to develop high-
* performance, cross-platform applications and libraries. The code contained
* herein is subject to the terms and conditions defined in the project license.
*
* Author: Michael Gene Brockus (Dreamer)
*
* Copyright (C) 2024 Fossil Logic. All rights reserved.
* -----------------------------------------------------------------------------
*/
#include <fossil/test/framework.h>

#include "fossil/io/framework.h"

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Utilites
// * * * * * * * * * * * * * * * * * * * * * * * *
// Setup steps for things like test fixtures and
// mock objects are set here.
// * * * * * * * * * * * * * * * * * * * * * * * *

// Define the test suite and add test cases
FOSSIL_TEST_SUITE(cpp_soap_suite);

// Setup function for the test suite
FOSSIL_SETUP(cpp_soap_suite) {
// Setup code here
}

// Teardown function for the test suite
FOSSIL_TEARDOWN(cpp_soap_suite) {
// Teardown code here
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Cases
// * * * * * * * * * * * * * * * * * * * * * * * *
// The test cases below are provided as samples, inspired
// by the Meson build system's approach of using test cases
// as samples for library usage.
// * * * * * * * * * * * * * * * * * * * * * * * *

FOSSIL_TEST_CASE(cpp_test_soap_sanitize) {
char input[] = "This is a test with curse1 and racist_phrase1.";
char expected[] = "This is a test with *** and ***.";

fossil_soap_sanitize(input);

ASSUME_ITS_EQUAL_CSTR(expected, input);
}

FOSSIL_TEST_CASE(cpp_test_soap_is_offensive) {
ASSUME_ITS_TRUE(fossil_soap_is_offensive("curse1"));
ASSUME_ITS_TRUE(fossil_soap_is_offensive("racist_phrase2"));
ASSUME_ITS_FALSE(fossil_soap_is_offensive("non_offensive_word"));
}

FOSSIL_TEST_CASE(cpp_test_soap_count_offensive) {
char input[] = "This is a test with curse1 and racist_phrase1";
ASSUME_ITS_EQUAL_I32(2, fossil_soap_count_offensive(input));
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *

FOSSIL_TEST_GROUP(cpp_soap_tests) {
FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_sanitize);
FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_is_offensive);
FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_count_offensive);

FOSSIL_TEST_REGISTER(cpp_soap_suite);
}
119 changes: 119 additions & 0 deletions code/tests/cases/test_stream.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* -----------------------------------------------------------------------------
* Project: Fossil Logic
*
* This file is part of the Fossil Logic project, which aims to develop high-
* performance, cross-platform applications and libraries. The code contained
* herein is subject to the terms and conditions defined in the project license.
*
* Author: Michael Gene Brockus (Dreamer)
*
* Copyright (C) 2024 Fossil Logic. All rights reserved.
* -----------------------------------------------------------------------------
*/
#include <fossil/test/framework.h>

#include "fossil/io/framework.h"


// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Utilites
// * * * * * * * * * * * * * * * * * * * * * * * *
// Setup steps for things like test fixtures and
// mock objects are set here.
// * * * * * * * * * * * * * * * * * * * * * * * *

// Define the test suite and add test cases
FOSSIL_TEST_SUITE(c_stream_suite);
fossil_fstream_t c_stream;

// Setup function for the test suite
FOSSIL_SETUP(c_stream_suite) {
// Setup code here
}

// Teardown function for the test suite
FOSSIL_TEARDOWN(c_stream_suite) {
// Teardown code here
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Cases
// * * * * * * * * * * * * * * * * * * * * * * * *
// The test cases below are provided as samples, inspired
// by the Meson build system's approach of using test cases
// as samples for library usage.
// * * * * * * * * * * * * * * * * * * * * * * * *

FOSSIL_TEST_CASE(c_test_stream_let_write_and_read_file) {
const char *filename = "testfile.txt";
const char *content = "This is a test.";

// Write data to the file
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w"));
fossil_fstream_write(&c_stream, content, strlen(content), 1);
fossil_fstream_close(&c_stream);

// Read data from the file
char buffer[1024];
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "r"));
fossil_fstream_read(&c_stream, buffer, sizeof(buffer), 1);
fossil_fstream_close(&c_stream);
}

FOSSIL_TEST_CASE(c_test_stream_let_open_and_close_file) {
const char *filename = "testfile.txt";

// Open the file
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w"));
fossil_fstream_close(&c_stream);
}

FOSSIL_TEST_CASE(c_test_stream_multiple_files) {
const char *filename1 = "testfile1.txt";
const char *filename2 = "testfile2.txt";

// Open the first file
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename1, "w"));
fossil_fstream_close(&c_stream);

// Open the second file
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename2, "w"));
fossil_fstream_close(&c_stream);
}

FOSSIL_TEST_CASE(c_test_stream_seek_and_tell) {
const char *filename = "testfile.txt";
const char *content = "This is a test.";

// Write data to the file
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w"));
fossil_fstream_write(&c_stream, content, strlen(content), 1);
fossil_fstream_close(&c_stream);

// Open the file
ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "r"));

// Seek to the end of the file
fossil_fstream_seek(&c_stream, 0, SEEK_END);

// Get the current position
long position = fossil_fstream_tell(&c_stream);

ASSUME_ITS_TRUE(position > 0);

// Close the file
fossil_fstream_close(&c_stream);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *

FOSSIL_TEST_GROUP(c_file_tests) {
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_write_and_read_file);
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_open_and_close_file);
FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_multiple_files);

FOSSIL_TEST_REGISTER(c_stream_suite);
}
Loading