예제 #1
0
void test_inserting_and_finding()
{
	struct avl_tree_node* root;
	int* value;

	root = avl_tree_create();
	root = avl_tree_insert(root, "esa", 3);
	root = avl_tree_insert(root, "vesa", 4);
	root = avl_tree_insert(root, "vvv", 5);
	root = avl_tree_insert(root, "aaa", 7);

	value = avl_tree_find(root, "vesa");
	assertIntEquals(4, *value);

	value = avl_tree_find(root, "esa");
	assertIntEquals(3, *value);

	value = avl_tree_find(root, "vvv");
	assertIntEquals(5, *value);

	value = avl_tree_find(root, "aaa");
	assertIntEquals(7, *value);

	value = avl_tree_find(root, "bbb");
	assertNull(value);

	avl_tree_destroy(root);
}
예제 #2
0
static int _testNewTaskTimer(void) {
  TaskTimer t = newTaskTimer(1);

  assertIntEquals(t->numTasks, 1);
  assertIntEquals(t->currentTask, -1);

  freeTaskTimer(t);
  return 0;
}
예제 #3
0
static int _testGetPlatformType(void) {
#if LINUX
  assertIntEquals(getPlatformType(), PLATFORM_LINUX);
#elif MACOSX
  assertIntEquals(getPlatformType(), PLATFORM_MACOSX);
#elif WINDOWS
  assertIntEquals(getPlatformType(), PLATFORM_WINDOWS);
#else
  assertIntEquals(getPlatformType(), PLATFORM_UNSUPPORTED);
#endif
  return 0;
}
예제 #4
0
static int _testTaskTimerDuration(void) {
  TaskTimer t = newTaskTimer(1);

  assertIntEquals(t->currentTask, -1);
  startTimingTask(t, 0);
  _testSleep();
  stopTiming(t);
  assertIntEquals(t->currentTask, -1);
  assertDoubleEquals(t->totalTaskTimes[0], SLEEP_DURATION_MS, MAX_TIMER_TOLERANCE_MS);

  freeTaskTimer(t);
  return 0;
}
void testHashMapGetMissingKey()
{
  long * v = 0;
  char * k1 = "Hello";
  long value = 1000;
  HashMap * map = hashMapCreate(11);
  hashMapPut(map, k1, &value);
  v = hashMapGet(map, "xxx");
  assertIntEquals("testHashMapGetMissingKey", 0, (int)v);
  v = hashMapGet(map, k1);
  assertIntEquals("testHashMapGetMissingKey", 1000, *v);
  hashMapFree(map);
  map = NULL;
}
예제 #6
0
static int _testNewFileDefault(void) {
  File f = newFile();
  assertNotNull(f);
  assertCharStringEquals(f->absolutePath, "");
  assertIntEquals(f->fileType, kFileTypeInvalid);
  return 0;
}
예제 #7
0
static int _testTaskTimerDurationMultipleTimes(void) {
  TaskTimer t = newTaskTimer(1);
  int i;

  for(i = 0; i < 5; i++) {
    assertIntEquals(t->currentTask, -1);
    startTimingTask(t, 0);
    _testSleep();
    stopTiming(t);
    assertIntEquals(t->currentTask, -1);
  }
  assertDoubleEquals(t->totalTaskTimes[0], 5.0 * SLEEP_DURATION_MS, MAX_TIMER_TOLERANCE_MS * 5.0);

  freeTaskTimer(t);
  return 0;
}
예제 #8
0
static int _testCallStopBeforeStart(void) {
  TaskTimer t = newTaskTimer(1);

  stopTiming(t);
  assertIntEquals(t->currentTask, -1);
  startTimingTask(t, 0);
  assertIntEquals(t->currentTask, 0);
  _testSleep();
  stopTiming(t);
  assertIntEquals(t->currentTask, -1);
  // Recorded time should be at most 1ms off
  assertDoubleEquals(t->totalTaskTimes[0], SLEEP_DURATION_MS, MAX_TIMER_TOLERANCE_MS);

  freeTaskTimer(t);
  return 0;
}
예제 #9
0
static int _testForeachOverEmptyList(void) {
  LinkedList l = newLinkedList();
  linkedListForeach(l, _linkedListEmptyCallback, NULL);
  assertIntEquals(_gNumForeachCallbacksMade, 0);
  freeLinkedList(l);
  return 0;
}
예제 #10
0
static int _testGuessSampleSourceTypeEmpty(void) {
  CharString empty = newCharString();
  SampleSource s = sampleSourceFactory(empty);
  assertIntEquals(SAMPLE_SOURCE_TYPE_SILENCE, s->sampleSourceType);
  freeSampleSource(s);
  freeCharString(empty);
  return 0;
}
예제 #11
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;
}
예제 #12
0
static int _testListInvalidDirectory(void) {
  CharString c = newCharStringWithCString("invalid");
  LinkedList l = listDirectory(c);
  assertIntEquals(linkedListLength(l), 0);
  freeLinkedList(l);
  freeCharString(c);
  return 0;
}
예제 #13
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;
}
예제 #14
0
static int _testAppendNullItemToList(void) {
  LinkedList l = newLinkedList();
  linkedListAppend(l, NULL);
  assertIsNull(l->item);
  assertIsNull(l->nextItem);
  assertIntEquals(linkedListLength(l), 0);
  freeLinkedList(l);
  return 0;
}
예제 #15
0
static int _testNewLinkedList(void) {
  LinkedList l = newLinkedList();
  assertNotNull(l);
  assertIsNull(l->nextItem);
  assertIntEquals(linkedListLength(l), 0);
  assert(l->item == NULL);
  freeLinkedList(l);
  return 0;
}
예제 #16
0
static int _testNewObject(void) {
  CharString c = newCharStringWithCString(TEST_PRESET_FILENAME);
  PluginPreset p = newPluginPreset(PRESET_TYPE_FXP, c);
  assertIntEquals(p->presetType, PRESET_TYPE_FXP);
  assertCharStringEquals(p->presetName, TEST_PRESET_FILENAME);
  freePluginPreset(p);
  freeCharString(c);
  return 0;
}
예제 #17
0
static int _testNewMidiSource(void) {
  CharString c = newCharStringWithCString(TEST_MIDI_FILENAME);
  MidiSource m = newMidiSource(MIDI_SOURCE_TYPE_FILE, c);
  assertCharStringEquals(TEST_MIDI_FILENAME, m->sourceName);
  assertIntEquals(MIDI_SOURCE_TYPE_FILE, m->midiSourceType);
  freeMidiSource(m);
  freeCharString(c);
  return 0;
}
예제 #18
0
void test_that_keys_are_copied()
{
	struct avl_tree_node* root;
	int* value;
	char key[] = "esa";
	root = avl_tree_create();

	root = avl_tree_insert(root, key, 3);

	value = avl_tree_find(root, "esa");
	assertIntEquals(3, *value);

	key[0] = 'a';
	value = avl_tree_find(root, "esa");
	assertIntEquals(3, *value);

	avl_tree_destroy(root);
}
예제 #19
0
void test_increasing()
{
	struct avl_tree_node* root;
	root = avl_tree_create();
	root = avl_tree_increase(root, "moi");
	root = avl_tree_increase(root, "hello");
	root = avl_tree_increase(root, "abc");
	root = avl_tree_increase(root, "hello");
	root = avl_tree_increase(root, "hello");
	root = avl_tree_increase(root, "eee");
	root = avl_tree_increase(root, "moi");
	assertIntEquals(3, *avl_tree_find(root, "hello"));
	assertIntEquals(1, *avl_tree_find(root, "abc"));
	assertIntEquals(2, *avl_tree_find(root, "moi"));
	assertIntEquals(1, *avl_tree_find(root, "eee"));
	assertNull(avl_tree_find(root, "dummy"));

	avl_tree_destroy(root);
}
예제 #20
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;
}
void testHashMapSixValues()
{
  long * v = 0;
  long values[] = {1000, 1001,1002,1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012};
  char * k1 = "Hello";
  char * k2 = "hello";
  char * k3 = "world";
  char * k4 = "World";
  char * k5 = "good";
  char * k6 = "bye";
  int i = 0;
  HashMap * map = hashMapCreate(3);
  hashMapPut(map, k1, &values[i++]);
  hashMapPut(map, k2, &values[i++]);
  hashMapPut(map, k3, &values[i++]);
  hashMapPut(map, k4, &values[i++]);
  hashMapPut(map, k5, &values[i++]);
  hashMapPut(map, k6, &values[i++]);
  
  v = hashMapGet(map, k1);

  assertIntEquals("testHashMapSixValues value 1", 1000, *v);
  v = hashMapGet(map, "hello");
  assertIntEquals("testHashMapSixValues value 2", 1001, *v);
  v = hashMapGet(map, "world");
  assertIntEquals("testHashMapSixValues value 3", 1002, *v);
  v = hashMapGet(map, "World");
  assertIntEquals("testHashMapSixValues value 4", 1003, *v);
  v = hashMapGet(map, "good");
  assertIntEquals("testHashMapSixValues value 5", 1004, *v);
  v = hashMapGet(map, "bye");
  assertIntEquals("testHashMapSixValues value 6", 1005, *v);
  hashMapFree(map);
  map = NULL;
}
int main(void) {

	EstEID_Map map = NULL;
	assertIntEquals(0, EstEID_mapSize(map));

	map = EstEID_mapPut(map, "foo", "bar");
	assertNotNull(map);
	assertIntEquals(1, EstEID_mapSize(map));

	map = EstEID_mapPut(map, "foo", "FOO");
	assertIntEquals(1, EstEID_mapSize(map));

	char *k = strdup("key");
	char *v = strdup("value");
	map = EstEID_mapPut(map, k, v);
	free(k);
	free(v);
	assertIntEquals(2, EstEID_mapSize(map));
	assertStringEquals("value", EstEID_mapGet(map, "key"));

	assertNull(EstEID_mapGet(map, "xyz"));

	EstEID_mapFree(map);


	EstEID_Map m = EstEID_mapPut(NULL, "a", "A");
	EstEID_mapPut(m, "b", "B");
	EstEID_mapPut(m, "c", "C");

	printf("map:\n");
	EstEID_mapPrint(stdout, m);

	EstEID_Map c = EstEID_mapClone(m);
	EstEID_mapFree(m);

	printf("clone:\n");
	EstEID_mapPrint(stdout, c);
	EstEID_mapFree(c);

}
예제 #23
0
static int _testPluginFactoryNullRoot(void)
{
    CharString silence = newCharStringWithCString("mrs_silence");
    Plugin p = pluginFactory(silence, NULL);

    assertNotNull(p);
    assertIntEquals(PLUGIN_TYPE_INTERNAL, p->interfaceType);
    assertCharStringEquals(silence->data, p->pluginName);

    freeCharString(silence);
    freePlugin(p);
    return 0;
}
예제 #24
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;
}
예제 #25
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;
}
예제 #26
0
void test_for_each()
{
	struct avl_tree_node* root;
	root = avl_tree_create();
	root = avl_tree_insert(root, "aaa", 3);
	root = avl_tree_insert(root, "vesa", 5);
	root = avl_tree_insert(root, "esa", 7);
	TOTAL = 1;
	avl_tree_for_each(root, test_function);
	assertIntEquals(3*5*7, TOTAL);

	avl_tree_destroy(root);
}
void testHashMapOneValue()
{
  HashMap * map = hashMapCreate(11);
  long value = 1999;
  hashMapPut(map, "Hello", &value);
  long * p = hashMapGet(map, "Hello");
  assertIntEquals("testHashMapOneValue", 1999, *p);

  // cleanup
  hashMapRemove(map, "Hello");
  hashMapFree(map);
  map = NULL;
  
}
예제 #28
0
void test_finding()
{
	struct avl_tree_node* root;
	int* value;

	root = avl_tree_create();
	root = avl_tree_insert(root, "esa", 3);

	value = avl_tree_find(root, "vesa");
	assertNull(value);

	value = avl_tree_find(root, "esa");
	assertIntEquals(3, *value);

	avl_tree_destroy(root);
}
예제 #29
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;
}
예제 #30
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;
}