From ccf13ba4704dcc02dfaa6ad2de87a0de5d85f1de Mon Sep 17 00:00:00 2001 From: herbglitch Date: Tue, 11 Mar 2025 00:41:24 -0600 Subject: [PATCH] renamed chemical to config, and renamed life to entity --- include/arc/std/entity.h | 36 ++++++++++ src/std/entity.c | 3 + tests/res/std/config/first.chemical | 5 ++ tests/std/config.c | 108 ++++++++++++++++++++++++++++ tests/std/entity.c | 5 ++ 5 files changed, 157 insertions(+) create mode 100644 include/arc/std/entity.h create mode 100644 src/std/entity.c create mode 100644 tests/res/std/config/first.chemical create mode 100644 tests/std/config.c create mode 100644 tests/std/entity.c diff --git a/include/arc/std/entity.h b/include/arc/std/entity.h new file mode 100644 index 0000000..a6dd54e --- /dev/null +++ b/include/arc/std/entity.h @@ -0,0 +1,36 @@ +#ifndef ARC_STD_ENTITY_H_ +#define ARC_STD_ENTITY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * @brief an entity component system type +*/ +typedef struct ARC_EntitySystem ARC_EntitySystem; + +/** + * @brief an entity component system type +*/ +typedef uint32_t ARC_Entity; + +/** + * @brief +*/ +void ARC_EntitySystem_Create(ARC_EntitySystem **entitySystem); + +/** + * @brief destroys an ARC_EntitySystem + * + * @param[in] vector ARC_EntitySystem to free +*/ +void ARC_EntitySystem_Destroy(ARC_EntitySystem *entitySystem); + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_STD_ENTITY_H_ diff --git a/src/std/entity.c b/src/std/entity.c new file mode 100644 index 0000000..c5bbcfb --- /dev/null +++ b/src/std/entity.c @@ -0,0 +1,3 @@ +#include "arc/std/entity.h" + + diff --git a/tests/res/std/config/first.chemical b/tests/res/std/config/first.chemical new file mode 100644 index 0000000..392097c --- /dev/null +++ b/tests/res/std/config/first.chemical @@ -0,0 +1,5 @@ +group test { + int32 test = 5; + + int32 test1 = -7; +} diff --git a/tests/std/config.c b/tests/std/config.c new file mode 100644 index 0000000..aa711e1 --- /dev/null +++ b/tests/std/config.c @@ -0,0 +1,108 @@ +#include "../test.h" +#include "arc/std/errno.h" +#include "arc/std/config.h" +#include "arc/std/parser.h" +#include "arc/std/parser/helpers.h" +#include + +static const char *testType = "int32"; + +void TEST_configType_CopyInt32Fn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config){ + //go into the tag + ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0); + if(childTagToken->id != ARC_CONFIG_NUMBER_SIGN){ + arc_errno = ARC_ERRNO_DATA; + ARC_DEBUG_LOG_ERROR("TEST_configType_CopyInt32Fn(type, parsedData, config), parsed data was not a "); + *type = NULL; + return; + } + + //check if the first tag is a minus sign and create a string starting with that if it is + childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 0); + ARC_String *int32String; + ARC_String_Create(&int32String, NULL, 0); + if(childTagToken->id == ARC_CONFIG_MINUS){ + ARC_String_AppendCStringWithStrlen(&int32String, "-"); + } + + ARC_ParserData_HelperRecurseStringAdd(&int32String, parsedData); + + //set the max character size 2,147,483,647 (10 characters) or -2,147,483,648 (11 characters) + uint32_t maxInt32Size = 10; + if(int32String->data[0] == '-'){ + maxInt32Size++; + } + + //if the string is bigger than the possible size return NULL and error + if(int32String->length > maxInt32Size){ + arc_errno = ARC_ERRNO_DATA; + ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("TEST_configType_CopyInt32Fn(type, parsedData, config), size \"%s\" was bigger or smaller than the max 2,147,483,647 or min -2,147,483,648", int32String->data); + *type = NULL; + ARC_String_Destroy(int32String); + return; + } + + if(int32String->length == maxInt32Size){ + char maxint32CStr[10] = "2147483647"; + + //offset starting index and last number if there is a negative + uint8_t stringIndex = 0; + if(int32String->data[0] == '-'){ + stringIndex++; + maxint32CStr[9]++; + } + + for(uint8_t index = 0; index < 10; index++, stringIndex++){ + if(int32String->data[stringIndex] > maxint32CStr[index]){ + arc_errno = ARC_ERRNO_DATA; + ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("TEST_configType_CopyInt32Fn(type, parsedData, config), size \"%s\" was bigger or smaller than the max 2,147,483,647 or min -2,147,483,648", int32String->data); + *type = NULL; + ARC_String_Destroy(int32String); + return; + } + } + } + + //copy the int32_t + *type = malloc(sizeof(int32_t)); + *(int32_t *)(*type) = (int32_t)ARC_String_ToInt64_t(int32String); + + //cleanup + ARC_String_Destroy(int32String); +} + +void TEST_configType_DestroyInt32Fn(void *type){ + free((int32_t *)type); +} + +ARC_TEST(config_BasicTest){ + ARC_Config *config; + ARC_Config_Create(&config); + + ARC_CHECK(arc_errno == 0); + + ARC_ConfigType int32Type = { + TEST_configType_CopyInt32Fn, + TEST_configType_DestroyInt32Fn + }; + ARC_Config_RegisterTypeWithCStr(config, testType, int32Type); + + char *tempCString = "tests/res/std/config/first.chemical"; + ARC_String *tempString; + ARC_String_CreateWithStrlen(&tempString, tempCString); + ARC_Config_LoadFromFile(config, tempString); + + int32_t testVal = *(int32_t *)ARC_Config_GetWithCStr(config, "test::test"); + ARC_CHECK(testVal == 5); + testVal = *(int32_t *)ARC_Config_GetWithCStr(config, "test::test1"); + ARC_CHECK(testVal == -7); + + ARC_Config_UnloadFromFile(config, tempString); + + void *nullVal = ARC_Config_GetWithCStr(config, "test::test"); + ARC_CHECK(nullVal == NULL); + + //cleanup + ARC_String_Destroy(tempString); + ARC_Config_Destroy(config); +} diff --git a/tests/std/entity.c b/tests/std/entity.c new file mode 100644 index 0000000..cf524e9 --- /dev/null +++ b/tests/std/entity.c @@ -0,0 +1,5 @@ +#include "../test.h" +#include "arc/std/entity.h" + +ARC_TEST(Entity_Init){ +}