diff --git a/.gitignore b/.gitignore
index 11cccdf..422d0ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,8 +4,11 @@
# Build files
src/sngrep
-src/*.o
-src/.deps
+tests/test-*.log
+tests/test-*.trs
+tests/test-???
+*/*.o
+*/.deps
src/config.h*
src/stamp-h1
@@ -22,6 +25,7 @@ configure
missing
install-sh
depcomp
+test-driver
# Ignore Doxygen generated files
doc/html
diff --git a/Makefile.am b/Makefile.am
index 215c0a1..b0dd2a5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,2 +1,2 @@
-SUBDIRS=src config doc
+SUBDIRS=src config doc tests
EXTRA_DIST=bootstrap.sh
diff --git a/configure.ac b/configure.ac
index bb1e5fb..9bc48bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -198,4 +198,5 @@ AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([config/Makefile])
AC_CONFIG_FILES([doc/Makefile])
+AC_CONFIG_FILES([tests/Makefile])
AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..affa206
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,10 @@
+check_PROGRAMS=test-001 test-002 test-003 test-004 test-005 test-006 test-007
+test_001_SOURCES=test_001.c
+test_002_SOURCES=test_002.c
+test_003_SOURCES=test_003.c
+test_004_SOURCES=test_004.c
+test_005_SOURCES=test_005.c
+test_006_SOURCES=test_006.c
+test_007_SOURCES=test_007.c ../src/vector.c
+
+TESTS = $(check_PROGRAMS)
\ No newline at end of file
diff --git a/tests/README b/tests/README
new file mode 100644
index 0000000..97dd0f9
--- /dev/null
+++ b/tests/README
@@ -0,0 +1,16 @@
+Basic testing programs for sngrep.
+
+This set of test will do some basic inputs to check sngrep screen navigation
+doesn't crash. This checks are ultra-super-basic.
+
+- test_001 : UI testing
+- test_002 : Call List testing
+- test_003 : Call Flow testing
+- test_004 : Call Raw testing
+- test_005 : Column selection testing
+- test_006 : Message diff testing
+- test_007: Test vector container structures
+
+Sample capture files has been taken from wireshark Wiki:
+- https://wiki.wireshark.org/SampleCaptures
+
diff --git a/tests/aaa.pcap b/tests/aaa.pcap
new file mode 100644
index 0000000..6e47833
Binary files /dev/null and b/tests/aaa.pcap differ
diff --git a/tests/test_001.c b/tests/test_001.c
new file mode 100644
index 0000000..f582272
--- /dev/null
+++ b/tests/test_001.c
@@ -0,0 +1,36 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_001.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic read from file test
+ */
+
+const char keys[] =
+ {
+ 27,
+ 10,
+ 0
+ };
+
+#include "test_input.c"
diff --git a/tests/test_002.c b/tests/test_002.c
new file mode 100644
index 0000000..847a933
--- /dev/null
+++ b/tests/test_002.c
@@ -0,0 +1,66 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_002.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic Call list testing
+ */
+
+const char keys[] =
+ {
+ /* Swap some options */
+ 'c', 'l', 'p', 'p',
+ /* Select some dialogs */
+ 107, 32, 107, 107, 32, 107, 107, 107, 32, 107, 107,
+ /* Enter Call Flow */
+ 10, 27,
+ /* Enter Call Raw */
+ 'R', 27,
+ /* Enter Filter screen */
+ 'F', 27,
+ /* Enter Column screen */
+ 't', 27,
+ /* Unselect some dialogs */
+ 32, 107, 32,
+ /* Move beyond list limits */
+ 107, 107, 107, 107, 107, 106,
+ 107, 107, 107, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 4, 4, 2, 2, 4, 2, 4, 2,
+ /* Enter help screen */
+ 'h', 100,
+ /* Enter save screen */
+ 's', 20, 30, 40, 50, 27,
+ /* Enter display filter */
+ '/', 20, 30, 40, 40, 10,
+ '/', 27,
+ /* Enter Call Flow once again */
+ 10, 27,
+ /* Exit */
+ 27,
+ 10,
+ 0
+ };
+
+#include "test_input.c"
diff --git a/tests/test_003.c b/tests/test_003.c
new file mode 100644
index 0000000..89e7dda
--- /dev/null
+++ b/tests/test_003.c
@@ -0,0 +1,74 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_003.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic Call Flow testing
+ */
+
+const char keys[] =
+ {
+ /* Select some dialogs */
+ 32, 107, 32, 107,
+ /* Enter Call Flow */
+ 10, 27,
+ /* Move arrow messages */
+ 107, 107, 107, 107, 107, 106,
+ 107, 107, 107, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 4, 4, 2, 2, 4, 2, 4, 2,
+ /* Reenter Call Flow */
+ 10,
+ /* Swap colors */
+ 'c', 'c', 'c', 'c', 'c', 'c',
+ /* Enter Extended Call Flow */
+ 'x', 'x', 'x', 'x',
+ /* Compress column display */
+ 's',
+ /* Toggle media display */
+ 'd', 'd', 'd', 'd', 'd',
+ /* Toggle Only SDP */
+ 'D',
+ /* Enter Call Raw (all dialogs) */
+ 'R', 27,
+ /* Enter Call Raw (single message) */
+ 10, 27,
+ /* Enter help screen */
+ 'h', 100,
+ /* Toggle raw screen */
+ 't', 't', 't', 't',
+ /* Change Raw size */
+ '0', '0', '0', '0', '0', '0', '0', '0',
+ '9', '9', '9', '9', '9', '9', '9', '9',
+ /* Reset Raw size */
+ 'T', 'T',
+ /* Leave Call Flow */
+ 27,
+ /* Exit */
+ 27,
+ 10,
+ 0
+ };
+
+#include "test_input.c"
diff --git a/tests/test_004.c b/tests/test_004.c
new file mode 100644
index 0000000..f71a8aa
--- /dev/null
+++ b/tests/test_004.c
@@ -0,0 +1,65 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_004.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic Call Raw testing
+ */
+const int keys[] =
+ {
+ /* Select some dialogs */
+ 32, 107, 107, 107, 32, 107,
+ /* Show Raw panel */
+ 'r',
+ /* Cicle options */
+ 'c', 'c', 'c', 'c', 'c', 'c',
+ 'a', 'a', 'a', 'a', 'a', 'a',
+ 'l', 'l', 'l', 'C', 'C', 'C',
+ /* Move through Raw panel */
+ 107, 107, 107, 107, 107, 106,
+ 107, 107, 107, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 4, 4, 2, 2, 4, 2, 4, 2,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ /* Enter save screen */
+ 's', 20, 30, 40, 50, 60, 27,
+ /* Leave call Raw */
+ 27,
+ /* Exit */
+ 27,
+ 10,
+ 0
+ };
+
+#include "test_input.c"
diff --git a/tests/test_005.c b/tests/test_005.c
new file mode 100644
index 0000000..b3c3b58
--- /dev/null
+++ b/tests/test_005.c
@@ -0,0 +1,63 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_005.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic Column selection testing
+ */
+
+const int keys[] =
+ {
+ /* Show Raw panel */
+ 't',
+ /* Cycle through fields */
+ 9, 9, 9, 9, 9, 9,
+ 9, 107, 107, 9, 106,
+ /* Move through Column list */
+ 107, 107, 107, 107, 107, 106,
+ 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 107, 107, 107,
+ 107, 107, 107, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ 106, 106, 106, 106, 106, 106,
+ /* Move items up and down */
+ '-', '-', '-', '-',
+ 107, 107,
+ '+', '+', '+', '+',
+ 107, 107,
+ '-', '-', '-', '-',
+ /* Apply new settings */
+ 10,
+ /* Exit */
+ 27,
+ 10,
+ 0
+ };
+
+#include "test_input.c"
diff --git a/tests/test_006.c b/tests/test_006.c
new file mode 100644
index 0000000..23a3825
--- /dev/null
+++ b/tests/test_006.c
@@ -0,0 +1,43 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_006.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic Message diff testing
+ */
+const int keys[] =
+ {
+ /* Select some dialog */
+ 107, 107, 107, 32, 10,
+ /* Move Select some messages */
+ 107, 107, 32, 32, 107, 32,
+ 107, 107, 107, 106, 32,
+ /* Leave Diff screen */
+ 27, 27,
+ /* Exit */
+ 27,
+ 10,
+ 0
+ };
+
+#include "test_input.c"
diff --git a/tests/test_007.c b/tests/test_007.c
new file mode 100644
index 0000000..09309c0
--- /dev/null
+++ b/tests/test_007.c
@@ -0,0 +1,79 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_vector.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic testing of vector structures
+ */
+
+#include "config.h"
+#include
+#include
+#include "vector.h"
+
+int main ()
+{
+ vector_t *vector;
+
+ // Basic Vector append/remove test
+ vector = vector_create(10, 10);
+ assert(vector);
+ assert(vector_count(vector) == 0);
+ vector_append(vector, 0);
+ assert(vector_count(vector) == 0);
+ vector_append(vector, malloc(1024));
+ assert(vector_count(vector) == 1);
+ assert(vector_first(vector) == vector_item(vector, 0));
+ vector_remove(vector, vector_first(vector));
+ assert(vector_count(vector) == 0);
+ assert(vector_first(vector) == vector_item(vector, 0));
+
+ // Vector overflow test
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ // Next append requires memory reallocation
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ vector_append(vector, malloc(32));
+ // Expected vector size
+ assert(vector_count(vector) == 16);
+ // Expected empty position
+ assert(vector_item(vector, vector_count(vector)) == 0);
+ // Remove position (use generic destroyer)
+ vector_set_destroyer(vector, vector_generic_destroyer);
+ vector_remove(vector, vector_item(vector, 12));
+ assert(vector_count(vector) == 15);
+
+ return 0;
+}
diff --git a/tests/test_input.c b/tests/test_input.c
new file mode 100644
index 0000000..2de35ac
--- /dev/null
+++ b/tests/test_input.c
@@ -0,0 +1,80 @@
+/**************************************************************************
+ **
+ ** sngrep - SIP Messages flow viewer
+ **
+ ** Copyright (C) 2015 Ivan Alonso (Kaian)
+ ** Copyright (C) 2015 Irontec SL. All rights reserved.
+ **
+ ** This program is free software: you can redistribute it and/or modify
+ ** it under the terms of the GNU General Public License as published by
+ ** the Free Software Foundation, either version 3 of the License, or
+ ** (at your option) any later version.
+ **
+ ** This program is distributed in the hope that it will be useful,
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ** GNU General Public License for more details.
+ **
+ ** You should have received a copy of the GNU General Public License
+ ** along with this program. If not, see .
+ **
+ ****************************************************************************/
+/**
+ * @file test_input.c
+ * @author Ivan Alonso [aka Kaian]
+ *
+ * Basic input injector for sngrep testing
+ */
+
+#include
+#include
+#include
+#include
+
+#ifndef TEST_MAX_DURATION
+#define TEST_MAX_DURATION 5
+#endif
+
+#ifndef TEST_INITIAL_WAIT
+#define TEST_INITIAL_WAIT 1000 * 600
+#endif
+
+#ifndef TEST_KEY_DELAY
+#define TEST_KEY_DELAY 1000
+#endif
+
+#ifndef TEST_PCAP_INPUT
+#define TEST_PCAP_INPUT "aaa.pcap"
+#endif
+
+int
+main()
+{
+ int ppipe[2];
+ int unused, ret;
+ unused = pipe(ppipe);
+
+ // Max test duration
+ alarm(TEST_MAX_DURATION);
+
+ if (!fork()) {
+ char *argv[] =
+ {
+ "../src/sngrep",
+ "-I",
+ TEST_PCAP_INPUT,
+ 0 };
+ dup2(ppipe[0], STDIN_FILENO);
+ execv(argv[0], argv);
+ } else {
+ usleep(TEST_INITIAL_WAIT);
+ int i;
+ for (i = 0; keys[i]; i++) {
+ unused = write(ppipe[1], &keys[i], sizeof(char));
+ usleep(TEST_KEY_DELAY);
+ }
+ unused = wait(&ret);
+ }
+
+ return ret;
+}