critical void getBSPacket(packet_t *myPacket) {
   uint8_t *packet_ptr = (uint8_t *) myPacket;
   uint8_t plen, i;

   plen = q_front() + HEADER_SIZE;
   for (i = 0; i < plen; i++)
      packet_ptr[i] = q_pop();
   newBSPacket--;
}
Esempio n. 2
0
int check_queue()
{
  QUEUE *queue;
  char *item;

  size_t counter;

  queue = q_init();
  if(!queue)
    {
      fprintf(stderr, "unable to initialize queue\n");
      return 0;
    }

  for(counter = 0; datas[counter]; counter ++)
    q_enqueue(queue, datas[counter], strlen(datas[counter]) + 1);

  item = (char *)q_front(queue);
  if(!item)
    {
      fprintf(stderr, "got NULL when expecting %s\n", datas[counter]);
      return 1;
    }
  if(strcmp(item, datas[0]))
    {
      fprintf(stderr, "q_front() returned %s, expecting %s\n", item, datas[0]);
      return 2;
    }

  for(counter = 0; datas[counter]; counter ++)
    {
      item = (char *)q_dequeue(queue);
      if(!item || strcmp(item, datas[counter]))
	{
	  fprintf(stderr, "got %s, expecting %s\n", item, datas[counter]);
	  return 3;
	}
      free(item);
    }
  
  item = (char *)q_dequeue(queue);
  if(item)
    {
      fprintf(stderr, "got %s when expecting NULL\n", item);
      return 4;
    }

  q_free(queue, QUEUE_NODEALLOC);

  return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
  size_t s = sizeof(int);
  int foo;
  {
    /*#Test_0*/
    queue q; q_init(&q, s);
    test(q_size(&q) == 0 && q_is_empty(&q));
  }
  {
    /*#Test_1*/
    queue q; q_init(&q, s);
    foo = 1; q_push(&q, &foo);
    test(q_size(&q) == 1 && !q_is_empty(&q) && *(int *)q_front(&q) == 1);
  }
  {
    /*#Test_2*/
    queue q; q_init(&q, s);
    foo = 2; q_push(&q, &foo);
    foo = 1; q_push(&q, &foo);
    test(
        q_size(&q) == 2 && 
        *(int *)q_front(&q) == 1 && 
        *(int *)q_back(&q) == 2);
  }
  {
    /*#Test_3*/
    queue q; q_init(&q, s);

    foo = 3; q_push(&q, &foo);
    foo = 2; q_push(&q, &foo);
    foo = 1; q_push(&q, &foo);

    q_pop(&q);
    BOOL bar = *(int *)q_front(&q) == 1 && *(int *)q_back(&q) == 2;

    q_pop(&q);
    bar &= *(int *)q_front(&q) == 1 && *(int *)q_back(&q) == 1;

    q_pop(&q);
    test(
        bar &&
        q_is_empty(&q));
  }
  {
    /*#Test_4*/
    queue q; q_init(&q, s);
    BOOL bar = TRUE;

    for (uint i = 0; i < N; ++i)
    {
      foo = i; q_push(&q, &foo);
    }

    for (uint i = 0; i < N; ++i)
    {
      bar &= *(int *)q_back(&q) == i;
      if (!bar) break;
      q_pop(&q);
    }

    test(
        bar&
        q_is_empty(&q));
  }

  return EXIT_SUCCESS;
}