ltm/test/instance.c

45 lines
1.2 KiB
C
Raw Normal View History

2024-03-27 11:16:15 +01:00
#include "test.h"
#include "ltm/common.h"
#include "ltm/template.h"
#include "ltm/template_internal.h"
void test_single_placeholder() {
const char *s = "Hello, {{ world }}!";
ltm_template *template;
TEST_ASSERT(ltm_template_compile(&template, s) == ltm_err_ok);
ltm_instance *instance;
TEST_CHECK(ltm_template_instantiate(&instance, template) == ltm_err_ok);
TEST_CHECK(ltm_instance_block_add_var(instance, "world", ltm_instance_block_type_buf, "World", 5) == ltm_err_ok);
TEST_CHECK(ltm_instance_size(instance) == 13);
char buf[13];
size_t written = 0;
TEST_CHECK(ltm_instance_write(&written, buf, 5, instance) == ltm_err_ok);
TEST_CHECK(written == 5);
written = 0;
TEST_CHECK(ltm_instance_write(&written, buf + 5, 5, instance) == ltm_err_ok);
TEST_CHECK(written == 5);
written = 0;
TEST_CHECK(ltm_instance_write(&written, buf + 10, 5, instance) == ltm_err_done);
TEST_CHECK(written == 3);
TEST_CHECK(strncmp(buf, "Hello, World!", 13) == 0);
TEST_DUMP("buf", buf, 13);
ltm_instance_free(instance);
ltm_template_free(template);
}
TEST_LIST = {
{ "instance single placeholder", test_single_placeholder },
{ NULL, NULL }
};