Exemplo n.º 1
0
void freeMidiSequence(MidiSequence self) {
  if (self != NULL) {
    freeLinkedListAndItems(self->midiEvents,
                           (LinkedListFreeItemFunc)freeMidiEvent);
    free(self);
  }
}
Exemplo n.º 2
0
static int _testListEmptyDirectory(void) {
  CharString tempDir = _fileUtilitiesMakeTempDir();
  LinkedList l = listDirectory(tempDir);

  assertIntEquals(linkedListLength(l), 0);
  removeDirectory(tempDir);

  freeCharString(tempDir);
  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}
Exemplo n.º 3
0
static int _testAppendItemToList(void) {
  LinkedList l = newLinkedList();
  CharString c = newCharString();
  charStringCopyCString(c, TEST_ITEM_STRING);
  linkedListAppend(l, c);
  assertNotNull(l->item);
  assertCharStringEquals(((CharString)l->item), TEST_ITEM_STRING);
  assertIsNull(l->nextItem);
  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}
Exemplo n.º 4
0
boolByte programOptionsParseConfigFile(ProgramOptions self, const CharString filename) {
  boolByte result = false;
  File configFile = NULL;
  LinkedList configFileLines = NULL;
  CharString* argvCharStrings;
  int argc;
  char** argv;
  int i;

  if(filename == NULL || charStringIsEmpty(filename)) {
    logCritical("Cannot read options from empty filename");
    return false;
  }

  configFile = newFileWithPath(filename);
  if(configFile == NULL || configFile->fileType != kFileTypeFile) {
    logCritical("Cannot read options from non-existent file '%s'", filename->data);
    freeFile(configFile);
    return false;
  }

  configFileLines = fileReadLines(configFile);
  if(configFileLines == NULL) {
    logInternalError("Could not split config file lines");
    return false;
  }
  else if(linkedListLength(configFileLines) == 0) {
    logInfo("Config file '%s' is empty", filename->data);
    freeLinkedList(configFileLines);
    freeFile(configFile);
    return true;
  }
  else {
    // Don't need the file anymore, it can be freed here
    freeFile(configFile);
  }

  argvCharStrings = (CharString*)linkedListToArray(configFileLines);
  argc = linkedListLength(configFileLines);
  argv = (char**)malloc(sizeof(char*) * (argc + 1));
  // Normally this would be the application name, don't care about it here
  argv[0] = NULL;
  for(i = 0; i < argc; i++) {
    argv[i + 1] = argvCharStrings[i]->data;
  }
  argc++;
  result = programOptionsParseArgs(self, argc, argv);

  freeLinkedListAndItems(configFileLines, (LinkedListFreeItemFunc)freeCharString);
  free(argvCharStrings);
  free(argv);
  return result;
}
Exemplo n.º 5
0
static int _testNumItemsInList(void) {
  CharString c;
  int i;
  LinkedList l = newLinkedList();
  for(i = 0; i < 100; i++) {
    c = newCharString();
    charStringCopyCString(c, TEST_ITEM_STRING);
    linkedListAppend(l, c);
  }
  assertIntEquals(linkedListLength(l), 100);
  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}
Exemplo n.º 6
0
static int _testForeachOverUserData(void) {
  LinkedList l = newLinkedList();
  CharString c = newCharString();

  charStringCopyCString(c, TEST_ITEM_STRING);
  linkedListAppend(l, c);
  linkedListForeach(l, _linkedListUserDataCallback, c);
  assertIntEquals(_gNumForeachCallbacksMade, 1);
  assert(_gForeachCallbackOk);

  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}
Exemplo n.º 7
0
void runInternalTestSuite(boolByte onlyPrintFailing) {
  TestSuite suiteResults;
  LinkedList internalTestSuites = _getTestSuites();

  if(onlyPrintFailing) {
    linkedListForeach(internalTestSuites, _setTestSuiteOnlyPrintFailing, NULL);
  }
  linkedListForeach(internalTestSuites, runTestSuite, NULL);
  // Create a new test suite to be used as the userData passed to the foreach loop
  suiteResults = newTestSuite("Suite results", NULL, NULL);
  linkedListForeach(internalTestSuites, _sumTestSuiteResults, suiteResults);

  fprintf(stderr, "\n== Ran %d function tests: %d passed, %d failed, %d skipped ==\n",
    suiteResults->numSuccess + suiteResults->numFail + suiteResults->numSkips,
    suiteResults->numSuccess, suiteResults->numFail, suiteResults->numSkips);

  freeLinkedListAndItems(internalTestSuites, (LinkedListFreeItemFunc)freeTestSuite);
  freeTestSuite(suiteResults);
}
Exemplo n.º 8
0
static int _testLinkedListToArray(void) {
  LinkedList l = newLinkedList();
  CharString* arr;
  CharString c;

  linkedListAppend(l, newCharStringWithCString("one"));
  linkedListAppend(l, newCharStringWithCString("two"));

  arr = (CharString*)linkedListToArray(l);
  assertNotNull(arr);
  c = (CharString)arr[0];
  assertCharStringEquals(c, "one");
  c = (CharString)arr[1];
  assertCharStringEquals(c, "two");
  assertIsNull(arr[2]);

  free(arr);
  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}
Exemplo n.º 9
0
static int _testAppendMultipleItemsToList(void) {
  LinkedListIterator i;
  LinkedList l = newLinkedList();
  CharString c = newCharString();
  CharString c2 = newCharString();

  charStringCopyCString(c, TEST_ITEM_STRING);
  charStringCopyCString(c2, OTHER_TEST_ITEM_STRING);
  linkedListAppend(l, c);
  linkedListAppend(l, c2);
  assertNotNull(l->item);
  assertCharStringEquals(((CharString)l->item), TEST_ITEM_STRING);
  assertNotNull(l->nextItem);
  i = l->nextItem;
  assertNotNull(i->item);
  assertCharStringEquals(((CharString)i->item), OTHER_TEST_ITEM_STRING);
  assertIsNull(i->nextItem);
  assertIntEquals(linkedListLength(l), 2);

  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}
Exemplo n.º 10
0
static int _testListDirectory(void) {
  CharString tempDir = _fileUtilitiesMakeTempDir();
  CharString tempFile = newCharString();
  CharString filename;
  CharString testFilename = newCharStringWithCString(TEST_FILENAME);
  LinkedList l;
  FILE *f;

  buildAbsolutePath(tempDir, testFilename, NULL, tempFile);
  f = fopen(tempFile->data, "w");
  assertNotNull(f);
  fclose(f);
  l = listDirectory(tempDir);
  assertIntEquals(linkedListLength(l), 1);
  filename = (CharString)l->item;
  assertCharStringEquals(filename, TEST_FILENAME);

  removeDirectory(tempDir);
  freeCharString(tempDir);
  freeCharString(tempFile);
  freeCharString(testFilename);
  freeLinkedListAndItems(l, (LinkedListFreeItemFunc)freeCharString);
  return 0;
}
Exemplo n.º 11
0
void freeTestSuite(TestSuite self) {
  if(self != NULL) {
    freeLinkedListAndItems(self->testCases, (LinkedListFreeItemFunc)freeTestCase);
    free(self);
  }
}