Esempio n. 1
0
static void
test_clone_string_array_duplicates_elements_while_leaving_token_values_intact(void)
{
  const gchar *arr[] = {
    "foo",
    "bar",
    "baz",
    NULL
  };
  GList *l, *l2;

  l = string_array_to_list(arr);
  l = g_list_append(l, GUINT_TO_POINTER(1));
  l = g_list_append(l, GUINT_TO_POINTER(2));
  l2 = string_list_clone(l);
  string_list_free(l);

  assert_gint(g_list_length(l2), 5, "converted list is not the expected length");
  assert_string(l2->data, "foo", "first element is expected to be foo");
  assert_string(l2->next->data, "bar", "second element is expected to be bar");
  assert_string(l2->next->next->data, "baz", "third element is expected to be baz");
  assert_gint(GPOINTER_TO_UINT(l2->next->next->next->data), 1, "fourth element is expected to be a token, with a value of 1");
  assert_gint(GPOINTER_TO_UINT(l2->next->next->next->next->data), 2, "fifth element is expected to be a token, with a value of 2");

  string_list_free(l2);
}
Esempio n. 2
0
CSVScannerOptions *
_default_options(const gchar *columns[])
{
  csv_scanner_options_clean(&options);
  csv_scanner_options_set_delimiters(&options, ",");
  csv_scanner_options_set_quote_pairs(&options, "\"\"''");
  csv_scanner_options_set_flags(&options, CSV_SCANNER_STRIP_WHITESPACE);
  csv_scanner_options_set_dialect(&options, CSV_SCANNER_ESCAPE_DOUBLE_CHAR);

  csv_scanner_options_set_columns(&options, string_array_to_list(columns));
  return &options;
}
Esempio n. 3
0
static void
test_string_array_to_list_converts_to_an_equivalent_glist(void)
{
  const gchar *arr[] = {
    "foo",
    "bar",
    "baz",
    NULL
  };
  GList *l;

  l = string_array_to_list(arr);
  assert_gint(g_list_length(l), 3, "converted list is not the expected length");
  assert_string(l->data, "foo", "first element is expected to be foo");
  assert_string(l->next->data, "bar", "second element is expected to be bar");
  assert_string(l->next->next->data, "baz", "third element is expected to be baz");
  string_list_free(l);
}
Esempio n. 4
0
int
testcase(gchar *msg, guint parse_flags, gint max_columns, guint32 flags, gchar *delimiters, gchar *quotes, gchar *null_value, gchar *first_value, ...)
{
  LogMessage *logmsg;
  LogColumnParser *p;
  gchar *expected_value;
  gint i;
  va_list va;
  NVTable *nvtable;

  const gchar *column_array[] =
  {
    "C1",
    "C2",
    "C3",
    "C4",
    "C5",
    "C6",
    "C7",
    "C8",
    "C9",
    "C10",
    "C11",
    "C12",
    "C13",
    "C14",
    "C15",
    "C16",
    "C17",
    "C18",
    "C19",
    "C20",
    "C21",
    "C22",
    "C23",
    "C24",
    "C25",
    "C26",
    "C27",
    "C28",
    "C29",
    "C30",
    NULL
  };
  gboolean success;

  if (max_columns != -1)
    {
      g_assert(max_columns < (sizeof(column_array) / sizeof(column_array[0])));

      column_array[max_columns] = NULL;
    }

  parse_options.flags = parse_flags;
  logmsg = log_msg_new(msg, strlen(msg), NULL, &parse_options);

  p = log_csv_parser_new();
  log_csv_parser_set_flags(p, flags);
  log_column_parser_set_columns(p, string_array_to_list(column_array));
  if (delimiters)
    log_csv_parser_set_delimiters(p, delimiters);
  if (quotes)
    log_csv_parser_set_quote_pairs(p, quotes);
  if (null_value)
    log_csv_parser_set_null_value(p, null_value);

  nvtable = nv_table_ref(logmsg->payload);
  success = log_parser_process(&p->super, &logmsg, NULL, log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), -1);
  nv_table_unref(nvtable);

  if (success && !first_value)
    {
      fprintf(stderr, "unexpected match; msg=%s\n", msg);
      exit(1);
    }
  if (!success && first_value)
    {
      fprintf(stderr, "unexpected non-match; msg=%s\n", msg);
      exit(1);
    }
  log_pipe_unref(&p->super.super);

  va_start(va, first_value);
  expected_value = first_value;
  i = 0;
  while (expected_value && column_array[i])
    {
      const gchar *value;
      gssize value_len;

      value = log_msg_get_value(logmsg, log_msg_get_value_handle(column_array[i]), &value_len);

      if (expected_value && expected_value[0])
        {
          TEST_ASSERT(value && value[0], "expected value set, but no actual value");
          TEST_ASSERT(strlen(expected_value) == value_len, "value length doesn't match actual length");
          TEST_ASSERT(strncmp(value, expected_value, value_len) == 0, "value does not match expected value");
        }
      else
        {
          TEST_ASSERT(!(value && value[0]), "expected unset, but actual value present");
        }

      expected_value = va_arg(va, char *);
      i++;
    }

  log_msg_unref(logmsg);
  return 1;
}
Esempio n. 5
0
LogParser *
_construct_parser(gint max_columns, gint dialect, gchar *delimiters, gchar *quotes, gchar *null_value, const gchar *string_delims[])
{
  LogParser *p;

  const gchar *column_array[] =
  {
    "C1",
    "C2",
    "C3",
    "C4",
    "C5",
    "C6",
    "C7",
    "C8",
    "C9",
    "C10",
    "C11",
    "C12",
    "C13",
    "C14",
    "C15",
    "C16",
    "C17",
    "C18",
    "C19",
    "C20",
    "C21",
    "C22",
    "C23",
    "C24",
    "C25",
    "C26",
    "C27",
    "C28",
    "C29",
    "C30",
    NULL
  };

  if (max_columns != -1)
    {
      g_assert(max_columns < (sizeof(column_array) / sizeof(column_array[0])));

      column_array[max_columns] = NULL;
    }

  p = csv_parser_new(NULL);
  csv_scanner_options_set_dialect(csv_parser_get_scanner_options(p), dialect);
  csv_scanner_options_set_columns(csv_parser_get_scanner_options(p), string_array_to_list(column_array));
  if (delimiters)
    csv_scanner_options_set_delimiters(csv_parser_get_scanner_options(p), delimiters);
  if (quotes)
    csv_scanner_options_set_quote_pairs(csv_parser_get_scanner_options(p), quotes);
  if (null_value)
    csv_scanner_options_set_null_value(csv_parser_get_scanner_options(p), null_value);

  if (string_delims)
    csv_scanner_options_set_string_delimiters(csv_parser_get_scanner_options(p), string_array_to_list(string_delims));

  return p;
}