Esempio n. 1
0
static void
update_data(grn_id record_id, unsigned int section,
            const gchar *old_name, const gchar *new_name)
{
    grn_obj old_value, new_value;
    const gchar *old_data, *new_data;

    GRN_TEXT_INIT(&old_value, GRN_OBJ_DO_SHALLOW_COPY);
    GRN_TEXT_INIT(&new_value, GRN_OBJ_DO_SHALLOW_COPY);

    if (old_name) {
        old_data = cut_get_fixture_data_string(old_name, NULL);
        GRN_TEXT_SET_REF(&old_value, old_data, strlen(old_data));
    }

    if (new_name) {
        new_data = cut_get_fixture_data_string(new_name, NULL);
        GRN_TEXT_SET_REF(&new_value, new_data, strlen(new_data));
    }

    grn_ii_column_update(context, inverted_index, record_id, section,
                         &old_value, &new_value, NULL);
    grn_obj_close(context, &old_value);
    grn_obj_close(context, &new_value);
}
Esempio n. 2
0
void
cut_setup(void)
{
  const gchar *database_path;

  cut_set_fixture_data_dir(grn_test_get_base_dir(),
                           "fixtures",
                           "story",
                           "taiyaki",
                           NULL);

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  assert_send_commands(cut_get_fixture_data_string("ddl.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("areas.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("categories.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("shops.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("synonyms.grn", NULL));
}
Esempio n. 3
0
void
test_attachment_save (void)
{
  GList *attachments, *node;

  document = load_document ("attachment.pdf");
  cut_assert_true (poppler_document_has_attachments (document));

  attachments = poppler_document_get_attachments (document);
  gcut_take_list (attachments, attachment_unref);
  for (node = attachments; node; node = g_list_next (node))
    {
      PopplerAttachment *attachment = node->data;
      const gchar *filename;
      gchar *contents;
      const gchar *expected_contents;
      GError *error = NULL;

      filename = cut_take_string (g_build_filename (tmp_dir,
                                                    attachment->name,
                                                    NULL));
      poppler_attachment_save (attachment, filename, &error);
      gcut_assert_error (error);

      g_file_get_contents (filename, &contents, NULL, &error);
      gcut_assert_error (error);
      expected_contents = cut_get_fixture_data_string (attachment->name, NULL);
      cut_set_message ("%s", attachment->name);
      cut_assert_equal_string_with_free (expected_contents, contents);
    }
}
Esempio n. 4
0
void
test_extract_attachments (const void *data)
{
    ExtractTestData *test_data = (ExtractTestData*)data;

    const char *body;
    MzAttachment expected = { NULL, NULL, NULL, 0 };
    const char *expected_data;
    unsigned int expected_size = 0;
    MzAttachment *actual;

    expected_data = mz_test_utils_load_data(test_data->expected_attachment_filename,
                                            &expected_size);
    expected.data = expected_data;
    expected.data_length = expected_size;
    expected.filename = (char*)test_data->expected_attachment_filename;

    body = cut_get_fixture_data_string(test_data->fixture_filename, NULL);
    cut_assert_not_null(body);

    actual_attachments = mz_utils_extract_attachments(body, test_data->boundary_string);
    cut_assert_not_null(actual_attachments);

    actual = actual_attachments->data;

    cut_trace(assert_equal_attachment(&expected, actual));
}
Esempio n. 5
0
void
test_get_content_transfer_encoding (void)
{
    char *content_transfer_encoding;
    const char *content;

    content = cut_get_fixture_data_string("attachment", NULL);
    cut_assert_not_null(content);

    content_transfer_encoding = mz_utils_get_content_transfer_encoding(content);
    cut_take_string(content_transfer_encoding);
    cut_assert_equal_string("base64", content_transfer_encoding);
}
Esempio n. 6
0
void
test_get_content_type (void)
{
    char *content_type;
    const char *content;

    content = cut_get_fixture_data_string("attachment", NULL);
    cut_assert_not_null(content);

    content_type = mz_utils_get_content_type(content);
    cut_take_string(content_type);
    cut_assert_equal_string("image/png", content_type);
}
Esempio n. 7
0
void
test_get_attachment_body_place (void)
{
    const char *content;
    const char *body;
    const char *expected_body;
    unsigned int size = 0;

    content = cut_get_fixture_data_string("attachment", NULL);
    cut_assert_not_null(content);

    expected_body = cut_get_fixture_data_string("attachment_body", NULL);
    cut_assert_not_null(expected_body);

    body = mz_utils_get_attachment_body_place(content,
                                              "--=-u231oNe9VILCVd42q7nh",
                                              &size);
    cut_assert_not_null(body);
    cut_assert_not_equal_int(0, size);

    cut_assert_equal_int(strlen(expected_body), size);
    cut_assert_equal_substring(expected_body, body, size);
}
Esempio n. 8
0
void
test_get_decoded_attachment_body (void)
{
    const char *content;
    const char *expected;
    const char *body;
    unsigned int size = 0;
    unsigned int expected_size = 0;

    content = cut_get_fixture_data_string("attachment", NULL);
    cut_assert_not_null(content);

    expected = mz_test_utils_load_data("t.png", &expected_size);
    cut_assert_not_null(expected);

    body = mz_utils_get_decoded_attachment_body(content,
                                                "--=-u231oNe9VILCVd42q7nh",
                                                &size);
    cut_assert_not_null(body);
    cut_assert_not_equal_int(0, size);

    cut_assert_equal_memory(expected, expected_size, body, size);
}
Esempio n. 9
0
static void
load_data(void)
{
  assert_send_commands(cut_get_fixture_data_string("ddl.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("shops.grn", NULL));
}