boolByte copyFileToDirectory(const CharString fileAbsolutePath, const CharString directoryAbsolutePath) { boolByte result = false; CharString fileOutPath = newCharStringWithCapacity(kCharStringLengthLong); CharString fileBasename = NULL; FILE *input = NULL; FILE *output = NULL; char ch; fileBasename = newCharStringWithCString(getFileBasename(fileAbsolutePath->data)); buildAbsolutePath(directoryAbsolutePath, fileBasename, NULL, fileOutPath); input = fopen(fileAbsolutePath->data, "rb"); if(input != NULL) { output = fopen(fileOutPath->data, "wb"); if(output != NULL) { while(fread(&ch, 1, 1, input) == 1) { fwrite(&ch, 1, 1, output); } result = true; } } if(input != NULL) { fclose(input); } if(output != NULL) { fclose(output); } freeCharString(fileOutPath); freeCharString(fileBasename); return result; }
static int _testLoadPluginWithAbsolutePath(const char *testName, const CharString applicationPath, const CharString resourcesPath) { File resourcesFile = newFileWithPath(resourcesPath); CharString vstDirName = newCharStringWithCString("vst"); File vstFile = newFileWithParent(resourcesFile, vstDirName); freeFile(resourcesFile); freeCharString(vstDirName); PlatformInfo platformInfo = newPlatformInfo(); CharString platformDirName = newCharStringWithCString(_getPlatformVstDirName(platformInfo)); File vstPlatformFile = newFileWithParent(vstFile, platformDirName); freeCharString(platformDirName); freePlatformInfo(platformInfo); freeFile(vstFile); CharString vstPluginName = newCharStringWithCString("again"); charStringAppendCString(vstPluginName, _getVst2xPlatformExtension()); File pluginFile = newFileWithParent(vstPlatformFile, vstPluginName); freeCharString(vstPluginName); freeFile(vstPlatformFile); CharString inputPath = getDefaultInputPath(resourcesPath); int result = runIntegrationTest( testName, buildTestArgumentString("--plugin \"%s\" --input \"%s\"", pluginFile->absolutePath->data, inputPath->data), RETURN_CODE_SUCCESS, kTestOutputPcm, applicationPath, resourcesPath); freeCharString(inputPath); freeFile(pluginFile); return result; }
void freeTaskTimer(TaskTimer self) { if(self != NULL) { freeCharString(self->component); freeCharString(self->subcomponent); free(self); } }
void freeErrorReporter(ErrorReporter errorReporter) { if (errorReporter != NULL) { freeCharString(errorReporter->reportName); freeCharString(errorReporter->reportDirPath); freeCharString(errorReporter->desktopPath); free(errorReporter); } }
void errorReporterRemapPath(ErrorReporter self, CharString path) { CharString basename = newCharString(); CharString outString = newCharStringWithCapacity(path->capacity); charStringCopyCString(basename, getFileBasename(path->data)); buildAbsolutePath(self->reportDirPath, basename, NULL, outString); charStringCopy(path, outString); freeCharString(basename); freeCharString(outString); }
static int _testBuildAbsolutePathNullFile(void) { CharString d = getCurrentDirectory(); CharString out = newCharString(); buildAbsolutePath(d, NULL, NULL, out); assert(charStringIsEmpty(out)); freeCharString(d); freeCharString(out); return 0; }
static int _testBuildAbsolutePathNullPath(void) { CharString f = newCharString(); CharString out = newCharString(); buildAbsolutePath(NULL, f, NULL, out); assert(charStringIsEmpty(out)); freeCharString(f); freeCharString(out); return 0; }
static int _testPluginFactoryEmptyPluginName(void) { CharString invalid = newCharString(); CharString pluginRoot = newCharString(); Plugin p = pluginFactory(invalid, pluginRoot); assertIsNull(p); freeCharString(invalid); freeCharString(pluginRoot); freePlugin(p); return 0; }
static int _testPluginFactoryInvalidPlugin(void) { CharString invalid = newCharStringWithCString("invalid"); CharString pluginRoot = newCharString(); Plugin p = pluginFactory(invalid, pluginRoot); assertIsNull(p); freeCharString(invalid); freeCharString(pluginRoot); freePlugin(p); return 0; }
static int _testBuildAbsolutePathEmptyPath(void) { CharString d = newCharString(); CharString f = newCharStringWithCString(TEST_FILENAME); CharString out = newCharString(); buildAbsolutePath(d, f, NULL, out); assert(charStringIsEmpty(out)); freeCharString(d); freeCharString(f); freeCharString(out); return 0; }
boolByte errorReporterShouldCopyPlugins(void) { CharString promptText = newCharStringWithCString(kErrorReportCopyPluginsPromptText); CharString wrappedPromptText; char response; wrappedPromptText = charStringWrap(promptText, 0); printf("%s", wrappedPromptText->data); freeCharString(wrappedPromptText); freeCharString(promptText); response = getchar(); return (response == 'y' || response == 'Y'); }
static void printVersion(void) { CharString versionString = buildInfoGetVersionString(); CharString wrappedLicenseInfo; CharString licenseString = newCharStringWithCString(LICENSE_STRING); printf("%s, build %ld\nCopyright (c) %ld, %s. All rights reserved.\n\n", versionString->data, buildInfoGetDatestamp(), buildInfoGetYear(), VENDOR_NAME); wrappedLicenseInfo = charStringWrap(licenseString, 0); printf("%s\n\n", wrappedLicenseInfo->data); freeCharString(licenseString); freeCharString(wrappedLicenseInfo); freeCharString(versionString); }
static int _testCopyInvalidFileToDirectory(void) { CharString tempDir = _fileUtilitiesMakeTempDir(); CharString testFilename = newCharStringWithCString(TEST_FILENAME); CharString invalid = newCharStringWithCString("invalid"); convertRelativePathToAbsolute(testFilename, invalid); assertFalse(copyFileToDirectory(invalid, tempDir)); removeDirectory(tempDir); freeCharString(testFilename); freeCharString(tempDir); freeCharString(invalid); return 0; }
static int _testLoadFxpPresetInVst(const char *testName, const CharString applicationPath, const CharString resourcesPath) { CharString inputPath = getDefaultInputPath(resourcesPath); CharString presetPath = getTestResourcePath(resourcesPath, "presets", "again-test.fxp"); int result = runIntegrationTest( testName, buildTestArgumentString("--plugin \"again,%s\" --input \"%s\"", presetPath->data, inputPath->data), RETURN_CODE_SUCCESS, kTestOutputPcm, applicationPath, resourcesPath); freeCharString(inputPath); freeCharString(presetPath); return result; }
static int _testPluginFactory(void) { CharString silence = newCharStringWithCString("mrs_silence"); CharString pluginRoot = newCharString(); Plugin p = pluginFactory(silence, pluginRoot); assertNotNull(p); assertIntEquals(PLUGIN_TYPE_INTERNAL, p->interfaceType); assertCharStringEquals(silence->data, p->pluginName); freeCharString(silence); freeCharString(pluginRoot); freePlugin(p); return 0; }
static int _testNewFileWithAbsolutePath(void) { CharString p = newCharString(); sprintf(p->data, "%s%c%s", "test", PATH_DELIMITER, "file"); freeCharString(c); return 0; }
boolByte removeDirectory(const CharString absolutePath) { boolByte result = false; #if UNIX if(!fileExists(absolutePath->data)) { return false; } // This is a bit lazy, perhaps... CharString removeCommand = newCharString(); snprintf(removeCommand->data, removeCommand->length, "/bin/rm -rf \"%s\"", absolutePath->data); result = system(removeCommand->data); freeCharString(removeCommand); return (result == 0); #elif WINDOWS SHFILEOPSTRUCTA fileOperation = {0}; fileOperation.wFunc = FO_DELETE; fileOperation.pFrom = absolutePath->data; fileOperation.fFlags = FOF_NO_UI; return (SHFileOperationA(&fileOperation) == 0); #else logUnsupportedFeature("Copy directory recursively"); return false; #endif }
static ProgramOption _findProgramOption(ProgramOptions self, const char* name) { ProgramOption potentialMatchOption, optionMatch; CharString optionStringWithoutDashes; unsigned int i; if(_isStringShortOption(name)) { for(i = 0; i < self->numOptions; i++) { potentialMatchOption = self->options[i]; if(potentialMatchOption->hasShortForm && potentialMatchOption->name->data[0] == name[1]) { return potentialMatchOption; } } } if(_isStringLongOption(name)) { optionMatch = NULL; optionStringWithoutDashes = newCharStringWithCapacity(kCharStringLengthShort); strncpy(optionStringWithoutDashes->data, name + 2, strlen(name) - 2); for(i = 0; i < self->numOptions; i++) { potentialMatchOption = self->options[i]; if(charStringIsEqualTo(potentialMatchOption->name, optionStringWithoutDashes, false)) { optionMatch = potentialMatchOption; break; } } freeCharString(optionStringWithoutDashes); return optionMatch; } // If no option was found, then return null return NULL; }
static void _logMessage(const LogLevel logLevel, const char *message, va_list arguments) { long elapsedTimeInMs; EventLogger eventLogger = _getEventLoggerInstance(); #if WINDOWS ULONGLONG currentTime; #else struct timeval currentTime; #endif if (eventLogger != NULL && logLevel >= eventLogger->logLevel) { CharString formattedMessage = newCharStringWithCapacity(kCharStringLengthDefault * 2); vsnprintf(formattedMessage->data, formattedMessage->capacity, message, arguments); #if WINDOWS currentTime = GetTickCount(); elapsedTimeInMs = (unsigned long)(currentTime - eventLogger->startTimeInMs); #else gettimeofday(¤tTime, NULL); elapsedTimeInMs = ((currentTime.tv_sec - (eventLogger->startTimeInSec + 1)) * 1000) + (currentTime.tv_usec / 1000) + (1000 - eventLogger->startTimeInMs); #endif _printMessage(logLevel, elapsedTimeInMs, getAudioClock()->currentFrame, formattedMessage->data, eventLogger); freeCharString(formattedMessage); } }
static int _testAppendItemToNullList(void) { CharString c = newCharString(); // The test here is not to crash linkedListAppend(NULL, c); freeCharString(c); return 0; }
static int _testBuildAbsolutePathWithFileExtensionTwice(void) { CharString d = newCharStringWithCString(ROOT_DIRECTORY); CharString out = newCharString(); CharString f = newCharStringWithCString(TEST_FILENAME); CharString expected = newCharString(); snprintf(expected->data, expected->capacity, "%s%c%s", ROOT_DIRECTORY, PATH_DELIMITER, TEST_FILENAME); buildAbsolutePath(d, f, "txt", out); assertCharStringEquals(out, expected->data); freeCharString(d); freeCharString(out); freeCharString(f); freeCharString(expected); return 0; }
static void _listAvailablePluginsInternal(void) { CharString internalLocation = newCharStringWithCString("(Internal)"); _logPluginLocation(internalLocation); logInfo(" %s", kInternalPluginPassthruName); logInfo(" %s", kInternalPluginSilenceName); freeCharString(internalLocation); }
static int _testNewFileWithRelativePath(void) { CharString p = newCharString(); sprintf(p->data, "%s%c%s", "test", PATH_DELIMITER, "file"); CharString pAbs = newCharString(); sprintf(p->data, "%s%s%c%s%c%s", ROOT_DIRECTORY, get); freeCharString(p); return 0; }
static int _testListInvalidDirectory(void) { CharString c = newCharStringWithCString("invalid"); LinkedList l = listDirectory(c); assertIntEquals(linkedListLength(l), 0); freeLinkedList(l); freeCharString(c); return 0; }
static int _testGuessSampleSourceTypeWrongCase(void) { CharString c = newCharStringWithCString("TEST.PCM"); SampleSource s = sampleSourceFactory(c); assertIntEquals(SAMPLE_SOURCE_TYPE_PCM, s->sampleSourceType); freeSampleSource(s); freeCharString(c); return 0; }
static int _testRemoveDirectory(void) { CharString tempDir = _fileUtilitiesMakeTempDir(); assert(_fileExists(tempDir->data)); assert(removeDirectory(tempDir)); assertFalse(_fileExists(tempDir->data)); freeCharString(tempDir); return 0; }
static int _testCopyFileToInvalidDirectory(void) { CharString tempFile = newCharString(); CharString testFilename = newCharStringWithCString(TEST_FILENAME); CharString invalid = newCharStringWithCString("invalid"); FILE *fp = fopen(TEST_FILENAME, "w"); assertNotNull(fp); fclose(fp); convertRelativePathToAbsolute(testFilename, tempFile); assertFalse(copyFileToDirectory(tempFile, invalid)); unlink(TEST_FILENAME); freeCharString(tempFile); freeCharString(testFilename); freeCharString(invalid); return 0; }
static int _testGuessSampleSourceTypePcm(void) { CharString c = newCharStringWithCString(TEST_SAMPLESOURCE_FILENAME); SampleSource s = sampleSourceFactory(c); assertIntEquals(SAMPLE_SOURCE_TYPE_PCM, s->sampleSourceType); freeSampleSource(s); freeCharString(c); return 0; }
static void _printTaskTime(void* item, void* userData) { TaskTimer taskTimer = (TaskTimer)item; TaskTimer totalTimer = (TaskTimer)userData; CharString prettyTimeString = taskTimerHumanReadbleString(taskTimer); double timePercentage = 100.0f * taskTimer->totalTaskTime / totalTimer->totalTaskTime; logInfo(" %s %s: %s (%2.1f%%)", taskTimer->component->data, taskTimer->subcomponent->data, prettyTimeString->data, timePercentage); freeCharString(prettyTimeString); }
static int _testGuessSampleSourceTypeEmpty(void) { CharString empty = newCharString(); SampleSource s = sampleSourceFactory(empty); assertIntEquals(SAMPLE_SOURCE_TYPE_SILENCE, s->sampleSourceType); freeSampleSource(s); freeCharString(empty); return 0; }