PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ test_optionlist()

static void test_optionlist ( void  )
static

Definition at line 273 of file liblwgeom/cunit/cu_misc.c.

274 {
275  size_t sz;
276  const char* value;
277  // zero out all the pointers so our list ends up null-terminated
278  char *olist[OPTION_LIST_SIZE];
279  char input[128];
280  memset(olist, 0, sizeof(olist));
281  // input string needs to be writeable because we are inserting nulls
282  strcpy(input, "key1=value1 key2=value2 ");
283  option_list_parse(input, olist);
284 
285  value = option_list_search(olist, "key1");
286  // printf("value: %s\n", value);
287  ASSERT_STRING_EQUAL("value1", value);
288  value = option_list_search(olist, "key2");
289  ASSERT_STRING_EQUAL("value2", value);
290  value = option_list_search(olist, "key3");
291  CU_ASSERT_EQUAL(NULL, value);
292 
293  sz = option_list_length(olist);
294  CU_ASSERT_EQUAL(4, sz);
295 
296  memset(olist, 0, sizeof(olist));
297  strcpy(input, " ");
298  option_list_parse(input, olist);
299  value = option_list_search(olist, "key1");
300  CU_ASSERT_EQUAL(NULL, value);
301 
302  memset(olist, 0, sizeof(olist));
303  strcpy(input, " key3= ");
304  option_list_parse(input, olist);
305  sz = option_list_length(olist);
306  CU_ASSERT_EQUAL(2, sz);
307 
308  strcpy(input, " key1=value1 key2='value2 value3' ");
309  memset(olist, 0, sizeof(olist));
310  option_list_gdal_parse(input, olist);
311  sz = option_list_length(olist);
312  CU_ASSERT_EQUAL(2, sz);
313  ASSERT_STRING_EQUAL("key1=value1", olist[0]);
314  ASSERT_STRING_EQUAL("key2='value2 value3'", olist[1]);
315 }
#define ASSERT_STRING_EQUAL(o, e)
int value
Definition: genraster.py:62
void option_list_gdal_parse(char *input, char **olist)
Definition: optionlist.c:121
size_t option_list_length(char **olist)
Returns the total number of keys and values in the list.
Definition: optionlist.c:73
const char * option_list_search(char **olist, const char *key)
Returns null if the key cannot be found.
Definition: optionlist.c:54
void option_list_parse(char *input, char **olist)
option_list is a null-terminated list of strings, where every odd string is a key and every even stri...
Definition: optionlist.c:86
#define OPTION_LIST_SIZE
Definition: optionlist.h:31

References ASSERT_STRING_EQUAL, option_list_gdal_parse(), option_list_length(), option_list_parse(), option_list_search(), OPTION_LIST_SIZE, and genraster::value.

Referenced by misc_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: