librfn
An ad-hoc utility library
enumtest.c
Go to the documentation of this file.
1 /*
2  * enumtest.c
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2012 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #undef NDEBUG
15 
16 #include <assert.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 #include <librfn.h>
22 
23 void test()
24 {
26  { "One One", 1 },
27  { "Two Two", 2 },
28  { "Three Three", 3 }
29  );
30 
31  assert(RF_ENUM_OUT_OF_RANGE == rf_string2enum(lookup, "Zero Zero"));
32  assert(1 == rf_string2enum(lookup, "One One"));
33  assert(2 == rf_string2enum(lookup, "Two Two"));
34  assert(3 == rf_string2enum(lookup, "Three Three"));
35 
36  assert(NULL == rf_enum2string(lookup, 0));
37  assert(0 == strcmp("One One", rf_enum2string(lookup, 1)));
38  assert(0 == strcmp("Two Two", rf_enum2string(lookup, 2)));
39  assert(0 == strcmp("Three Three", rf_enum2string(lookup, 3)));
40  assert(NULL == rf_enum2string(lookup, 4));
41 }
42 
43 int main()
44 {
45  test();
46  return 0;
47 }
#define RF_ENUMTABLE_INITIALIZER(...)
Definition: enum.h:54
void test()
Definition: enumtest.c:23
const char * rf_enum2string(rf_enumtable_t *t, int e)
Definition: enum.c:18
int rf_string2enum(rf_enumtable_t *t, const char *s)
Definition: enum.c:28
int main()
Definition: enumtest.c:43
Lookup table used for the conversions.
Definition: enum.h:43
#define RF_ENUM_OUT_OF_RANGE
Definition: enum.h:56