Skip to content

Commit

Permalink
util/action: convert unittests to FAIL/PASS API
Browse files Browse the repository at this point in the history
  • Loading branch information
jufajardini authored and victorjulien committed May 28, 2022
1 parent 9b9b6aa commit 43d28f2
Showing 1 changed file with 41 additions and 76 deletions.
117 changes: 41 additions & 76 deletions src/util-action.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ int ActionInitConfig()
*/
static int UtilActionTest01(void)
{
int res = 1;
char config[] = "\
%YAML 1.1\n\
---\n\
Expand All @@ -185,21 +184,18 @@ action-order:\n\
ConfYamlLoadString(config, strlen(config));

ActionInitConfig();
if (action_order_sigs[0] != ACTION_PASS ||
action_order_sigs[1] != ACTION_DROP ||
action_order_sigs[2] != ACTION_REJECT ||
action_order_sigs[3] != ACTION_ALERT)
{
res = 0;
}
FAIL_IF_NOT(action_order_sigs[0] == ACTION_PASS);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_REJECT);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_ALERT);
ConfRestoreContextBackup();

/* Restore default values */
action_order_sigs[0] = ACTION_PASS;
action_order_sigs[1] = ACTION_DROP;
action_order_sigs[2] = ACTION_REJECT;
action_order_sigs[3] = ACTION_ALERT;
return res;
PASS;
}

/**
Expand All @@ -208,7 +204,6 @@ action-order:\n\
*/
static int UtilActionTest02(void)
{
int res = 1;
char config[] = "\
%YAML 1.1\n\
---\n\
Expand All @@ -223,21 +218,18 @@ action-order:\n\
ConfYamlLoadString(config, strlen(config));

ActionInitConfig();
if (action_order_sigs[0] != ACTION_PASS ||
action_order_sigs[1] != ACTION_DROP ||
action_order_sigs[2] != ACTION_REJECT ||
action_order_sigs[3] != ACTION_ALERT)
{
res = 0;
}
FAIL_IF_NOT(action_order_sigs[0] == ACTION_PASS);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_REJECT);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_ALERT);
ConfRestoreContextBackup();

/* Restore default values */
action_order_sigs[0] = ACTION_PASS;
action_order_sigs[1] = ACTION_DROP;
action_order_sigs[2] = ACTION_REJECT;
action_order_sigs[3] = ACTION_ALERT;
return res;
PASS;
}

/**
Expand All @@ -246,7 +238,6 @@ action-order:\n\
*/
static int UtilActionTest03(void)
{
int res = 1;
char config[] = "\
%YAML 1.1\n\
---\n\
Expand All @@ -260,21 +251,18 @@ action-order:\n\
ConfYamlLoadString(config, strlen(config));

ActionInitConfig();
if (action_order_sigs[0] != ACTION_PASS ||
action_order_sigs[1] != ACTION_DROP ||
action_order_sigs[2] != ACTION_REJECT ||
action_order_sigs[3] != ACTION_ALERT)
{
res = 0;
}
FAIL_IF_NOT(action_order_sigs[0] == ACTION_PASS);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_REJECT);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_ALERT);
ConfRestoreContextBackup();

/* Restore default values */
action_order_sigs[0] = ACTION_PASS;
action_order_sigs[1] = ACTION_DROP;
action_order_sigs[2] = ACTION_REJECT;
action_order_sigs[3] = ACTION_ALERT;
return res;
PASS;
}

/**
Expand All @@ -283,7 +271,6 @@ action-order:\n\
*/
static int UtilActionTest04(void)
{
int res = 1;
char config[] = "\
%YAML 1.1\n\
---\n\
Expand All @@ -294,21 +281,18 @@ action-order:\n";
ConfYamlLoadString(config, strlen(config));

ActionInitConfig();
if (action_order_sigs[0] != ACTION_PASS ||
action_order_sigs[1] != ACTION_DROP ||
action_order_sigs[2] != ACTION_REJECT ||
action_order_sigs[3] != ACTION_ALERT)
{
res = 0;
}
FAIL_IF_NOT(action_order_sigs[0] == ACTION_PASS);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_REJECT);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_ALERT);
ConfRestoreContextBackup();

/* Restore default values */
action_order_sigs[0] = ACTION_PASS;
action_order_sigs[1] = ACTION_DROP;
action_order_sigs[2] = ACTION_REJECT;
action_order_sigs[3] = ACTION_ALERT;
return res;
PASS;
}

