Browse Source

Starting to write ttail_search + tests

Yann Weber 7 years ago
parent
commit
e46400754a
6 changed files with 130 additions and 7 deletions
  1. 5
    3
      src/Makefile.am
  2. 7
    0
      src/include/config.h.in
  3. 51
    0
      src/include/ttail_search.h
  4. 12
    0
      src/ttail_search.c
  5. 8
    4
      tests/Makefile.am
  6. 47
    0
      tests/ttail_search_check.c

+ 5
- 3
src/Makefile.am View File

@@ -1,5 +1,7 @@
1 1
 bin_PROGRAMS = ttail
2
-noinst_LIBRARIES=libttail.a
2
+noinst_LIBRARIES=libttail_init.a libttail_search.a
3 3
 
4
-libttail_a_SOURCES = ttail_init.c
5
-ttail_SOURCES = main.c ttail_init.c
4
+libttail_init_a_SOURCES = ttail_init.c
5
+libttail_search_a_SOURCES = ttail_search.c
6
+libttail_search_a_CFLAGS = @CFLAGS@ -D_NOSTATIC
7
+ttail_SOURCES = main.c ttail_init.c ttail_search.c

+ 7
- 0
src/include/config.h.in View File

@@ -1,5 +1,12 @@
1 1
 /* src/include/config.h.in.  Generated from configure.ac by autoheader.  */
2 2
 
3
+/* used by libcheck to disable static functions */
4
+#ifdef _NOSTATIC
5
+#define _static
6
+#else
7
+#define _static static
8
+#endif
9
+
3 10
 #undef TTAIL_FMT_REGEX
4 11
 
5 12
 /* Define to 1 if you have the <dlfcn.h> header file. */

+ 51
- 0
src/include/ttail_search.h View File

@@ -0,0 +1,51 @@
1
+#ifndef _ttail_init_h__
2
+#define _ttail_init_h__
3
+
4
+#include <string.h>
5
+#include <time.h>
6
+#include <regex.h>
7
+
8
+#include "config.h"
9
+#include "ttail.h"
10
+
11
+/**@brief Comparison results
12
+ *
13
+ * -1 if a < b, 1 if a > b, 0 if a == b, -2 if exception
14
+ *
15
+ * If an exception occur, exception flags are set with | on the result.
16
+ * Exceptions flags are : TTAIL_NODATE_A and TTAIL_NODATE_B
17
+ */
18
+typedef int ttail_cmp_res;
19
+
20
+/**@brief Loglines comparison function
21
+ *@param ttail_t* ttail
22
+ *@param const char* logline a
23
+ *@param const char* logline b
24
+ *@return @ref ttail_cmp_res
25
+ */
26
+ttail_cmp_res ttail_cmp_loglines(ttail_t*, const char*, const char*);
27
+
28
+/**@brief compare a logline to a date
29
+ *@param ttail_t* ttail
30
+ *@param const char* logline
31
+ *@param struct tm* @see time.h
32
+ *@return @ref ttail_cmp_res
33
+ */
34
+ttail_cmp_res ttail_cmp_logline(ttail_t*, const char*, struct tm*);
35
+
36
+/**@brief Fetch a date from a logline
37
+ *@param ttail_t* ttail
38
+ *@param const char* logline
39
+ *@param struct tm* tm will be set to extracted date if not NULL
40
+ *@return 0 if ok, -1 if error
41
+ */
42
+int ttail_logline2date(ttail_t*, const char*, struct tm*);
43
+
44
+/**@brief Apply the choosen substitution to the logline
45
+ *@param ttail_t* ttail
46
+ *@param const char* logline
47
+ *@return a pointer on the begining of the subst string
48
+ */
49
+_static const char* ttail_logline_subst(ttail_t*, const char*);
50
+
51
+#endif

+ 12
- 0
src/ttail_search.c View File

@@ -0,0 +1,12 @@
1
+#include "ttail_search.h"
2
+
3
+int ttail_logline2date(ttail_t* ttail, const char* logline, struct tm* tm)
4
+{
5
+	ttail_logline_subst(ttail, logline);
6
+	return 0;
7
+}
8
+
9
+_static const char* ttail_logline_subst(ttail_t* ttail, const char* logline)
10
+{
11
+	return logline;
12
+}

+ 8
- 4
tests/Makefile.am View File

@@ -1,10 +1,14 @@
1
-TESTS = ttail_argparse_check ttail_init_check
2
-check_PROGRAMS = ttail_argparse_check ttail_init_check
1
+TESTS = ttail_argparse_check ttail_init_check ttail_search_check
2
+check_PROGRAMS = ttail_argparse_check ttail_init_check ttail_search_check
3 3
 
4 4
 ttail_argparse_check_SOURCES = ttail_argparse_check.c
5 5
 ttail_argparse_check_CFLAGS = @CHECK_CFLAGS@
6
-ttail_argparse_check_LDADD =  $(top_builddir)/src/libttail.a @CHECK_LIBS@
6
+ttail_argparse_check_LDADD =  $(top_builddir)/src/libttail_init.a @CHECK_LIBS@
7 7
 
8 8
 ttail_init_check_SOURCES = ttail_init_check.c
9 9
 ttail_init_check_CFLAGS = @CHECK_CFLAGS@
10
-ttail_init_check_LDADD =  $(top_builddir)/src/libttail.a @CHECK_LIBS@
10
+ttail_init_check_LDADD =  $(top_builddir)/src/libttail_init.a @CHECK_LIBS@
11
+
12
+ttail_search_check_SOURCES = ttail_search_check.c
13
+ttail_search_check_CFLAGS = @CHECK_CFLAGS@ -D_NOSTATIC
14
+ttail_search_check_LDADD =  $(top_builddir)/src/libttail_search.a @CHECK_LIBS@

+ 47
- 0
tests/ttail_search_check.c View File

@@ -0,0 +1,47 @@
1
+#include <check.h>
2
+
3
+#include "ttail.h"
4
+#include "ttail_search.h"
5
+
6
+ttail_t *ttail;
7
+#define __Fname_sz 5
8
+#define FNAME_NO_EXIST 0
9
+#define FNAME_EXIST 1
10
+
11
+START_TEST (test_search_subst)
12
+{
13
+	ttail_logline_subst(ttail, "Hello world !");
14
+}
15
+END_TEST
16
+
17
+Suite * ttail_search_suite(void)
18
+{
19
+	Suite *s;
20
+	TCase *tc_search_subst;
21
+
22
+	s = suite_create("ttail search checks");
23
+	tc_search_subst = tcase_create("ttail_logline_subst checks");
24
+	/*
25
+	tcase_add_checked_fixture(tc_serch_,
26
+		setup_ttail_empty, teardown_ttail);
27
+	*/
28
+	tcase_add_test(tc_search_subst, test_search_subst);
29
+
30
+	suite_add_tcase(s, tc_search_subst);
31
+	return s;
32
+}
33
+
34
+int main(void)
35
+{
36
+	int number_failed = 0;
37
+	SRunner *sr;
38
+
39
+	sr = srunner_create(ttail_search_suite());
40
+	srunner_set_fork_status(sr, CK_FORK);
41
+
42
+	srunner_run_all(sr,CK_VERBOSE);
43
+	number_failed = srunner_ntests_failed(sr);
44
+	srunner_free(sr);
45
+	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
46
+
47
+}

Loading…
Cancel
Save