Skip to content
This repository has been archived by the owner on Feb 16, 2025. It is now read-only.

Commit

Permalink
core: update even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kodebach committed Nov 3, 2019
1 parent 22f6443 commit a61af5a
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 225 deletions.
3 changes: 2 additions & 1 deletion src/libs/elektra/keyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,8 @@ ssize_t keyAddName (Key * key, const char * newName)
static const char * elektraKeyFindBaseNamePtr (Key * key)
{
// TODO (kodebach): check and document
const char * slash = strstr (key->key, ":/") + 1;
const char * slash = strstr (key->key, ":/");
slash = slash == NULL ? key->key : slash + 1;
const char * end = key->key + key->keySize - 2;
const char * lastPart = slash == end ? NULL : slash;
while ((slash = strchr (slash + 1, '/')) != NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/elektra/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int elektraProcessPlugin (Key * cur, int * pluginNumber, char ** pluginName, cha

if (fullname[2] == '#')
{
char prefixReferenceName[] = "system/elektra/plugins/";
char prefixReferenceName[] = "system:/elektra/plugins/";

/* We have a back reference here */
if (fullname[fullsize - 2] == '#')
Expand Down
6 changes: 3 additions & 3 deletions src/libs/meta/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ int elektraKeyCmpOrder (const Key * ka, const Key * kb)
/**
* creates an metadata array or appends another element to an existing metadata array
* e.g.
* Key *key = keyNew("user/test", KEY_END);
* Key *key = keyNew("user:/test", KEY_END);
* elektraMetaArrayAdd(key, "test", "val0");
* key now has "test/#0" with value "val0" as metadata
* elektraMetaArrayAdd(key, "test", "val1");
Expand Down Expand Up @@ -931,7 +931,7 @@ void elektraMetaArrayAdd (Key * key, const char * metaName, const char * value)
keyAddBaseName (arrayKey, keyString (meta));
}
elektraArrayIncName (arrayKey);
const char * arrayName = keyName (arrayKey) + sizeof ("meta/") - 1;
const char * arrayName = keyName (arrayKey) + sizeof ("meta:/") - 1;
keySetMeta (key, arrayName, value);
keySetMeta (key, metaName, keyBaseName (arrayKey));
keyDel (arrayKey);
Expand Down Expand Up @@ -1221,7 +1221,7 @@ int elektraSortTopology (KeySet * ks, Key ** array)
{
cur = localArray[j];
KeySet * deps = elektraMetaArrayToKS (cur, "dep");
keyDel (ksLookupByName (deps, "meta/dep", KDB_O_POP));
keyDel (ksLookupByName (deps, "meta:/dep", KDB_O_POP));
Key * tmpDep;
switch (ksGetSize (deps))
{
Expand Down
6 changes: 3 additions & 3 deletions src/libs/opts/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ bool processSpec (struct Specification * spec, KeySet * ks, Key * parentKey)
Key * specParent = keyDup (parentKey);
if (keyGetNamespace (parentKey) != KEY_NS_SPEC)
{
keySetName (specParent, "spec/");
keySetName (specParent, "spec:/");

const char * parent = strchr (keyName (parentKey), '/');
if (parent != NULL)
Expand Down Expand Up @@ -866,7 +866,7 @@ int writeArgsValues (KeySet * ks, Key * keyWithOpt, KeySet * args)
return 0;
}

Key * procKey = keyNew ("proc/", KEY_END);
Key * procKey = keyNew ("proc:/", KEY_END);
keyAddName (procKey, strchr (keyName (keyWithOpt), '/'));

Key * insertKey = keyDup (procKey);
Expand Down Expand Up @@ -939,7 +939,7 @@ int addProcKey (KeySet * ks, const Key * key, Key * valueKey)
return 1;
}

Key * procKey = keyNew ("proc/", KEY_END);
Key * procKey = keyNew ("proc:/", KEY_END);
keyAddName (procKey, strchr (keyName (key), '/'));

bool isArrayKey = elektraStrCmp (keyBaseName (procKey), "#") == 0;
Expand Down
14 changes: 7 additions & 7 deletions tests/ctest/test_conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
do \
{ \
const char * value = (val); \
Key * k = keyNew ("user/test", KEY_VALUE, value, KEY_END); \
Key * k = keyNew ("user:/test", KEY_VALUE, value, KEY_END); \
ctype expected = (expect); \
ctype var; \
succeed_if (elektraKeyTo##Type (k, &var) == 1, val " couldn't be read"); \
Expand All @@ -38,7 +38,7 @@
ctype value = (val); \
{ \
char * s = elektra##Type##ToString (value); \
Key * k = keyNew ("user/test", KEY_VALUE, s, KEY_END); \
Key * k = keyNew ("user:/test", KEY_VALUE, s, KEY_END); \
ctype var; \
succeed_if (elektraKeyTo##Type (k, &var) == 1, strval " couldn't be read back (1)"); \
succeed_if (var == value, strval " not read back correctly"); \
Expand All @@ -47,7 +47,7 @@
} \
\
{ \
Key * k = keyNew ("user/test", KEY_VALUE, string, KEY_END); \
Key * k = keyNew ("user:/test", KEY_VALUE, string, KEY_END); \
ctype var; \
succeed_if (elektraKeyTo##Type (k, &var) == 1, strval " couldn't be read (1)"); \
char * s = elektra##Type##ToString (var); \
Expand All @@ -64,11 +64,11 @@
ctype value = (val); \
{ \
char * s = elektra##Type##ToString (value); \
Key * k = keyNew ("user/test", KEY_VALUE, s, KEY_END); \
Key * k = keyNew ("user:/test", KEY_VALUE, s, KEY_END); \
ctype var; \
succeed_if (elektraKeyTo##Type (k, &var) == 1, strval " couldn't be read back (1)"); \
char * s1 = elektra##Type##ToString (var); \
Key * k1 = keyNew ("user/test", KEY_VALUE, s1, KEY_END); \
Key * k1 = keyNew ("user:/test", KEY_VALUE, s1, KEY_END); \
ctype var1; \
succeed_if (elektraKeyTo##Type (k1, &var1) == 1, strval " couldn't be read back (2)"); \
succeed_if (var1 == var, strval " not read back correctly"); \
Expand All @@ -79,11 +79,11 @@
} \
\
{ \
Key * k = keyNew ("user/test", KEY_VALUE, string, KEY_END); \
Key * k = keyNew ("user:/test", KEY_VALUE, string, KEY_END); \
ctype var; \
succeed_if (elektraKeyTo##Type (k, &var) == 1, strval " couldn't be read (1)"); \
char * s = elektra##Type##ToString (var); \
Key * k1 = keyNew ("user/test", KEY_VALUE, s, KEY_END); \
Key * k1 = keyNew ("user:/test", KEY_VALUE, s, KEY_END); \
ctype var1; \
succeed_if (elektraKeyTo##Type (k, &var1) == 1, strval " couldn't be read (2)"); \
char * s1 = elektra##Type##ToString (var1); \
Expand Down
4 changes: 2 additions & 2 deletions tests/ctest/test_globbing.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "tests.h"

#define BASE_KEY "user/tests/globbing"
#define BASE_KEY "user:/tests/globbing"

#define should_match(k, p) succeed_if (check_key (k, p) == 0, p " does not match " k)
#define should_not_match(KEY_NAME, PATTERN) \
Expand Down Expand Up @@ -70,7 +70,7 @@ static void test_underscore (void)
should_match (BASE_KEY "/longkey123__31", BASE_KEY "/_");
should_match (BASE_KEY "/1231412", BASE_KEY "/_");
should_match (BASE_KEY "/#1231231", BASE_KEY "/_");
should_match (BASE_KEY "/#__1234", BASE_KEY "/_");
should_match (BASE_KEY "/\\#__1234", BASE_KEY "/_");
should_match (BASE_KEY "/????aased12355", BASE_KEY "/_");
should_match (BASE_KEY "/***", BASE_KEY "/_");
should_match (BASE_KEY "/_", BASE_KEY "/_");
Expand Down
34 changes: 17 additions & 17 deletions tests/ctest/test_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void test_ro (void)
succeed_if (keySetBinary (key, "a", 2) == -1, "read only string, not allowed to set");

key->flags |= KEY_FLAG_RO_NAME;
succeed_if (keySetName (key, "user/") == -1, "read only name, not allowed to set");
succeed_if (keySetName (key, "user:/") == -1, "read only name, not allowed to set");

key->flags |= KEY_FLAG_RO_META;
succeed_if (keySetMeta (key, "meta", "value") == -1, "read only meta, not allowed to set");
Expand All @@ -32,7 +32,7 @@ static void test_uid (void)
{
Key * key;

key = keyNew ("user/uid", KEY_UID, 100, KEY_END);
key = keyNew ("user:/uid", KEY_UID, 100, KEY_END);
succeed_if_same_string (keyValue (keyGetMeta (key, "uid")), "100");
succeed_if (keyGetUID (key) == 100, "uid was not set correctly");

Expand Down Expand Up @@ -75,7 +75,7 @@ static void test_uid (void)

keyDel (key);

key = keyNew ("user/uid", KEY_END);
key = keyNew ("user:/uid", KEY_END);
succeed_if (keyValue (keyGetMeta (key, "uid")) == 0, "got value, but uid was not set up to now");
succeed_if (keyGetUID (key) == (uid_t) -1, "got value, but uid was not set up to now");

Expand Down Expand Up @@ -129,29 +129,29 @@ static void test_owner (void)
succeed_if_same_string (keyOwner (key), "");
succeed_if (keyDel (key) == 0, "could not delete key");

succeed_if (key = keyNew ("system/key", KEY_END), "could not create new key");
succeed_if (key = keyNew ("system:/key", KEY_END), "could not create new key");
succeed_if (keyValue (keyGetMeta (key, "owner")) == 0, "owner set for empty key");
succeed_if_same_string (keyOwner (key), "");
succeed_if (keyDel (key) == 0, "could not delete key");

succeed_if (key = keyNew ("user/key", KEY_END), "could not create new key");
succeed_if (key = keyNew ("user:/key", KEY_END), "could not create new key");
succeed_if (keyValue (keyGetMeta (key, "owner")) == 0, "owner set for empty key");
succeed_if_same_string (keyOwner (key), "");
succeed_if (keyDel (key) == 0, "could not delete key");

succeed_if (key = keyNew ("user/key", KEY_END), "could not create new key");
succeed_if (key = keyNew ("user:/key", KEY_END), "could not create new key");
succeed_if (keySetOwner (key, "markus") == sizeof ("markus"), "could not set owner markus");
succeed_if_same_string (keyValue (keyGetMeta (key, "owner")), "markus");
succeed_if_same_string (keyOwner (key), "markus");
succeed_if (keyDel (key) == 0, "could not delete key");

setenv ("USER", "markus", 1);
succeed_if (key = keyNew ("user/key", KEY_END), "could not create new key with env");
succeed_if (key = keyNew ("user:/key", KEY_END), "could not create new key with env");
succeed_if (keyValue (keyGetMeta (key, "owner")) == 0, "owner set for empty key with env");
succeed_if_same_string (keyOwner (key), "");
succeed_if (keyDel (key) == 0, "could not delete key with env");

succeed_if (key = keyNew ("user/key", KEY_END), "could not create new key with env");
succeed_if (key = keyNew ("user:/key", KEY_END), "could not create new key with env");
succeed_if (keySetMeta (key, "owner", "myowner") == 8, "owner set for empty key with env");
succeed_if_same_string (keyString (keyGetMeta (key, "owner")), "myowner");
succeed_if (keyDel (key) == 0, "could not delete key with env");
Expand All @@ -161,7 +161,7 @@ static void test_mode (void)
{
Key * key;

key = keyNew ("user/mode", KEY_MODE, 0100, KEY_END);
key = keyNew ("user:/mode", KEY_MODE, 0100, KEY_END);
succeed_if_same_string (keyValue (keyGetMeta (key, "mode")), "100");
succeed_if (keyGetMode (key) == 0100, "mode was not set correctly");

Expand Down Expand Up @@ -205,7 +205,7 @@ static void test_mode (void)

keyDel (key);

key = keyNew ("user/mode", KEY_END);
key = keyNew ("user:/mode", KEY_END);
succeed_if (keyValue (keyGetMeta (key, "mode")) == 0, "got value, but mode was not set up to now");
succeed_if (keyGetMode (key) == KDB_FILE_MODE, "KDB_FILE_MODE not default on new key");

Expand All @@ -218,23 +218,23 @@ static void test_mode (void)

static void test_metaKeySet (void)
{
Key * key = keyNew ("user/test", KEY_END);
Key * key = keyNew ("user:/test", KEY_END);
keySetMeta (key, "meta/test1", "value1");
keySetMeta (key, "meta/test2", "value2");
keySetMeta (key, "meta/test3", "value3");

KeySet * metaKeys = elektraKeyGetMetaKeySet (key);

/* test whether the metakeyset contains all keys */
Key * metaKey = ksLookupByName (metaKeys, "meta/meta/test1", KDB_O_NONE);
Key * metaKey = ksLookupByName (metaKeys, "meta:/meta/test1", KDB_O_NONE);
exit_if_fail (metaKey, "the first metakey was not found in the metakeyset");
succeed_if (!strcmp (keyString (metaKey), "value1"), "the first metakey in the metakeyset has a wrong value");

metaKey = ksLookupByName (metaKeys, "meta/meta/test2", KDB_O_NONE);
metaKey = ksLookupByName (metaKeys, "meta:/meta/test2", KDB_O_NONE);
exit_if_fail (metaKey, "the second metakey was not found in the metakeyset");
succeed_if (!strcmp (keyString (metaKey), "value2"), "the second metakey in the metakeyset has a wrong value");

metaKey = ksLookupByName (metaKeys, "meta/meta/test3", KDB_O_NONE);
metaKey = ksLookupByName (metaKeys, "meta:/meta/test3", KDB_O_NONE);
exit_if_fail (metaKey, "the third metakey was not found in the metakeyset");
succeed_if (!strcmp (keyString (metaKey), "value3"), "the third metakey in the metakeyset has a wrong value");

Expand Down Expand Up @@ -265,11 +265,11 @@ static void test_metaArrayToKS (void)
KeySet * ks = elektraMetaArrayToKS (test, "dep");
Key * cur;
cur = ksNext (ks);
succeed_if (cur && !strcmp (keyName (cur), "meta/dep"), "failed!");
succeed_if (cur && !strcmp (keyName (cur), "meta:/dep"), "failed!");
cur = ksNext (ks);
succeed_if (cur && !strcmp (keyName (cur), "meta/dep/#0"), "failed!");
succeed_if (cur && !strcmp (keyName (cur), "meta:/dep/#0"), "failed!");
cur = ksNext (ks);
succeed_if (cur && !strcmp (keyName (cur), "meta/dep/#1"), "failed!");
succeed_if (cur && !strcmp (keyName (cur), "meta:/dep/#1"), "failed!");
keyDel (test);
ksDel (ks);
}
Expand Down
30 changes: 5 additions & 25 deletions tests/ctest/test_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,24 @@ static void test_keyNamespace (void)

succeed_if (keyGetNamespace (0) == KEY_NS_NONE, "null key");

key = keyNew ("user/", KEY_END);
key = keyNew ("user:/", KEY_END);
succeed_if (keyGetNamespace (key) == KEY_NS_USER, "user namespace not KEY_NS_USER");
succeed_if (keyNameIsSystem (keyName (key)) == 0, "user name is not system");
succeed_if (keyIsSystem (key) == 0, "user key is not system");
succeed_if (keyNameIsUser (keyName (key)) == 1, "user name is not user");
succeed_if (keyIsUser (key) == 1, "user key is not user");
keyDel (key);

key = keyNew ("user/key", KEY_END);
key = keyNew ("user:/key", KEY_END);
succeed_if (keyGetNamespace (key) == KEY_NS_USER, "user namespace not KEY_NS_USER");
succeed_if (keyNameIsSystem (keyName (key)) == 0, "user name is not system");
succeed_if (keyIsSystem (key) == 0, "user key is not system");
succeed_if (keyNameIsUser (keyName (key)) == 1, "user name is not user");
succeed_if (keyIsUser (key) == 1, "user key is not user");
keyDel (key);

key = keyNew ("system/", KEY_END);
key = keyNew ("system:/", KEY_END);
succeed_if (keyGetNamespace (key) == KEY_NS_SYSTEM, "system namespace not KEY_NS_SYSTEM");
succeed_if (keyNameIsSystem (keyName (key)) == 1, "system name is not system");
succeed_if (keyIsSystem (key) == 1, "system key is not system");
succeed_if (keyNameIsUser (keyName (key)) == 0, "system name is not system");
succeed_if (keyIsUser (key) == 0, "system key is not system");
keyDel (key);

key = keyNew ("system/key", KEY_END);
key = keyNew ("system:/key", KEY_END);
succeed_if (keyGetNamespace (key) == KEY_NS_SYSTEM, "system namespace not KEY_NS_SYSTEM");
succeed_if (keyNameIsSystem (keyName (key)) == 1, "system name is not system");
succeed_if (keyIsSystem (key) == 1, "system key is not system");
succeed_if (keyNameIsUser (keyName (key)) == 0, "system name is not system");
succeed_if (keyIsUser (key) == 0, "system key is not system");
keyDel (key);

key = keyNew ("spec/key", KEY_END);
key = keyNew ("spec:/key", KEY_END);
succeed_if (keyGetNamespace (key) == KEY_NS_SPEC, "Spec namespace not KEY_NS_SPEC");
succeed_if (keyNameIsSpec (keyName (key)) == 1, "Spec name is not Spec");
succeed_if (keyIsSpec (key) == 1, "Spec key is not Spec");
succeed_if (keyNameIsUser (keyName (key)) == 0, "Spec name is not Spec");
succeed_if (keyIsUser (key) == 0, "Spec key is not Spec");
keyDel (key);

key = keyNew ("/key", KEY_CASCADING_NAME, KEY_END);
Expand Down
Loading

0 comments on commit a61af5a

Please sign in to comment.