Skip to content

Commit

Permalink
Merge branch 'master' into test-utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoellendorf committed Mar 17, 2024
2 parents 5a5ff19 + 50fc293 commit 432fe69
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/trigger-gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: trigger-gitlab-ci
run-name: ${{ github.event_name }} triggered by ${{ github.actor }}

on: [push]
on:
push:
branches:
- master

jobs:
trigger-gitlab-ci:
Expand Down
3 changes: 3 additions & 0 deletions src/dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ const char * dictionary_get(const dictionary * d, const char * key, const char *
unsigned hash ;
size_t i ;

if(d == NULL || key == NULL)
return def ;

hash = dictionary_hash(key);
for (i=0 ; i<d->size ; i++) {
if (d->key[i]==NULL)
Expand Down
49 changes: 49 additions & 0 deletions test/test_dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,52 @@ void Test_dictionary_dump(CuTest *tc)

dictionary_del(dic);
}

void Test_dictionary_get(CuTest *tc)
{
dictionary *dic;
int i, j;
char sec_name[32];
char key_name[64];

/*NULL test*/
CuAssertPtrEquals(tc, NULL, dictionary_get(NULL, NULL, NULL));
CuAssertPtrEquals(tc, NULL, dictionary_get(NULL, "string", NULL));

/*Check the def return element*/
dic = dictionary_new(DICTMINSZ);
CuAssertPtrNotNull(tc, dic);
CuAssertPtrEquals(tc, NULL, dictionary_get(dic, "dummy", NULL));
CuAssertStrEquals(tc, "def", dictionary_get(dic, NULL, "def"));
CuAssertStrEquals(tc, "def", dictionary_get(dic, "dummy", "def"));

/*Populate the dictionary*/
for (i = 1; i < 3; ++i)
{
sprintf(sec_name, "sec%d", i);
dictionary_set(dic, sec_name, "");
for (j = 1; j < 5; ++j)
{
sprintf(key_name, "%s:key%d", sec_name, j);
dictionary_set(dic, key_name, "dummy_value");
CuAssertStrEquals(tc, "dummy_value",
dictionary_get(dic, key_name, "string"));
}
}

/*Test get dictionary section value*/
CuAssertStrEquals(tc, "",
dictionary_get(dic, "sec1", NULL));
CuAssertStrEquals(tc, "",
dictionary_get(dic, "sec1", "def"));

/*delete and set a key in a dictionary*/
dictionary_unset(dic, "sec1:key4");
CuAssertStrEquals(tc, "def",
dictionary_get(dic, "sec1:key4", "def"));
dictionary_set(dic, "sec1:key4", "dummy_value");
CuAssertStrEquals(tc, "dummy_value",
dictionary_get(dic, "sec1:key4", "def"));

dictionary_del(dic);
}

0 comments on commit 432fe69

Please sign in to comment.