LongBowString * longBowString_Create(const size_t initialSize) { LongBowString *result = longBowMemory_Allocate(sizeof(LongBowString)); result->end = initialSize; result->buffer = longBowMemory_Allocate(initialSize); result->cursor = 0; return result; }
LongBowTestCaseClipBoard * longBowTestCaseClipBoard_Create(void *shared) { LongBowTestCaseClipBoard *result = longBowMemory_Allocate(sizeof(LongBowTestCaseClipBoard)); longBowTestCaseClipBoard_Set(result, shared); return result; }
LongBowString * longBowString_CreateString(const char *string) { LongBowString *result = longBowMemory_Allocate(sizeof(LongBowString)); result->end = strlen(string) + 1; result->buffer = longBowMemory_StringCopy(string); result->cursor = result->end - 1; result->buffer[result->cursor] = 0; return result; }
LongBowProperties * longBowProperties_Create(void) { LongBowProperties *result = longBowMemory_Allocate(sizeof(LongBowProperties)); if (result != NULL) { result->list = longBowArrayList_Create((void (*)(void **)) _property_Destroy); } return result; }
LongBowArrayList * longBowArrayList_Create(void (*destroyElement)(void **elementAddress)) { LongBowArrayList *result = longBowMemory_Allocate(sizeof(LongBowArrayList)); if (result != NULL) { result->numberOfElements = 0; result->limit = 0; result->array = NULL; result->destroyElement = destroyElement; } return result; }
LongBowSubProcess * longBowSubProcess_Exec(const char *path, ... /*, (char *)0 */) { va_list ap; va_start(ap, path); size_t count = 0; for (char *arg = va_arg(ap, char *); arg != NULL; arg = va_arg(ap, char *)) { count++; } LongBowSubProcess *result = longBowMemory_Allocate(sizeof(LongBowSubProcess)); result->path = path; longBowMemory_Allocate(sizeof(char *) * count + 1); va_end(ap); // This relies on the last element being all zeros. va_start(ap, path); for (size_t i = 0; i < count; i++) { result->arguments[i] = va_arg(ap, char *); } va_end(ap); result->pid = fork(); if (result->pid == 0) { _resetAllSignals(); printf("Exec %s\n", result->path); int error = execv(result->path, result->arguments); printf("Error %d\n", error); perror(path); exit(1); } printf("Process group child=%d, parent=%d\n", getpgid(result->pid), getpgrp()); return result; }
LongBowArrayList * longBowArrayList_Copy(const LongBowArrayList *original) { longBowArrayList_AssertValid(original); LongBowArrayList *result = longBowMemory_Allocate(sizeof(LongBowArrayList)); if (result != NULL) { for (size_t i = 0; i < original->numberOfElements; i++) { longBowArrayList_Add(result, original->array[i]); } } return result; }
bool longBowProperties_Set(LongBowProperties *properties, const char *name, const char *value) { bool result = false; _Property *property = _longBowProperties_Get(properties, name); if (property == NULL) { property = longBowMemory_Allocate(sizeof(_Property)); property->name = longBowMemory_StringCopy(name); property->value = longBowMemory_StringCopy(value); longBowArrayList_Add(properties->list, property); result = true; } else { longBowMemory_Deallocate((void **) &property->value); property->value = longBowMemory_StringCopy(value); } return result; }
LongBowTestCase * longBowTestCase_Create(const char *testCaseName, const LongBowTestFixture *testFixture, LongBowTestCaseFunction *testCase, const LongBowTestCaseMetaData *metaData) { assert(testCaseName != NULL); LongBowTestCase *result = longBowMemory_Allocate(sizeof(LongBowTestCase)); if (result != NULL) { result->testCaseName = testCaseName; int status = asprintf(&result->fullName, "%s/%s", longBowTestFixture_GetFullName(testFixture), testCaseName); assert(status != -1); result->fixture = testFixture; result->testCase = testCase; result->runtime = longBowRuntime_Create(&metaData->expectedResult, longBowTestRunner_GetConfiguration(longBowTestFixture_GetRunner(testFixture))); result->metaData = metaData; } return result; }
LongBowConfig * longBowConfig_Create(int argc, char *argv[], const char *mainFileName) { LongBowConfig *result = longBowMemory_Allocate(sizeof(LongBowConfig)); result->properties = longBowProperties_Create(); longBowProperties_Set(result->properties, "trace", "false"); longBowProperties_Set(result->properties, "silent", "false"); longBowProperties_Set(result->properties, "run-forked", "false"); for (int i = 1; i < argc; i++) { if (longBowString_Equals("--help", argv[i]) || longBowString_Equals("-h", argv[i])) { // If the option is "--help", // then let all of the sub-systems that also take arguments process that option also. printf("LongBow %s\n", longBowAbout_Version()); printf("%s\n", longBowAbout_MiniNotice()); printf("Options\n"); //printf(" --main Print the name of the main test runner source file.\n"); printf(" --help Print this help message.\n"); printf(" --run-forked Run the tests as forked processes.\n"); printf(" --run-nonforked Run the tests in the same process (default).\n"); printf(" --version Print the version of LongBow used for this test.\n"); printf(" --core-dump Produce a core file upon the first failed assertion.\n"); printf(" --set name=value Set a configuration property name to the specified value\n"); longBowTestRunner_ConfigHelp(); longBowTestFixture_ConfigHelp(); longBowTestCase_ConfigHelp(); longBowReportRuntime_Create(argc, argv); longBowConfig_Destroy(&result); printf("\n"); return NULL; } else if (longBowString_Equals("--main", argv[i])) { printf("%s\n", mainFileName); longBowConfig_Destroy(&result); return NULL; } else if (longBowString_Equals("--version", argv[i])) { printf("%s\n", longBowAbout_Version()); longBowConfig_Destroy(&result); return NULL; } else if (longBowString_Equals("--run-nonforked", argv[i])) { longBowProperties_Set(result->properties, "run-forked", "false"); } else if (longBowString_Equals("--run-forked", argv[i])) { printf("?\n"); longBowProperties_Set(result->properties, "run-forked", "true"); } else if (longBowString_Equals("--trace", argv[i])) { longBowProperties_Set(result->properties, "trace", "true"); } else if (longBowString_Equals("--silent", argv[i])) { longBowProperties_Set(result->properties, "silent", "true"); } else if (longBowString_Equals("--core-dump", argv[i])) { longBowProperties_Set(result->properties, "core-dump", "true"); } else if (longBowString_StartsWith(argv[i], "--set")) { char *parameter = argv[++i]; if (_longBowConfig_Set(result, parameter) == false) { printf("Could not set parameter: %s\n", parameter); } } else if (longBowString_StartsWith(argv[i], "--show")) { _longBowConfig_Show(result); } else { printf("Unknown option '%s'\n", argv[i]); } } LongBowReportConfig *reportConfiguration = longBowReportRuntime_Create(argc, argv); if (reportConfiguration == NULL) { longBowConfig_Destroy(&result); result = NULL; } else { if (result == NULL) { // nothing to do. } else { result->reportConfiguration = reportConfiguration; } } if (result != NULL) { _longBowConfig_SetupEnvironment(result); } return result; }