aboutsummaryrefslogblamecommitdiffstats
path: root/unit/ck-test.c
blob: 12644316c4347eaf7a8b9125f962ba952bfb88c2 (plain) (tree)
1
2
3
4
5
6
7
8
9



                   
                   
 
                                
               
 


                                                         

                     










                                            

 







                                     


            
                
                                                 
                                                 
                                                 
                          



               
#include <assert.h>
#include <stdio.h>
#include <string.h>

#include "cklist.h"

/* total number of unit tests */
#define TOTAL 2

#define CK_UNIT_TESTS                                   \
  X(ck_list_init, "Basic cklist test")                  \
  X(ck_list_exists, "Test list exists function")

void ck_list_init() {
  cklist *ckl1 = list_make_new();
  cklist *ckl2 = list_make_and_add("first");
  list_add(ckl2, "second");
  list_add(ckl1, "first");
  list_add(ckl1, "second");
  assert(strcmp(list_get_at(ckl1, 0),
		list_get_at(ckl2, 0)) == 0);
  assert(strcmp(list_get_at(ckl1, 1),
		list_get_at(ckl2, 1)) == 0);
  list_free(ckl1);
  list_free(ckl2);
}

void ck_list_exists() {
  cklist *ckl = list_make_new();
  list_add(ckl, "first");
  list_add(ckl, "second");
  assert(list_exists(ckl, "first"));
  assert(list_exists(ckl, "second"));
  assert(!list_exists(ckl, "thrid"));
  list_free(ckl);
}

int main() {
  int count = 1;
#define X(TEST, DESC)				\
  printf("[%d/%d] %s\n", count++, TOTAL, DESC); \
  TEST();					\
  printf("=> Passed\n\n");
  CK_UNIT_TESTS
#undef X
}