From 723c66bf34a885925d123bc00bcc9811fcbe7ddf Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Wed, 1 Jan 2025 18:06:57 -0600 Subject: [PATCH 01/10] adding myshell and noshell --- code/logic/fossil/crabdb/framework.h | 2 + code/logic/fossil/crabdb/myshell.h | 336 +++++++++++++++++++++++++++ code/logic/fossil/crabdb/noshell.h | 321 +++++++++++++++++++++++++ code/logic/myshell.c | 235 +++++++++++++++++++ code/logic/noshell.c | 238 +++++++++++++++++++ 5 files changed, 1132 insertions(+) create mode 100644 code/logic/fossil/crabdb/myshell.h create mode 100644 code/logic/fossil/crabdb/noshell.h create mode 100644 code/logic/myshell.c create mode 100644 code/logic/noshell.c diff --git a/code/logic/fossil/crabdb/framework.h b/code/logic/fossil/crabdb/framework.h index 2fc88e4..376b89a 100644 --- a/code/logic/fossil/crabdb/framework.h +++ b/code/logic/fossil/crabdb/framework.h @@ -15,5 +15,7 @@ #define FOSSIL_CRABDB_FRAMEWORK_H #include "database.h" +#include "myshell.h" +#include "noshell.h" #endif /* FOSSIL_CRABDB_FRAMEWORK_H */ diff --git a/code/logic/fossil/crabdb/myshell.h b/code/logic/fossil/crabdb/myshell.h new file mode 100644 index 0000000..dd735c5 --- /dev/null +++ b/code/logic/fossil/crabdb/myshell.h @@ -0,0 +1,336 @@ +/* + * ----------------------------------------------------------------------------- + * 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. + * ----------------------------------------------------------------------------- + */ +#ifndef FOSSIL_CRABDB_MYSHELL_H +#define FOSSIL_CRABDB_MYSHELL_H + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// ***************************************************************************** +// Enumerations for Data Types and Attributes +// ***************************************************************************** + +// =========================================================== +// MyShell Error Codes +// =========================================================== +typedef enum { + FOSSIL_MYSHELL_ERROR_SUCCESS = 0, + FOSSIL_MYSHELL_ERROR_INVALID_FILE, + FOSSIL_MYSHELL_ERROR_FILE_NOT_FOUND, + FOSSIL_MYSHELL_ERROR_IO, + FOSSIL_MYSHELL_ERROR_INVALID_QUERY, + FOSSIL_MYSHELL_ERROR_CONCURRENCY, + FOSSIL_MYSHELL_ERROR_NOT_FOUND, + FOSSIL_MYSHELL_ERROR_ALREADY_EXISTS, + FOSSIL_MYSHELL_ERROR_BACKUP_FAILED, + FOSSIL_MYSHELL_ERROR_RESTORE_FAILED, + FOSSIL_MYSHELL_ERROR_UNKNOWN +} fossil_myshell_error_t; + +// ***************************************************************************** +// Database API Functions +// ***************************************************************************** + +// =========================================================== +// MyShell Functions +// =========================================================== + +// CRUD operations + +/** + * @brief Creates a new record in the database. + * + * @param file_name The name of the database file. + * @param key The key of the record. + * @param value The value of the record. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_create_record(const char *file_name, const char *key, const char *value); + +/** + * @brief Reads a record from the database. + * + * @param file_name The name of the database file. + * @param key The key of the record to read. + * @param value The buffer to store the value of the record. + * @param buffer_size The size of the buffer. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_read_record(const char *file_name, const char *key, char *value, size_t buffer_size); + +/** + * @brief Updates the value of a record in the database. + * + * @param file_name The name of the database file. + * @param key The key of the record to update. + * @param new_value The new value to set. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_update_record(const char *file_name, const char *key, const char *new_value); + +/** + * @brief Deletes a record from the database. + * + * @param file_name The name of the database file. + * @param key The key of the record to delete. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_delete_record(const char *file_name, const char *key); + +// Database management + +/** + * @brief Creates a new database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_create_database(const char *file_name); + +/** + * @brief Opens an existing database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_open_database(const char *file_name); + +/** + * @brief Closes an open database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_close_database(const char *file_name); + +/** + * @brief Deletes a database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_delete_database(const char *file_name); + +// Backup and Restore + +/** + * @brief Backs up a database file. + * + * @param source_file The name of the source database file. + * @param backup_file The name of the backup file. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_backup_database(const char *source_file, const char *backup_file); + +/** + * @brief Restores a database file from a backup. + * + * @param backup_file The name of the backup file. + * @param destination_file The name of the destination database file. + * @return 0 on success, non-zero on error. + */ +fossil_myshell_error_t fossil_myshell_restore_database(const char *backup_file, const char *destination_file); + +// Query and data validation + +/** + * @brief Validates the file extension of a database file. + * + * @param file_name The name of the database file. + * @return True if the file extension is valid, false otherwise. + */ +bool fossil_myshell_validate_extension(const char *file_name); + +/** + * @brief Validates a data string. + * + * @param data The data string to validate. + * @return True if the data is valid, false otherwise. + */ +bool fossil_myshell_validate_data(const char *data); + +#ifdef __cplusplus +} +#include + +namespace fossil { + +/** + * @class MyShell + * @brief A class that provides an interface to interact with the Fossil MyShell database. + * + * This class encapsulates the functionality of the Fossil MyShell, providing methods to + * create, read, update, and delete records in the database. It also provides methods to + * manage the database, enable/disable concurrency, backup/restore the database, and perform + * sorting, aggregation, and filtering operations. + * + * @note The class manages the lifecycle of the database, ensuring proper initialization + * and release of resources. + */ +class MyShell { +public: + // CRUD operations + + /** + * @brief Creates a new record in the database. + * + * @param fileName The name of the database file. + * @param key The key of the record. + * @param value The value of the record. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t createRecord(const std::string &fileName, const std::string &key, const std::string &value) { + return fossil_myshell_create_record(fileName.c_str(), key.c_str(), value.c_str()); + } + + /** + * @brief Reads a record from the database. + * + * @param fileName The name of the database file. + * @param key The key of the record to read. + * @param value The buffer to store the value of the record. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t readRecord(const std::string &fileName, const std::string &key, std::string &value) { + char buffer[1024]; + fossil_myshell_error_t result = fossil_myshell_read_record(fileName.c_str(), key.c_str(), buffer, sizeof(buffer)); + if (result == FOSSIL_MYSHELL_ERROR_SUCCESS) { + value = buffer; + } + return result; + } + + /** + * @brief Updates the value of a record in the database. + * + * @param fileName The name of the database file. + * @param key The key of the record to update. + * @param newValue The new value to set. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t updateRecord(const std::string &fileName, const std::string &key, const std::string &newValue) { + return fossil_myshell_update_record(fileName.c_str(), key.c_str(), newValue.c_str()); + } + + /** + * @brief Deletes a record from the database. + * + * @param fileName The name of the database file. + * @param key The key of the record to delete. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t deleteRecord(const std::string &fileName, const std::string &key) { + return fossil_myshell_delete_record(fileName.c_str(), key.c_str()); + } + + // Database management + /** + * @brief Creates a new database file. + * + * @param fileName The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t createDatabase(const std::string &fileName) { + return fossil_myshell_create_database(fileName.c_str()); + } + + /** + * @brief Opens an existing database file. + * + * @param fileName The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t openDatabase(const std::string &fileName) { + return fossil_myshell_open_database(fileName.c_str()); + } + + /** + * @brief Closes an open database file. + * + * @param fileName The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t closeDatabase(const std::string &fileName) { + return fossil_myshell_close_database(fileName.c_str()); + } + + /** + * @brief Deletes a database file. + * + * @param fileName The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t deleteDatabase(const std::string &fileName) { + return fossil_myshell_delete_database(fileName.c_str()); + } + + // Backup and Restore + /** + * @brief Backs up a database file. + * + * @param sourceFile The name of the source database file. + * @param backupFile The name of the backup file. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t backupDatabase(const std::string &sourceFile, const std::string &backupFile) { + return fossil_myshell_backup_database(sourceFile.c_str(), backupFile.c_str()); + } + + /** + * @brief Restores a database file from a backup. + * + * @param backupFile The name of the backup file. + * @param destinationFile The name of the destination database file. + * @return 0 on success, non-zero on error. + */ + static fossil_myshell_error_t restoreDatabase(const std::string &backupFile, const std::string &destinationFile) { + return fossil_myshell_restore_database(backupFile.c_str(), destinationFile.c_str()); + } + + // Query and data validation + /** + * @brief Validates the file extension of a database file. + * + * @param fileName The name of the database file. + * @return True if the file extension is valid, false otherwise. + */ + static bool validateExtension(const std::string &fileName) { + return fossil_myshell_validate_extension(fileName.c_str()); + } + + /** + * @brief Validates a data string. + * + * @param data The data string to validate. + * @return True if the data is valid, false otherwise. + */ + static bool validateData(const std::string &data) { + return fossil_myshell_validate_data(data.c_str()); + } +}; + +} + +#endif + +#endif /* FOSSIL_CRABDB_FRAMEWORK_H */ diff --git a/code/logic/fossil/crabdb/noshell.h b/code/logic/fossil/crabdb/noshell.h new file mode 100644 index 0000000..8b135f2 --- /dev/null +++ b/code/logic/fossil/crabdb/noshell.h @@ -0,0 +1,321 @@ +/* + * ----------------------------------------------------------------------------- + * 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. + * ----------------------------------------------------------------------------- + */ +#ifndef FOSSIL_CRABDB_NOSHELL_H +#define FOSSIL_CRABDB_NOSHELL_H + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// ***************************************************************************** +// Enumerations for Data Types and Attributes +// ***************************************************************************** + +// =========================================================== +// NoShell Error Codes +// =========================================================== +typedef enum { + FOSSIL_NOSHELL_ERROR_SUCCESS = 0, + FOSSIL_NOSHELL_ERROR_INVALID_FILE, + FOSSIL_NOSHELL_ERROR_FILE_NOT_FOUND, + FOSSIL_NOSHELL_ERROR_IO, + FOSSIL_NOSHELL_ERROR_INVALID_QUERY, + FOSSIL_NOSHELL_ERROR_CONCURRENCY, + FOSSIL_NOSHELL_ERROR_NOT_FOUND, + FOSSIL_NOSHELL_ERROR_ALREADY_EXISTS, + FOSSIL_NOSHELL_ERROR_BACKUP_FAILED, + FOSSIL_NOSHELL_ERROR_RESTORE_FAILED, + FOSSIL_NOSHELL_ERROR_UNKNOWN +} fossil_noshell_error_t; + +// ***************************************************************************** +// Database API Functions +// ***************************************************************************** + +// =========================================================== +// NoShell Functions +// =========================================================== + +// CRUD operations + +/** + * @brief Inserts a new document into the database. + * + * @param file_name The name of the database file. + * @param document The document to insert. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_insert(const char *file_name, const char *document); + +/** + * @brief Finds a document in the database based on a query. + * + * @param file_name The name of the database file. + * @param query The query to search for. + * @param result The buffer to store the result. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_find(const char *file_name, const char *query, char *result, size_t buffer_size); + +/** + * @brief Updates a document in the database based on a query. + * + * @param file_name The name of the database file. + * @param query The query to search for. + * @param new_document The new document to update. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_update(const char *file_name, const char *query, const char *new_document); + +/** + * @brief Removes a document from the database based on a query. + * + * @param file_name The name of the database file. + * @param query The query to search for. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_remove(const char *file_name, const char *query); + +// Database management + +/** + * @brief Creates a new database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_create_database(const char *file_name); + +/** + * @brief Opens an existing database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_open_database(const char *file_name); + +/** + * @brief Closes an open database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_close_database(const char *file_name); + +/** + * @brief Deletes a database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_delete_database(const char *file_name); + +// Backup and Restore + +/** + * @brief Backs up a database file. + * + * @param source_file The name of the source database file. + * @param backup_file The name of the backup file. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_backup_database(const char *source_file, const char *backup_file); + +/** + * @brief Restores a database file from a backup. + * + * @param backup_file The name of the backup file. + * @param destination_file The name of the destination database file. + * @return 0 on success, non-zero on error. + */ +fossil_noshell_error_t fossil_noshell_restore_database(const char *backup_file, const char *destination_file); + +// Query and data validation + +/** + * @brief Validates the file extension of a database file. + * + * @param file_name The name of the database file. + * @return True if the file extension is valid, false otherwise. + */ +bool fossil_noshell_validate_extension(const char *file_name); + +/** + * @brief Validates a document string. + * + * @param document The document string to validate. + * @return True if the document is valid, false otherwise. + */ +bool fossil_noshell_validate_document(const char *document); + +#ifdef __cplusplus +} +#include + +namespace fossil { + +// +class NoShell { +public: + // CRUD operations + /** + * @brief Inserts a new document into the database. + * + * @param file_name The name of the database file. + * @param document The document to insert. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t insert(const std::string &file_name, const std::string &document) { + return fossil_noshell_insert(file_name.c_str(), document.c_str()); + } + + /** + * @brief Finds a document in the database based on a query. + * + * @param file_name The name of the database file. + * @param query The query to search for. + * @param result The buffer to store the result. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t find(const std::string &file_name, const std::string &query, std::string &result) { + char buffer[1024]; + fossil_noshell_error_t error = fossil_noshell_find(file_name.c_str(), query.c_str(), buffer, sizeof(buffer)); + if (error == FOSSIL_NOSHELL_ERROR_SUCCESS) { + result = buffer; + } + return error; + } + + /** + * @brief Updates a document in the database based on a query. + * + * @param file_name The name of the database file. + * @param query The query to search for. + * @param new_document The new document to update. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t update(const std::string &file_name, const std::string &query, const std::string &new_document) { + return fossil_noshell_update(file_name.c_str(), query.c_str(), new_document.c_str()); + } + + /** + * @brief Removes a document from the database based on a query. + * + * @param file_name The name of the database file. + * @param query The query to search for. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t remove(const std::string &file_name, const std::string &query) { + return fossil_noshell_remove(file_name.c_str(), query.c_str()); + } + + // Database management + /** + * @brief Creates a new database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t createDatabase(const std::string &file_name) { + return fossil_noshell_create_database(file_name.c_str()); + } + + /** + * @brief Opens an existing database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t openDatabase(const std::string &file_name) { + return fossil_noshell_open_database(file_name.c_str()); + } + + /** + * @brief Closes an open database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t closeDatabase(const std::string &file_name) { + return fossil_noshell_close_database(file_name.c_str()); + } + + /** + * @brief Deletes a database file. + * + * @param file_name The name of the database file. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t deleteDatabase(const std::string &file_name) { + return fossil_noshell_delete_database(file_name.c_str()); + } + + // Backup and Restore + /** + * @brief Backs up a database file. + * + * @param source_file The name of the source database file. + * @param backup_file The name of the backup file. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t backupDatabase(const std::string &source_file, const std::string &backup_file) { + return fossil_noshell_backup_database(source_file.c_str(), backup_file.c_str()); + } + + /** + * @brief Restores a database file from a backup. + * + * @param backup_file The name of the backup file. + * @param destination_file The name of the destination database file. + * @return 0 on success, non-zero on error. + */ + static fossil_noshell_error_t restoreDatabase(const std::string &backup_file, const std::string &destination_file) { + return fossil_noshell_restore_database(backup_file.c_str(), destination_file.c_str()); + } + + // Query and data validation + /** + * @brief Validates the file extension of a database file. + * + * @param file_name The name of the database file. + * @return True if the file extension is valid, false otherwise. + */ + static bool validateExtension(const std::string &file_name) { + return fossil_noshell_validate_extension(file_name.c_str()); + } + + /** + * @brief Validates a document string. + * + * @param document The document string to validate. + * @return True if the document is valid, false otherwise. + */ + static bool validateDocument(const std::string &document) { + return fossil_noshell_validate_document(document.c_str()); + } +}; + +} + +#endif + +#endif /* FOSSIL_CRABDB_FRAMEWORK_H */ diff --git a/code/logic/myshell.c b/code/logic/myshell.c new file mode 100644 index 0000000..304629d --- /dev/null +++ b/code/logic/myshell.c @@ -0,0 +1,235 @@ +/* + * ----------------------------------------------------------------------------- + * 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/crabdb/myshell.h" +#include +#include +#include + +// =========================================================== +// Helper functions +// =========================================================== + +static FILE* open_file(const char *file_name, const char *mode) { + return fopen(file_name, mode); +} + +static void close_file(FILE *file) { + if (file != NULL) { + fclose(file); + } +} + +// =========================================================== +// CRUD Operations +// =========================================================== + +fossil_myshell_error_t fossil_myshell_create_record(const char *file_name, const char *key, const char *value) { + FILE *file = open_file(file_name, "a"); + if (!file) { + return FOSSIL_MYSHELL_ERROR_IO; + } + + fprintf(file, "%s=%s\n", key, value); + close_file(file); + + return FOSSIL_MYSHELL_ERROR_SUCCESS; +} + +fossil_myshell_error_t fossil_myshell_read_record(const char *file_name, const char *key, char *value, size_t buffer_size) { + FILE *file = open_file(file_name, "r"); + if (!file) { + return FOSSIL_MYSHELL_ERROR_IO; + } + + char line[256]; + while (fgets(line, sizeof(line), file)) { + char *line_key = strtok(line, "="); + char *line_value = strtok(NULL, "\n"); + + if (line_key && strcmp(line_key, key) == 0) { + strncpy(value, line_value, buffer_size); + close_file(file); + return FOSSIL_MYSHELL_ERROR_SUCCESS; + } + } + + close_file(file); + return FOSSIL_MYSHELL_ERROR_NOT_FOUND; +} + +fossil_myshell_error_t fossil_myshell_update_record(const char *file_name, const char *key, const char *new_value) { + FILE *file = open_file(file_name, "r+"); + if (!file) { + return FOSSIL_MYSHELL_ERROR_IO; + } + + char line[256]; + long pos; + bool found = false; + while ((pos = ftell(file)) != -1 && fgets(line, sizeof(line), file)) { + char *line_key = strtok(line, "="); + + if (line_key && strcmp(line_key, key) == 0) { + found = true; + break; + } + } + + if (!found) { + close_file(file); + return FOSSIL_MYSHELL_ERROR_NOT_FOUND; + } + + fseek(file, pos, SEEK_SET); + fprintf(file, "%s=%s\n", key, new_value); + close_file(file); + + return FOSSIL_MYSHELL_ERROR_SUCCESS; +} + +fossil_myshell_error_t fossil_myshell_delete_record(const char *file_name, const char *key) { + FILE *file = open_file(file_name, "r"); + if (!file) { + return FOSSIL_MYSHELL_ERROR_IO; + } + + FILE *temp_file = open_file("temp.crabdb", "w"); + if (!temp_file) { + close_file(file); + return FOSSIL_MYSHELL_ERROR_IO; + } + + char line[256]; + bool deleted = false; + while (fgets(line, sizeof(line), file)) { + char *line_key = strtok(line, "="); + if (line_key && strcmp(line_key, key) == 0) { + deleted = true; + } else { + fputs(line, temp_file); + } + } + + close_file(file); + close_file(temp_file); + + if (deleted) { + remove(file_name); + rename("temp.crabdb", file_name); + return FOSSIL_MYSHELL_ERROR_SUCCESS; + } + + remove("temp.crabdb"); + return FOSSIL_MYSHELL_ERROR_NOT_FOUND; +} + +// =========================================================== +// Database Management +// =========================================================== + +fossil_myshell_error_t fossil_myshell_create_database(const char *file_name) { + FILE *file = open_file(file_name, "w"); + if (!file) { + return FOSSIL_MYSHELL_ERROR_IO; + } + + close_file(file); + return FOSSIL_MYSHELL_ERROR_SUCCESS; +} + +fossil_myshell_error_t fossil_myshell_open_database(const char *file_name) { + FILE *file = open_file(file_name, "r"); + if (!file) { + return FOSSIL_MYSHELL_ERROR_FILE_NOT_FOUND; + } + + close_file(file); + return FOSSIL_MYSHELL_ERROR_SUCCESS; +} + +fossil_myshell_error_t fossil_myshell_close_database(const char *file_name) { + return FOSSIL_MYSHELL_ERROR_SUCCESS; // No specific action required for closure. +} + +fossil_myshell_error_t fossil_myshell_delete_database(const char *file_name) { + if (remove(file_name) == 0) { + return FOSSIL_MYSHELL_ERROR_SUCCESS; + } + + return FOSSIL_MYSHELL_ERROR_IO; +} + +// =========================================================== +// Backup and Restore +// =========================================================== + +fossil_myshell_error_t fossil_myshell_backup_database(const char *source_file, const char *backup_file) { + FILE *source = open_file(source_file, "rb"); + if (!source) { + return FOSSIL_MYSHELL_ERROR_IO; + } + + FILE *backup = open_file(backup_file, "wb"); + if (!backup) { + close_file(source); + return FOSSIL_MYSHELL_ERROR_IO; + } + + char buffer[1024]; + size_t bytes_read; + while ((bytes_read = fread(buffer, 1, sizeof(buffer), source)) > 0) { + fwrite(buffer, 1, bytes_read, backup); + } + + close_file(source); + close_file(backup); + + return FOSSIL_MYSHELL_ERROR_SUCCESS; +} + +fossil_myshell_error_t fossil_myshell_restore_database(const char *backup_file, const char *destination_file) { + FILE *backup = open_file(backup_file, "rb"); + if (!backup) { + return FOSSIL_MYSHELL_ERROR_IO; + } + + FILE *destination = open_file(destination_file, "wb"); + if (!destination) { + close_file(backup); + return FOSSIL_MYSHELL_ERROR_IO; + } + + char buffer[1024]; + size_t bytes_read; + while ((bytes_read = fread(buffer, 1, sizeof(buffer), backup)) > 0) { + fwrite(buffer, 1, bytes_read, destination); + } + + close_file(backup); + close_file(destination); + + return FOSSIL_MYSHELL_ERROR_SUCCESS; +} + +// =========================================================== +// Query and Data Validation +// =========================================================== + +bool fossil_myshell_validate_extension(const char *file_name) { + return strstr(file_name, ".crabdb") != NULL; +} + +bool fossil_myshell_validate_data(const char *data) { + return data != NULL && strlen(data) > 0; +} diff --git a/code/logic/noshell.c b/code/logic/noshell.c new file mode 100644 index 0000000..1c891e8 --- /dev/null +++ b/code/logic/noshell.c @@ -0,0 +1,238 @@ +/* + * ----------------------------------------------------------------------------- + * 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/crabdb/noshell.h" +#include +#include +#include + +// =========================================================== +// Helper functions +// =========================================================== + +static FILE* open_file(const char *file_name, const char *mode) { + return fopen(file_name, mode); +} + +static void close_file(FILE *file) { + if (file != NULL) { + fclose(file); + } +} + +// =========================================================== +// CRUD Operations +// =========================================================== + +fossil_noshell_error_t fossil_noshell_insert(const char *file_name, const char *document) { + FILE *file = open_file(file_name, "a"); + if (!file) { + return FOSSIL_NOSHELL_ERROR_IO; + } + + fprintf(file, "%s\n", document); + close_file(file); + + return FOSSIL_NOSHELL_ERROR_SUCCESS; +} + +fossil_noshell_error_t fossil_noshell_find(const char *file_name, const char *query, char *result, size_t buffer_size) { + FILE *file = open_file(file_name, "r"); + if (!file) { + return FOSSIL_NOSHELL_ERROR_IO; + } + + char line[256]; + while (fgets(line, sizeof(line), file)) { + if (strstr(line, query)) { + strncpy(result, line, buffer_size); + close_file(file); + return FOSSIL_NOSHELL_ERROR_SUCCESS; + } + } + + close_file(file); + return FOSSIL_NOSHELL_ERROR_NOT_FOUND; +} + +fossil_noshell_error_t fossil_noshell_update(const char *file_name, const char *query, const char *new_document) { + FILE *file = open_file(file_name, "r+"); + if (!file) { + return FOSSIL_NOSHELL_ERROR_IO; + } + + FILE *temp_file = open_file("temp.crabdb", "w"); + if (!temp_file) { + close_file(file); + return FOSSIL_NOSHELL_ERROR_IO; + } + + char line[256]; + bool updated = false; + while (fgets(line, sizeof(line), file)) { + if (strstr(line, query)) { + fputs(new_document, temp_file); + fputs("\n", temp_file); + updated = true; + } else { + fputs(line, temp_file); + } + } + + close_file(file); + close_file(temp_file); + + if (updated) { + remove(file_name); + rename("temp.crabdb", file_name); + return FOSSIL_NOSHELL_ERROR_SUCCESS; + } + + remove("temp.crabdb"); + return FOSSIL_NOSHELL_ERROR_NOT_FOUND; +} + +fossil_noshell_error_t fossil_noshell_remove(const char *file_name, const char *query) { + FILE *file = open_file(file_name, "r"); + if (!file) { + return FOSSIL_NOSHELL_ERROR_IO; + } + + FILE *temp_file = open_file("temp.crabdb", "w"); + if (!temp_file) { + close_file(file); + return FOSSIL_NOSHELL_ERROR_IO; + } + + char line[256]; + bool removed = false; + while (fgets(line, sizeof(line), file)) { + if (!strstr(line, query)) { + fputs(line, temp_file); + } else { + removed = true; + } + } + + close_file(file); + close_file(temp_file); + + if (removed) { + remove(file_name); + rename("temp.crabdb", file_name); + return FOSSIL_NOSHELL_ERROR_SUCCESS; + } + + remove("temp.crabdb"); + return FOSSIL_NOSHELL_ERROR_NOT_FOUND; +} + +// =========================================================== +// Database Management +// =========================================================== + +fossil_noshell_error_t fossil_noshell_create_database(const char *file_name) { + FILE *file = open_file(file_name, "w"); + if (!file) { + return FOSSIL_NOSHELL_ERROR_IO; + } + + close_file(file); + return FOSSIL_NOSHELL_ERROR_SUCCESS; +} + +fossil_noshell_error_t fossil_noshell_open_database(const char *file_name) { + FILE *file = open_file(file_name, "r"); + if (!file) { + return FOSSIL_NOSHELL_ERROR_FILE_NOT_FOUND; + } + + close_file(file); + return FOSSIL_NOSHELL_ERROR_SUCCESS; +} + +fossil_noshell_error_t fossil_noshell_close_database(const char *file_name) { + return FOSSIL_NOSHELL_ERROR_SUCCESS; // No specific action required for closure. +} + +fossil_noshell_error_t fossil_noshell_delete_database(const char *file_name) { + if (remove(file_name) == 0) { + return FOSSIL_NOSHELL_ERROR_SUCCESS; + } + + return FOSSIL_NOSHELL_ERROR_IO; +} + +// =========================================================== +// Backup and Restore +// =========================================================== + +fossil_noshell_error_t fossil_noshell_backup_database(const char *source_file, const char *backup_file) { + FILE *source = open_file(source_file, "rb"); + if (!source) { + return FOSSIL_NOSHELL_ERROR_IO; + } + + FILE *backup = open_file(backup_file, "wb"); + if (!backup) { + close_file(source); + return FOSSIL_NOSHELL_ERROR_IO; + } + + char buffer[1024]; + size_t bytes_read; + while ((bytes_read = fread(buffer, 1, sizeof(buffer), source)) > 0) { + fwrite(buffer, 1, bytes_read, backup); + } + + close_file(source); + close_file(backup); + + return FOSSIL_NOSHELL_ERROR_SUCCESS; +} + +fossil_noshell_error_t fossil_noshell_restore_database(const char *backup_file, const char *destination_file) { + FILE *backup = open_file(backup_file, "rb"); + if (!backup) { + return FOSSIL_NOSHELL_ERROR_IO; + } + + FILE *destination = open_file(destination_file, "wb"); + if (!destination) { + close_file(backup); + return FOSSIL_NOSHELL_ERROR_IO; + } + + char buffer[1024]; + size_t bytes_read; + while ((bytes_read = fread(buffer, 1, sizeof(buffer), backup)) > 0) { + fwrite(buffer, 1, bytes_read, destination); + } + + close_file(backup); + close_file(destination); + + return FOSSIL_NOSHELL_ERROR_SUCCESS; +} + +// =========================================================== +// Query and Data Validation +// =========================================================== + +bool fossil_noshell_validate_extension(const char *file_name) { + return strstr(file_name, ".crabdb") != NULL; +} + +bool fossil_noshell_validate_document(const char *document) { + return document != NULL && strlen(document) > 0; +} From 25e2ab892567057f82c1703e53bab8ca8bf44ce0 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Wed, 1 Jan 2025 18:07:08 -0600 Subject: [PATCH 02/10] list new source files --- code/logic/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/logic/meson.build b/code/logic/meson.build index 09da756..6b013c2 100644 --- a/code/logic/meson.build +++ b/code/logic/meson.build @@ -6,7 +6,7 @@ dep = [ ] fossil_crabdb_lib = library('fossil-crabdb', - files('database.c'), + files('database.c', 'myshell.c', 'noshell.c'), install: true, dependencies: dep, include_directories: dir) From c3399116a52fdcccda48ce03a55824d3fe2a407a Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Wed, 1 Jan 2025 18:07:16 -0600 Subject: [PATCH 03/10] update readme --- README.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 85a59a9..7b74de3 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ # ***Blue Crab Database by Fossil Logic*** -CrabDB is a lightweight, portable key-value database designed to provide fast and efficient data storage in a simple, easy-to-use format. Inspired by the metaphor of a book, CrabDB organizes data as pages in a book, where each page represents an entry in the database. This structure makes it intuitive to understand and interact with, while maintaining high performance for both small and large datasets. +CrabDB is a lightweight, portable key-value database designed to offer fast and efficient data storage in a user-friendly format. Available in two distinct interfaces—**MyShell** and **NoShell**—CrabDB tailors its experience to fit various use cases, from those who prefer a SQL-like syntax to those who prefer raw, key-based access. Its book-inspired structure, where each entry is akin to a page in a book, makes managing key-value pairs intuitive and easy to understand, while ensuring high performance across both small and large datasets. -## Key Features: -- **Portable**: Designed to be platform-independent, CrabDB works seamlessly across different operating systems, allowing you to store and manage data with minimal dependencies. -- **Book-Like Structure**: The database's organization is inspired by a book, where each entry is like a page in a book. This simple, yet powerful structure makes it easy to conceptualize and manage key-value pairs. -- **Search and Lookup**: Quickly search and retrieve values by key with efficient lookup operations, making it ideal for use in a wide range of applications, from small utilities to larger systems. -- **Simple API**: The database API is designed to be straightforward and easy to use, with a focus on simplicity and readability. Whether you're storing data for a small project or a larger system, CrabDB's API is intuitive enough for anyone to get started quickly. -- **Efficient Memory Management**: With a focus on performance, CrabDB minimizes memory usage while maintaining fast access times and stable behavior, even with a growing dataset. +## Key Features + +| **Feature** | **MyShell** | **NoShell** | +|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------| +| **Portability & Cross-Platform** | Works across different operating systems, offering seamless performance with minimal dependencies. | Works across various platforms without external dependencies, ensuring smooth performance. | +| **Interface** | SQL-like command interface, ideal for users familiar with relational databases. | Direct key-value CRUD operations with a minimalistic approach, no query language required. | +| **CRUD Operations** | Insert, find, update, and delete key-value pairs with SQL-like commands. | Perform CRUD operations using direct key-value access. | +| **Backup and Restore** | Supports backup and restore features using MyShell's command-line interface. | Allows for easy backup and restore of database files with no query overhead. | +| **API** | Intuitive API designed for SQL-like interaction. | Simple API for minimalistic key-value operations. | +| **Memory Management** | Optimized for low memory usage and fast access, even with large datasets. | Ensures efficient memory usage and performance, even with direct key-value access. | +| **Database Management** | Full support for creating, opening, closing, and deleting databases, as well as managing backups. | Supports similar database management operations with a direct approach, including backups and restores. | ## Prerequisites @@ -32,7 +37,7 @@ Before getting started, make sure you have the following installed: # ====================== [wrap-git] url = https://github.com/fossillogic/fossil-crabdb.git - revision = v0.2.0 + revision = v0.2.1 [provide] fossil-crabdb = fossil_crabdb_dep From e5dbba21b25b1a73ace0a8764ec069ec4c15d564 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 2 Jan 2025 11:44:44 -0600 Subject: [PATCH 04/10] split crabdb into to two --- code/logic/database.c | 525 --------------------------- code/logic/fossil/crabdb/database.h | 356 ------------------ code/logic/fossil/crabdb/framework.h | 1 - code/logic/myshell.c | 68 ++-- code/logic/noshell.c | 72 ++-- code/tests/meson.build | 2 +- 6 files changed, 57 insertions(+), 967 deletions(-) delete mode 100644 code/logic/database.c delete mode 100644 code/logic/fossil/crabdb/database.h diff --git a/code/logic/database.c b/code/logic/database.c deleted file mode 100644 index 4243719..0000000 --- a/code/logic/database.c +++ /dev/null @@ -1,525 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * 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/crabdb/database.h" - -static fossil_crabdb_transaction_t *active_transaction = NULL; // Current active transaction - -char *custom_strdup(const char *str) { - if (str == NULL) { - return NULL; - } - size_t len = strlen(str); - char *copy = (char *)malloc(len + 1); - if (copy == NULL) { - return NULL; - } - strcpy(copy, str); - return copy; -} - -// ***************************************************************************** -// Database API Functions -// ***************************************************************************** - -/** - * @brief Initializes a new empty database. - */ -fossil_crabdb_book_t* fossil_crabdb_init(void) { - fossil_crabdb_book_t *book = (fossil_crabdb_book_t *)malloc(sizeof(fossil_crabdb_book_t)); - if (book == NULL) { - return NULL; - } - book->head = NULL; - book->tail = NULL; - book->size = 0; - return book; -} - -/** - * @brief Releases all resources used by the database. - */ -void fossil_crabdb_release(fossil_crabdb_book_t *book) { - if (book == NULL) { - return; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - fossil_crabdb_page_t *next = current->next; - free(current->entry.key); - free(current->entry.value); - free(current); - current = next; - } - free(book); -} - -/** - * @brief Inserts a new key-value pair into the database. - */ -bool fossil_crabdb_insert(fossil_crabdb_book_t *book, const char *key, const char *value, fossil_crabdb_attributes_t attributes) { - if (book == NULL || key == NULL || value == NULL) { - return false; - } - fossil_crabdb_page_t *page = (fossil_crabdb_page_t *)malloc(sizeof(fossil_crabdb_page_t)); - if (page == NULL) { - return false; - } - page->entry.key = custom_strdup(key); - page->entry.value = custom_strdup(value); - page->entry.attributes = attributes; - page->next = NULL; - if (book->head == NULL) { - book->head = page; - book->tail = page; - page->prev = NULL; - } else { - book->tail->next = page; - page->prev = book->tail; - book->tail = page; - } - book->size++; - return true; -} - -/** - * @brief Updates the value of an existing key. - */ -bool fossil_crabdb_update(fossil_crabdb_book_t *book, const char *key, const char *new_value) { - if (book == NULL || key == NULL || new_value == NULL) { - return false; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - if (strcmp(current->entry.key, key) == 0) { - free(current->entry.value); - current->entry.value = custom_strdup(new_value); - return true; - } - current = current->next; - } - return false; -} - -/** - * @brief Deletes an entry from the database by key. - */ -bool fossil_crabdb_delete(fossil_crabdb_book_t *book, const char *key) { - if (book == NULL || key == NULL) { - return false; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - if (strcmp(current->entry.key, key) == 0) { - if (current->prev != NULL) { - current->prev->next = current->next; - } else { - book->head = current->next; - } - if (current->next != NULL) { - current->next->prev = current->prev; - } else { - book->tail = current->prev; - } - free(current->entry.key); - free(current->entry.value); - free(current); - book->size--; - return true; - } - current = current->next; - } - return false; -} - -/** - * @brief Searches for an entry by key. - */ -fossil_crabdb_entry_t* fossil_crabdb_search(fossil_crabdb_book_t *book, const char *key) { - if (book == NULL || key == NULL) { - return NULL; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - if (strcmp(current->entry.key, key) == 0) { - return ¤t->entry; - } - current = current->next; - } - return NULL; -} - -/** - * @brief Displays all entries in the database. - */ -void fossil_crabdb_display(fossil_crabdb_book_t *book) { - if (book == NULL) { - return; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - printf("Key: %s, Value: %s\n", current->entry.key, current->entry.value); - current = current->next; - } -} - -/** - * @brief Counts the number of entries in the database. - */ -size_t fossil_crabdb_size(fossil_crabdb_book_t *book) { - if (book == NULL) { - return 0; - } - return book->size; -} - -/** - * @brief Checks if the database is empty. - */ -bool fossil_crabdb_is_empty(fossil_crabdb_book_t *book) { - return book == NULL || book->size == 0; -} - -/** - * @brief Clears all entries from the database. - */ -void fossil_crabdb_clear(fossil_crabdb_book_t *book) { - if (book == NULL) { - return; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - fossil_crabdb_page_t *next = current->next; - free(current->entry.key); - free(current->entry.value); - free(current); - current = next; - } - book->head = NULL; - book->tail = NULL; - book->size = 0; -} - -// ***************************************************************************** -// Relational Operations -// ***************************************************************************** - -/** - * @brief Joins two databases based on matching keys. - */ -fossil_crabdb_book_t* fossil_crabdb_join(fossil_crabdb_book_t *book1, fossil_crabdb_book_t *book2) { - if (book1 == NULL || book2 == NULL) { - return NULL; - } - fossil_crabdb_book_t *result = fossil_crabdb_init(); - if (result == NULL) { - return NULL; - } - fossil_crabdb_page_t *current1 = book1->head; - while (current1 != NULL) { - fossil_crabdb_page_t *current2 = book2->head; - while (current2 != NULL) { - if (strcmp(current1->entry.key, current2->entry.key) == 0) { - fossil_crabdb_insert(result, current1->entry.key, current1->entry.value, current1->entry.attributes); - fossil_crabdb_insert(result, current2->entry.key, current2->entry.value, current2->entry.attributes); - } - current2 = current2->next; - } - current1 = current1->next; - } - return result; -} - -/** - * @brief Filters database entries based on a condition. - */ -fossil_crabdb_book_t* fossil_crabdb_filter(fossil_crabdb_book_t *book, bool (*predicate)(fossil_crabdb_entry_t *)) { - if (book == NULL || predicate == NULL) { - return NULL; - } - fossil_crabdb_book_t *result = fossil_crabdb_init(); - if (result == NULL) { - return NULL; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - if (predicate(¤t->entry)) { - fossil_crabdb_insert(result, current->entry.key, current->entry.value, current->entry.attributes); - } - current = current->next; - } - return result; -} - -/** - * @brief Merges two databases into one. - */ -fossil_crabdb_book_t* fossil_crabdb_merge(fossil_crabdb_book_t *book1, fossil_crabdb_book_t *book2) { - if (book1 == NULL || book2 == NULL) { - return NULL; - } - fossil_crabdb_book_t *result = fossil_crabdb_init(); - if (result == NULL) { - return NULL; - } - fossil_crabdb_page_t *current = book1->head; - while (current != NULL) { - fossil_crabdb_insert(result, current->entry.key, current->entry.value, current->entry.attributes); - current = current->next; - } - current = book2->head; - while (current != NULL) { - fossil_crabdb_insert(result, current->entry.key, current->entry.value, current->entry.attributes); - current = current->next; - } - return result; -} - -// ***************************************************************************** -// Transaction Management -// ***************************************************************************** - -/** - * @brief Begins a new transaction. - */ -fossil_crabdb_transaction_t* fossil_crabdb_transaction_begin(fossil_crabdb_book_t *book, const char *name) { - if (book == NULL || name == NULL) { - return NULL; - } - fossil_crabdb_transaction_t *transaction = (fossil_crabdb_transaction_t *)malloc(sizeof(fossil_crabdb_transaction_t)); - if (transaction == NULL) { - return NULL; - } - transaction->name = custom_strdup(name); - transaction->snapshot = *book; - transaction->next = active_transaction; - active_transaction = transaction; - return transaction; -} - -/** - * @brief Commits a transaction, saving changes. - */ -bool fossil_crabdb_transaction_commit(fossil_crabdb_book_t *book, fossil_crabdb_transaction_t *transaction) { - if (book == NULL || transaction == NULL) { - return false; - } - fossil_crabdb_transaction_t *current = active_transaction; - while (current != NULL) { - if (current == transaction) { - active_transaction = current->next; - fossil_crabdb_release(¤t->snapshot); - free(current->name); - free(current); - return true; - } - current = current->next; - } - return false; -} - -/** - * @brief Rolls back a transaction, restoring the previous state. - */ -bool fossil_crabdb_transaction_rollback(fossil_crabdb_book_t *book, fossil_crabdb_transaction_t *transaction) { - if (book == NULL || transaction == NULL) { - return false; - } - fossil_crabdb_transaction_t *current = active_transaction; - while (current != NULL) { - if (current == transaction) { - active_transaction = current->next; - *book = current->snapshot; - fossil_crabdb_release(¤t->snapshot); - free(current->name); - free(current); - return true; - } - current = current->next; - } - return false; -} - -/** - * @brief Releases a transaction's resources. - */ -void fossil_crabdb_transaction_release(fossil_crabdb_transaction_t *transaction) { - if (transaction == NULL) { - return; - } - fossil_crabdb_release(&transaction->snapshot); - free(transaction->name); - free(transaction); -} - -// ***************************************************************************** -// Utility Functions -// ***************************************************************************** - -/** - * @brief Dumps the database content to a file. - */ -bool fossil_crabdb_dump_to_file(fossil_crabdb_book_t *book, const char *filename) { - if (book == NULL || filename == NULL) { - return false; - } - FILE *file = fopen(filename, "w"); - if (file == NULL) { - return false; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - fprintf(file, "%s=%s\n", current->entry.key, current->entry.value); - current = current->next; - } - fclose(file); - return true; -} - -/** - * @brief Loads the database content from a file. - */ -bool fossil_crabdb_load_from_file(fossil_crabdb_book_t *book, const char *filename) { - if (book == NULL || filename == NULL) { - return false; - } - FILE *file = fopen(filename, "r"); - if (file == NULL) { - return false; - } - char line[256]; - while (fgets(line, sizeof(line), file) != NULL) { - char *key = strtok(line, "="); - char *value = strtok(NULL, "\n"); - fossil_crabdb_insert(book, key, value, (fossil_crabdb_attributes_t){false, false, false}); - } - fclose(file); - return true; -} - -/** - * @brief Validates the integrity of the database. - */ -bool fossil_crabdb_validate(fossil_crabdb_book_t *book) { - if (book == NULL) { - return false; - } - fossil_crabdb_page_t *current = book->head; - while (current != NULL) { - if (current->entry.key == NULL || current->entry.value == NULL) { - return false; - } - current = current->next; - } - return true; -} - -// ***************************************************************************** -// Helper Functions for Merge Sort -// ***************************************************************************** - -/** - * @brief Splits the linked list into two halves. - * - * @param head Pointer to the head of the list. - * @param front Pointer to store the first half of the list. - * @param back Pointer to store the second half of the list. - */ -static void split_list(fossil_crabdb_page_t *head, fossil_crabdb_page_t **front, fossil_crabdb_page_t **back) { - fossil_crabdb_page_t *slow = head; - fossil_crabdb_page_t *fast = head->next; - - while (fast != NULL) { - fast = fast->next; - if (fast != NULL) { - slow = slow->next; - fast = fast->next; - } - } - - *front = head; - *back = slow->next; - slow->next = NULL; -} - -/** - * @brief Merges two sorted linked lists based on the sorting order. - * - * @param left Pointer to the first sorted list. - * @param right Pointer to the second sorted list. - * @param order Sorting order (ascending or descending). - * @return Pointer to the merged list. - */ -static fossil_crabdb_page_t *merge_sorted_lists(fossil_crabdb_page_t *left, fossil_crabdb_page_t *right, fossil_crabdb_sort_order_t order) { - if (left == NULL) return right; - if (right == NULL) return left; - - int cmp = strcmp(left->entry.key, right->entry.key); - bool condition = (order == FOSSIL_CRABDB_SORT_ASCENDING) ? (cmp <= 0) : (cmp >= 0); - - if (condition) { - left->next = merge_sorted_lists(left->next, right, order); - left->next->prev = left; - left->prev = NULL; - return left; - } else { - right->next = merge_sorted_lists(left, right->next, order); - right->next->prev = right; - right->prev = NULL; - return right; - } -} - -/** - * @brief Performs an in-place merge sort on a doubly linked list. - * - * @param head Pointer to the head of the list. - * @param order Sorting order (ascending or descending). - * @return Pointer to the sorted list. - */ -static fossil_crabdb_page_t *merge_sort(fossil_crabdb_page_t *head, fossil_crabdb_sort_order_t order) { - if (head == NULL || head->next == NULL) { - return head; - } - - fossil_crabdb_page_t *front = NULL; - fossil_crabdb_page_t *back = NULL; - split_list(head, &front, &back); - - front = merge_sort(front, order); - back = merge_sort(back, order); - - return merge_sorted_lists(front, back, order); -} - -// ***************************************************************************** -// Public Function Implementation -// ***************************************************************************** - -int fossil_crabdb_sort(fossil_crabdb_book_t *book, fossil_crabdb_sort_order_t order) { - if (book == NULL || book->head == NULL) { - return -1; // Error: Invalid input - } - - // Perform merge sort - book->head = merge_sort(book->head, order); - - // Update the tail pointer after sorting - fossil_crabdb_page_t *current = book->head; - while (current->next != NULL) { - current = current->next; - } - book->tail = current; - - return 0; // Success -} diff --git a/code/logic/fossil/crabdb/database.h b/code/logic/fossil/crabdb/database.h deleted file mode 100644 index df6144f..0000000 --- a/code/logic/fossil/crabdb/database.h +++ /dev/null @@ -1,356 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * 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. - * ----------------------------------------------------------------------------- - */ -#ifndef FOSSIL_CRABDB_DB_H -#define FOSSIL_CRABDB_DB_H - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// ***************************************************************************** -// Enumerations for Data Types and Attributes -// ***************************************************************************** - -/** - * @brief Enumerates sorting orders for fossil_crabdb_sort operations. - */ -typedef enum { - FOSSIL_CRABDB_SORT_ASCENDING, // Sort in ascending order - FOSSIL_CRABDB_SORT_DESCENDING // Sort in descending order -} fossil_crabdb_sort_order_t; - -/** - * @brief Represents additional attributes for each database entry. - */ -typedef struct { - bool is_primary_key; // Entry is a primary key - bool is_unique; // Entry is unique - bool is_nullable; // Entry allows null values -} fossil_crabdb_attributes_t; - -// ***************************************************************************** -// Database Structures -// ***************************************************************************** - -typedef struct { - char *key; // Key - char *value; // Value - fossil_crabdb_attributes_t attributes;// Attributes -} fossil_crabdb_entry_t; - -/** - * Doubly linked list node representing a database entry. - */ -typedef struct fossil_crabdb_node { - fossil_crabdb_entry_t entry; - struct fossil_crabdb_node *next; - struct fossil_crabdb_node *prev; -} fossil_crabdb_page_t; - -/** - * Represents the database as a doubly linked list (a "book"). - */ -typedef struct { - fossil_crabdb_page_t *head; - fossil_crabdb_page_t *tail; - size_t size; -} fossil_crabdb_book_t; - -/** - * Represents a transaction. - */ -typedef struct fossil_crabdb_transaction { - char *name; // Transaction name - fossil_crabdb_book_t snapshot; // Database snapshot - struct fossil_crabdb_transaction *next; // Next transaction -} fossil_crabdb_transaction_t; - -// ***************************************************************************** -// Database API Functions -// ***************************************************************************** - -/** - * @brief Initializes a new empty database. - */ -fossil_crabdb_book_t* fossil_crabdb_init(void); - -/** - * @brief Releases all resources used by the database. - */ -void fossil_crabdb_release(fossil_crabdb_book_t *book); - -/** - * @brief Inserts a new key-value pair into the database. - */ -bool fossil_crabdb_insert(fossil_crabdb_book_t *book, const char *key, const char *value, fossil_crabdb_attributes_t attributes); - -/** - * @brief Updates the value of an existing key. - */ -bool fossil_crabdb_update(fossil_crabdb_book_t *book, const char *key, const char *new_value); - -/** - * @brief Deletes an entry from the database by key. - */ -bool fossil_crabdb_delete(fossil_crabdb_book_t *book, const char *key); - -/** - * @brief Searches for an entry by key. - */ -fossil_crabdb_entry_t* fossil_crabdb_search(fossil_crabdb_book_t *book, const char *key); - -/** - * @brief Displays all entries in the database. - */ -void fossil_crabdb_display(fossil_crabdb_book_t *book); - -/** - * @brief Counts the number of entries in the database. - */ -size_t fossil_crabdb_size(fossil_crabdb_book_t *book); - -/** - * @brief Checks if the database is empty. - */ -bool fossil_crabdb_is_empty(fossil_crabdb_book_t *book); - -/** - * @brief Clears all entries from the database. - */ -void fossil_crabdb_clear(fossil_crabdb_book_t *book); - -// ***************************************************************************** -// Relational Operations -// ***************************************************************************** - -/** - * @brief Joins two databases based on matching keys. - */ -fossil_crabdb_book_t* fossil_crabdb_join(fossil_crabdb_book_t *book1, fossil_crabdb_book_t *book2); - -/** - * @brief Filters database entries based on a condition. - */ -fossil_crabdb_book_t* fossil_crabdb_filter(fossil_crabdb_book_t *book, bool (*predicate)(fossil_crabdb_entry_t *)); - -/** - * @brief Merges two databases into one. - */ -fossil_crabdb_book_t* fossil_crabdb_merge(fossil_crabdb_book_t *book1, fossil_crabdb_book_t *book2); - -/** - * @brief Sorts the database by key. - * - * @param book Pointer to the database (fossil_crabdb_book_t). - * @param order Sorting order (ascending or descending). - * @return 0 on success, non-zero on error. - */ -int fossil_crabdb_sort(fossil_crabdb_book_t *book, fossil_crabdb_sort_order_t order); - -// ***************************************************************************** -// Transaction Management -// ***************************************************************************** - -/** - * @brief Begins a new transaction. - */ -fossil_crabdb_transaction_t* fossil_crabdb_transaction_begin(fossil_crabdb_book_t *book, const char *name); - -/** - * @brief Commits a transaction, saving changes. - */ -bool fossil_crabdb_transaction_commit(fossil_crabdb_book_t *book, fossil_crabdb_transaction_t *transaction); - -/** - * @brief Rolls back a transaction, restoring the previous state. - */ -bool fossil_crabdb_transaction_rollback(fossil_crabdb_book_t *book, fossil_crabdb_transaction_t *transaction); - -/** - * @brief Releases a transaction's resources. - */ -void fossil_crabdb_transaction_release(fossil_crabdb_transaction_t *transaction); - -// ***************************************************************************** -// Utility Functions -// ***************************************************************************** - -/** - * @brief Dumps the database content to a file. - */ -bool fossil_crabdb_dump_to_file(fossil_crabdb_book_t *book, const char *filename); - -/** - * @brief Loads the database content from a file. - */ -bool fossil_crabdb_load_from_file(fossil_crabdb_book_t *book, const char *filename); - -/** - * @brief Validates the integrity of the database. - */ -bool fossil_crabdb_validate(fossil_crabdb_book_t *book); - -#ifdef __cplusplus -} -#include - -namespace fossil { - -/** - * @class CrabDB - * @brief A class that provides an interface to interact with the Fossil CrabDB database. - * - * This class encapsulates the functionality of the Fossil CrabDB, providing methods to - * insert, update, remove, search, display, and manage entries in the database. - * - * @note The class manages the lifecycle of the database, ensuring proper initialization - * and release of resources. - */ -class CrabDB { -public: - /** - * @brief Constructs a new CrabDB object. - */ - CrabDB() { - book = fossil_crabdb_init(); - } - - /** - * @brief Destroys the CrabDB object. - */ - ~CrabDB() { - fossil_crabdb_release(book); - } - - /** - * @brief Inserts a new key-value pair into the database. - * - * @param key The key to insert. - * @param value The value to insert. - * @param attributes Additional attributes for the entry. - * @return True if the entry was inserted successfully, false otherwise. - */ - bool insert(const std::string &key, const std::string &value, fossil_crabdb_attributes_t attributes) { - return fossil_crabdb_insert(book, key.c_str(), value.c_str(), attributes); - } - - /** - * @brief Updates the value of an existing key. - * - * @param key The key to update. - * @param new_value The new value to set. - * @return True if the key was updated successfully, false otherwise. - */ - bool update(const std::string &key, const std::string &new_value) { - return fossil_crabdb_update(book, key.c_str(), new_value.c_str()); - } - - /** - * @brief Removes an entry from the database by key. - * - * @param key The key to remove. - * @return True if the entry was removed successfully, false otherwise. - */ - bool remove(const std::string &key) { - return fossil_crabdb_delete(book, key.c_str()); - } - - /** - * @brief Searches for an entry by key. - * - * @param key The key to search for. - * @return A pointer to the entry if found, nullptr otherwise. - */ - fossil_crabdb_entry_t* search(const std::string &key) { - return fossil_crabdb_search(book, key.c_str()); - } - - /** - * @brief Displays all entries in the database. - */ - void display() { - fossil_crabdb_display(book); - } - - /** - * @brief Counts the number of entries in the database. - * - * @return The number of entries in the database. - */ - size_t size() { - return fossil_crabdb_size(book); - } - - /** - * @brief Checks if the database is empty. - * - * @return True if the database is empty, false otherwise. - */ - bool isEmpty() { - return fossil_crabdb_is_empty(book); - } - - /** - * @brief Clears all entries from the database. - */ - void clear() { - fossil_crabdb_clear(book); - } - - /** - * @brief Sorts the database by key. - * - * @param order The sorting order (ascending or descending). - * @return 0 on success, non-zero on error. - */ - bool dumpToFile(const std::string &filename) { - return fossil_crabdb_dump_to_file(book, filename.c_str()); - } - - /** - * @brief Loads the database content from a file. - * - * @param filename The name of the file to load. - * @return True if the database was loaded successfully, false otherwise. - */ - bool loadFromFile(const std::string &filename) { - return fossil_crabdb_load_from_file(book, filename.c_str()); - } - - /** - * @brief Validates the integrity of the database. - * - * @return True if the database is valid, false otherwise. - */ - bool validate() { - return fossil_crabdb_validate(book); - } - -private: - fossil_crabdb_book_t *book; -}; - -} - -#endif - -#endif /* FOSSIL_CRABDB_FRAMEWORK_H */ diff --git a/code/logic/fossil/crabdb/framework.h b/code/logic/fossil/crabdb/framework.h index 376b89a..78002c5 100644 --- a/code/logic/fossil/crabdb/framework.h +++ b/code/logic/fossil/crabdb/framework.h @@ -14,7 +14,6 @@ #ifndef FOSSIL_CRABDB_FRAMEWORK_H #define FOSSIL_CRABDB_FRAMEWORK_H -#include "database.h" #include "myshell.h" #include "noshell.h" diff --git a/code/logic/myshell.c b/code/logic/myshell.c index 304629d..c10b923 100644 --- a/code/logic/myshell.c +++ b/code/logic/myshell.c @@ -16,38 +16,24 @@ #include #include -// =========================================================== -// Helper functions -// =========================================================== - -static FILE* open_file(const char *file_name, const char *mode) { - return fopen(file_name, mode); -} - -static void close_file(FILE *file) { - if (file != NULL) { - fclose(file); - } -} - // =========================================================== // CRUD Operations // =========================================================== fossil_myshell_error_t fossil_myshell_create_record(const char *file_name, const char *key, const char *value) { - FILE *file = open_file(file_name, "a"); + FILE *file = fopen(file_name, "a"); if (!file) { return FOSSIL_MYSHELL_ERROR_IO; } fprintf(file, "%s=%s\n", key, value); - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_SUCCESS; } fossil_myshell_error_t fossil_myshell_read_record(const char *file_name, const char *key, char *value, size_t buffer_size) { - FILE *file = open_file(file_name, "r"); + FILE *file = fopen(file_name, "r"); if (!file) { return FOSSIL_MYSHELL_ERROR_IO; } @@ -59,17 +45,17 @@ fossil_myshell_error_t fossil_myshell_read_record(const char *file_name, const c if (line_key && strcmp(line_key, key) == 0) { strncpy(value, line_value, buffer_size); - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_SUCCESS; } } - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_NOT_FOUND; } fossil_myshell_error_t fossil_myshell_update_record(const char *file_name, const char *key, const char *new_value) { - FILE *file = open_file(file_name, "r+"); + FILE *file = fopen(file_name, "r+"); if (!file) { return FOSSIL_MYSHELL_ERROR_IO; } @@ -87,26 +73,26 @@ fossil_myshell_error_t fossil_myshell_update_record(const char *file_name, const } if (!found) { - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_NOT_FOUND; } fseek(file, pos, SEEK_SET); fprintf(file, "%s=%s\n", key, new_value); - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_SUCCESS; } fossil_myshell_error_t fossil_myshell_delete_record(const char *file_name, const char *key) { - FILE *file = open_file(file_name, "r"); + FILE *file = fopen(file_name, "r"); if (!file) { return FOSSIL_MYSHELL_ERROR_IO; } - FILE *temp_file = open_file("temp.crabdb", "w"); + FILE *temp_file = fopen("temp.crabdb", "w"); if (!temp_file) { - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_IO; } @@ -121,8 +107,8 @@ fossil_myshell_error_t fossil_myshell_delete_record(const char *file_name, const } } - close_file(file); - close_file(temp_file); + fclose(file); + fclose(temp_file); if (deleted) { remove(file_name); @@ -139,22 +125,22 @@ fossil_myshell_error_t fossil_myshell_delete_record(const char *file_name, const // =========================================================== fossil_myshell_error_t fossil_myshell_create_database(const char *file_name) { - FILE *file = open_file(file_name, "w"); + FILE *file = fopen(file_name, "w"); if (!file) { return FOSSIL_MYSHELL_ERROR_IO; } - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_SUCCESS; } fossil_myshell_error_t fossil_myshell_open_database(const char *file_name) { - FILE *file = open_file(file_name, "r"); + FILE *file = fopen(file_name, "r"); if (!file) { return FOSSIL_MYSHELL_ERROR_FILE_NOT_FOUND; } - close_file(file); + fclose(file); return FOSSIL_MYSHELL_ERROR_SUCCESS; } @@ -175,14 +161,14 @@ fossil_myshell_error_t fossil_myshell_delete_database(const char *file_name) { // =========================================================== fossil_myshell_error_t fossil_myshell_backup_database(const char *source_file, const char *backup_file) { - FILE *source = open_file(source_file, "rb"); + FILE *source = fopen(source_file, "rb"); if (!source) { return FOSSIL_MYSHELL_ERROR_IO; } - FILE *backup = open_file(backup_file, "wb"); + FILE *backup = fopen(backup_file, "wb"); if (!backup) { - close_file(source); + fclose(source); return FOSSIL_MYSHELL_ERROR_IO; } @@ -192,21 +178,21 @@ fossil_myshell_error_t fossil_myshell_backup_database(const char *source_file, c fwrite(buffer, 1, bytes_read, backup); } - close_file(source); - close_file(backup); + fclose(source); + fclose(backup); return FOSSIL_MYSHELL_ERROR_SUCCESS; } fossil_myshell_error_t fossil_myshell_restore_database(const char *backup_file, const char *destination_file) { - FILE *backup = open_file(backup_file, "rb"); + FILE *backup = fopen(backup_file, "rb"); if (!backup) { return FOSSIL_MYSHELL_ERROR_IO; } - FILE *destination = open_file(destination_file, "wb"); + FILE *destination = fopen(destination_file, "wb"); if (!destination) { - close_file(backup); + fclose(backup); return FOSSIL_MYSHELL_ERROR_IO; } @@ -216,8 +202,8 @@ fossil_myshell_error_t fossil_myshell_restore_database(const char *backup_file, fwrite(buffer, 1, bytes_read, destination); } - close_file(backup); - close_file(destination); + fclose(backup); + fclose(destination); return FOSSIL_MYSHELL_ERROR_SUCCESS; } diff --git a/code/logic/noshell.c b/code/logic/noshell.c index 1c891e8..d71653a 100644 --- a/code/logic/noshell.c +++ b/code/logic/noshell.c @@ -16,38 +16,24 @@ #include #include -// =========================================================== -// Helper functions -// =========================================================== - -static FILE* open_file(const char *file_name, const char *mode) { - return fopen(file_name, mode); -} - -static void close_file(FILE *file) { - if (file != NULL) { - fclose(file); - } -} - // =========================================================== // CRUD Operations // =========================================================== fossil_noshell_error_t fossil_noshell_insert(const char *file_name, const char *document) { - FILE *file = open_file(file_name, "a"); + FILE *file = fopen(file_name, "a"); if (!file) { return FOSSIL_NOSHELL_ERROR_IO; } fprintf(file, "%s\n", document); - close_file(file); + fclose(file); return FOSSIL_NOSHELL_ERROR_SUCCESS; } fossil_noshell_error_t fossil_noshell_find(const char *file_name, const char *query, char *result, size_t buffer_size) { - FILE *file = open_file(file_name, "r"); + FILE *file = fopen(file_name, "r"); if (!file) { return FOSSIL_NOSHELL_ERROR_IO; } @@ -56,24 +42,24 @@ fossil_noshell_error_t fossil_noshell_find(const char *file_name, const char *qu while (fgets(line, sizeof(line), file)) { if (strstr(line, query)) { strncpy(result, line, buffer_size); - close_file(file); + fclose(file); return FOSSIL_NOSHELL_ERROR_SUCCESS; } } - close_file(file); + fclose(file); return FOSSIL_NOSHELL_ERROR_NOT_FOUND; } fossil_noshell_error_t fossil_noshell_update(const char *file_name, const char *query, const char *new_document) { - FILE *file = open_file(file_name, "r+"); + FILE *file = fopen(file_name, "r+"); if (!file) { return FOSSIL_NOSHELL_ERROR_IO; } - FILE *temp_file = open_file("temp.crabdb", "w"); + FILE *temp_file = fopen("temp.crabdb", "w"); if (!temp_file) { - close_file(file); + fclose(file); return FOSSIL_NOSHELL_ERROR_IO; } @@ -89,8 +75,8 @@ fossil_noshell_error_t fossil_noshell_update(const char *file_name, const char * } } - close_file(file); - close_file(temp_file); + fclose(file); + fclose(temp_file); if (updated) { remove(file_name); @@ -103,14 +89,14 @@ fossil_noshell_error_t fossil_noshell_update(const char *file_name, const char * } fossil_noshell_error_t fossil_noshell_remove(const char *file_name, const char *query) { - FILE *file = open_file(file_name, "r"); + FILE *file = fopen(file_name, "r"); if (!file) { return FOSSIL_NOSHELL_ERROR_IO; } - FILE *temp_file = open_file("temp.crabdb", "w"); + FILE *temp_file = fopen("temp.crabdb", "w"); if (!temp_file) { - close_file(file); + fclose(file); return FOSSIL_NOSHELL_ERROR_IO; } @@ -124,8 +110,8 @@ fossil_noshell_error_t fossil_noshell_remove(const char *file_name, const char * } } - close_file(file); - close_file(temp_file); + fclose(file); + fclose(temp_file); if (removed) { remove(file_name); @@ -142,22 +128,22 @@ fossil_noshell_error_t fossil_noshell_remove(const char *file_name, const char * // =========================================================== fossil_noshell_error_t fossil_noshell_create_database(const char *file_name) { - FILE *file = open_file(file_name, "w"); + FILE *file = fopen(file_name, "w"); if (!file) { return FOSSIL_NOSHELL_ERROR_IO; } - close_file(file); + fclose(file); return FOSSIL_NOSHELL_ERROR_SUCCESS; } fossil_noshell_error_t fossil_noshell_open_database(const char *file_name) { - FILE *file = open_file(file_name, "r"); + FILE *file = fopen(file_name, "r"); if (!file) { return FOSSIL_NOSHELL_ERROR_FILE_NOT_FOUND; } - close_file(file); + fclose(file); return FOSSIL_NOSHELL_ERROR_SUCCESS; } @@ -178,14 +164,14 @@ fossil_noshell_error_t fossil_noshell_delete_database(const char *file_name) { // =========================================================== fossil_noshell_error_t fossil_noshell_backup_database(const char *source_file, const char *backup_file) { - FILE *source = open_file(source_file, "rb"); + FILE *source = fopen(source_file, "rb"); if (!source) { return FOSSIL_NOSHELL_ERROR_IO; } - FILE *backup = open_file(backup_file, "wb"); + FILE *backup = fopen(backup_file, "wb"); if (!backup) { - close_file(source); + fclose(source); return FOSSIL_NOSHELL_ERROR_IO; } @@ -195,21 +181,21 @@ fossil_noshell_error_t fossil_noshell_backup_database(const char *source_file, c fwrite(buffer, 1, bytes_read, backup); } - close_file(source); - close_file(backup); + fclose(source); + fclose(backup); return FOSSIL_NOSHELL_ERROR_SUCCESS; } fossil_noshell_error_t fossil_noshell_restore_database(const char *backup_file, const char *destination_file) { - FILE *backup = open_file(backup_file, "rb"); + FILE *backup = fopen(backup_file, "rb"); if (!backup) { return FOSSIL_NOSHELL_ERROR_IO; } - FILE *destination = open_file(destination_file, "wb"); + FILE *destination = fopen(destination_file, "wb"); if (!destination) { - close_file(backup); + fclose(backup); return FOSSIL_NOSHELL_ERROR_IO; } @@ -219,8 +205,8 @@ fossil_noshell_error_t fossil_noshell_restore_database(const char *backup_file, fwrite(buffer, 1, bytes_read, destination); } - close_file(backup); - close_file(destination); + fclose(backup); + fclose(destination); return FOSSIL_NOSHELL_ERROR_SUCCESS; } diff --git a/code/tests/meson.build b/code/tests/meson.build index 3311383..da530d9 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -3,7 +3,7 @@ if get_option('with_test').enabled() test_c = ['unit_runner.c'] test_cases = [ - 'database', # 'query', 'search' + 'myshell', 'noshell' ] foreach cases : test_cases From ae7a305a6773330a0ed1832488de2c151d1dec26 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 2 Jan 2025 12:55:35 -0600 Subject: [PATCH 05/10] rewrite test cases --- code/tests/cases/test_database.c | 194 ------------------ code/tests/cases/test_database.cpp | 253 ----------------------- code/tests/cases/test_myshell.c | 137 +++++++++++++ code/tests/cases/test_myshell.cpp | 230 +++++++++++++++++++++ code/tests/cases/test_noshell.c | 179 ++++++++++++++++ code/tests/cases/test_noshell.cpp | 316 +++++++++++++++++++++++++++++ 6 files changed, 862 insertions(+), 447 deletions(-) delete mode 100644 code/tests/cases/test_database.c delete mode 100644 code/tests/cases/test_database.cpp create mode 100644 code/tests/cases/test_myshell.c create mode 100644 code/tests/cases/test_myshell.cpp create mode 100644 code/tests/cases/test_noshell.c create mode 100644 code/tests/cases/test_noshell.cpp diff --git a/code/tests/cases/test_database.c b/code/tests/cases/test_database.c deleted file mode 100644 index f3f9414..0000000 --- a/code/tests/cases/test_database.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * 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 - -#include "fossil/crabdb/framework.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Utilities -// * * * * * * * * * * * * * * * * * * * * * * * * -// Setup steps for things like test fixtures and -// mock objects are set here. -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_SUITE(c_crabdb_fixture); - -FOSSIL_SETUP(c_crabdb_fixture) { - // Setup the test fixture -} - -FOSSIL_TEARDOWN(c_crabdb_fixture) { - // Teardown the test fixture -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Blue CrabDB Database -// * * * * * * * * * * * * * * * * * * * * * * * * - -// Test case for initializing a new database -FOSSIL_TEST_CASE(c_test_crabdb_init) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - ASSUME_NOT_CNULL(book); - ASSUME_ITS_TRUE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for inserting a new key-value pair -FOSSIL_TEST_CASE(c_test_crabdb_insert) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - bool result = fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - ASSUME_ITS_TRUE(result); - ASSUME_ITS_FALSE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for updating an existing key -FOSSIL_TEST_CASE(c_test_crabdb_update) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - bool result = fossil_crabdb_update(book, "key1", "new_value1"); - ASSUME_ITS_TRUE(result); - fossil_crabdb_entry_t *entry = fossil_crabdb_search(book, "key1"); - ASSUME_NOT_CNULL(entry); - ASSUME_ITS_TRUE(strcmp(entry->value, "new_value1") == 0); - fossil_crabdb_release(book); -} - -// Test case for deleting an entry by key -FOSSIL_TEST_CASE(c_test_crabdb_delete) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - bool result = fossil_crabdb_delete(book, "key1"); - ASSUME_ITS_TRUE(result); - ASSUME_ITS_TRUE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for searching an entry by key -FOSSIL_TEST_CASE(c_test_crabdb_search) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_entry_t *entry = fossil_crabdb_search(book, "key1"); - ASSUME_NOT_CNULL(entry); - ASSUME_ITS_TRUE(strcmp(entry->value, "value1") == 0); - fossil_crabdb_release(book); -} - -// Test case for clearing all entries from the database -FOSSIL_TEST_CASE(c_test_crabdb_clear) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_clear(book); - ASSUME_ITS_TRUE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for joining two databases -FOSSIL_TEST_CASE(c_test_crabdb_join) { - fossil_crabdb_book_t *book1 = fossil_crabdb_init(); - fossil_crabdb_book_t *book2 = fossil_crabdb_init(); - fossil_crabdb_insert(book1, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_insert(book2, "key1", "value2", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_book_t *result = fossil_crabdb_join(book1, book2); - ASSUME_NOT_CNULL(result); - ASSUME_ITS_TRUE(fossil_crabdb_size(result) == 2); - fossil_crabdb_release(book1); - fossil_crabdb_release(book2); - fossil_crabdb_release(result); -} - -// Test case for filtering database entries -static bool filter_key1(fossil_crabdb_entry_t *entry) { - return strcmp(entry->key, "key1") == 0; -} - -FOSSIL_TEST_CASE(c_test_crabdb_filter) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_insert(book, "key2", "value2", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_book_t *result = fossil_crabdb_filter(book, filter_key1); - ASSUME_NOT_CNULL(result); - ASSUME_ITS_TRUE(fossil_crabdb_size(result) == 1); - fossil_crabdb_release(book); - fossil_crabdb_release(result); -} - -// Test case for merging two databases -FOSSIL_TEST_CASE(c_test_crabdb_merge) { - fossil_crabdb_book_t *book1 = fossil_crabdb_init(); - fossil_crabdb_book_t *book2 = fossil_crabdb_init(); - fossil_crabdb_insert(book1, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_insert(book2, "key2", "value2", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_book_t *result = fossil_crabdb_merge(book1, book2); - ASSUME_NOT_CNULL(result); - ASSUME_ITS_TRUE(fossil_crabdb_size(result) == 2); - fossil_crabdb_release(book1); - fossil_crabdb_release(book2); - fossil_crabdb_release(result); -} - -// Test case for validating the integrity of the database -FOSSIL_TEST_CASE(c_test_crabdb_validate) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - bool result = fossil_crabdb_validate(book); - ASSUME_ITS_TRUE(result); - fossil_crabdb_release(book); -} - -// Test case for sorting the database in ascending order -FOSSIL_TEST_CASE(c_test_crabdb_sort_ascending) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key3", "value3", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_insert(book, "key2", "value2", (fossil_crabdb_attributes_t){false, false, false}); - int result = fossil_crabdb_sort(book, FOSSIL_CRABDB_SORT_ASCENDING); - ASSUME_ITS_TRUE(result == 0); - fossil_crabdb_page_t *current = book->head; - ASSUME_ITS_TRUE(strcmp(current->entry.key, "key1") == 0); - fossil_crabdb_release(book); -} - -// Test case for sorting the database in descending order -FOSSIL_TEST_CASE(c_test_crabdb_sort_descending) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, "key1", "value1", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_insert(book, "key3", "value3", (fossil_crabdb_attributes_t){false, false, false}); - fossil_crabdb_insert(book, "key2", "value2", (fossil_crabdb_attributes_t){false, false, false}); - int result = fossil_crabdb_sort(book, FOSSIL_CRABDB_SORT_DESCENDING); - ASSUME_ITS_TRUE(result == 0); - fossil_crabdb_page_t *current = book->head; - ASSUME_ITS_TRUE(strcmp(current->entry.key, "key3") == 0); - fossil_crabdb_release(book); -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST_GROUP(c_crab_database_tests) { - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_init); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_insert); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_update); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_delete); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_search); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_clear); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_join); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_filter); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_merge); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_validate); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_sort_ascending); - FOSSIL_TEST_ADD(c_crabdb_fixture, c_test_crabdb_sort_descending); - - FOSSIL_TEST_REGISTER(c_crabdb_fixture); -} // end of tests diff --git a/code/tests/cases/test_database.cpp b/code/tests/cases/test_database.cpp deleted file mode 100644 index b68b114..0000000 --- a/code/tests/cases/test_database.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * 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 - -#include "fossil/crabdb/framework.h" - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Utilities -// * * * * * * * * * * * * * * * * * * * * * * * * -// Setup steps for things like test fixtures and -// mock objects are set here. -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_SUITE(cpp_crabdb_fixture); - -FOSSIL_SETUP(cpp_crabdb_fixture) { - // Setup the test fixture -} - -FOSSIL_TEARDOWN(cpp_crabdb_fixture) { - // Teardown the test fixture -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Blue CrabDB Database -// * * * * * * * * * * * * * * * * * * * * * * * * - -// Test case for initializing a new database -FOSSIL_TEST_CASE(cpp_test_crabdb_init) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - ASSUME_NOT_CNULL(book); - ASSUME_ITS_TRUE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for inserting a new key-value pair -FOSSIL_TEST_CASE(cpp_test_crabdb_insert) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - bool result = fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - ASSUME_ITS_TRUE(result); - ASSUME_ITS_FALSE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for updating an existing key -FOSSIL_TEST_CASE(cpp_test_crabdb_update) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - bool result = fossil_crabdb_update(book, const_cast("key1"), const_cast("new_value1")); - ASSUME_ITS_TRUE(result); - fossil_crabdb_entry_t *entry = fossil_crabdb_search(book, const_cast("key1")); - ASSUME_NOT_CNULL(entry); - ASSUME_ITS_TRUE(strcmp(entry->value, "new_value1") == 0); - fossil_crabdb_release(book); -} - -// Test case for deleting an entry by key -FOSSIL_TEST_CASE(cpp_test_crabdb_delete) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - bool result = fossil_crabdb_delete(book, const_cast("key1")); - ASSUME_ITS_TRUE(result); - ASSUME_ITS_TRUE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for searching an entry by key -FOSSIL_TEST_CASE(cpp_test_crabdb_search) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - fossil_crabdb_entry_t *entry = fossil_crabdb_search(book, const_cast("key1")); - ASSUME_NOT_CNULL(entry); - ASSUME_ITS_TRUE(strcmp(entry->value, "value1") == 0); - fossil_crabdb_release(book); -} - -// Test case for clearing all entries from the database -FOSSIL_TEST_CASE(cpp_test_crabdb_clear) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - fossil_crabdb_clear(book); - ASSUME_ITS_TRUE(fossil_crabdb_is_empty(book)); - fossil_crabdb_release(book); -} - -// Test case for joining two databases -FOSSIL_TEST_CASE(cpp_test_crabdb_join) { - fossil_crabdb_book_t *book1 = fossil_crabdb_init(); - fossil_crabdb_book_t *book2 = fossil_crabdb_init(); - fossil_crabdb_insert(book1, const_cast("key1"), const_cast("value1"), {false, false, false}); - fossil_crabdb_insert(book2, const_cast("key1"), const_cast("value2"), {false, false, false}); - fossil_crabdb_book_t *result = fossil_crabdb_join(book1, book2); - ASSUME_NOT_CNULL(result); - ASSUME_ITS_TRUE(fossil_crabdb_size(result) == 2); - fossil_crabdb_release(book1); - fossil_crabdb_release(book2); - fossil_crabdb_release(result); -} - -// Test case for filtering database entries -static bool filter_key1(fossil_crabdb_entry_t *entry) { - return strcmp(entry->key, "key1") == 0; -} - -FOSSIL_TEST_CASE(cpp_test_crabdb_filter) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - fossil_crabdb_insert(book, const_cast("key2"), const_cast("value2"), {false, false, false}); - fossil_crabdb_book_t *result = fossil_crabdb_filter(book, filter_key1); - ASSUME_NOT_CNULL(result); - ASSUME_ITS_TRUE(fossil_crabdb_size(result) == 1); - fossil_crabdb_release(book); - fossil_crabdb_release(result); -} - -// Test case for merging two databases -FOSSIL_TEST_CASE(cpp_test_crabdb_merge) { - fossil_crabdb_book_t *book1 = fossil_crabdb_init(); - fossil_crabdb_book_t *book2 = fossil_crabdb_init(); - fossil_crabdb_insert(book1, const_cast("key1"), const_cast("value1"), {false, false, false}); - fossil_crabdb_insert(book2, const_cast("key2"), const_cast("value2"), {false, false, false}); - fossil_crabdb_book_t *result = fossil_crabdb_merge(book1, book2); - ASSUME_NOT_CNULL(result); - ASSUME_ITS_TRUE(fossil_crabdb_size(result) == 2); - fossil_crabdb_release(book1); - fossil_crabdb_release(book2); - fossil_crabdb_release(result); -} - -// Test case for validating the integrity of the database -FOSSIL_TEST_CASE(cpp_test_crabdb_validate) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - bool result = fossil_crabdb_validate(book); - ASSUME_ITS_TRUE(result); - fossil_crabdb_release(book); -} - -// Test case for sorting the database in ascending order -FOSSIL_TEST_CASE(cpp_test_crabdb_sort_ascending) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key3"), const_cast("value3"), {false, false, false}); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - fossil_crabdb_insert(book, const_cast("key2"), const_cast("value2"), {false, false, false}); - int result = fossil_crabdb_sort(book, FOSSIL_CRABDB_SORT_ASCENDING); - ASSUME_ITS_TRUE(result == 0); - fossil_crabdb_page_t *current = book->head; - ASSUME_ITS_TRUE(strcmp(current->entry.key, "key1") == 0); - fossil_crabdb_release(book); -} - -// Test case for sorting the database in descending order -FOSSIL_TEST_CASE(cpp_test_crabdb_sort_descending) { - fossil_crabdb_book_t *book = fossil_crabdb_init(); - fossil_crabdb_insert(book, const_cast("key1"), const_cast("value1"), {false, false, false}); - fossil_crabdb_insert(book, const_cast("key3"), const_cast("value3"), {false, false, false}); - fossil_crabdb_insert(book, const_cast("key2"), const_cast("value2"), {false, false, false}); - int result = fossil_crabdb_sort(book, FOSSIL_CRABDB_SORT_DESCENDING); - ASSUME_ITS_TRUE(result == 0); - fossil_crabdb_page_t *current = book->head; - ASSUME_ITS_TRUE(strcmp(current->entry.key, "key3") == 0); - fossil_crabdb_release(book); -} - -// Test case for inserting a new key-value pair using CrabDB class -FOSSIL_TEST_CASE(cpp_test_crabdb_class_insert) { - fossil::CrabDB db; - bool result = db.insert("key1", "value1", {false, false, false}); - ASSUME_ITS_TRUE(result); - ASSUME_ITS_FALSE(db.isEmpty()); -} - -// Test case for updating an existing key using CrabDB class -FOSSIL_TEST_CASE(cpp_test_crabdb_class_update) { - fossil::CrabDB db; - db.insert("key1", "value1", {false, false, false}); - bool result = db.update("key1", "new_value1"); - ASSUME_ITS_TRUE(result); - fossil_crabdb_entry_t *entry = db.search("key1"); - ASSUME_NOT_CNULL(entry); - ASSUME_ITS_TRUE(strcmp(entry->value, "new_value1") == 0); -} - -// Test case for deleting an entry by key using CrabDB class -FOSSIL_TEST_CASE(cpp_test_crabdb_class_delete) { - fossil::CrabDB db; - db.insert("key1", "value1", {false, false, false}); - bool result = db.remove("key1"); - ASSUME_ITS_TRUE(result); - ASSUME_ITS_TRUE(db.isEmpty()); -} - -// Test case for searching an entry by key using CrabDB class -FOSSIL_TEST_CASE(cpp_test_crabdb_class_search) { - fossil::CrabDB db; - db.insert("key1", "value1", {false, false, false}); - fossil_crabdb_entry_t *entry = db.search("key1"); - ASSUME_NOT_CNULL(entry); - ASSUME_ITS_TRUE(strcmp(entry->value, "value1") == 0); -} - -// Test case for clearing all entries from the database using CrabDB class -FOSSIL_TEST_CASE(cpp_test_crabdb_class_clear) { - fossil::CrabDB db; - db.insert("key1", "value1", {false, false, false}); - db.clear(); - ASSUME_ITS_TRUE(db.isEmpty()); -} - -// Test case for validating the integrity of the database using CrabDB class -FOSSIL_TEST_CASE(cpp_test_crabdb_class_validate) { - fossil::CrabDB db; - db.insert("key1", "value1", {false, false, false}); - bool result = db.validate(); - ASSUME_ITS_TRUE(result); -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST_GROUP(cpp_crab_database_tests) { - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_init); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_insert); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_update); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_delete); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_search); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_clear); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_join); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_filter); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_merge); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_validate); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_sort_ascending); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_sort_descending); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_class_insert); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_class_update); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_class_delete); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_class_search); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_class_clear); - FOSSIL_TEST_ADD(cpp_crabdb_fixture, cpp_test_crabdb_class_validate); - - FOSSIL_TEST_REGISTER(cpp_crabdb_fixture); -} // end of tests diff --git a/code/tests/cases/test_myshell.c b/code/tests/cases/test_myshell.c new file mode 100644 index 0000000..04b74ed --- /dev/null +++ b/code/tests/cases/test_myshell.c @@ -0,0 +1,137 @@ +/* + * ----------------------------------------------------------------------------- + * 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 + +#include "fossil/crabdb/framework.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilities +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_SUITE(c_myshell_fixture); + +FOSSIL_SETUP(c_myshell_fixture) { + // Setup the test fixture +} + +FOSSIL_TEARDOWN(c_myshell_fixture) { + // Teardown the test fixture +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Blue CrabDB Database +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Test case for creating a new record in the database file +FOSSIL_TEST_CASE(c_test_myshell_create_record) { + const char *file_name = "test.crabdb"; + fossil_myshell_create_database(file_name); + fossil_myshell_error_t result = fossil_myshell_create_record(file_name, "key1", "value1"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + char value[256]; + result = fossil_myshell_read_record(file_name, "key1", value, sizeof(value)); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(strcmp(value, "value1") == 0); + + fossil_myshell_delete_database(file_name); +} + +// Test case for reading a non-existent record from the database file +FOSSIL_TEST_CASE(c_test_myshell_read_nonexistent_record) { + const char *file_name = "test.crabdb"; + fossil_myshell_create_database(file_name); + + char value[256]; + fossil_myshell_error_t result = fossil_myshell_read_record(file_name, "nonexistent_key", value, sizeof(value)); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil_myshell_delete_database(file_name); +} + +// Test case for updating a non-existent record in the database file +FOSSIL_TEST_CASE(c_test_myshell_update_nonexistent_record) { + const char *file_name = "test.crabdb"; + fossil_myshell_create_database(file_name); + + fossil_myshell_error_t result = fossil_myshell_update_record(file_name, "nonexistent_key", "new_value"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil_myshell_delete_database(file_name); +} + +// Test case for deleting a non-existent record from the database file +FOSSIL_TEST_CASE(c_test_myshell_delete_nonexistent_record) { + const char *file_name = "test.crabdb"; + fossil_myshell_create_database(file_name); + + fossil_myshell_error_t result = fossil_myshell_delete_record(file_name, "nonexistent_key"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil_myshell_delete_database(file_name); +} + +// Test case for backing up and restoring a database file +FOSSIL_TEST_CASE(c_test_myshell_backup_restore) { + const char *file_name = "test.crabdb"; + const char *backup_file = "backup.crabdb"; + fossil_myshell_create_database(file_name); + fossil_myshell_create_record(file_name, "key1", "value1"); + + fossil_myshell_error_t result = fossil_myshell_backup_database(file_name, backup_file); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + fossil_myshell_delete_database(file_name); + result = fossil_myshell_restore_database(backup_file, file_name); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + char value[256]; + result = fossil_myshell_read_record(file_name, "key1", value, sizeof(value)); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(strcmp(value, "value1") == 0); + + fossil_myshell_delete_database(file_name); + fossil_myshell_delete_database(backup_file); +} + +// Test case for validating the file extension of a database file +FOSSIL_TEST_CASE(c_test_myshell_validate_extension) { + ASSUME_ITS_TRUE(fossil_myshell_validate_extension("test.crabdb")); + ASSUME_ITS_FALSE(fossil_myshell_validate_extension("test.txt")); +} + +// Test case for validating data +FOSSIL_TEST_CASE(c_test_myshell_validate_data) { + ASSUME_ITS_TRUE(fossil_myshell_validate_data("valid_data")); + ASSUME_ITS_FALSE(fossil_myshell_validate_data(NULL)); + ASSUME_ITS_FALSE(fossil_myshell_validate_data("")); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * +FOSSIL_TEST_GROUP(c_myshell_database_tests) { + FOSSIL_TEST_ADD(c_myshell_fixture, c_test_myshell_create_record); + FOSSIL_TEST_ADD(c_myshell_fixture, c_test_myshell_read_nonexistent_record); + FOSSIL_TEST_ADD(c_myshell_fixture, c_test_myshell_update_nonexistent_record); + FOSSIL_TEST_ADD(c_myshell_fixture, c_test_myshell_delete_nonexistent_record); + FOSSIL_TEST_ADD(c_myshell_fixture, c_test_myshell_backup_restore); + FOSSIL_TEST_ADD(c_myshell_fixture, c_test_myshell_validate_extension); + FOSSIL_TEST_ADD(c_myshell_fixture, c_test_myshell_validate_data); + + FOSSIL_TEST_REGISTER(c_myshell_fixture); +} // end of tests diff --git a/code/tests/cases/test_myshell.cpp b/code/tests/cases/test_myshell.cpp new file mode 100644 index 0000000..4ad4262 --- /dev/null +++ b/code/tests/cases/test_myshell.cpp @@ -0,0 +1,230 @@ +/* + * ----------------------------------------------------------------------------- + * 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 + +#include "fossil/crabdb/framework.h" +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilities +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_SUITE(cpp_myshell_fixture); + +FOSSIL_SETUP(cpp_myshell_fixture) { + // Setup the test fixture +} + +FOSSIL_TEARDOWN(cpp_myshell_fixture) { + // Teardown the test fixture +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Blue CrabDB Database +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Test case for creating a new record in the database file +FOSSIL_TEST_CASE(cpp_test_myshell_create_record) { + std::string file_name = "test.crabdb"; + fossil_myshell_create_database(file_name.c_str()); + fossil_myshell_error_t result = fossil_myshell_create_record(file_name.c_str(), "key1", "value1"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + char value[256]; + result = fossil_myshell_read_record(file_name.c_str(), "key1", value, sizeof(value)); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(strcmp(value, "value1") == 0); + + fossil_myshell_delete_database(file_name.c_str()); +} + +// Test case for reading a non-existent record from the database file +FOSSIL_TEST_CASE(cpp_test_myshell_read_nonexistent_record) { + std::string file_name = "test.crabdb"; + fossil_myshell_create_database(file_name.c_str()); + + char value[256]; + fossil_myshell_error_t result = fossil_myshell_read_record(file_name.c_str(), "nonexistent_key", value, sizeof(value)); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil_myshell_delete_database(file_name.c_str()); +} + +// Test case for updating a non-existent record in the database file +FOSSIL_TEST_CASE(cpp_test_myshell_update_nonexistent_record) { + std::string file_name = "test.crabdb"; + fossil_myshell_create_database(file_name.c_str()); + + fossil_myshell_error_t result = fossil_myshell_update_record(file_name.c_str(), "nonexistent_key", "new_value"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil_myshell_delete_database(file_name.c_str()); +} + +// Test case for deleting a non-existent record from the database file +FOSSIL_TEST_CASE(cpp_test_myshell_delete_nonexistent_record) { + std::string file_name = "test.crabdb"; + fossil_myshell_create_database(file_name.c_str()); + + fossil_myshell_error_t result = fossil_myshell_delete_record(file_name.c_str(), "nonexistent_key"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil_myshell_delete_database(file_name.c_str()); +} + +// Test case for backing up and restoring a database file +FOSSIL_TEST_CASE(cpp_test_myshell_backup_restore) { + std::string file_name = "test.crabdb"; + std::string backup_file = "backup.crabdb"; + fossil_myshell_create_database(file_name.c_str()); + fossil_myshell_create_record(file_name.c_str(), "key1", "value1"); + + fossil_myshell_error_t result = fossil_myshell_backup_database(file_name.c_str(), backup_file.c_str()); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + fossil_myshell_delete_database(file_name.c_str()); + result = fossil_myshell_restore_database(backup_file.c_str(), file_name.c_str()); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + char value[256]; + result = fossil_myshell_read_record(file_name.c_str(), "key1", value, sizeof(value)); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(strcmp(value, "value1") == 0); + + fossil_myshell_delete_database(file_name.c_str()); + fossil_myshell_delete_database(backup_file.c_str()); +} + +// Test case for validating the file extension of a database file +FOSSIL_TEST_CASE(cpp_test_myshell_validate_extension) { + ASSUME_ITS_TRUE(fossil_myshell_validate_extension("test.crabdb")); + ASSUME_ITS_FALSE(fossil_myshell_validate_extension("test.txt")); +} + +// Test case for validating data +FOSSIL_TEST_CASE(cpp_test_myshell_validate_data) { + ASSUME_ITS_TRUE(fossil_myshell_validate_data("valid_data")); + ASSUME_ITS_FALSE(fossil_myshell_validate_data(NULL)); + ASSUME_ITS_FALSE(fossil_myshell_validate_data("")); +} + +// Test case for creating a new record using MyShell class +FOSSIL_TEST_CASE(cpp_test_myshell_class_create_record) { + std::string file_name = "test.crabdb"; + fossil::MyShell::createDatabase(file_name); + fossil_myshell_error_t result = fossil::MyShell::createRecord(file_name, "key1", "value1"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + std::string value; + result = fossil::MyShell::readRecord(file_name, "key1", value); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(value == "value1"); + + fossil::MyShell::deleteDatabase(file_name); +} + +// Test case for reading a non-existent record using MyShell class +FOSSIL_TEST_CASE(cpp_test_myshell_class_read_nonexistent_record) { + std::string file_name = "test.crabdb"; + fossil::MyShell::createDatabase(file_name); + + std::string value; + fossil_myshell_error_t result = fossil::MyShell::readRecord(file_name, "nonexistent_key", value); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil::MyShell::deleteDatabase(file_name); +} + +// Test case for updating a non-existent record using MyShell class +FOSSIL_TEST_CASE(cpp_test_myshell_class_update_nonexistent_record) { + std::string file_name = "test.crabdb"; + fossil::MyShell::createDatabase(file_name); + + fossil_myshell_error_t result = fossil::MyShell::updateRecord(file_name, "nonexistent_key", "new_value"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil::MyShell::deleteDatabase(file_name); +} + +// Test case for deleting a non-existent record using MyShell class +FOSSIL_TEST_CASE(cpp_test_myshell_class_delete_nonexistent_record) { + std::string file_name = "test.crabdb"; + fossil::MyShell::createDatabase(file_name); + + fossil_myshell_error_t result = fossil::MyShell::deleteRecord(file_name, "nonexistent_key"); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_NOT_FOUND); + + fossil::MyShell::deleteDatabase(file_name); +} + +// Test case for backing up and restoring a database using MyShell class +FOSSIL_TEST_CASE(cpp_test_myshell_class_backup_restore) { + std::string file_name = "test.crabdb"; + std::string backup_file = "backup.crabdb"; + fossil::MyShell::createDatabase(file_name); + fossil::MyShell::createRecord(file_name, "key1", "value1"); + + fossil_myshell_error_t result = fossil::MyShell::backupDatabase(file_name, backup_file); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + fossil::MyShell::deleteDatabase(file_name); + result = fossil::MyShell::restoreDatabase(backup_file, file_name); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + + std::string value; + result = fossil::MyShell::readRecord(file_name, "key1", value); + ASSUME_ITS_TRUE(result == FOSSIL_MYSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(value == "value1"); + + fossil::MyShell::deleteDatabase(file_name); + fossil::MyShell::deleteDatabase(backup_file); +} + +// Test case for validating the file extension using MyShell class +FOSSIL_TEST_CASE(cpp_test_myshell_class_validate_extension) { + ASSUME_ITS_TRUE(fossil::MyShell::validateExtension("test.crabdb")); + ASSUME_ITS_FALSE(fossil::MyShell::validateExtension("test.txt")); +} + +// Test case for validating data using MyShell class +FOSSIL_TEST_CASE(cpp_test_myshell_class_validate_data) { + ASSUME_ITS_TRUE(fossil::MyShell::validateData("valid_data")); + ASSUME_ITS_FALSE(fossil::MyShell::validateData(NULL)); + ASSUME_ITS_FALSE(fossil::MyShell::validateData("")); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * +FOSSIL_TEST_GROUP(cpp_myshell_database_tests) { + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_create_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_read_nonexistent_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_update_nonexistent_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_delete_nonexistent_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_backup_restore); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_validate_extension); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_validate_data); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_create_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_read_nonexistent_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_update_nonexistent_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_delete_nonexistent_record); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_backup_restore); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_validate_extension); + FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_validate_data); + + FOSSIL_TEST_REGISTER(cpp_myshell_fixture); +} // end of tests diff --git a/code/tests/cases/test_noshell.c b/code/tests/cases/test_noshell.c new file mode 100644 index 0000000..ee92202 --- /dev/null +++ b/code/tests/cases/test_noshell.c @@ -0,0 +1,179 @@ +/* + * ----------------------------------------------------------------------------- + * 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 + +#include "fossil/crabdb/framework.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilities +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_SUITE(c_noshell_fixture); + +FOSSIL_SETUP(c_noshell_fixture) { + // Setup the test fixture +} + +FOSSIL_TEARDOWN(c_noshell_fixture) { + // Teardown the test fixture +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Blue CrabDB Database +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Test case for creating a new database +FOSSIL_TEST_CASE(c_test_noshell_create_database) { + fossil_noshell_error_t result = fossil_noshell_create_database("test.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + remove("test.crabdb"); +} + +// Test case for opening an existing database +FOSSIL_TEST_CASE(c_test_noshell_open_database) { + FILE *file = fopen("test.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_open_database("test.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + remove("test.crabdb"); +} + +// Test case for deleting a database +FOSSIL_TEST_CASE(c_test_noshell_delete_database) { + FILE *file = fopen("test.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_delete_database("test.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); +} + +// Test case for inserting a document into the database +FOSSIL_TEST_CASE(c_test_noshell_insert_document) { + FILE *file = fopen("test.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_insert("test.crabdb", "document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + remove("test.crabdb"); +} + +// Test case for finding a document in the database +FOSSIL_TEST_CASE(c_test_noshell_find_document) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + char result[256]; + fossil_noshell_error_t error = fossil_noshell_find("test.crabdb", "document1", result, sizeof(result)); + ASSUME_ITS_TRUE(error == FOSSIL_NOSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(strcmp(result, "document1\n") == 0); + remove("test.crabdb"); +} + +// Test case for updating a document in the database +FOSSIL_TEST_CASE(c_test_noshell_update_document) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_update("test.crabdb", "document1", "new_document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + char updated_result[256]; + fossil_noshell_find("test.crabdb", "new_document1", updated_result, sizeof(updated_result)); + ASSUME_ITS_TRUE(strcmp(updated_result, "new_document1\n") == 0); + remove("test.crabdb"); +} + +// Test case for removing a document from the database +FOSSIL_TEST_CASE(c_test_noshell_remove_document) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_remove("test.crabdb", "document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + char removed_result[256]; + fossil_noshell_error_t error = fossil_noshell_find("test.crabdb", "document1", removed_result, sizeof(removed_result)); + ASSUME_ITS_TRUE(error == FOSSIL_NOSHELL_ERROR_NOT_FOUND); + remove("test.crabdb"); +} + +// Test case for backing up a database +FOSSIL_TEST_CASE(c_test_noshell_backup_database) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_backup_database("test.crabdb", "backup.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + FILE *backup = fopen("backup.crabdb", "r"); + ASSUME_NOT_CNULL(backup); + char buffer[256]; + fgets(buffer, sizeof(buffer), backup); + ASSUME_ITS_TRUE(strcmp(buffer, "document1\n") == 0); + fclose(backup); + remove("test.crabdb"); + remove("backup.crabdb"); +} + +// Test case for restoring a database from a backup +FOSSIL_TEST_CASE(c_test_noshell_restore_database) { + FILE *backup = fopen("backup.crabdb", "w"); + fprintf(backup, "document1\n"); + fclose(backup); + fossil_noshell_error_t result = fossil_noshell_restore_database("backup.crabdb", "restored.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + FILE *restored = fopen("restored.crabdb", "r"); + ASSUME_NOT_CNULL(restored); + char buffer[256]; + fgets(buffer, sizeof(buffer), restored); + ASSUME_ITS_TRUE(strcmp(buffer, "document1\n") == 0); + fclose(restored); + remove("backup.crabdb"); + remove("restored.crabdb"); +} + +// Test case for validating the file extension +FOSSIL_TEST_CASE(c_test_noshell_validate_extension) { + bool result = fossil_noshell_validate_extension("test.crabdb"); + ASSUME_ITS_TRUE(result); + result = fossil_noshell_validate_extension("test.txt"); + ASSUME_ITS_FALSE(result); +} + +// Test case for validating a document +FOSSIL_TEST_CASE(c_test_noshell_validate_document) { + bool result = fossil_noshell_validate_document("document1"); + ASSUME_ITS_TRUE(result); + result = fossil_noshell_validate_document(""); + ASSUME_ITS_FALSE(result); + result = fossil_noshell_validate_document(NULL); + ASSUME_ITS_FALSE(result); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * +FOSSIL_TEST_GROUP(c_noshell_database_tests) { + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_create_database); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_open_database); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_delete_database); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_insert_document); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_find_document); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_update_document); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_remove_document); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_backup_database); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_restore_database); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_validate_extension); + FOSSIL_TEST_ADD(c_noshell_fixture, c_test_noshell_validate_document); + + FOSSIL_TEST_REGISTER(c_noshell_fixture); +} // end of tests diff --git a/code/tests/cases/test_noshell.cpp b/code/tests/cases/test_noshell.cpp new file mode 100644 index 0000000..13bd021 --- /dev/null +++ b/code/tests/cases/test_noshell.cpp @@ -0,0 +1,316 @@ +/* + * ----------------------------------------------------------------------------- + * 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 + +#include "fossil/crabdb/framework.h" +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilities +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_SUITE(cpp_noshell_fixture); + +FOSSIL_SETUP(cpp_noshell_fixture) { + // Setup the test fixture +} + +FOSSIL_TEARDOWN(cpp_noshell_fixture) { + // Teardown the test fixture +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Blue CrabDB Database +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Test case for creating a new database +FOSSIL_TEST_CASE(cpp_test_noshell_create_database) { + fossil_noshell_error_t result = fossil_noshell_create_database("test.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::remove("test.crabdb"); +} + +// Test case for opening an existing database +FOSSIL_TEST_CASE(cpp_test_noshell_open_database) { + FILE *file = fopen("test.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_open_database("test.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::remove("test.crabdb"); +} + +// Test case for deleting a database +FOSSIL_TEST_CASE(cpp_test_noshell_delete_database) { + FILE *file = fopen("test.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_delete_database("test.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); +} + +// Test case for inserting a document into the database +FOSSIL_TEST_CASE(cpp_test_noshell_insert_document) { + FILE *file = fopen("test.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_insert("test.crabdb", "document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::remove("test.crabdb"); +} + +// Test case for finding a document in the database +FOSSIL_TEST_CASE(cpp_test_noshell_find_document) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + char result[256]; + fossil_noshell_error_t error = fossil_noshell_find("test.crabdb", "document1", result, sizeof(result)); + ASSUME_ITS_TRUE(error == FOSSIL_NOSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(strcmp(result, "document1\n") == 0); + std::remove("test.crabdb"); +} + +// Test case for updating a document in the database +FOSSIL_TEST_CASE(cpp_test_noshell_update_document) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_update("test.crabdb", "document1", "new_document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + char updated_result[256]; + fossil_noshell_find("test.crabdb", "new_document1", updated_result, sizeof(updated_result)); + ASSUME_ITS_TRUE(strcmp(updated_result, "new_document1\n") == 0); + std::remove("test.crabdb"); +} + +// Test case for removing a document from the database +FOSSIL_TEST_CASE(cpp_test_noshell_remove_document) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_remove("test.crabdb", "document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + char removed_result[256]; + fossil_noshell_error_t error = fossil_noshell_find("test.crabdb", "document1", removed_result, sizeof(removed_result)); + ASSUME_ITS_TRUE(error == FOSSIL_NOSHELL_ERROR_NOT_FOUND); + std::remove("test.crabdb"); +} + +// Test case for backing up a database +FOSSIL_TEST_CASE(cpp_test_noshell_backup_database) { + FILE *file = fopen("test.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil_noshell_backup_database("test.crabdb", "backup.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + FILE *backup = fopen("backup.crabdb", "r"); + ASSUME_NOT_CNULL(backup); + char buffer[256]; + fgets(buffer, sizeof(buffer), backup); + ASSUME_ITS_TRUE(strcmp(buffer, "document1\n") == 0); + fclose(backup); + std::remove("test.crabdb"); + std::remove("backup.crabdb"); +} + +// Test case for restoring a database from a backup +FOSSIL_TEST_CASE(cpp_test_noshell_restore_database) { + FILE *backup = fopen("backup.crabdb", "w"); + fprintf(backup, "document1\n"); + fclose(backup); + fossil_noshell_error_t result = fossil_noshell_restore_database("backup.crabdb", "restored.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + FILE *restored = fopen("restored.crabdb", "r"); + ASSUME_NOT_CNULL(restored); + char buffer[256]; + fgets(buffer, sizeof(buffer), restored); + ASSUME_ITS_TRUE(strcmp(buffer, "document1\n") == 0); + fclose(restored); + std::remove("backup.crabdb"); + std::remove("restored.crabdb"); +} + +// Test case for validating the file extension +FOSSIL_TEST_CASE(cpp_test_noshell_validate_extension) { + bool result = fossil_noshell_validate_extension("test.crabdb"); + ASSUME_ITS_TRUE(result); + result = fossil_noshell_validate_extension("test.txt"); + ASSUME_ITS_FALSE(result); +} + +// Test case for validating a document +FOSSIL_TEST_CASE(cpp_test_noshell_validate_document) { + bool result = fossil_noshell_validate_document("document1"); + ASSUME_ITS_TRUE(result); + result = fossil_noshell_validate_document(""); + ASSUME_ITS_FALSE(result); + result = fossil_noshell_validate_document(NULL); + ASSUME_ITS_FALSE(result); +} + +// Test case for creating a new database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_create_database) { + fossil_noshell_error_t result = fossil::NoShell::createDatabase("test_class.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::remove("test_class.crabdb"); +} + +// Test case for opening an existing database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_open_database) { + FILE *file = fopen("test_class.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil::NoShell::openDatabase("test_class.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::remove("test_class.crabdb"); +} + +// Test case for deleting a database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_delete_database) { + FILE *file = fopen("test_class.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil::NoShell::deleteDatabase("test_class.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); +} + +// Test case for inserting a document into the database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_insert_document) { + FILE *file = fopen("test_class.crabdb", "w"); + fclose(file); + fossil_noshell_error_t result = fossil::NoShell::insert("test_class.crabdb", "document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::remove("test_class.crabdb"); +} + +// Test case for finding a document in the database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_find_document) { + FILE *file = fopen("test_class.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + std::string result; + fossil_noshell_error_t error = fossil::NoShell::find("test_class.crabdb", "document1", result); + ASSUME_ITS_TRUE(error == FOSSIL_NOSHELL_ERROR_SUCCESS); + ASSUME_ITS_TRUE(result == "document1\n"); + std::remove("test_class.crabdb"); +} + +// Test case for updating a document in the database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_update_document) { + FILE *file = fopen("test_class.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil::NoShell::update("test_class.crabdb", "document1", "new_document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::string updated_result; + fossil::NoShell::find("test_class.crabdb", "new_document1", updated_result); + ASSUME_ITS_TRUE(updated_result == "new_document1\n"); + std::remove("test_class.crabdb"); +} + +// Test case for removing a document from the database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_remove_document) { + FILE *file = fopen("test_class.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil::NoShell::remove("test_class.crabdb", "document1"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + std::string removed_result; + fossil_noshell_error_t error = fossil::NoShell::find("test_class.crabdb", "document1", removed_result); + ASSUME_ITS_TRUE(error == FOSSIL_NOSHELL_ERROR_NOT_FOUND); + std::remove("test_class.crabdb"); +} + +// Test case for backing up a database using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_backup_database) { + FILE *file = fopen("test_class.crabdb", "w"); + fprintf(file, "document1\n"); + fclose(file); + fossil_noshell_error_t result = fossil::NoShell::backupDatabase("test_class.crabdb", "backup_class.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + FILE *backup = fopen("backup_class.crabdb", "r"); + ASSUME_NOT_CNULL(backup); + char buffer[256]; + fgets(buffer, sizeof(buffer), backup); + ASSUME_ITS_TRUE(strcmp(buffer, "document1\n") == 0); + fclose(backup); + std::remove("test_class.crabdb"); + std::remove("backup_class.crabdb"); +} + +// Test case for restoring a database from a backup using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_restore_database) { + FILE *backup = fopen("backup_class.crabdb", "w"); + fprintf(backup, "document1\n"); + fclose(backup); + fossil_noshell_error_t result = fossil::NoShell::restoreDatabase("backup_class.crabdb", "restored_class.crabdb"); + ASSUME_ITS_TRUE(result == FOSSIL_NOSHELL_ERROR_SUCCESS); + FILE *restored = fopen("restored_class.crabdb", "r"); + ASSUME_NOT_CNULL(restored); + char buffer[256]; + fgets(buffer, sizeof(buffer), restored); + ASSUME_ITS_TRUE(strcmp(buffer, "document1\n") == 0); + fclose(restored); + std::remove("backup_class.crabdb"); + std::remove("restored_class.crabdb"); +} + +// Test case for validating the file extension using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_validate_extension) { + bool result = fossil::NoShell::validateExtension("test_class.crabdb"); + ASSUME_ITS_TRUE(result); + result = fossil::NoShell::validateExtension("test.txt"); + ASSUME_ITS_FALSE(result); +} + +// Test case for validating a document using NoShell class +FOSSIL_TEST_CASE(cpp_test_noshell_class_validate_document) { + bool result = fossil::NoShell::validateDocument("document1"); + ASSUME_ITS_TRUE(result); + result = fossil::NoShell::validateDocument(""); + ASSUME_ITS_FALSE(result); + result = fossil::NoShell::validateDocument(NULL); + ASSUME_ITS_FALSE(result); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * +FOSSIL_TEST_GROUP(cpp_noshell_database_tests) { + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_create_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_open_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_delete_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_insert_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_find_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_update_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_remove_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_backup_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_restore_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_validate_extension); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_validate_document); + + // Adding new class-based test cases + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_create_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_open_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_delete_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_insert_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_find_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_update_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_remove_document); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_backup_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_restore_database); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_validate_extension); + FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_validate_document); + + FOSSIL_TEST_REGISTER(cpp_noshell_fixture); +} // end of tests From 226e96e0656a6de6044590bbfe9580f33f4bd9e4 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 2 Jan 2025 12:58:53 -0600 Subject: [PATCH 06/10] remove old file from list --- code/logic/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/logic/meson.build b/code/logic/meson.build index 6b013c2..2c746ab 100644 --- a/code/logic/meson.build +++ b/code/logic/meson.build @@ -6,7 +6,7 @@ dep = [ ] fossil_crabdb_lib = library('fossil-crabdb', - files('database.c', 'myshell.c', 'noshell.c'), + files('myshell.c', 'noshell.c'), install: true, dependencies: dep, include_directories: dir) From 81568de7afd0fa203252e6c5d59d1100037bbb4c Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 2 Jan 2025 12:59:01 -0600 Subject: [PATCH 07/10] add comment --- code/tests/cases/test_myshell.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/tests/cases/test_myshell.cpp b/code/tests/cases/test_myshell.cpp index 4ad4262..495441f 100644 --- a/code/tests/cases/test_myshell.cpp +++ b/code/tests/cases/test_myshell.cpp @@ -218,6 +218,8 @@ FOSSIL_TEST_GROUP(cpp_myshell_database_tests) { FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_backup_restore); FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_validate_extension); FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_validate_data); + + // Adding new class-based test cases FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_create_record); FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_read_nonexistent_record); FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_update_nonexistent_record); From 212652594d5110b1e276ecc08d2b152948c67044 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 2 Jan 2025 13:32:06 -0600 Subject: [PATCH 08/10] rm unused functions --- code/logic/fossil/crabdb/myshell.h | 18 ------------------ code/logic/fossil/crabdb/noshell.h | 18 ------------------ code/logic/myshell.c | 4 ---- code/logic/noshell.c | 4 ---- 4 files changed, 44 deletions(-) diff --git a/code/logic/fossil/crabdb/myshell.h b/code/logic/fossil/crabdb/myshell.h index dd735c5..30e8855 100644 --- a/code/logic/fossil/crabdb/myshell.h +++ b/code/logic/fossil/crabdb/myshell.h @@ -115,14 +115,6 @@ fossil_myshell_error_t fossil_myshell_create_database(const char *file_name); */ fossil_myshell_error_t fossil_myshell_open_database(const char *file_name); -/** - * @brief Closes an open database file. - * - * @param file_name The name of the database file. - * @return 0 on success, non-zero on error. - */ -fossil_myshell_error_t fossil_myshell_close_database(const char *file_name); - /** * @brief Deletes a database file. * @@ -264,16 +256,6 @@ class MyShell { return fossil_myshell_open_database(fileName.c_str()); } - /** - * @brief Closes an open database file. - * - * @param fileName The name of the database file. - * @return 0 on success, non-zero on error. - */ - static fossil_myshell_error_t closeDatabase(const std::string &fileName) { - return fossil_myshell_close_database(fileName.c_str()); - } - /** * @brief Deletes a database file. * diff --git a/code/logic/fossil/crabdb/noshell.h b/code/logic/fossil/crabdb/noshell.h index 8b135f2..fb011cc 100644 --- a/code/logic/fossil/crabdb/noshell.h +++ b/code/logic/fossil/crabdb/noshell.h @@ -113,14 +113,6 @@ fossil_noshell_error_t fossil_noshell_create_database(const char *file_name); */ fossil_noshell_error_t fossil_noshell_open_database(const char *file_name); -/** - * @brief Closes an open database file. - * - * @param file_name The name of the database file. - * @return 0 on success, non-zero on error. - */ -fossil_noshell_error_t fossil_noshell_close_database(const char *file_name); - /** * @brief Deletes a database file. * @@ -249,16 +241,6 @@ class NoShell { return fossil_noshell_open_database(file_name.c_str()); } - /** - * @brief Closes an open database file. - * - * @param file_name The name of the database file. - * @return 0 on success, non-zero on error. - */ - static fossil_noshell_error_t closeDatabase(const std::string &file_name) { - return fossil_noshell_close_database(file_name.c_str()); - } - /** * @brief Deletes a database file. * diff --git a/code/logic/myshell.c b/code/logic/myshell.c index c10b923..7652f96 100644 --- a/code/logic/myshell.c +++ b/code/logic/myshell.c @@ -144,10 +144,6 @@ fossil_myshell_error_t fossil_myshell_open_database(const char *file_name) { return FOSSIL_MYSHELL_ERROR_SUCCESS; } -fossil_myshell_error_t fossil_myshell_close_database(const char *file_name) { - return FOSSIL_MYSHELL_ERROR_SUCCESS; // No specific action required for closure. -} - fossil_myshell_error_t fossil_myshell_delete_database(const char *file_name) { if (remove(file_name) == 0) { return FOSSIL_MYSHELL_ERROR_SUCCESS; diff --git a/code/logic/noshell.c b/code/logic/noshell.c index d71653a..7422d7c 100644 --- a/code/logic/noshell.c +++ b/code/logic/noshell.c @@ -147,10 +147,6 @@ fossil_noshell_error_t fossil_noshell_open_database(const char *file_name) { return FOSSIL_NOSHELL_ERROR_SUCCESS; } -fossil_noshell_error_t fossil_noshell_close_database(const char *file_name) { - return FOSSIL_NOSHELL_ERROR_SUCCESS; // No specific action required for closure. -} - fossil_noshell_error_t fossil_noshell_delete_database(const char *file_name) { if (remove(file_name) == 0) { return FOSSIL_NOSHELL_ERROR_SUCCESS; From ae0f75de4fb1a752c3541921e3f78d15e4269785 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 2 Jan 2025 13:54:27 -0600 Subject: [PATCH 09/10] fix cases --- code/tests/cases/test_myshell.cpp | 8 -------- code/tests/cases/test_noshell.cpp | 11 ----------- 2 files changed, 19 deletions(-) diff --git a/code/tests/cases/test_myshell.cpp b/code/tests/cases/test_myshell.cpp index 495441f..f8dceb9 100644 --- a/code/tests/cases/test_myshell.cpp +++ b/code/tests/cases/test_myshell.cpp @@ -200,13 +200,6 @@ FOSSIL_TEST_CASE(cpp_test_myshell_class_validate_extension) { ASSUME_ITS_FALSE(fossil::MyShell::validateExtension("test.txt")); } -// Test case for validating data using MyShell class -FOSSIL_TEST_CASE(cpp_test_myshell_class_validate_data) { - ASSUME_ITS_TRUE(fossil::MyShell::validateData("valid_data")); - ASSUME_ITS_FALSE(fossil::MyShell::validateData(NULL)); - ASSUME_ITS_FALSE(fossil::MyShell::validateData("")); -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -226,7 +219,6 @@ FOSSIL_TEST_GROUP(cpp_myshell_database_tests) { FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_delete_nonexistent_record); FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_backup_restore); FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_validate_extension); - FOSSIL_TEST_ADD(cpp_myshell_fixture, cpp_test_myshell_class_validate_data); FOSSIL_TEST_REGISTER(cpp_myshell_fixture); } // end of tests diff --git a/code/tests/cases/test_noshell.cpp b/code/tests/cases/test_noshell.cpp index 13bd021..2496e9d 100644 --- a/code/tests/cases/test_noshell.cpp +++ b/code/tests/cases/test_noshell.cpp @@ -273,16 +273,6 @@ FOSSIL_TEST_CASE(cpp_test_noshell_class_validate_extension) { ASSUME_ITS_FALSE(result); } -// Test case for validating a document using NoShell class -FOSSIL_TEST_CASE(cpp_test_noshell_class_validate_document) { - bool result = fossil::NoShell::validateDocument("document1"); - ASSUME_ITS_TRUE(result); - result = fossil::NoShell::validateDocument(""); - ASSUME_ITS_FALSE(result); - result = fossil::NoShell::validateDocument(NULL); - ASSUME_ITS_FALSE(result); -} - // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Pool // * * * * * * * * * * * * * * * * * * * * * * * * @@ -310,7 +300,6 @@ FOSSIL_TEST_GROUP(cpp_noshell_database_tests) { FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_backup_database); FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_restore_database); FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_validate_extension); - FOSSIL_TEST_ADD(cpp_noshell_fixture, cpp_test_noshell_class_validate_document); FOSSIL_TEST_REGISTER(cpp_noshell_fixture); } // end of tests From d55ed30a84f31a743cb807275a5ab5fb6285d8c4 Mon Sep 17 00:00:00 2001 From: "Michael Gene Brockus (Dreamer)" Date: Thu, 2 Jan 2025 14:00:28 -0600 Subject: [PATCH 10/10] from 0.2.0 to 0.2.1 --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 58c6392..ea92e4f 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project('Fossil Blue Crab', 'c', 'cpp', meson_version: '>=1.3.0', license: 'MPL-2.0', - version: '0.2.0', + version: '0.2.1', default_options: ['c_std=c17,c18', 'cpp_std=c++20']) subdir('code')