#include <check.h>
#include <stdlib.h>
+
#include "../os_regex/os_regex.h"
#include "../os_regex/os_regex_internal.h"
Suite *test_suite(void);
+
START_TEST(test_success_match1)
{
{NULL, NULL, NULL}
};
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(OS_Match2(tests[i][0],tests[i][1]),
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(OS_Match2(tests[i][0], tests[i][1]),
"%s should have OS_Match2 true with %s: Ref: %s",
tests[i][0], tests[i][1], tests[i][1]);
}
{NULL, NULL, NULL}
};
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(!OS_Match2(tests[i][0],tests[i][1]),
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(!OS_Match2(tests[i][0], tests[i][1]),
"%s should have OS_Match2 false with %s: Ref: %s",
tests[i][0], tests[i][1], tests[i][2]);
}
{"^\\S+ [(\\d+:\\d+:\\d+)] \\.+ (\\d+.\\d+.\\d+.\\d+)\\p*\\d* -> (\\d+.\\d+.\\d+.\\d+)\\p*", "snort: [1:590:12] RPC portmap ypserv request UDP [Classification: Decode of an RPC Query] [Priority: 2]: {UDP} 10.4.11.94:669 -> 10.4.3.20:111", ""},
{"^\\S+ [(\\d+:\\d+:\\d+)] \\.+ (\\d+.\\d+.\\d+.\\d+)\\p*\\d* -> (\\d+.\\d+.\\d+.\\d+)\\p*", "snort: [1:590:12] RPC portmap ypserv request UDP [Classification: Decode of an RPC Query] [Priority: 2]: {UDP} 10.4.11.94:670 -> 10.4.3.20:111", ""},
{"^\\S+ [(\\d+:\\d+:\\d+)] \\.+ (\\d+.\\d+.\\d+.\\d+)\\p*\\d* -> (\\d+.\\d+.\\d+.\\d+)\\p*", "snort: [1:1421:11] SNMP AgentX/tcp request [Classification: Attempted Information Leak] [Priority: 2]: {TCP} 10.4.12.26:37020 -> 10.4.10.231:705", ""},
- {NULL,NULL,NULL}
+ {NULL, NULL, NULL}
};
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(OS_Regex(tests[i][0],tests[i][1]),
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(OS_Regex(tests[i][0], tests[i][1]),
"%s should have OS_Regex true with %s: Ref: %s",
tests[i][0], tests[i][1], tests[i][2]);
}
{"test123(\\d)", "test123a", ""},
{"\\(test)", "test", ""},
{"(\\w+)(\\d+)", "1 1", ""},
- {NULL,NULL,NULL},
+ {NULL, NULL, NULL},
};
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(!OS_Regex(tests[i][0],tests[i][1]),
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(!OS_Regex(tests[i][0], tests[i][1]),
"%s should have OS_Regex false with %s: Ref: %s",
tests[i][0], tests[i][1], tests[i][2]);
}
* Please note that all strings are \ escaped
*/
const char *tests[][2] = {
- { "test", "this is a test" },
- { "test", "thistestiswithoutspaces" },
- { "test|not", "test" },
- { "test|not", "not" },
- { "^test", "test on start" },
- {NULL,NULL},
- };
-
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(OS_WordMatch(tests[i][0],tests[i][1]),
- "%s should match positive with %s by OS_WordMatch",
- tests[i][0], tests[i][1]);
+ { "test", "this is a test" },
+ { "test", "thistestiswithoutspaces" },
+ { "test|not", "test" },
+ { "test|not", "not" },
+ { "^test", "test on start" },
+ {NULL, NULL},
+ };
+
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(OS_WordMatch(tests[i][0], tests[i][1]),
+ "%s should match positive with %s by OS_WordMatch",
+ tests[i][0], tests[i][1]);
}
}
* Please note that all strings are \ escaped
*/
const char *tests[][2] = {
- { "-test", "this is a test" },
- { "", "test" },
- { "test|not", "negative" },
- { "test", "" },
- { "^test", "starttest" },
- {NULL,NULL},
- };
-
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(!OS_WordMatch(tests[i][0],tests[i][1]),
- "%s should not match positive with %s by OS_WordMatch",
- tests[i][0], tests[i][1]);
+ { "-test", "this is a test" },
+ { "", "test" },
+ { "test|not", "negative" },
+ { "test", "" },
+ { "^test", "starttest" },
+ {NULL, NULL},
+ };
+
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(!OS_WordMatch(tests[i][0], tests[i][1]),
+ "%s should not match positive with %s by OS_WordMatch",
+ tests[i][0], tests[i][1]);
}
}
* Please note that all strings are \ escaped
*/
const char *tests[] = {
- "1",
- "0123",
- NULL,
- };
+ "1",
+ "0123",
+ NULL,
+ };
- for(i=0; tests[i] != NULL ; i++) {
+ for (i = 0; tests[i] != NULL ; i++) {
ck_assert_msg(OS_StrIsNum(tests[i]),
- "%s should match positive by OS_StrIsNum",
- tests[i]);
+ "%s should match positive by OS_StrIsNum",
+ tests[i]);
}
}
* Please note that all strings are \ escaped
*/
const char *tests[] = {
- "test",
- "1234e",
- "-1",
- "+1",
- NULL,
- };
-
- for(i=0; tests[i] != NULL ; i++) {
+ "test",
+ "1234e",
+ "-1",
+ "+1",
+ NULL,
+ };
+
+ for (i = 0; tests[i] != NULL ; i++) {
ck_assert_msg(!OS_StrIsNum(tests[i]),
- "%s should not match positive by OS_StrIsNum",
- tests[i]);
+ "%s should not match positive by OS_StrIsNum",
+ tests[i]);
}
}
* Please note that all strings are \ escaped
*/
const char *tests[][3] = {
- { "test", "test1234", "4" },
- { "test1234", "test", "4" },
- { "test", "test", "4" },
- { "test", "", "0" },
- { "", "test", "0" },
- {NULL,NULL,NULL},
- };
-
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_uint_eq(OS_StrHowClosedMatch(tests[i][0],tests[i][1])
- , (unsigned) atoi(tests[i][2]));
+ { "test", "test1234", "4" },
+ { "test1234", "test", "4" },
+ { "test", "test", "4" },
+ { "test", "", "0" },
+ { "", "test", "0" },
+ {NULL, NULL, NULL},
+ };
+
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_uint_eq(OS_StrHowClosedMatch(tests[i][0], tests[i][1])
+ , (unsigned) atoi(tests[i][2]));
}
}
* Please note that all strings are \ escaped
*/
const char *tests[][15] = {
- { "X", "testX1234", "4", "test", "1234", NULL},
- { "X", "XtestX1234X", "4", "", "test", "1234", "", NULL},
- { "Y", "testX1234", "4", "testX1234", NULL},
- { "X", "testXX1234", "4", "test", "", "1234", NULL},
- { "X", "testX1234", "1", "testX1234", NULL},
- { "X", "testX1234X5678", "2", "test", "1234X5678", NULL},
- { "X", "testX1234", "0", NULL},
- {NULL},
- };
-
- for(i=0; tests[i][0] != NULL; i++) {
+ { "X", "testX1234", "4", "test", "1234", NULL},
+ { "X", "XtestX1234X", "4", "", "test", "1234", "", NULL},
+ { "Y", "testX1234", "4", "testX1234", NULL},
+ { "X", "testXX1234", "4", "test", "", "1234", NULL},
+ { "X", "testX1234", "1", "testX1234", NULL},
+ { "X", "testX1234X5678", "2", "test", "1234X5678", NULL},
+ { "X", "testX1234", "0", NULL},
+ {NULL},
+ };
+
+ for (i = 0; tests[i][0] != NULL; i++) {
char **result = OS_StrBreak(tests[i][0][0], tests[i][1], (unsigned) atoi(tests[i][2]));
int j = 3;
- if(tests[i][j] == NULL)
- {
+ if (tests[i][j] == NULL) {
ck_assert_ptr_eq(result, NULL);
continue;
}
int k;
- for(k = 0; tests[i][j] != NULL; j++, k++)
- {
+ for (k = 0; tests[i][j] != NULL; j++, k++) {
ck_assert_ptr_ne(result[k], NULL);
ck_assert_str_eq(result[k], tests[i][j]);
}
ck_assert_ptr_eq(result[k], NULL);
- k=0;
- while(result[k])
+ k = 0;
+ while (result[k]) {
free(result[k++]);
+ }
free(result);
}
{ "from (\\S*\\d+.\\d+.\\d+.\\d\\d*\\d*)", "sshd[21576]: Illegal user web14 from ::ffff:212.227.60.55", "::ffff:212.227.60.55", NULL},
{ "^sshd[\\d+]: Accepted \\S+ for (\\S+) from (\\S+) port ", "sshd[21405]: Accepted password for root from 192.1.1.1 port 6023", "root", "192.1.1.1", NULL},
{ ": \\((\\S+)@(\\S+)\\) [", "pure-ftpd: (?@enigma.lab.ossec.net) [INFO] New connection from enigma.lab.ossec.net", "?", "enigma.lab.ossec.net", NULL},
- {NULL,NULL,NULL}
+ {NULL, NULL, NULL}
};
- for(i=0; tests[i][0] != NULL; i++) {
+ for (i = 0; tests[i][0] != NULL; i++) {
OSRegex reg;
ck_assert_int_eq(OSRegex_Compile(tests[i][0], ®, OS_RETURN_SUBSTRING), 1);
- ck_assert_ptr_ne(OSRegex_Execute(tests[i][1], ®), NULL);
+ ck_assert_ptr_ne((void *)OSRegex_Execute(tests[i][1], ®), NULL);
int j;
int k;
- for(j = 2, k = 0; tests[i][j] != NULL; j++, k++)
- {
+ for (j = 2, k = 0; tests[i][j] != NULL; j++, k++) {
ck_assert_ptr_ne(result[k], NULL);
ck_assert_str_eq(result[k], tests[i][j]);
}
{
unsigned char test = 0;
- while(1)
- {
- if((test >= 48 && test <= 57) // 0-9
+ while (1) {
+ if ((test >= 48 && test <= 57) // 0-9
|| (test >= 65 && test <= 90) // A-Z
|| (test >= 97 && test <= 122) // a-z
|| test == '(' || test == ')' || test == '-'
|| test == '.' || test == '@' || test == '/'
- || test == '_')
- {
+ || test == '_') {
ck_assert_msg(isValidChar(test) == 1, "char %d should be a valid hostname char", test);
- }
- else
- {
+ } else {
ck_assert_msg(isValidChar(test) != 1, "char %d should not be a valid hostname char", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test >= 65 && test <= 90) // A-Z
- {
- ck_assert_msg(charmap[test] == test+32, "char %d should resolve to lowercase version %d and not to %d", test, test+32, charmap[test]);
- }
- else
- {
+ while (1) {
+ if (test >= 65 && test <= 90) { // A-Z
+ ck_assert_msg(charmap[test] == test + 32, "char %d should resolve to lowercase version %d and not to %d", test, test + 32, charmap[test]);
+ } else {
ck_assert_msg(charmap[test] == test, "char %d should resolve to itself and not to %d", test, charmap[test]);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test >= '0' && test <= '9')
- {
+ while (1) {
+ if (test >= '0' && test <= '9') {
ck_assert_msg(regexmap[1][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[1][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if((test >= 'a' && test <= 'z')
+ while (1) {
+ if ((test >= 'a' && test <= 'z')
|| (test >= 'A' && test <= 'Z')
|| (test >= '0' && test <= '9')
|| test == '-' || test == '@'
- || test == '_')
- {
+ || test == '_') {
ck_assert_msg(regexmap[2][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[2][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == ' ')
- {
+ while (1) {
+ if (test == ' ') {
ck_assert_msg(regexmap[3][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[3][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == '<' || test == '>' || test == '!' || test == '?'
+ while (1) {
+ if (test == '<' || test == '>' || test == '!' || test == '?'
|| test == '"' || test == '\'' || test == '#'
|| test == '$' || test == '%' || test == '&'
|| test == '(' || test == ')' || test == '+'
|| test == '-' || test == ':' || test == '|'
|| test == '.' || test == ';' || test == '='
|| test == '[' || test == ']' || test == '{'
- || test == '}')
- {
+ || test == '}') {
ck_assert_msg(regexmap[4][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[4][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == '(')
- {
+ while (1) {
+ if (test == '(') {
ck_assert_msg(regexmap[5][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[5][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == ')')
- {
+ while (1) {
+ if (test == ')') {
ck_assert_msg(regexmap[6][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[6][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == '\\')
- {
+ while (1) {
+ if (test == '\\') {
ck_assert_msg(regexmap[7][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[7][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(!(test >= '0' && test <= '9'))
- {
+ while (1) {
+ if (!(test >= '0' && test <= '9')) {
ck_assert_msg(regexmap[8][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[8][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(!((test >= 'a' && test <= 'z')
+ while (1) {
+ if (!((test >= 'a' && test <= 'z')
|| (test >= 'A' && test <= 'Z')
|| (test >= '0' && test <= '9')
- || test == '_' || test == 127))
- {
+ || test == '-' || test == '@'
+ || test == '_')) {
ck_assert_msg(regexmap[9][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[9][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test != ' ')
- {
+ while (1) {
+ if (test != ' ') {
ck_assert_msg(regexmap[10][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[10][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
+ while (1) {
ck_assert_msg(regexmap[11][test] == 1, "char %d should match", test);
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == '\t')
- {
+ while (1) {
+ if (test == '\t') {
ck_assert_msg(regexmap[12][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[12][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == '$')
- {
+ while (1) {
+ if (test == '$') {
ck_assert_msg(regexmap[13][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[13][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == '|')
- {
+ while (1) {
+ if (test == '|') {
ck_assert_msg(regexmap[14][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[14][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
{
unsigned char test = 0;
- while(1)
- {
- if(test == '<')
- {
+ while (1) {
+ if (test == '<') {
ck_assert_msg(regexmap[15][test] == 1, "char %d should match", test);
- }
- else
- {
+ } else {
ck_assert_msg(regexmap[15][test] != 1, "char %d should not match", test);
}
- if(test == 255)
- {
+ if (test == 255) {
break;
}
test++;
* Please note that all strings are \ escaped
*/
const char *tests[][2] = {
- { "test1234", "test" },
- { "test", "test" },
- { "test", "" },
- { "", "" },
- {NULL,NULL},
- };
-
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(OS_StrStartsWith(tests[i][0],tests[i][1]),
- "%s should match positive with %s by OS_StrStartsWith",
- tests[i][0], tests[i][1]);
+ { "test1234", "test" },
+ { "test", "test" },
+ { "test", "" },
+ { "", "" },
+ {NULL, NULL},
+ };
+
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(OS_StrStartsWith(tests[i][0], tests[i][1]),
+ "%s should match positive with %s by OS_StrStartsWith",
+ tests[i][0], tests[i][1]);
}
}
* Please note that all strings are \ escaped
*/
const char *tests[][2] = {
- { "test", "test1234" },
- { "", "test" },
- {NULL,NULL},
- };
-
- for(i=0; tests[i][0] != NULL ; i++) {
- ck_assert_msg(!OS_StrStartsWith(tests[i][0],tests[i][1]),
- "%s should not match positive with %s by OS_StrStartsWith",
- tests[i][0], tests[i][1]);
+ { "test", "test1234" },
+ { "", "test" },
+ {NULL, NULL},
+ };
+
+ for (i = 0; tests[i][0] != NULL ; i++) {
+ ck_assert_msg(!OS_StrStartsWith(tests[i][0], tests[i][1]),
+ "%s should not match positive with %s by OS_StrStartsWith",
+ tests[i][0], tests[i][1]);
}
}