void test_before_request_ctx_reload(void) { name = "bola.md"; title = "my title"; content = "bolac"; parsed_content = "parsed content"; parsed_content_css = "my css"; slug = "bola"; headline = "head"; commit = "guda"; unix_utc = -1; needs_reload = TRUE; expected_ttl = 5.0; balde_app_t *app = balde_app_init(); balde_app_set_user_data_destroy_func(app, (GDestroyNotify) bluster_gist_ctx_free); bluster_before_request(app, NULL); bluster_gist_ctx_t *ctx = balde_app_get_user_data(app); g_assert(ctx != NULL); g_assert(ctx->files != NULL); bluster_gist_file_t *file = ctx->files->data; g_assert_cmpstr(file->name, ==, "bola.md"); g_assert_cmpstr(file->content, ==, "bolac"); g_assert_cmpstr(file->slug, ==, "bola"); g_assert(ctx->files->next == NULL); g_assert_cmpstr(ctx->commit, ==, "guda"); g_assert(ctx->datetime != NULL); g_assert(ctx == balde_app_get_user_data(app)); balde_app_free(app); }
void test_before_request_ctx_reload_with_old_ctx(void) { name = "bola.md"; title = "my title"; content = "bolac"; parsed_content = "<p>parsed content</p>"; parsed_content_css = "my css"; slug = "bola"; headline = "head"; commit = "guda"; unix_utc = -1; needs_reload = TRUE; expected_ttl = 10.0; bluster_gist_ctx_t *old_ctx = g_new(bluster_gist_ctx_t, 1); old_ctx->files = NULL; old_ctx->headline = NULL; bluster_gist_file_t *f = g_new(bluster_gist_file_t, 1); f->name = g_strdup("bola.md"); f->title = g_strdup("my old title"); f->content = g_strdup("chunda"); f->parsed_content = g_new(bluster_markdown_t, 1); f->parsed_content->content = g_strdup("<p>chunda</p>"); f->parsed_content->css = NULL; f->slug = g_strdup("bola"); old_ctx->files = g_slist_append(old_ctx->files, f); old_ctx->commit = g_strdup("arcoiro"); old_ctx->datetime = NULL; balde_app_t *app = balde_app_init(); balde_app_set_user_data_destroy_func(app, (GDestroyNotify) bluster_gist_ctx_free); balde_app_set_config(app, "gist_ttl", "10"); balde_app_set_user_data(app, old_ctx); bluster_before_request(app, NULL); bluster_gist_ctx_t *ctx = balde_app_get_user_data(app); g_assert(ctx != NULL); g_assert(ctx->files != NULL); g_assert_cmpstr(ctx->headline, ==, "head"); bluster_gist_file_t *file = ctx->files->data; g_assert_cmpstr(file->name, ==, "bola.md"); g_assert_cmpstr(file->title, ==, "my title"); g_assert_cmpstr(file->content, ==, "bolac"); g_assert_cmpstr(file->parsed_content->content, ==, "<p>parsed content</p>"); g_assert_cmpstr(file->parsed_content->css, ==, "my css"); g_assert_cmpstr(file->slug, ==, "bola"); g_assert(ctx->files->next == NULL); g_assert_cmpstr(ctx->commit, ==, "guda"); g_assert(ctx->datetime != NULL); g_assert(ctx == balde_app_get_user_data(app)); g_assert(ctx != old_ctx); balde_app_free(app); }
void test_app_free_user_data(void) { balde_app_t *app = balde_app_init(); balde_app_set_user_data_destroy_func(app, g_free); balde_app_set_user_data(app, g_strdup("bola")); g_assert_cmpstr(balde_app_get_user_data(app), ==, "bola"); balde_app_free_user_data(app); g_assert(balde_app_get_user_data(app) == NULL); balde_app_free(app); }
int main(int argc, char **argv) { curl_global_init(CURL_GLOBAL_ALL); balde_app_t *app = balde_app_init(); balde_resources_load(app, resources_get_resource()); balde_app_set_user_data_destroy_func(app, (GDestroyNotify) bluster_gist_ctx_free); balde_app_add_before_request(app, bluster_before_request); balde_app_add_url_rule(app, "main", "/", BALDE_HTTP_GET, main_view); balde_app_add_url_rule(app, "content", "/<slug>/", BALDE_HTTP_GET, main_view); balde_app_set_config_from_envvar(app, "oauth_token", "BLUSTER_OAUTH_TOKEN", TRUE); balde_app_set_config_from_envvar(app, "gist_id", "BLUSTER_GIST_ID", FALSE); balde_app_set_config_from_envvar(app, "gist_ttl", "BLUSTER_GIST_TTL", TRUE); balde_app_run(app, argc, argv); balde_app_free(app); curl_global_cleanup(); return 0; }