FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_fossconfig.c File Reference

Unit tests for the fossconfig library section of libfossology. More...

#include <fossconfig.h>
#include <stdio.h>
#include <libfocunit.h>
Include dependency graph for test_fossconfig.c:

Go to the source code of this file.

Macros

#define CONF_FILE   "confdata/conftest.conf"
 
#define NONE   "none"
 
#define GROUP(g)   GROUP_##g
 
#define KEY(g, k)   GROUP_##g##_KEY_##k
 
#define VAL(g, v)   GROUP_##g##_VALUE_##v
 
#define VAL_IDX(g, v, i)   GROUP_##g##_VALUE_##v##_##i
 
#define GROUP_0   "one"
 
#define GROUP_0_KEY_0   "key_a"
 
#define GROUP_0_VALUE_0   "hello"
 
#define GROUP_0_KEY_1   "key_b"
 
#define GROUP_0_VALUE_1   "goodbye"
 
#define GROUP_1   "two"
 
#define GROUP_1_KEY_0   "another"
 
#define GROUP_1_VALUE_0   "value"
 
#define GROUP_1_KEY_1   "names"
 
#define GROUP_1_VALUE_1   "Bob, Marry, Mark, Larry, Vincent, Alex"
 
#define GROUP_2   "three"
 
#define GROUP_2_KEY_0   "this"
 
#define GROUP_2_VALUE_0   "group"
 
#define GROUP_2_KEY_1   "has"
 
#define GROUP_2_VALUE_1   "3"
 
#define GROUP_2_KEY_2   "key"
 
#define GROUP_2_VALUE_2   "literals"
 
#define GROUP_3   "four"
 
#define GROUP_3_KEY_0   "is"
 
#define GROUP_3_VALUE_0_0   "is"
 
#define GROUP_3_VALUE_0_1   "a"
 
#define GROUP_3_VALUE_0_2   "list"
 
#define GROUP_3_VALUE_0_3   "group"
 
#define GROUP_3_KEY_1   "there"
 
#define GROUP_3_VALUE_1_0   "there"
 
#define GROUP_3_VALUE_1_1   "are"
 
#define GROUP_3_VALUE_1_2   "two"
 
#define GROUP_3_VALUE_1_3   "lists"
 
#define GROUP_3_VALUE_1_4   "in"
 
#define GROUP_3_VALUE_1_5   "this"
 
#define GROUP_3_VALUE_1_6   "group"
 
#define GROUP_3_KEY_2   "not"
 
#define GROUP_3_VALUE_2   "list"
 
#define CONFIG_GET_LIST_ASSERT(g, k, i)
 

Functions

void test_fo_config_load ()
 test the fo_config_load function. More...
 
void test_fo_config_group_set ()
 Test the group set function. More...
 
void test_fo_config_key_set ()
 Test the key set function. Again, keys are stored in alphabetical order, so the comparison order may be wonky. More...
 
void test_fo_config_has_group ()
 Tests the has group function. More...
 
void test_fo_config_has_key ()
 Test the has key function. More...
 
void test_fo_config_get ()
 Test the get function. This will also test the error cases of invalid key and invalid group names. More...
 
void test_fo_config_is_list ()
 Tests the is list function. More...
 
void test_fo_config_list_length ()
 Tests the list length function. More...
 
void test_fo_config_get_list ()
 Tests the get list function. More...
 
void test_fo_config_free ()
 Tests the config free function. This makes sure that everything is correctly set to NULL after a free. More...
 

Variables

fo_conftest_data
 
CU_TestInfo fossconfig_testcases []
 

Detailed Description

Unit tests for the fossconfig library section of libfossology.

Definition in file test_fossconfig.c.

Macro Definition Documentation

◆ CONFIG_GET_LIST_ASSERT

#define CONFIG_GET_LIST_ASSERT (   g,
  k,
 
)
Value:
tmp = fo_config_get_list(test_data, GROUP(g), KEY(g, k), i, &error); \
FO_ASSERT_STRING_EQUAL(tmp, VAL_IDX(g, k, i)); \
FO_ASSERT_PTR_NULL(error); \
if(error) g_clear_error(&error)
char * fo_config_get_list(fo_conf *conf, char *group, char *key, int idx, GError **error)
Definition: fossconfig.c:382
#define GROUP
Default group ID.
Definition: libfossrepo.c:37

Function Documentation

◆ test_fo_config_free()

void test_fo_config_free ( )

