Exemplo n.º 1
0
void test_listRemoveTail_given_list_of_0x100_0x200_0x300_should_return_0x300()
{
  LinkedList list ;
  ListElement listElement1 ;
  ListElement listElement2;
  ListElement listElement3;
  ListElement *returnElement;
  
  initLinkedList(&list);
  
  listElementCreate(&listElement1,0x100);
  listElementCreate(&listElement2,0x200);
  listElementCreate(&listElement3,0x300);
  
  listAddTail(&list,&listElement1);
  listAddTail(&list,&listElement2);
  listAddTail(&list,&listElement3);

  
  returnElement = listRemoveTail(&list);

  TEST_ASSERT_EQUAL(&listElement3,returnElement);
  TEST_ASSERT_EQUAL(0x300,returnElement->data);
  TEST_ASSERT_EQUAL(NULL,returnElement->next);
  
  TEST_ASSERT_EQUAL(&listElement1,list.head);
  TEST_ASSERT_EQUAL(&listElement2,list.tail);
}
Exemplo n.º 2
0
void test_listAddTail_0x500_given_list_contains_0x100_0x200_0x300()
{
  LinkedList list ;
  ListElement listElement1 ;
  ListElement listElement2;
  ListElement listElement3;
  ListElement listElement4;
  
  initLinkedList(&list);
  
  listElementCreate(&listElement1,0x100);
  listElementCreate(&listElement2,0x200);
  listElementCreate(&listElement3,0x300);
  listElementCreate(&listElement4,0x500);
  
  listAddHead(&list,&listElement3);
  listAddHead(&list,&listElement2);
  listAddHead(&list,&listElement1);
  
  TEST_ASSERT_EQUAL(&listElement1,list.head);
  TEST_ASSERT_EQUAL(&listElement3,list.tail);
  TEST_ASSERT_EQUAL(0x100,list.head->data);
  TEST_ASSERT_EQUAL(0x200,(list.head)->next->data);
  TEST_ASSERT_EQUAL(0x300,(list.head)->next->next->data);
  
  listAddTail(&list,&listElement4);
  
  TEST_ASSERT_EQUAL(&listElement4,list.tail);
  TEST_ASSERT_EQUAL(0x500,list.tail->data);
  TEST_ASSERT_EQUAL(NULL,list.tail->next);
}
Exemplo n.º 3
0
void test_travel_1step_beforeTarget_given_3_element_list_target_Tail_should_return_list_1()
{
	LinkedList *list0 = listCreate(0x100);
	LinkedList *list1 = listCreate(0x200);
	LinkedList *list2 = listCreate(0x300);
	LinkedList *Head,*Tail, *Target ;
	
	listAddHead(&Head,list0);
	setTail(&Tail,list0);
	listAddTail(&Tail,list1);
	listAddTail(&Tail,list2);
	
	Target = travel_1step_beforeTarget(Head,Tail);
	
	TEST_ASSERT_EQUAL(list1,Target);

}
Exemplo n.º 4
0
void test_travel_1step_beforeTarget_given_not_found_should_return_NULL()
{
	LinkedList *list0 = listCreate(0x100);
	LinkedList *list1 = listCreate(0x200);
	LinkedList *list2 = listCreate(0x300);
	LinkedList *list3 = listCreate(0x400);
	LinkedList *Head,*Tail, *Target ;
	
	listAddHead(&Head,list0);
	setTail(&Tail,Head);
	listAddTail(&Tail,list1);
	listAddTail(&Tail,list2);
	
	Target = travel_1step_beforeTarget(Head,list3);
	TEST_ASSERT_NULL(Target);
	
	DestroyAllList(&Head,&Tail);
}
Exemplo n.º 5
0
void test_searchListForData_given_0x400_should_return_NULL_for_not_found()
{
	LinkedList *list0 = listCreate(0x100);
	LinkedList *list1 = listCreate(0x200);
	LinkedList *list2 = listCreate(0x300);
	LinkedList *Head,*Tail, *Found ;
	
	listAddHead(&Head,list0);
	setTail(&Tail,Head);
	listAddTail(&Tail,list1);
	listAddTail(&Tail,list2);
	
	Found = searchListForData(Head,0x400);
	
	TEST_ASSERT_NULL(Found);

	DestroyAllList(&Head,&Tail);
	
}
Exemplo n.º 6
0
void *
produce(void *arg)
{
	list *l = (list *)arg;
	for(int i = 0; i < NUM_JOBS; i++) {
		char buf[32];
		sprintf(buf, "msg.%d", i);
		listAddTail(l, strdup(buf));
	}
	return 0;
}
Exemplo n.º 7
0
void test_searchListForData_given_0x300_should_return_list2()
{
	LinkedList *list0 = listCreate(0x100);
	LinkedList *list1 = listCreate(0x200);
	LinkedList *list2 = listCreate(0x300);
	LinkedList *Head,*Tail, *Found ;
	
	listAddHead(&Head,list0);
	setTail(&Tail,Head);
	listAddTail(&Tail,list1);
	listAddTail(&Tail,list2);
	
	Found = searchListForData(Head,0x300);
	
	TEST_ASSERT_EQUAL(list2,Found);
	TEST_ASSERT_EQUAL(0x300,Found->data);
	
	DestroyAllList(&Head,&Tail);
	
}
Exemplo n.º 8
0
int addTimer(Timer *timer)
{
   u64 rflags;
   lockSpinLockCloseInterrupt(&timerLock,&rflags);

   for(ListHead *list = timers.next;list != &timers;list = list->next)
   {
      Timer *__timer = listEntry(list,Timer,list);
      if(__timer->ticks > timer->ticks)
      { /*Add this timer to a appropriate position.*/
         listAddTail(&timer->list,&__timer->list);
         goto end;
      }
   }
   /*Add this timer to the last position.*/
   listAddTail(&timer->list,&timers);
end:
   unlockSpinLockRestoreInterrupt(&timerLock,&rflags);
   return 0;
}
Exemplo n.º 9
0
void test_listAddTail_given_emptyList()
{
  LinkedList list ;
  ListElement listElement ;
  
  initLinkedList(&list);
  
  listElementCreate(&listElement,0x100);
  
  listAddTail(&list,&listElement);
  
  TEST_ASSERT_EQUAL(&listElement,list.head);
  TEST_ASSERT_EQUAL(&listElement,list.tail);
  TEST_ASSERT_EQUAL(0x100,list.head->data);
  TEST_ASSERT_EQUAL(NULL,list.head->next);
  TEST_ASSERT_EQUAL(0x100,list.tail->data);
  TEST_ASSERT_EQUAL(NULL,list.tail->next);
}