/**
Expand All @@ -318,7 +302,6 @@ action-order:\n";
*/
static int UtilActionTest05(void)
{
int res = 1;
char config[] = "\
%YAML 1.1\n\
---\n\
Expand All @@ -334,29 +317,25 @@ action-order:\n\
ConfYamlLoadString(config, strlen(config));

ActionInitConfig();
if (action_order_sigs[0] != ACTION_PASS ||
action_order_sigs[1] != ACTION_DROP ||
action_order_sigs[2] != ACTION_REJECT ||
action_order_sigs[3] != ACTION_ALERT)
{
res = 0;
}
FAIL_IF_NOT(action_order_sigs[0] == ACTION_PASS);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_REJECT);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_ALERT);
ConfRestoreContextBackup();

/* Restore default values */
action_order_sigs[0] = ACTION_PASS;
action_order_sigs[1] = ACTION_DROP;
action_order_sigs[2] = ACTION_REJECT;
action_order_sigs[3] = ACTION_ALERT;
return res;
PASS;
}

/**
* \test Check that we load a valid config
*/
static int UtilActionTest06(void)
{
int res = 1;
char config[] = "\
%YAML 1.1\n\
---\n\
Expand All @@ -371,29 +350,25 @@ action-order:\n\
ConfYamlLoadString(config, strlen(config));

ActionInitConfig();
if (action_order_sigs[0] != ACTION_ALERT ||
action_order_sigs[1] != ACTION_DROP ||
action_order_sigs[2] != ACTION_REJECT ||
action_order_sigs[3] != ACTION_PASS)
{
res = 0;
}
FAIL_IF_NOT(action_order_sigs[0] == ACTION_ALERT);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_REJECT);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_PASS);
ConfRestoreContextBackup();

/* Restore default values */
action_order_sigs[0] = ACTION_PASS;
action_order_sigs[1] = ACTION_DROP;
action_order_sigs[2] = ACTION_REJECT;
action_order_sigs[3] = ACTION_ALERT;
return res;
PASS;
}

/**
* \test Check that we load a valid config
*/
static int UtilActionTest07(void)
{
int res = 1;
char config[] = "\
%YAML 1.1\n\
---\n\
Expand All @@ -408,21 +383,18 @@ action-order:\n\
ConfYamlLoadString(config, strlen(config));

ActionInitConfig();
if (action_order_sigs[0] != ACTION_PASS ||
action_order_sigs[1] != ACTION_ALERT ||
action_order_sigs[2] != ACTION_DROP ||
action_order_sigs[3] != ACTION_REJECT)
{
res = 0;
}
FAIL_IF_NOT(action_order_sigs[0] == ACTION_PASS);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_ALERT);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_REJECT);
ConfRestoreContextBackup();

/* Restore default values */
action_order_sigs[0] = ACTION_PASS;
action_order_sigs[1] = ACTION_DROP;
action_order_sigs[2] = ACTION_REJECT;
action_order_sigs[3] = ACTION_ALERT;
return res;
PASS;
}

/**
Expand All @@ -431,28 +403,21 @@ action-order:\n\
*/
static int UtilActionTest08(void)
{
int res = 1;
char config[] = "%YAML 1.1\n"
"---\n";

ConfCreateContextBackup();
ConfInit();
ConfYamlLoadString(config, strlen(config));

if (ActionInitConfig() != 0) {
res = 0;
goto done;
}
if (action_order_sigs[0] != ACTION_PASS ||
action_order_sigs[1] != ACTION_DROP ||
action_order_sigs[2] != ACTION_REJECT ||
action_order_sigs[3] != ACTION_ALERT) {
res = 0;
}
FAIL_IF_NOT(ActionInitConfig() == 0);
FAIL_IF_NOT(action_order_sigs[0] == ACTION_PASS);
FAIL_IF_NOT(action_order_sigs[1] == ACTION_DROP);
FAIL_IF_NOT(action_order_sigs[2] == ACTION_REJECT);
FAIL_IF_NOT(action_order_sigs[3] == ACTION_ALERT);

done:
ConfRestoreContextBackup();
return res;
PASS;
}

/* Register unittests */
Expand Down

0 comments on commit 43d28f2

Please sign in to comment.