Tests the config free function. This makes sure that everything is correctly set to NULL after a free.

Test:
  1. Call fo_config_free() on test data
  2. Check if everything is freed/NULLed
Returns
void

Definition at line 426 of file test_fossconfig.c.

◆ test_fo_config_get()

void test_fo_config_get ( )

Test the get function. This will also test the error cases of invalid key and invalid group names.

Test:
  1. Test fo_config_get() for known group and keys
  2. Call fo_config_get() on missing group/keys and check the error returned
Returns

Definition at line 262 of file test_fossconfig.c.

◆ test_fo_config_get_list()

void test_fo_config_get_list ( )

Tests the get list function.

Test:
Tests a none list key, and the index being out of the valid range.
Returns
void

Definition at line 367 of file test_fossconfig.c.

◆ test_fo_config_group_set()

void test_fo_config_group_set ( )

Test the group set function.

Note
Note that the order the groups are in the names array is different from the order they are declared in the file. This is because the names are stored internally in alphabetical order.
Test:
  1. Get the group set for the test data using fo_config_group_set()
  2. Check if the group names returned match the actual names
Returns
void

Definition at line 172 of file test_fossconfig.c.

◆ test_fo_config_has_group()

void test_fo_config_has_group ( )

Tests the has group function.

Test:
  1. Check fo_config_has_group() on test data for TRUE and FALSE conditions
Returns
void

Definition at line 230 of file test_fossconfig.c.

◆ test_fo_config_has_key()

void test_fo_config_has_key ( )

Test the has key function.

Test:
There are three cases here because there are two ways that a config can not have a key. If the key isn't in the group or the group doesn't exist
Returns
void

Definition at line 246 of file test_fossconfig.c.

◆ test_fo_config_is_list()

void test_fo_config_is_list ( )

Tests the is list function.

Test:
Tests groups that has both and a group that doesn't have a list. Error cases are tested elsewhere.
Returns
void

Definition at line 315 of file test_fossconfig.c.

◆ test_fo_config_key_set()

void test_fo_config_key_set ( )

Test the key set function. Again, keys are stored in alphabetical order, so the comparison order may be wonky.

Test:
  1. From the test data, get the key list using fo_config_key_set() for each group
  2. Check if the key values match
Returns
void

Definition at line 194 of file test_fossconfig.c.

◆ test_fo_config_list_length()

void test_fo_config_list_length ( )

Tests the list length function.

Test:
Checks both lists in the test file and tests a none-list key error
Returns
void

Definition at line 333 of file test_fossconfig.c.

◆ test_fo_config_load()

void test_fo_config_load ( )

test the fo_config_load function.

Test:
This should check all of the error conditions using different configuration files as will as a successful load. It is important to note that if the fo_config_load of the valid configuration file fails, all following test cases will fail as a result. Because of this, a failure here will cause a fatal abort of testing.
Returns
void

Definition at line 105 of file test_fossconfig.c.

Variable Documentation

◆ fossconfig_testcases

CU_TestInfo fossconfig_testcases[]
Initial value:
=
{
{"fo_config_load()", test_fo_config_load},
{"fo_config_group_set()", test_fo_config_group_set},
{"fo_config_key_set()", test_fo_config_key_set},
{"fo_config_has_group()", test_fo_config_has_group},
{"fo_config_has_key()", test_fo_config_has_key},
{"fo_config_get()", test_fo_config_get},
{"fo_config_is_list()", test_fo_config_is_list},
{"fo_config_list_length()", test_fo_config_list_length},
{"fo_config_get_list()", test_fo_config_get_list},
{"fo_config_free()", test_fo_config_free},
CU_TEST_INFO_NULL
}
void test_fo_config_group_set()
Test the group set function.
void test_fo_config_list_length()
Tests the list length function.
void test_fo_config_free()
Tests the config free function. This makes sure that everything is correctly set to NULL after a free...
void test_fo_config_load()
test the fo_config_load function.
void test_fo_config_get_list()
Tests the get list function.
void test_fo_config_get()
Test the get function. This will also test the error cases of invalid key and invalid group names.
void test_fo_config_has_key()
Test the has key function.
void test_fo_config_has_group()
Tests the has group function.
void test_fo_config_key_set()
Test the key set function. Again, keys are stored in alphabetical order, so the comparison order may ...
void test_fo_config_is_list()
Tests the is list function.

Definition at line 435 of file test_fossconfig.c.