File: grok_capture.test.c

package info (click to toggle)
grok 1.20110708.1-4.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,408 kB
  • ctags: 1,006
  • sloc: ansic: 3,469; ruby: 987; makefile: 276; sh: 124; yacc: 106
file content (73 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <string.h>
#include "grok.h"
#include "test.h"
#include "grok_capture.h"

void test_grok_capture_get_by_id(void) {
  INIT;

  grok_capture src;
  const grok_capture *dst;
  grok_capture_init(&grok, &src);

  src.id = 9;
  src.name = "Test";
  src.name_len = strlen(src.name);
  src.pcre_capture_number = 15;
  grok_capture_add(&grok, &src);
  dst = grok_capture_get_by_id(&grok, src.id);

  CU_ASSERT(src.id == dst->id);
  CU_ASSERT(src.pcre_capture_number == dst->pcre_capture_number);
  CU_ASSERT(!strcmp(src.name, dst->name));
  CLEANUP;
} 

void test_grok_capture_get_by_name(void) {
  INIT;
  int ret;

  grok_capture src;
  const grok_capture *dst;
  grok_capture_init(&grok, &src);

  src.id = 9;
  src.name = "Test";
  src.name_len = strlen(src.name);
  src.pcre_capture_number = 15;
  grok_capture_add(&grok, &src);
  dst = grok_capture_get_by_name(&grok, src.name);
  CU_ASSERT(dst != NULL);
  CU_ASSERT(src.id == dst->id);
  CU_ASSERT(src.pcre_capture_number == dst->pcre_capture_number);
  CU_ASSERT(!strcmp(src.name, dst->name));

  src.pcre_capture_number = 30;
  grok_capture_add(&grok, &src);
  dst = grok_capture_get_by_name(&grok, src.name);
  CU_ASSERT(dst != NULL);
  CU_ASSERT(src.id == dst->id);
  CU_ASSERT(src.pcre_capture_number == dst->pcre_capture_number);
  CU_ASSERT(!strcmp(src.name, dst->name));
  CLEANUP;
} 

void test_grok_capture_get_by_capture_number(void) {
  INIT;

  grok_capture src;
  const grok_capture *dst;
  grok_capture_init(&grok, &src);

  src.id = 0;
  src.name = strdup("Test");
  src.pcre_capture_number = 15;
  grok_capture_add(&grok, &src);
  dst = grok_capture_get_by_capture_number(&grok, src.pcre_capture_number);

  CU_ASSERT(dst != NULL);
  CU_ASSERT(src.id == dst->id);
  CU_ASSERT(src.pcre_capture_number == dst->pcre_capture_number);
  CU_ASSERT(!strcmp(src.name, dst->name));
  free(src.name);
}