Core: registro de metadados de blocos (tb_meta) + testes; metadados declarados nas libraries
This commit is contained in:
1 parent
22ae18f508
commit
036162280d
14 files changed
+397
-2
No files matched your search
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* meta_test.c - testa o registro de metadados de blocos (core tb_meta).
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <tinyblocks/tinyblocks.h>
|
||||
#include <tb_operators.h>
|
||||
|
||||
static int fails = 0;
|
||||
#define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0)
|
||||
|
||||
int main(void) {
|
||||
TinyBlocks* rt;
|
||||
tinyblocks_init(&rt, NULL);
|
||||
tb_library_register(rt, tb_operators_get_library());
|
||||
|
||||
CHECK(tb_meta_count() > 10, "metadados declarados pela operators");
|
||||
|
||||
const TinyBlocks_BlockMeta* m = tb_meta_find("Math.Add");
|
||||
CHECK(m != NULL, "acha Math.Add");
|
||||
if (m) {
|
||||
CHECK(m->func_name && !strcmp(m->func_name, "eval_add"), "funcao = eval_add");
|
||||
CHECK(m->doc && strstr(m->doc, "Soma"), "doc menciona 'Soma'");
|
||||
CHECK(m->file && strstr(m->file, "tb_operators.c"), "arquivo tb_operators.c");
|
||||
}
|
||||
|
||||
const TinyBlocks_BlockMeta* lt = tb_meta_find("Operators.Lt");
|
||||
CHECK(lt && lt->func_name && !strcmp(lt->func_name, "eval_op_lt"), "funcao de Operators.Lt");
|
||||
|
||||
CHECK(tb_meta_find("Nao.Existe") == NULL, "bloco desconhecido -> NULL");
|
||||
CHECK(tb_meta_at(0) != NULL, "tb_meta_at(0)");
|
||||
CHECK(tb_meta_at(99999) == NULL, "tb_meta_at fora do range -> NULL");
|
||||
|
||||
if (m) {
|
||||
char path[1200];
|
||||
CHECK(tb_meta_resolve_file(m->file, path, sizeof(path)), "resolve o arquivo-fonte");
|
||||
int line = tb_meta_line(m);
|
||||
CHECK(line > 0, "localiza a linha de eval_add");
|
||||
if (line > 0) {
|
||||
char buf[1024];
|
||||
int got = tb_meta_read_lines(m, line, 1, buf, sizeof(buf));
|
||||
CHECK(got == 1 && strstr(buf, "eval_add"), "le a linha da funcao");
|
||||
}
|
||||
}
|
||||
|
||||
tinyblocks_deinit(&rt);
|
||||
|
||||
if (fails) printf("\n%d FALHA(S)\n", fails);
|
||||
else printf("\nTUDO OK\n");
|
||||
return fails != 0;
|
||||
}
|
||||
Reference in new issue
Block a user