Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3851 from lawli3t/improve-tests-keymeta
Browse files Browse the repository at this point in the history
Add additional test cases for module keymeta
  • Loading branch information
mpranj authored Sep 26, 2021
2 parents 817f7eb + bae4e2e commit 28bbf3e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 16 deletions.
4 changes: 2 additions & 2 deletions doc/api_review/core/keyCopyAllMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@

- [x] Function code is fully covered by tests
- [ ] All possible error states are covered by tests
- [ ] add test for dest NULL
- [ ] add test for source NULL
- [x] add test for dest NULL
- [x] add test for source NULL
- All possible enum values are covered by tests
- [x] No inconsistencies between tests and documentation

Expand Down
2 changes: 1 addition & 1 deletion doc/api_review/core/keyCurrentMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

- [x] Function code is fully covered by tests
- [ ] All possible error states are covered by tests
- [ ] add check for null pointer
- [x] add check for null pointer
- All possible enum values are covered by tests
- [x] No inconsistencies between tests and documentation

Expand Down
6 changes: 3 additions & 3 deletions doc/api_review/core/keyGetMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
### Tests

- [ ] Function code is fully covered by tests
- [ ] see below
- [x] see below
- [ ] All possible error states are covered by tests
- [ ] key is 0
- [ ] metaName is 0
- [x] key is 0
- [x] metaName is 0
- All possible enum values are covered by tests
- [x] No inconsistencies between tests and documentation

Expand Down
6 changes: 3 additions & 3 deletions doc/api_review/core/keyMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@

- [x] Function code is fully covered by tests
- [ ] All possible error states are covered by tests
- [ ] add check if key is NULL
- [ ] add check if key has no metadata
- [ ] add test if metadata is read-only
- [x] add check if key is NULL
- [x] add check if key has no metadata
- [x] add test if metadata is read-only
- All possible enum values are covered by tests
- [ ] No inconsistencies between tests and documentation

Expand Down
2 changes: 1 addition & 1 deletion doc/api_review/core/keyNextMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

- [x] Function code is fully covered by tests
- [ ] All possible error states are covered by tests
- [ ] add check for NULL pointer
- [x] add check for NULL pointer
- All possible enum values are covered by tests
- [x] No inconsistencies between tests and documentation

Expand Down
2 changes: 1 addition & 1 deletion doc/api_review/core/keyRewindMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

- [x] Function code is fully covered by tests
- [ ] All possible error states are covered by tests
- [ ] add test for null pointer
- [x] add test for null pointer
- All possible enum values are covered by tests
- [x] No inconsistencies between tests and documentation

Expand Down
8 changes: 4 additions & 4 deletions doc/api_review/core/keySetMeta.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@
### Tests

- [x] Function code is fully covered by tests
- [ ] memory errors hard to cover
- [x] memory errors hard to cover
- [ ] All possible error states are covered by tests
- [ ] memory errors hard to cover
- [x] memory errors hard to cover
- All possible enum values are covered by tests
- [ ] No inconsistencies between tests and documentation
- [ ] test case for key 0
- [ ] test case for name 0
- [x] test case for key 0
- [x] test case for name 0
- [ ] test case for invalid name

## Summary
Expand Down
1 change: 1 addition & 0 deletions doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ _(Michael Tucek)_
- Use clang-format 12 for Restyled and update Restyled version. _(Mihael Pranjić)_
- Update all Restyled formatters to current versions. _(Mihael Pranjić)_
- Add additional test cases for module `keytest` _(@lawli3t)_
- Add additional test cases for module `keymeta` _(@lawli3t)_
- <<TODO>>
- <<TODO>>

Expand Down
2 changes: 1 addition & 1 deletion src/libs/elektra/keymeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const Key * keyCurrentMeta (const Key * key)
* Do a shallow copy of metadata with name @p metaName from source to dest.
*
* Afterwards @p source and @p dest will have the same metadata referred with
* @p metaName. If the Key with name @p metaName doesn't exist in @p src -
* @p metaName. If the Key with name @p metaName doesn't exist in @p source -
* it gets deleted in @p dest.
*
* For example the metadata type is copied into the
Expand Down
29 changes: 29 additions & 0 deletions tests/abi/testabi_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ static void test_basic (void)
keyDel (key);
}

static void test_null_pointer (void)
{
Key * key;

key = keyNew ("user:/test1", KEY_END);
exit_if_fail (key, "could not create new key");

succeed_if (keyRewindMeta (0) == -1, "Could rewind NULL Key");

succeed_if (keyGetMeta (0, "test") == 0, "Could get meta of NULL Key");
succeed_if (keyGetMeta (key, 0) == 0, "Could get meta of NULL metaName");

succeed_if (keyMeta (0) == 0, "Could get metadata of NULL Key");
succeed_if (keyCurrentMeta (0) == 0, "Could get current meta Key of NULL key");
succeed_if (keyNextMeta (0) == 0, "Could get next meta Key of NULL key");

succeed_if (keyCopyMeta (0, key, "test") == -1, "Could copy metadata to NULL Key");
succeed_if (keyCopyMeta (key, 0, "test") == -1, "Could copy metadata from NULL Key");

succeed_if (keyCopyAllMeta (0, key) == -1, "Could copy all metadata to NULL Key");
succeed_if (keyCopyAllMeta (key, 0) == -1, "Could copy all metadata from NULL Key");

succeed_if (keySetMeta (0, "test", "test"), "Could set metadata to NULL Key");
succeed_if (keySetMeta (key, 0, "test"), "Could set metadata with NULL metaName");

keyDel (key);
}

static void test_iterate (void)
{
Key * key;
Expand Down Expand Up @@ -594,6 +622,7 @@ int main (int argc, char ** argv)
init (argc, argv);

test_basic ();
test_null_pointer ();
test_iterate ();
test_size ();
test_dup ();
Expand Down

0 comments on commit 28bbf3e

Please sign in to comment.