test_silut.c 1.18 KB
Newer Older
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/**
* This is a test for silut in $package$
*/
#include "si_test.h"
#include "silut.h"


TEST_FUNC(silut) {  
  Silut * aid;
  static Silut lut[] = {
    { 0, "zero"},
    { 2, "two" },
    { 1, "one" },
    SILUT_DONE
  };
  
  static Silut lut_s[] = {
    { 1, "one" },
    { 2, "two" },
    { 0, "zero"},
    SILUT_DONE
  };
  
  static Silut lut_i[] = {
    { 0, "zero"},
    { 1, "one" },
    { 2, "two" },    
    SILUT_DONE
  };

  
  
  aid = silut_lsearchi(lut, 55);
  TEST_NULL(aid);
  aid = silut_lsearchcstr(lut, "banana");
  TEST_NULL(aid);
  aid = silut_lsearchi(lut, 2);
  TEST_NOTNULL(aid);
  TEST_INTEQ(aid->integer, 2);
  TEST_STREQ(aid->string, "two");
  aid = silut_lsearchcstr(lut, "two");
  TEST_NOTNULL(aid);
  TEST_INTEQ(aid->integer, 2);
  TEST_STREQ(aid->string, "two");
  aid = silut_bsearchcstr(lut_s, "two");
  TEST_NOTNULL(aid);
  TEST_INTEQ(aid->integer, 2);
  TEST_STREQ(aid->string, "two");
  aid = silut_bsearchcstr(lut_s, "banana");
  TEST_NULL(aid);
  
  aid = silut_bsearchint(lut_i, 1);
  TEST_NOTNULL(aid);
  TEST_STREQ(aid->string, "one");
  TEST_INTEQ(aid->integer, 1);
    
  
  TEST_DONE();
}


int main(void) {
  TEST_INIT();
  TEST_RUN(silut);
  TEST_REPORT();
}