- tb_environ_config_path: caminho padrao ($XDG_CONFIG_HOME/tinyblocks/ settings.csv ou $HOME/.config/tinyblocks/settings.csv). - tb_environ_env_path: le TINYBLOCKS_SETTINGS. - tb_environ_export_csv_meta: escreve uma linha de metadados "# arquivo_config,<caminho>" antes da tabela; export_csv agora tambem cria as pastas do caminho (mkdir -p). - Editor: o CSV de settings passa a ser salvo no caminho do arquivo de configuracao (mostrado no campo) e inclui esse caminho no proprio CSV. - Nova linha de opcoes com o toggle "Detectar caminho de TINYBLOCKS_SETTINGS" (checkbox): ligado usa a variavel de ambiente, desligado usa o caminho padrao; mostra o valor atual (ou "nao definida"). - Testes: test-environ cobre config_path/env_path/export_csv_meta e a criacao de pastas; harness passa a ligar o toggle com TINYBLOCKS_SETTINGS e confere a linha de metadados no CSV.
427 lines
20 KiB
C
427 lines
20 KiB
C
/* Harness headless do editor: dirige Editor.Scene com um bloco de eventos
|
|
* falso e inspeciona os comandos de desenho produzidos por on_draw. */
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <tinyblocks/tinyblocks.h>
|
|
#include <tinyblocks/tb_renderable_block.h>
|
|
#include <tb_editor.h>
|
|
#include <tb_graphics.h>
|
|
#include <tb_events.h>
|
|
#include <tb_control.h>
|
|
#include <tb_operators.h>
|
|
#include <tb_variables.h>
|
|
#include <tb_appearance.h>
|
|
#include <tb_pen.h>
|
|
|
|
static TinyBlocks* rt;
|
|
static TinyBlocks_Block *ev, *scene;
|
|
static TinyBlocks_DrawCmd cmds[TB_DRAW_CMD_CAP];
|
|
static uint32_t ncmd;
|
|
static int fails = 0;
|
|
|
|
static void eval_ev(TinyBlocks_Block* self, TinyBlocks* rt) { (void)rt; self->dirty = false; }
|
|
|
|
static void draw(void) {
|
|
TinyBlocks_RenderableBlock* rb = NULL;
|
|
if (scene->type->on_draw(scene, rt, &rb) && rb) {
|
|
ncmd = rb->count;
|
|
memcpy(cmds, rb->cmds, ncmd * sizeof(cmds[0]));
|
|
}
|
|
tb_renderable_release_all();
|
|
}
|
|
|
|
static void frame(float mx, float my, int ld, int lu, int rd, int sc, const char* text) {
|
|
tb_block_set_output(ev, GFX_IN_MOUSE_X, tb_value_real(mx));
|
|
tb_block_set_output(ev, GFX_IN_MOUSE_Y, tb_value_real(my));
|
|
tb_block_set_output(ev, GFX_IN_MOUSE_L_DOWN, tb_value_integer(ld));
|
|
tb_block_set_output(ev, GFX_IN_MOUSE_L_UP, tb_value_integer(lu));
|
|
tb_block_set_output(ev, GFX_IN_MOUSE_R_DOWN, tb_value_integer(rd));
|
|
tb_block_set_output(ev, GFX_IN_KEY, tb_value_integer(sc));
|
|
tb_block_set_output(ev, GFX_IN_KEY_MOD, tb_value_integer(0));
|
|
tb_block_set_output(ev, GFX_IN_MOD_STATE, tb_value_integer(0));
|
|
tb_block_set_output(ev, GFX_IN_TEXT, tb_value_text(text ? text : ""));
|
|
tb_block_set_output(ev, GFX_IN_DROP_FILE, tb_value_text(""));
|
|
tb_block_set_output(ev, GFX_IN_SCROLL_DX, tb_value_real(0));
|
|
tb_block_set_output(ev, GFX_IN_SCROLL_DY, tb_value_real(0));
|
|
tb_block_set_output(ev, GFX_IN_WIN_W, tb_value_integer(1280));
|
|
tb_block_set_output(ev, GFX_IN_WIN_H, tb_value_integer(720));
|
|
tb_block_eval(scene, rt);
|
|
draw();
|
|
}
|
|
|
|
enum { R_ANY, R_CAT, R_FLY, R_WS, R_STAGE };
|
|
static bool in_region(float x, int r) {
|
|
switch (r) {
|
|
case R_CAT: return x < 68;
|
|
case R_FLY: return x >= 68 && x < 318;
|
|
case R_WS: return x >= 318 && x < 920;
|
|
case R_STAGE: return x >= 920;
|
|
default: return true;
|
|
}
|
|
}
|
|
|
|
/* Centro (aprox.) do n-ésimo texto igual a s na região */
|
|
static bool find(const char* s, int region, int nth, float* x, float* y) {
|
|
for (uint32_t i = 0; i < ncmd; i++) {
|
|
TinyBlocks_DrawCmd* c = &cmds[i];
|
|
if (c->kind != TB_DRAW_TEXT || strcmp(c->text, s) != 0 || !in_region(c->x, region)) continue;
|
|
if (nth-- > 0) continue;
|
|
*x = c->x + 3; *y = c->y - c->font_size*0.36f;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static bool stage_has(const char* s) {
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, s)) return true;
|
|
return false;
|
|
}
|
|
static bool any_has(const char* s) {
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, s)) return true;
|
|
return false;
|
|
}
|
|
static bool ws_has(const char* s) {
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && in_region(cmds[i].x, R_WS) && strcmp(cmds[i].text, s) == 0) return true;
|
|
return false;
|
|
}
|
|
static void dump_stage(void) {
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && cmds[i].y > 130) printf(" | %s\n", cmds[i].text);
|
|
}
|
|
|
|
#define CHECK(cond, msg) do { if (cond) printf("ok %s\n", msg); else { printf("FAIL %s\n", msg); fails++; dump_stage(); } } while (0)
|
|
|
|
static void click(float x, float y) { frame(x, y, 1, 0, 0, 0, NULL); frame(x, y, 0, 1, 0, 0, NULL); }
|
|
static void drag(float x0, float y0, float x1, float y1) {
|
|
frame(x0, y0, 1, 0, 0, 0, NULL);
|
|
frame(x0 + 8, y0 + 8, 0, 0, 0, 0, NULL);
|
|
frame(x1, y1, 0, 0, 0, 0, NULL);
|
|
frame(x1, y1, 0, 1, 0, 0, NULL);
|
|
}
|
|
static void type(const char* s) { frame(0, 0, 0, 0, 0, 0, s); }
|
|
static void key(int sc, float x, float y) { frame(x, y, 0, 0, 0, sc, NULL); }
|
|
static void flag(void) { click(920 + 30, 44 + 22); }
|
|
|
|
static bool need(const char* s, int region, int nth, float* x, float* y) {
|
|
if (find(s, region, nth, x, y)) return true;
|
|
printf("FAIL não achei \"%s\"\n", s); fails++;
|
|
return false;
|
|
}
|
|
|
|
int main(void) {
|
|
tinyblocks_init(&rt, NULL);
|
|
tb_graphics_set_backend(tb_graphics_null_backend());
|
|
tb_library_register(rt, tb_events_get_library());
|
|
tb_library_register(rt, tb_control_get_library());
|
|
tb_library_register(rt, tb_operators_get_library());
|
|
tb_library_register(rt, tb_variables_get_library());
|
|
tb_library_register(rt, tb_appearance_get_library());
|
|
tb_library_register(rt, tb_pen_get_library());
|
|
tb_library_register(rt, tb_graphics_get_library());
|
|
tb_library_register(rt, tb_editor_get_library());
|
|
(void)eval_ev;
|
|
ev = tb_block_create(rt, tb_type_block_find(rt, "Graphics.Input"));
|
|
scene = tb_block_create(rt, tb_type_block_find(rt, "Editor.Scene"));
|
|
tb_block_set_default(scene, 0, tb_value_block(ev));
|
|
|
|
float x, y, x2, y2;
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
printf("comandos de desenho no 1º frame: %u (cap %d)\n", ncmd, TB_DRAW_CMD_CAP);
|
|
CHECK(ncmd > 100 && ncmd < TB_DRAW_CMD_CAP, "frame inicial cabe no RenderableBlock");
|
|
|
|
/* 1. Script de exemplo */
|
|
flag();
|
|
CHECK(stage_has("x vale = 1") && stage_has("x vale = 5") && !stage_has("x vale = 6"),
|
|
"bandeira roda o script de exemplo (x vale = 1..5)");
|
|
|
|
/* 2. Arrastar "escreva" do flyout para uma área livre e clicar nele */
|
|
if (need("Aparência", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("escreva", R_FLY, 0, &x, &y)) drag(x, y, 600, 560);
|
|
CHECK(find("escreva", R_WS, 1, &x, &y), "bloco do flyout aparece no workspace");
|
|
if (need("escreva", R_WS, 1, &x, &y)) click(x, y);
|
|
CHECK(stage_has("Olá!"), "clique no bloco solto executa (Olá!)");
|
|
|
|
/* 3. Encaixar o "escreva Olá!" logo abaixo do chapéu */
|
|
float hx, hy;
|
|
if (need("quando a bandeira for clicado", R_WS, 0, &hx, &hy) && need("escreva", R_WS, 1, &x, &y)) {
|
|
/* hat: rótulo em (bx+10, by+18+18); fundo em by+54 - alvo: topo do bloco em by+54 */
|
|
float bx = hx - 3 - 10, by = hy - 18 - 18;
|
|
float gx = x - 3 - 10, gy = y - 18; /* canto do bloco arrastado */
|
|
drag(x, y, x + (bx - gx), y + (by + 54 - gy) + 6);
|
|
}
|
|
flag();
|
|
CHECK(stage_has("Olá!") && stage_has("x vale = 5"), "encaixe sob o chapéu: script roda os dois");
|
|
float oy1 = 0, oy2 = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920) {
|
|
if (!strcmp(cmds[i].text, "Olá!") && !oy1) oy1 = cmds[i].y;
|
|
if (!strcmp(cmds[i].text, "x vale = 1") && !oy2) oy2 = cmds[i].y;
|
|
}
|
|
CHECK(oy1 > 0 && oy2 > oy1, "ordem de execução: Olá! antes de x vale");
|
|
|
|
/* 4. Repórter "+": solto, editar campos, clicar - balão */
|
|
if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("+", R_FLY, 0, &x, &y)) drag(x, y, 640, 470);
|
|
if (need("+", R_WS, 0, &x, &y)) {
|
|
click(x - 22, y); type("2"); key(TB_KEY_RETURN, 0, 0);
|
|
if (need("+", R_WS, 0, &x, &y)) { click(x + 22, y); type("3"); key(TB_KEY_RETURN, 0, 0); }
|
|
if (need("+", R_WS, 0, &x, &y)) click(x, y);
|
|
}
|
|
CHECK(ws_has("5"), "repórter clicado mostra balão com 5 (2+3)");
|
|
|
|
/* 5. Encaixar o repórter (2+3) no campo de "mude x para (0)" */
|
|
if (need("para", R_WS, 0, &x2, &y2) && need("+", R_WS, 0, &x, &y)) {
|
|
float zx, zy; int k = 0;
|
|
while (find("0", R_WS, k, &zx, &zy) && !(zx > x2 && zy > y2 - 4 && zy < y2 + 4)) k++;
|
|
float tgt_left = zx - 3 - 10, rep_left = x - 3 - 43;
|
|
drag(x, y, x + (tgt_left - rep_left), y + (zy - y));
|
|
}
|
|
flag();
|
|
CHECK(stage_has("x vale = 10") && stage_has("x vale = 6") && !stage_has("x vale = 5"),
|
|
"repórter encaixado: x começa em 5 (x vale = 6..10)");
|
|
|
|
/* 6. Delete sobre o "escreva Olá!" apaga só ele; o resto sobe */
|
|
if (need("escreva", R_WS, 0, &x, &y)) {
|
|
float ox, oy; find("Olá!", R_WS, 0, &ox, &oy);
|
|
if (oy < y) find("escreva", R_WS, 1, &x, &y); /* o do "Olá!" é o primeiro de cima */
|
|
key(TB_KEY_DELETE, x, y);
|
|
}
|
|
flag();
|
|
CHECK(!stage_has("Olá!") && stage_has("x vale = 10"), "Delete remove o bloco e mantém o resto do script");
|
|
|
|
/* 7. Arrastar de volta para a paleta apaga */
|
|
if (need("Aparência", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("escreva", R_FLY, 0, &x, &y)) drag(x, y, 700, 600);
|
|
int before = 0; while (find("escreva", R_WS, before, &x2, &y2)) before++;
|
|
float lx = 0, ly = 0; for (int k = 0; find("escreva", R_WS, k, &x2, &y2); k++) if (y2 > ly) { lx = x2; ly = y2; }
|
|
drag(lx, ly, 150, 400);
|
|
int after = 0; while (find("escreva", R_WS, after, &x2, &y2)) after++;
|
|
CHECK(after == before - 1, "soltar bloco sobre a paleta apaga");
|
|
|
|
/* 8. Bloco composto "dobro(n)" criado pelo diálogo; corpo: devolva n + 1 */
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("Criar um Bloco", R_FLY, 0, &x, &y)) click(x, y);
|
|
if (need("nome do bloco", R_WS, 0, &x, &y)) click(x, y);
|
|
type("dobro");
|
|
if (need("numérica ou texto", R_WS, 0, &x, &y)) click(x, y);
|
|
type("n");
|
|
key(TB_KEY_RETURN, 0, 0); /* OK no diálogo */
|
|
CHECK(ws_has("parâmetro"), "diálogo cria o bloco composto e o corpo com o parâmetro");
|
|
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("devolva", R_FLY, 0, &x, &y)) drag(x, y, 450, 300);
|
|
if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("+", R_FLY, 0, &x, &y)) drag(x, y, 470, 450);
|
|
/* encaixa o parâmetro n no slot esquerdo do "+" */
|
|
{
|
|
float px, py, zx, zy;
|
|
if (need("parâmetro", R_WS, 0, &px, &py) && need("+", R_WS, 0, &x, &y)) {
|
|
int k = 0; bool got = false;
|
|
while (find("0", R_WS, k++, &zx, &zy))
|
|
if (zy > y - 4 && zy < y + 4 && zx < x) { got = true; break; }
|
|
if (!got) { printf("FAIL slot esquerdo do +\n"); fails++; }
|
|
else drag(px, py, px + ((zx - 3 - 10) - (px - 3 - 10)), zy);
|
|
}
|
|
}
|
|
/* digita 1 no slot direito do "+" */
|
|
if (need("+", R_WS, 0, &x, &y)) {
|
|
float zx, zy; int k = 0;
|
|
while (find("0", R_WS, k++, &zx, &zy))
|
|
if (zy > y - 4 && zy < y + 4 && zx > x) {
|
|
click(zx, zy); type("1"); key(TB_KEY_RETURN, 0, 0); break;
|
|
}
|
|
}
|
|
if (need("+", R_WS, 0, &x, &y) && need("=", R_WS, 0, &x2, &y2)) {
|
|
float rep_left = x - 3 - 10;
|
|
{ float px, py; if (find("parâmetro", R_WS, 0, &px, &py)) rep_left = px - 3 - 10 - 10; }
|
|
drag(x, y, x + ((x2 + 12) - rep_left), y + (y2 - y));
|
|
}
|
|
if (need("Salvar", R_WS, 0, &x, &y)) click(x, y);
|
|
CHECK(find("dobro", R_ANY, 0, &x, &y), "bloco composto salvo");
|
|
if (need("Código", R_ANY, 0, &x, &y)) click(x, y);
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("dobro", R_FLY, 0, &x, &y)) drag(x, y, 650, 640);
|
|
{
|
|
float sx, sy;
|
|
if (find("n", R_WS, 0, &sx, &sy)) {
|
|
click(sx, sy);
|
|
key(TB_KEY_BACKSPACE, 0, 0);
|
|
type("21"); key(TB_KEY_RETURN, 0, 0);
|
|
}
|
|
}
|
|
if (need("dobro", R_WS, 0, &x, &y)) click(x, y);
|
|
CHECK(ws_has("22"), "bloco composto dobro(21) = 22");
|
|
if (!ws_has("22")) { for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind==TB_DRAW_TEXT && in_region(cmds[i].x,R_WS)) printf(" ws: %s (%.0f,%.0f)\n", cmds[i].text, cmds[i].x, cmds[i].y); }
|
|
|
|
/* 9. Laço infinito é interrompido */
|
|
if (need("Controle", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("repita até que", R_FLY, 0, &x, &y)) drag(x, y, 700, 300);
|
|
if (need("repita até que", R_WS, 0, &x, &y)) click(x, y);
|
|
CHECK(stage_has("limite de passos"), "laço infinito é abortado com aviso");
|
|
|
|
/* 10. Caneta: desenhar no palco embutido */
|
|
int circles_before = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == TB_DRAW_FILL_CIRCLE && cmds[i].x >= 920 && cmds[i].y > 90 && cmds[i].y < 340) circles_before++;
|
|
if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("desenhe círculo em x", R_FLY, 0, &x, &y)) drag(x, y, 600, 650);
|
|
if (need("desenhe círculo em x", R_WS, 0, &x, &y)) click(x, y);
|
|
int circles = 0; float cx = 0, cy = 0, cr = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_FILL_CIRCLE && cmds[i].x >= 920 && cmds[i].y > 90 && cmds[i].y < 340) {
|
|
circles++; cx = cmds[i].x; cy = cmds[i].y; cr = cmds[i].param;
|
|
}
|
|
printf(" círculo no palco: (%.1f, %.1f) r=%.1f\n", cx, cy, cr);
|
|
CHECK(circles == circles_before + 1 && fabsf(cx - (928 + 172)) < 2 && fabsf(cy - (44 + 44 + 1 + 128)) < 2,
|
|
"bloco da caneta desenha círculo centrado no palco embutido");
|
|
if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y);
|
|
if (need("apague tudo", R_FLY, 0, &x, &y)) drag(x, y, 600, 700);
|
|
if (need("apague tudo", R_WS, 0, &x, &y)) click(x, y);
|
|
circles = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++) if (cmds[i].kind == TB_DRAW_FILL_CIRCLE && cmds[i].x >= 920 && cmds[i].y > 90 && cmds[i].y < 340) circles++;
|
|
CHECK(circles == circles_before, "\"apague tudo\" limpa o palco");
|
|
|
|
/* 11. Destacar o palco numa janela própria e recolher de volta */
|
|
click(1280 - 50 + 20, 44 + 22);
|
|
CHECK(any_has("Palco aberto em outra janela"), "palco destacado abre janela própria");
|
|
click(1280 - 50 + 20, 44 + 22);
|
|
CHECK(!any_has("Palco aberto em outra janela"), "palco recolhido volta ao painel");
|
|
|
|
/* 12. Salvar e abrir projeto (.json) via tinyblocks-blueprint */
|
|
const char* proj = "/tmp/tb_harness_proj.json";
|
|
remove(proj);
|
|
if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y);
|
|
for (int i = 0; i < 16; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type(proj);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
CHECK(any_has("Projeto salvo"), "salvar projeto escreve o .json");
|
|
if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y);
|
|
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type(proj);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_has("Projeto aberto"), "abrir projeto le o .json");
|
|
CHECK(find("quando a bandeira for clicado", R_WS, 0, &x, &y),
|
|
"estado restaurado apos abrir (chapéu de exemplo de volta)");
|
|
remove(proj);
|
|
|
|
/* 13. Abrir um projeto escrito a mao (aba distinta) */
|
|
const char* openjson = "/tmp/tb_harness_open.json";
|
|
FILE* pf = fopen(openjson, "wb");
|
|
if (pf) {
|
|
fputs("{\"format\":\"tinyblocks-project\",\"version\":1,\"cur_tab\":0,"
|
|
"\"tabs\":[{\"name\":\"Aberto!\",\"composite\":false,\"comp_id\":-1,\"color\":0,"
|
|
"\"blocks\":["
|
|
"{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40,\"next\":1},"
|
|
"{\"i\":1,\"type\":\"IO.Print\",\"x\":40,\"y\":100,\"in_text\":[\"Oi do arquivo\",\"\"]},"
|
|
"{\"i\":2,\"type\":\"Stage.Circle\",\"x\":40,\"y\":180,\"in_text\":[\"0\",\"0\",\"80\"]}"
|
|
"],\"top\":[0,2]}],"
|
|
"\"user_blocks\":[],\"variables\":[{\"name\":\"x\",\"kind\":0,\"num\":7,\"text\":\"\"}]}", pf);
|
|
fclose(pf);
|
|
}
|
|
if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y);
|
|
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type(openjson);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Aberto!", R_ANY, 0, &x, &y), "abrir projeto de arquivo externo (aba Aberto!)");
|
|
CHECK(find("Oi do arquivo", R_WS, 0, &x, &y), "bloco do arquivo externo aparece no workspace");
|
|
remove(openjson);
|
|
|
|
/* 14. Exportar pelo menu de contexto do botao Exportar */
|
|
if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y);
|
|
CHECK(find("Exportar JSON", R_FLY, 0, &x, &y) && find("Exportar XML", R_FLY, 0, &x, &y)
|
|
&& find("Exportar CSV", R_FLY, 0, &x, &y), "botao Exportar abre menu com JSON/XML/CSV");
|
|
const char* expf = "/tmp/tb_harness_export.xml";
|
|
remove(expf);
|
|
if (need("Exportar XML", R_FLY, 0, &x, &y)) click(x, y);
|
|
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type(expf);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_has("Exportado xml"), "exportar XML pelo menu escreve o arquivo");
|
|
remove(expf);
|
|
|
|
/* 15. Regressao: arrastar um bloco da Caneta para o chapeu */
|
|
if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int clear_before = 0;
|
|
{ float a, b; for (int k = 0; find("apague tudo", R_WS, k, &a, &b); k++) clear_before++; }
|
|
if (need("apague tudo", R_FLY, 0, &x, &y)) {
|
|
float hx, hy;
|
|
if (need("quando a bandeira for clicado", R_WS, 0, &hx, &hy)) {
|
|
float bx = hx - 3 - 10, by = hy - 18 - 18;
|
|
float gx = x - 3 - 10, gy = y - 18;
|
|
drag(x, y, x + (bx - gx), y + (by + 54 - gy) + 6);
|
|
}
|
|
}
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int clear_after = 0;
|
|
{ float a, b; for (int k = 0; find("apague tudo", R_WS, k, &a, &b); k++) clear_after++; }
|
|
CHECK(clear_after == clear_before + 1, "arrastar bloco da Caneta para o chapeu");
|
|
|
|
/* 16. Gestor de libraries (tinyblocks-libman), UI desenhada pelo editor */
|
|
CHECK(!find("Blueprint", R_CAT, 0, &x, &y), "categoria Blueprint ainda nao existe");
|
|
if (need("Bibliotecas", R_WS, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Escolha uma Extensão", R_ANY, 0, &x, &y), "abre a tela do libman");
|
|
CHECK(find("Buscar", R_ANY, 0, &x, &y), "libman mostra o campo de busca");
|
|
type("blueprint");
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("tinyblocks-blueprint", R_ANY, 0, &x, &y), "busca filtra por nome");
|
|
if (need("tinyblocks-blueprint", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(!find("Escolha uma Extensão", R_ANY, 0, &x, &y), "libman fecha apos carregar");
|
|
CHECK(find("Blueprint", R_CAT, 0, &x, &y), "library carregada aparece na paleta");
|
|
|
|
/* 17. Botao de extensoes no fim do painel (estilo Scratch) */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
click(34, 720 - 28);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Escolha uma Extensão", R_ANY, 0, &x, &y), "botao de extensoes no painel abre o libman");
|
|
key(TB_KEY_ESCAPE, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
|
|
/* 18. Tela de Configuracoes (settings da tinyblocks-environ) */
|
|
remove("build/settings_test.csv");
|
|
setenv("TINYBLOCKS_SETTINGS", "build/settings_test.csv", 1);
|
|
click(1231, 22); /* botao Config (WIN_W=1280) */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Configurações", R_ANY, 0, &x, &y), "botao Config abre a tela de configuracoes");
|
|
CHECK(find("Detectar caminho de TINYBLOCKS_SETTINGS", R_ANY, 0, &x, &y),
|
|
"mostra o toggle da variavel de ambiente");
|
|
CHECK(find("autor", R_ANY, 0, &x, &y), "listas as settings do store (autor)");
|
|
click(50, 84); /* liga o toggle de deteccao pelo env */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("build/settings_test.csv", R_ANY, 0, &x, &y),
|
|
"toggle passa a usar o caminho de TINYBLOCKS_SETTINGS");
|
|
click(200, 194); /* seleciona a linha 'autor' */
|
|
type("maria");
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
click(922, 136); /* botao Salvar (CSV no arquivo de config) */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
{
|
|
FILE* sf = fopen("build/settings_test.csv", "rb");
|
|
char sbuf[512] = "";
|
|
if (sf) { size_t sn = fread(sbuf, 1, sizeof(sbuf)-1, sf); sbuf[sn] = 0; fclose(sf); }
|
|
CHECK(strstr(sbuf, "# arquivo_config,build/settings_test.csv") != NULL,
|
|
"CSV inclui o caminho do arquivo de configuracao");
|
|
CHECK(strstr(sbuf, "chave,valor") != NULL, "settings salvas em CSV (cabecalho)");
|
|
CHECK(strstr(sbuf, "autor,maria") != NULL, "valor editado gravado no CSV");
|
|
remove("build/settings_test.csv");
|
|
}
|
|
key(TB_KEY_ESCAPE, 0, 0); /* fecha a tela */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(!find("Configurações", R_ANY, 0, &x, &y), "Esc fecha as configuracoes");
|
|
unsetenv("TINYBLOCKS_SETTINGS");
|
|
|
|
printf("comandos de desenho no último frame: %u\n", ncmd);
|
|
tinyblocks_deinit(&rt);
|
|
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
|
return fails != 0;
|
|
}
|