File: test_queue.c

package info (click to toggle)
netproc 0.6.6-0.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: ansic: 7,876; makefile: 101; sh: 12
file content (49 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#include <stdlib.h>

#include "queue.h"
#include "unity.h"

#define TOT_DATA 99

struct mydata
{
  int data;
};

static struct mydata *
create_mydata ( size_t i )
{
  struct mydata *d = malloc ( sizeof *d );
  TEST_ASSERT_NOT_NULL ( d );

  d->data = i;
  return d;
}

void
test_queue ( void )
{
  struct queue *q = queue_new ( free );
  TEST_ASSERT_NOT_NULL ( q );

  // enqueue return size of queue if sucess, this should be different of 0
  for ( int i = 0; i < TOT_DATA; i++ )
    {
      TEST_ASSERT_EQUAL_INT ( i + 1, enqueue ( q, create_mydata ( i ) ) );
    }

  TEST_ASSERT_EQUAL_INT ( TOT_DATA, get_queue_size ( q ) );

  struct mydata *d;
  for ( int i = 0; i < TOT_DATA - 5; i++ )
    {
      TEST_ASSERT_NOT_NULL ( ( d = dequeue ( q ) ) );
      TEST_ASSERT_EQUAL_INT ( i, d->data );
      free ( d );
    }

  TEST_ASSERT_EQUAL_INT ( 5, get_queue_size ( q ) );

  queue_destroy ( q );
}