Library nova, no papel do ATK/GtkAccessible: cada quadro o editor monta uma árvore acessível (papel, nome, descrição, valor, estados, ações, retângulo), com ids estáveis, eventos entre quadros (foco, estado, nome, valor, componente novo, aviso) e uma ponte para o narrador (TINYBLOCKS_A11Y=log liga uma ponte de texto no stderr). Cada parte da tela se descreve onde é desenhada: menu, áreas, categorias, paleta, abas, blocos (rótulo falado, campos, bocas, parâmetros do defina), grupos, palco, saída, menus e diálogos. As ações agem pelo mesmo caminho do mouse e rolam até o componente se ele estiver fora da vista. API: tb_editor_accessible(scene). O harness acha componentes pela árvore (categorias, cenários 8 e 27) e tem um cenário só de acessibilidade; test-a11y testa a library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1290 lines
66 KiB
C
1290 lines
66 KiB
C
#define _POSIX_C_SOURCE 200809L
|
|
/* 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 <sys/stat.h>
|
|
#include <unistd.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_errors.h>
|
|
#include <tb_operators.h>
|
|
#include <tb_variables.h>
|
|
#include <tb_appearance.h>
|
|
#include <tb_pen.h>
|
|
#include <tb_curves.h>
|
|
#include <tb_base64.h>
|
|
#include <tb_ppm.h>
|
|
#include <tb_input_lib.h>
|
|
#include <tb_environ.h>
|
|
#include <tb_a11y.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 int g_mods = 0;
|
|
static void mods(int m) { g_mods = m; }
|
|
|
|
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 float g_scroll_dy = 0.f;
|
|
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(g_mods));
|
|
tb_block_set_output(ev, GFX_IN_MOD_STATE, tb_value_integer(g_mods));
|
|
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(g_scroll_dy));
|
|
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();
|
|
g_scroll_dy = 0.f;
|
|
}
|
|
/* Roda do mouse (usada para o zoom na aba de imagem) */
|
|
static void scroll(float mx, float my, float dy) {
|
|
g_scroll_dy = dy;
|
|
frame(mx, my, 0, 0, 0, 0, NULL);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
/* == Interface de acessibilidade: componentes por papel + nome ===
|
|
* (nao depende do texto desenhado nem de coordenadas fixas) */
|
|
static TinyBlocks_A11yTree* A(void) { return tb_editor_accessible(scene); }
|
|
static const TinyBlocks_A11yNode* N(int n) { return tb_a11y_node(A(), n); }
|
|
static int ax_in(int from, TinyBlocks_A11yRole r, const char* name) { return tb_a11y_find(A(), from, r, name, 0); }
|
|
static int ax_part(int from, TinyBlocks_A11yRole r, const char* part) { return tb_a11y_find_part(A(), from, r, part, 0); }
|
|
static int ax_need(int from, TinyBlocks_A11yRole r, const char* name) {
|
|
int n = ax_in(from, r, name);
|
|
if (n < 0) { printf("FAIL não achei o %s \"%s\" na árvore acessível\n", tb_a11y_role_name(r), name); fails++; }
|
|
return n;
|
|
}
|
|
static const char* ax_value(int n) { return n >= 0 ? N(n)->value : ""; }
|
|
static int ax_count(int from, TinyBlocks_A11yRole r, const char* name) {
|
|
int k = 0;
|
|
while (tb_a11y_find(A(), from, r, name, k) >= 0) k++;
|
|
return k;
|
|
}
|
|
|
|
/* Categoria (aba da coluna "Categorias") */
|
|
static bool find_cat(const char* s, int nth, float* x, float* y) {
|
|
int list = ax_in(0, TB_A11Y_TAB_LIST, "Categorias");
|
|
int n = list >= 0 ? tb_a11y_find(A(), list, TB_A11Y_TAB, s, nth) : -1;
|
|
if (n < 0) return false;
|
|
tb_a11y_point(A(), n, x, y);
|
|
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) {
|
|
if (region == R_CAT) return find_cat(s, nth, x, 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;
|
|
}
|
|
|
|
/* Bloco "+" na area de trabalho (nao o "+" da barra de abas) */
|
|
static bool block_plus(float* x, float* y, float min_y) {
|
|
for (int k = 0; find("+", R_WS, k, x, y); k++) if (*y > min_y) return true;
|
|
printf("FAIL não achei o bloco \"+\"\n"); fails++;
|
|
return false;
|
|
}
|
|
|
|
/* Texto s na mesma linha de (ax, ay), a direita de ax */
|
|
static bool find_near(const char* s, float ax, float ay, float* x, float* y) {
|
|
for (int k = 0; find(s, R_WS, k, x, y); k++)
|
|
if (*y > ay - 6 && *y < ay + 6 && *x > ax) 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;
|
|
}
|
|
/* Mensagens de status: palco/saída ou avisos flutuantes (toasts), em qualquer lugar */
|
|
static bool any_has(const char* s) {
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && 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 int ws_count(const char* s) {
|
|
int n = 0;
|
|
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) n++;
|
|
return n;
|
|
}
|
|
static bool find_tabbar(const char* s, 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) continue;
|
|
if (c->y < 40 || c->y > 86) continue;
|
|
*x = c->x + 3; *y = c->y - c->font_size*0.36f;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
static bool find_sub(const char* sub, float* x, float* y) {
|
|
for (uint32_t i = 0; i < ncmd; i++) {
|
|
TinyBlocks_DrawCmd* c = &cmds[i];
|
|
if (c->kind != TB_DRAW_TEXT || !strstr(c->text, sub)) continue;
|
|
*x = c->x + 3; *y = c->y - c->font_size*0.36f;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
/* Conta pixels nao-brancos da ultima imagem desenhada no workspace */
|
|
/* Largura da maior imagem do workspace (a folha de desenho) */
|
|
static float img_draw_w(void) {
|
|
float best = 0, w = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++) {
|
|
if (cmds[i].kind != TB_DRAW_IMAGE || !cmds[i].image || !in_region(cmds[i].x, R_WS)) continue;
|
|
float a = cmds[i].w * cmds[i].h;
|
|
if (a > best) { best = a; w = cmds[i].w; }
|
|
}
|
|
return w;
|
|
}
|
|
static int img_nonwhite(void) {
|
|
/* A folha de desenho e a MAIOR imagem do workspace (miniaturas sao pequenas) */
|
|
const TinyBlocks_Image* im = NULL;
|
|
float best = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++) {
|
|
if (cmds[i].kind != TB_DRAW_IMAGE || !cmds[i].image || !in_region(cmds[i].x, R_WS)) continue;
|
|
float a = cmds[i].w * cmds[i].h;
|
|
if (a < 20000.f) continue; /* ignora miniaturas */
|
|
if (a > best) { best = a; im = cmds[i].image; }
|
|
}
|
|
if (!im) return -1;
|
|
int W = tb_image_width(im), H = tb_image_height(im), n = 0;
|
|
for (int y = 0; y < H; y++)
|
|
for (int x = 0; x < W; x++) {
|
|
uint8_t r, g, b, a;
|
|
if (tb_image_get_pixel(im, x, y, &r, &g, &b, &a) && a > 0 &&
|
|
(r < 240 || g < 240 || b < 240)) n++;
|
|
}
|
|
return n;
|
|
}
|
|
static bool any_substr(const char* s) {
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, s)) return true;
|
|
return false;
|
|
}
|
|
static bool ws_substr(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) && strstr(cmds[i].text, s)) return true;
|
|
return false;
|
|
}
|
|
static void dump_ws(void) {
|
|
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);
|
|
}
|
|
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); }
|
|
|
|
/* Executa uma acao acessivel e roda um quadro (a arvore e redesenhada) */
|
|
static bool ax_do(int n, TinyBlocks_A11yAction a) {
|
|
if (n < 0) return false;
|
|
float x, y;
|
|
tb_a11y_point(A(), n, &x, &y);
|
|
bool ok = tb_a11y_do_action(A(), n, a);
|
|
frame(x, y, 0, 0, 0, 0, NULL);
|
|
return ok;
|
|
}
|
|
/* Arrasta o componente pelo seu ponto, levando o canto dele para (tx, ty) */
|
|
static void ax_drag_to(int n, float tx, float ty) {
|
|
if (n < 0) return;
|
|
float px, py;
|
|
tb_a11y_point(A(), n, &px, &py);
|
|
drag(px, py, tx + (px - N(n)->x), ty + (py - N(n)->y));
|
|
}
|
|
|
|
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) {
|
|
/* configurações isoladas: o harness não lê nem grava o ~/.config real */
|
|
setenv("XDG_CONFIG_HOME", "/tmp/tb_harness_cfg", 1);
|
|
unsetenv("TINYBLOCKS_SETTINGS");
|
|
remove("/tmp/tb_harness_cfg/tinyblocks/settings.csv");
|
|
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_errors_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_curves_get_library());
|
|
tb_library_register(rt, tb_base64_get_library());
|
|
tb_library_register(rt, tb_ppm_get_library());
|
|
tb_library_register(rt, tb_input_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); click(x, y); } /* clique duplo */
|
|
}
|
|
CHECK(ws_has("5"), "clique duplo no repórter 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.
|
|
* Tudo achado pela interface de acessibilidade (papel + nome). */
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
ax_do(ax_need(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE);
|
|
{
|
|
int dlg = ax_need(0, TB_A11Y_DIALOG, "Criar um Bloco");
|
|
int nome = ax_in(dlg, TB_A11Y_TEXT_FIELD, "Nome do bloco");
|
|
CHECK(dlg >= 0 && (N(dlg)->states & TB_A11Y_MODAL), "diálogo \"Criar um Bloco\" na árvore, modal");
|
|
CHECK(nome >= 0 && tb_a11y_focus(A()) == nome, "o foco abre no campo \"Nome do bloco\"");
|
|
}
|
|
type("dobro");
|
|
CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_TEXT_FIELD, "Nome do bloco")), "dobro"), "o nome digitado é o valor do campo");
|
|
ax_do(ax_need(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_BUTTON, "Adicionar entrada de número ou texto"),
|
|
TB_A11Y_ACT_ACTIVATE);
|
|
type("n");
|
|
CHECK(!strcmp(ax_value(tb_a11y_focus(A())), "n"), "a entrada nova recebe o foco e o nome n");
|
|
ax_do(ax_need(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco"), TB_A11Y_BUTTON, "OK"), TB_A11Y_ACT_ACTIVATE);
|
|
CHECK(ax_in(0, TB_A11Y_DIALOG, "Criar um Bloco") < 0, "OK fecha o diálogo");
|
|
|
|
int panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
|
int def = ax_in(panel, TB_A11Y_BLOCK, "defina dobro (n)");
|
|
/* como no Scratch: o "defina" aparece na própria aba, e o parâmetro só dentro dele */
|
|
CHECK(def >= 0, "Criar um Bloco põe \"defina dobro (n)\" na mesma aba");
|
|
CHECK(ax_count(panel, TB_A11Y_BLOCK, "n") == 1 && ax_in(def, TB_A11Y_BLOCK, "n") >= 0,
|
|
"sem parâmetros soltos: o \"n\" está no protótipo do defina");
|
|
CHECK(ax_in(panel, TB_A11Y_BLOCK, "quando a bandeira for clicado") >= 0, "sem abrir aba nova: os scripts continuam ali");
|
|
float dfx = def >= 0 ? N(def)->x : 0, dfy = def >= 0 ? N(def)->y : 0, dfh = def >= 0 ? N(def)->h : 0;
|
|
|
|
/* devolva embaixo do "defina"; um "+" solto ao lado */
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
ax_drag_to(ax_part(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BLOCK, "devolva"), dfx, dfy + dfh);
|
|
if (need("Operadores", R_CAT, 0, &x, &y)) click(x, y);
|
|
{
|
|
int ops = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Operadores");
|
|
ax_drag_to(ax_part(ops, TB_A11Y_BLOCK, ") + ("), dfx + 300, dfy + 110);
|
|
}
|
|
/* o parâmetro sai arrastando de dentro do "defina" para o 1o campo do "+" */
|
|
{
|
|
panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
|
int plus = ax_in(ax_in(panel, TB_A11Y_LIST, "Pilha: (0) + (0)"), TB_A11Y_BLOCK, "(0) + (0)");
|
|
int slot = ax_in(plus, TB_A11Y_TEXT_FIELD, NULL);
|
|
if (slot >= 0) ax_drag_to(ax_in(ax_in(panel, TB_A11Y_BLOCK, "defina dobro (n)"), TB_A11Y_BLOCK, "n"),
|
|
N(slot)->x, N(slot)->y);
|
|
panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
|
CHECK(ax_in(panel, TB_A11Y_BLOCK, "(n) + (0)") >= 0, "arrastar o parâmetro do defina põe \"n\" no +");
|
|
}
|
|
/* 1 no outro campo do "+" */
|
|
ax_do(ax_in(ax_in(0, TB_A11Y_BLOCK, "(n) + (0)"), TB_A11Y_TEXT_FIELD, NULL), TB_A11Y_ACT_EDIT);
|
|
key(TB_KEY_BACKSPACE, 0, 0);
|
|
type("1"); key(TB_KEY_RETURN, 0, 0);
|
|
/* o "+" no campo de valor do devolva (o 2o campo) */
|
|
{
|
|
int dev = ax_part(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "devolva");
|
|
int val = dev >= 0 ? tb_a11y_find(A(), dev, TB_A11Y_TEXT_FIELD, NULL, 1) : -1;
|
|
if (val >= 0) ax_drag_to(ax_need(0, TB_A11Y_BLOCK, "(n) + (1)"), N(val)->x, N(val)->y);
|
|
CHECK(ax_part(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "= ((n) + (1))") >= 0,
|
|
"corpo: devolva (n) + (1)");
|
|
}
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
{
|
|
int mine = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Meus Blocos");
|
|
int call = ax_in(mine, TB_A11Y_BLOCK, "dobro (n)");
|
|
CHECK(call >= 0, "bloco dobro aparece em Meus Blocos");
|
|
ax_drag_to(call, dfx + 330, dfy - 60);
|
|
}
|
|
{
|
|
panel = ax_in(0, TB_A11Y_TAB_PANEL, NULL);
|
|
int call = ax_in(panel, TB_A11Y_BLOCK, "dobro (n)");
|
|
ax_do(ax_in(call, TB_A11Y_TEXT_FIELD, NULL), TB_A11Y_ACT_EDIT);
|
|
key(TB_KEY_BACKSPACE, 0, 0);
|
|
type("21"); key(TB_KEY_RETURN, 0, 0);
|
|
call = ax_in(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "dobro (21)");
|
|
ax_do(call, TB_A11Y_ACT_ACTIVATE);
|
|
ax_do(call, TB_A11Y_ACT_ACTIVATE); /* clique duplo: balão com o valor */
|
|
}
|
|
CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_STATUS, "Resultado")), "22"), "bloco composto dobro(21) = 22");
|
|
|
|
/* 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);
|
|
/* laço sem fim roda quadro a quadro (estilo Scratch): não trava nem aborta */
|
|
for (int i = 0; i < 5; i++) frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(!stage_has("limite de passos"), "laço sem fim roda sem travar (sem aviso de limite)");
|
|
click(1280 - 360 + 76, 44 + 22); /* botão vermelho */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
|
|
/* 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);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
/* a área do palco sai da janela principal; fica um botão "Palco" no menu */
|
|
bool no_menu = false, no_painel = false;
|
|
float cx = 0, cy = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++) {
|
|
if (cmds[i].kind != TB_DRAW_TEXT || strcmp(cmds[i].text, "Palco") != 0) continue;
|
|
if (cmds[i].y < 44) { no_menu = true; cx = cmds[i].x + 3; cy = 22; }
|
|
else no_painel = true;
|
|
}
|
|
CHECK(no_menu && !no_painel, "palco destacado abre janela própria (botão \"Palco\" no menu)");
|
|
if (no_menu) click(cx, cy); /* recolhe no próximo quadro */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 920 && y > 44, "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");
|
|
{
|
|
/* aviso flutuante (toast) sobre a área de scripts, não no menu */
|
|
bool flutua = false;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "Projeto salvo") &&
|
|
cmds[i].x > 318 && cmds[i].x < 920 && cmds[i].y > 400) flutua = true;
|
|
CHECK(flutua, "mensagem vira aviso flutuante no canto da área de scripts");
|
|
/* salvar de novo: a mesma mensagem vira contador (x2) */
|
|
if (need("Salvar", 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);
|
|
if (find("Substituir", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_has("(x2)"), "mensagem repetida vira contador (x2)");
|
|
}
|
|
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);
|
|
|
|
/* 13b. Explorador de arquivos (tinyblocks-editor-files) */
|
|
{
|
|
const char* fdir = "/tmp/tb_harness_fdlg";
|
|
char fp[256];
|
|
mkdir(fdir, 0755);
|
|
snprintf(fp, sizeof(fp), "%s/sub", fdir);
|
|
mkdir(fp, 0755);
|
|
snprintf(fp, sizeof(fp), "%s/nota.md", fdir);
|
|
FILE* tf = fopen(fp, "wb");
|
|
if (tf) { fputs("oi", tf); fclose(tf); }
|
|
snprintf(fp, sizeof(fp), "%s/proj.json", fdir);
|
|
tf = fopen(fp, "wb");
|
|
if (tf) {
|
|
fputs("{\"format\":\"tinyblocks-project\",\"version\":1,\"cur_tab\":0,"
|
|
"\"tabs\":[{\"name\":\"Explorado\",\"composite\":false,\"comp_id\":-1,\"color\":0,"
|
|
"\"blocks\":[{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40}],"
|
|
"\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", tf);
|
|
fclose(tf);
|
|
}
|
|
if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y);
|
|
CHECK(find("Abrir projeto", R_ANY, 0, &x, &y), "Abrir mostra o explorador de arquivos");
|
|
type(fdir);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
CHECK(find("proj.json", R_ANY, 0, &x, &y) && find("sub", R_ANY, 0, &x, &y)
|
|
&& !find("nota.md", R_ANY, 0, &x, &y),
|
|
"explorador lista pastas + .json e filtra o resto");
|
|
if (need("proj.json", R_ANY, 0, &x, &y)) { click(x, y); click(x, y); }
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_has("Projeto aberto") && find("Explorado", R_ANY, 0, &x, &y),
|
|
"duplo clique no explorador abre o projeto");
|
|
|
|
if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y);
|
|
CHECK(find("Salvar projeto", R_ANY, 0, &x, &y), "Salvar mostra o explorador de arquivos");
|
|
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type("proj");
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
CHECK(find("Substituir", R_ANY, 0, &x, &y), "salvar sobre arquivo existente pede confirmacao");
|
|
if (need("Substituir", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_has("Projeto salvo") && !find("Salvar projeto", R_ANY, 0, &x, &y),
|
|
"Substituir grava o .json (extensao completada) e fecha");
|
|
|
|
if (need("Abrir", R_FLY, 0, &x, &y)) click(x, y);
|
|
key(TB_KEY_ESCAPE, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(!find("Abrir projeto", R_ANY, 0, &x, &y), "Esc fecha o explorador");
|
|
|
|
remove(fp);
|
|
snprintf(fp, sizeof(fp), "%s/nota.md", fdir); remove(fp);
|
|
snprintf(fp, sizeof(fp), "%s/sub", fdir); rmdir(fp);
|
|
rmdir(fdir);
|
|
}
|
|
|
|
/* 13c. "desenhe [lista de pontos]" (Caneta) + tipo do valor no balao */
|
|
{
|
|
const char* dj = "/tmp/tb_harness_draw.json";
|
|
FILE* df = fopen(dj, "wb");
|
|
if (df) {
|
|
fputs("{\"format\":\"tinyblocks-project\",\"version\":1,\"cur_tab\":0,"
|
|
"\"tabs\":[{\"name\":\"Desenho\",\"composite\":false,\"comp_id\":-1,\"color\":0,"
|
|
"\"blocks\":["
|
|
"{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40,\"next\":1},"
|
|
"{\"i\":1,\"type\":\"Stage.Draw\",\"x\":40,\"y\":100,\"parent\":0,\"prel\":0,"
|
|
"\"args\":[2,-1,-1],\"in_text\":[\"\",\"0\",\"0\"]},"
|
|
"{\"i\":2,\"type\":\"Curves.Line\",\"x\":0,\"y\":0,\"parent\":1,\"prel\":3,"
|
|
"\"in_text\":[\"-100\",\"0\",\"100\",\"50\",\"10\"]},"
|
|
"{\"i\":3,\"type\":\"Curves.Line\",\"x\":40,\"y\":220,"
|
|
"\"in_text\":[\"0\",\"0\",\"100\",\"0\",\"20\"]}"
|
|
"],\"top\":[0,3]}],\"user_blocks\":[],\"variables\":[]}", df);
|
|
fclose(df);
|
|
}
|
|
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(dj);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Desenho", R_ANY, 0, &x, &y), "projeto com 'desenhe' aberto");
|
|
int before = 0, after = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_STROKE_LINE && cmds[i].x >= 920) before++;
|
|
flag();
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_STROKE_LINE && cmds[i].x >= 920) after++;
|
|
CHECK(after >= before + 10, "desenhe (reta com 10 passos) traca 10 segmentos no palco");
|
|
/* repórter solto (o encaixado roda a pilha inteira, como no Scratch) */
|
|
if (need("reta de x", R_WS, 1, &x, &y)) { click(x, y); click(x, y); }
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("lista de pontos", R_WS, 0, &x, &y), "balao mostra o tipo 'lista de pontos'");
|
|
remove(dj);
|
|
}
|
|
|
|
/* 13d. "sempre": uma volta por quadro quando desenha; para no botão vermelho */
|
|
{
|
|
const char* fj = "/tmp/tb_harness_forever.json";
|
|
FILE* ff = fopen(fj, "wb");
|
|
if (ff) {
|
|
fputs("{\"format\":\"tinyblocks-project\",\"version\":1,\"cur_tab\":0,"
|
|
"\"tabs\":[{\"name\":\"Sempre\",\"composite\":false,\"comp_id\":-1,\"color\":0,"
|
|
"\"blocks\":["
|
|
"{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40,\"next\":1},"
|
|
"{\"i\":1,\"type\":\"Control.Forever\",\"x\":40,\"y\":100,\"parent\":0,\"prel\":0,\"sub\":[2,-1]},"
|
|
"{\"i\":2,\"type\":\"IO.Print\",\"x\":0,\"y\":0,\"parent\":1,\"prel\":1,\"next\":3,"
|
|
"\"in_text\":[\"volta\",\"\"]},"
|
|
"{\"i\":3,\"type\":\"Stage.Circle\",\"x\":0,\"y\":0,\"parent\":2,\"prel\":0,"
|
|
"\"in_text\":[\"0\",\"0\",\"30\"]}"
|
|
"],\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", ff);
|
|
fclose(ff);
|
|
}
|
|
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(fj);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("sempre", R_WS, 0, &x, &y), "bloco 'sempre' aparece no projeto");
|
|
flag();
|
|
for (int i = 0; i < 6; i++) frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int voltas = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, "volta")) voltas++;
|
|
CHECK(voltas >= 4 && voltas <= 12, "'sempre' com caneta anima: ~uma volta por quadro");
|
|
click(1280 - 360 + 76, 44 + 22); /* botão vermelho */
|
|
for (int i = 0; i < 6; i++) frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int depois = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920 && strstr(cmds[i].text, "volta")) depois++;
|
|
CHECK(depois == 0, "botão vermelho para o 'sempre' (e limpa a saída)");
|
|
remove(fj);
|
|
}
|
|
|
|
/* 13e. Sensores: posição do mouse no palco e última tecla, num "sempre" */
|
|
{
|
|
const char* sj = "/tmp/tb_harness_sensores.json";
|
|
FILE* sf = fopen(sj, "wb");
|
|
if (sf) {
|
|
fputs("{\"format\":\"tinyblocks-project\",\"version\":1,\"cur_tab\":0,"
|
|
"\"tabs\":[{\"name\":\"Sensores\",\"composite\":false,\"comp_id\":-1,\"color\":0,"
|
|
"\"blocks\":["
|
|
"{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40,\"next\":1},"
|
|
"{\"i\":1,\"type\":\"Control.Forever\",\"x\":40,\"y\":100,\"parent\":0,\"prel\":0,\"sub\":[2,-1]},"
|
|
"{\"i\":2,\"type\":\"Stage.Clear\",\"x\":0,\"y\":0,\"parent\":1,\"prel\":1,\"next\":3},"
|
|
"{\"i\":3,\"type\":\"IO.Print\",\"x\":0,\"y\":0,\"parent\":2,\"prel\":0,\"args\":[4,5]},"
|
|
"{\"i\":4,\"type\":\"Input.MouseX\",\"x\":0,\"y\":0,\"parent\":3,\"prel\":3},"
|
|
"{\"i\":5,\"type\":\"Input.LastKey\",\"x\":0,\"y\":0,\"parent\":3,\"prel\":4}"
|
|
"],\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", sf);
|
|
fclose(sf);
|
|
}
|
|
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(sj);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
flag();
|
|
/* vista do palco no painel: origem (929, 89), 342 px = 480 do palco;
|
|
x do palco 100 -> 929 + 171 + 100 * 342/480 */
|
|
float px = 929.f + 171.f + 100.f * 342.f / 480.f, py = 89.f + 100.f;
|
|
for (int i = 0; i < 3; i++) frame(px, py, 0, 0, 0, 0, NULL);
|
|
CHECK(stage_has("100"), "posição x do mouse sobre o palco = 100");
|
|
if (!stage_has("100"))
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && cmds[i].x >= 920) printf(" palco: '%s'\n", cmds[i].text);
|
|
frame(px, py, 0, 0, 0, TB_KEY_SPACE, NULL);
|
|
for (int i = 0; i < 3; i++) frame(px, py, 0, 0, 0, 0, NULL);
|
|
CHECK(stage_has("espaço"), "última tecla = espaço");
|
|
click(1280 - 360 + 76, 44 + 22); /* botão vermelho */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
remove(sj);
|
|
}
|
|
|
|
/* 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");
|
|
|
|
/* 19. Previa de resultado: curva (lista de pontos) em balão, clique duplo */
|
|
if (need("Curvas", R_CAT, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
if (need("círculo em (", R_FLY, 0, &x, &y)) drag(x, y, 620, 500);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
if (need("círculo em (", R_WS, 0, &x, &y)) { click(x, y); click(x, y); }
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
{
|
|
int lines = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_STROKE_LINE && in_region(cmds[i].x, R_WS)) lines++;
|
|
CHECK(lines >= 20, "clique duplo na curva desenha a polilinha no balão");
|
|
}
|
|
CHECK(ws_has("37 pontos"), "balão mostra a contagem de pontos da curva");
|
|
|
|
/* 20. Previa de imagem: PPM.New em balão desenha TB_DRAW_IMAGE */
|
|
if (need("PPM", R_CAT, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
if (need("nova imagem(", R_FLY, 0, &x, &y)) drag(x, y, 640, 520);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
if (need("nova imagem(", R_WS, 0, &x, &y)) { click(x, y); click(x, y); }
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
{
|
|
int imgs = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_IMAGE) imgs++;
|
|
CHECK(imgs >= 1, "clique duplo numa imagem desenha TB_DRAW_IMAGE no balão");
|
|
}
|
|
CHECK(ws_has("32x32"), "balão mostra as dimensões da imagem");
|
|
|
|
/* 21. Tooltip de metadados: Alt + hover sobre um bloco (Stage.Clear) */
|
|
if (need("Caneta", R_CAT, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
if (need("apague tudo", R_FLY, 0, &x, &y)) drag(x, y, 520, 430);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
{
|
|
float bx = 0, by = 0;
|
|
if (find("apague tudo", R_WS, 0, &bx, &by)) {
|
|
mods(TB_MOD_ALT);
|
|
frame(bx, by, 0, 0, 0, 0, NULL);
|
|
CHECK(any_substr("eval_clear"), "Alt+hover mostra o tooltip com a funcao C");
|
|
CHECK(any_substr("tb_pen.c"), "tooltip mostra o arquivo-fonte");
|
|
CHECK(any_substr("Limpa o palco"), "tooltip mostra a descricao (doc)");
|
|
/* clica na previa do codigo -> abre aba de codigo na linha */
|
|
float px = 0, py = 0;
|
|
if (find_sub("tb_stage_clear", &px, &py)) {
|
|
mods(0);
|
|
click(px, py);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_substr("tb_pen.c"), "clique na previa abre aba de codigo do arquivo");
|
|
CHECK(ws_substr("eval_clear"), "aba de codigo mostra o codigo na linha da funcao");
|
|
} else { mods(0); CHECK(false, "achei a previa do codigo no tooltip"); }
|
|
} else { CHECK(false, "achei o bloco 'apague tudo' no workspace"); }
|
|
}
|
|
|
|
/* 22. Botao "+" -> nova aba: Editor de Codigo */
|
|
key(TB_KEY_ESCAPE, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
{
|
|
float px = 0, py = 0;
|
|
if (find_tabbar("+", &px, &py)) click(px, py); else { CHECK(false, "achei o botao +"); }
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Editor de Código", R_ANY, 0, &x, &y) && find("Novo bloco", R_ANY, 0, &x, &y) &&
|
|
find("Blueprint", R_ANY, 0, &x, &y), "menu '+' lista Blueprint, Novo bloco, Imagem e Código");
|
|
CHECK(find("Edição de Imagem", R_ANY, 0, &x, &y), "menu '+' oferece Edição de Imagem");
|
|
if (need("Editor de Código", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
type("int x = 42;");
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(ws_has("int"), "aba de codigo realca 'int' (palavra-chave)");
|
|
CHECK(ws_has("42"), "aba de codigo realca o numero 42");
|
|
CHECK(ws_has(";"), "aba de codigo realca a pontuacao");
|
|
CHECK(!any_has("</code>"), "aba de codigo nao mostra a marcacao </code>");
|
|
}
|
|
|
|
/* 23. Botao "+" -> nova aba: Edição de Imagem */
|
|
key(TB_KEY_ESCAPE, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
{
|
|
float px = 0, py = 0;
|
|
if (find_tabbar("+", &px, &py)) click(px, py); else { CHECK(false, "achei o botao +"); }
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
if (need("Edição de Imagem", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Camadas", R_WS, 0, &x, &y), "aba de imagem mostra a lista de camadas");
|
|
CHECK(find("Salvar", R_WS, 0, &x, &y), "aba de imagem mostra o botao Salvar");
|
|
CHECK(find("Desfazer", R_WS, 0, &x, &y), "aba de imagem mostra o botao Desfazer");
|
|
CHECK(find("Cores", R_WS, 0, &x, &y), "aba de imagem mostra a coluna de cores");
|
|
CHECK(find("Paleta", R_WS, 0, &x, &y), "aba de imagem mostra a paleta rapida");
|
|
CHECK(x > 700, "cores ficam na lateral direita");
|
|
{
|
|
int imgs = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_IMAGE && in_region(cmds[i].x, R_WS)) imgs++;
|
|
CHECK(imgs >= 1, "aba de imagem desenha a folha de desenho");
|
|
}
|
|
}
|
|
|
|
/* 24. Pintar na aba de imagem (ferramenta pincel) */
|
|
{
|
|
int before = img_nonwhite();
|
|
CHECK(before == 0, "folha de desenho comeca em branco");
|
|
click(345, 192); /* botao da ferramenta pincel */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
drag(500, 300, 560, 400); /* pinta um traco no canvas */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int after = img_nonwhite();
|
|
CHECK(after > 0, "pincel pinta pixels na folha de desenho");
|
|
click(421, 703); /* botao Desfazer */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(img_nonwhite() == 0, "Desfazer volta a folha em branco");
|
|
click(345, 292); /* ferramenta retangulo */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
drag(560, 280, 680, 360);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int rect_px = img_nonwhite();
|
|
CHECK(rect_px > 100, "ferramenta retangulo desenha o contorno");
|
|
click(345, 342); /* ferramenta elipse */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
drag(620, 290, 690, 390);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(img_nonwhite() > rect_px, "ferramenta elipse desenha o contorno");
|
|
click(345, 392); /* ferramenta preencher */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
click(620, 320); /* dentro do retangulo */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
click(520, 400); /* fora das formas */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int fill_px = img_nonwhite();
|
|
CHECK(fill_px > rect_px * 3, "ferramenta preencher alaga a area branca");
|
|
click(345, 492); /* conta-gotas */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
click(520, 400);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
{
|
|
bool found = false;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "Cor do pixel")) found = true;
|
|
CHECK(found, "conta-gotas informa a cor capturada");
|
|
}
|
|
/* 24b. Escolher uma cor na paleta lateral e desenhar com ela */
|
|
{
|
|
click(803, 277); /* segundo quadradinho da paleta (branco) */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
bool dark = false;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && strstr(cmds[i].text, "#FFFFFF")) dark = true;
|
|
CHECK(dark, "paleta lateral troca a cor da ferramenta");
|
|
click(345, 142); /* selecionar */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Desfazer", R_WS, 0, &x, &y), "ferramenta selecionar continua disponivel");
|
|
}
|
|
CHECK(find("Fundo", R_WS, 0, &x, &y), "lista de camadas mostra a camada Fundo");
|
|
CHECK(find("+ Raster", R_WS, 0, &x, &y), "botao de nova camada raster");
|
|
CHECK(find("+ Vetor", R_WS, 0, &x, &y), "botao de nova camada vetorial");
|
|
CHECK(find("Fundo", R_WS, 0, &x, &y), "achei a camada Fundo");
|
|
click(x - 29, y + 6); /* olho da camada Fundo: esconde */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
/* sem camada visivel nao ha imagem nenhuma na folha (=-1) */
|
|
CHECK(img_nonwhite() <= 0, "camada pode ser escondida");
|
|
click(x - 29, y + 6); /* olho: mostra de novo */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(img_nonwhite() > 0, "camada pode ser mostrada de novo");
|
|
}
|
|
|
|
/* 22. Áreas estilo Blender: redimensionar arrastando a borda, trocar de lugar pela alça */
|
|
{
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Blocos", R_ANY, 0, &x, &y) && x < 100, "paleta tem cabeçalho \"Blocos\" com alça");
|
|
/* borda paleta | scripts em x = 318: arrasta 100 px para a direita */
|
|
drag(318, 400, 418, 400);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
bool largo = false;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_SET_CLIP && cmds[i].x == 68 && cmds[i].w > 340) largo = true;
|
|
CHECK(largo, "arrastar a borda alarga a paleta (418 px)");
|
|
float px0 = 0, py0 = 0;
|
|
CHECK(find("Palco", R_ANY, 0, &px0, &py0) && px0 > 920, "palco continua na direita");
|
|
/* alça do palco (ao lado do botão de destacar) -> solta sobre os scripts */
|
|
drag(1280 - 50 - 18 - 8 + 9, 44 + 22, 640, 400);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 418 && x < 900, "alça troca o palco com a área de scripts");
|
|
/* e de volta: a alça do palco agora está no meio da tela */
|
|
drag(418 + (1280 - 360 - 418) - 50 - 18 - 8 + 9, 44 + 22, 1100, 200); /* scripts, em cima à direita */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(find("Palco", R_ANY, 0, &x, &y) && x > 920, "trocar de novo devolve o palco à direita");
|
|
/* layout salvo nas configurações (arquivo isolado do harness) */
|
|
CHECK(!strcmp(tb_environ_get("editor.layout"), "H0:418(p,H1:360(s,V0:310(t,o)))"),
|
|
"layout salvo em editor.layout (paleta com 418 px)");
|
|
FILE* cf = fopen("/tmp/tb_harness_cfg/tinyblocks/settings.csv", "rb");
|
|
char cbuf[1024] = "";
|
|
if (cf) { size_t n = fread(cbuf, 1, sizeof(cbuf) - 1, cf); cbuf[n] = 0; fclose(cf); }
|
|
CHECK(strstr(cbuf, "editor.layout") != NULL, "layout gravado no arquivo de configurações");
|
|
}
|
|
|
|
/* 23. Abas: arrastar na barra reordena (como no navegador) */
|
|
{
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
/* rótulos das abas na barra (y 44..80), em ordem de x */
|
|
char nomes[8][64]; float xs[8]; int n = 0;
|
|
for (uint32_t i = 0; i < ncmd && n < 8; i++) {
|
|
if (cmds[i].kind != TB_DRAW_TEXT || cmds[i].y < 50 || cmds[i].y > 80) continue;
|
|
if (cmds[i].x < 318 || cmds[i].x > 900 || !strcmp(cmds[i].text, "=") || !strcmp(cmds[i].text, "+")) continue;
|
|
snprintf(nomes[n], 64, "%s", cmds[i].text); xs[n] = cmds[i].x; n++;
|
|
}
|
|
CHECK(n >= 2, "há pelo menos duas abas para reordenar");
|
|
if (n >= 2) {
|
|
char primeira[64]; snprintf(primeira, 64, "%s", nomes[0]);
|
|
float sx = xs[0] + 10;
|
|
drag(sx, 62, sx + 150 + 20, 62); /* passa do meio da vizinha */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
float nx = 0, ny = 0;
|
|
bool achou = false;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && !strcmp(cmds[i].text, primeira) && cmds[i].y > 50 && cmds[i].y < 80) {
|
|
nx = cmds[i].x; ny = cmds[i].y; achou = true;
|
|
}
|
|
(void)ny;
|
|
CHECK(achou && nx > xs[1] - 20, "arrastar a aba para a direita troca a ordem com a vizinha");
|
|
|
|
/* arrastar a aba para longe da barra destaca numa janela própria */
|
|
drag(nx + 10, 62, nx + 10, 400);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
bool na_barra = false, no_menu = false;
|
|
float mxp = 0;
|
|
for (uint32_t i = 0; i < ncmd; i++) {
|
|
if (cmds[i].kind != TB_DRAW_TEXT || strcmp(cmds[i].text, primeira) != 0) continue;
|
|
if (cmds[i].y > 50 && cmds[i].y < 80) na_barra = true;
|
|
if (cmds[i].y < 44) { no_menu = true; mxp = cmds[i].x + 3; }
|
|
}
|
|
CHECK(!na_barra && no_menu, "aba arrastada para fora vira janela (botão no menu)");
|
|
if (no_menu) click(mxp, 22); /* volta para a barra */
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
na_barra = false;
|
|
for (uint32_t i = 0; i < ncmd; i++)
|
|
if (cmds[i].kind == TB_DRAW_TEXT && !strcmp(cmds[i].text, primeira) && cmds[i].y > 50 && cmds[i].y < 80)
|
|
na_barra = true;
|
|
CHECK(na_barra, "botão no menu traz a aba de volta para a barra");
|
|
}
|
|
}
|
|
|
|
/* 24. Notação do fórum (scratchblocks): Abrir .txt cria aba; Exportar gera o texto */
|
|
{
|
|
const char* src = "/tmp/tb_harness_sb.txt";
|
|
const char* dst = "/tmp/tb_harness_sb_out.txt";
|
|
const char* script =
|
|
"when flag clicked\n"
|
|
"set [x v] to (0)\n"
|
|
"repeat (3)\n"
|
|
" change [x v] by (1)\n"
|
|
"end\n"
|
|
"say (x)\n";
|
|
FILE* f = fopen(src, "wb");
|
|
if (f) { fputs(script, f); fclose(f); }
|
|
remove(dst);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
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(src);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_has("Importado: 1 script"), "Abrir um .txt em scratchblocks cria aba com o script");
|
|
CHECK(any_has("de tb_harness_sb.txt"), "aba nova recebe o nome do arquivo");
|
|
CHECK(find("repita", R_WS, 0, &x, &y) || ws_has("repita"), "blocos importados aparecem (repita)");
|
|
if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y);
|
|
if (need("Exportar scratchblocks", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
/* prévia: mostra o texto antes de exportar */
|
|
CHECK(find("when flag clicked", R_ANY, 0, &x, &y) && find("Copiar", R_ANY, 0, &x, &y),
|
|
"Exportar scratchblocks abre a prévia com o texto");
|
|
if (need("Copiar", R_ANY, 0, &x, &y)) click(x, y);
|
|
char* clip = tb_graphics_get_clipboard();
|
|
CHECK(clip && strstr(clip, "[scratchblocks]\nwhen flag clicked\n") && strstr(clip, "[/scratchblocks]"),
|
|
"Copiar põe o texto com [scratchblocks] na área de transferência");
|
|
free(clip);
|
|
if (need("Salvar...", R_ANY, 0, &x, &y)) click(x, y);
|
|
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type(dst);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
char got[512] = "";
|
|
f = fopen(dst, "rb");
|
|
if (f) { size_t n = fread(got, 1, sizeof(got) - 1, f); got[n] = 0; fclose(f); }
|
|
CHECK(!strcmp(got, script), "Exportar scratchblocks gera o mesmo texto");
|
|
if (strcmp(got, script)) printf("---- exportado:\n%s----\n", got);
|
|
/* colar do fórum: a área de transferência vira uma aba */
|
|
tb_graphics_set_clipboard("[scratchblocks]\nwhen flag clicked\nerase all\n[/scratchblocks]\n");
|
|
if (need("Exportar", R_FLY, 0, &x, &y)) click(x, y);
|
|
if (need("Colar scratchblocks", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(any_has("Importado: 1 script(s) de Colado"), "Colar scratchblocks importa da área de transferência");
|
|
remove(src); remove(dst);
|
|
}
|
|
|
|
printf("comandos de desenho no último frame: %u\n", ncmd);
|
|
/* 26. Erros: tente / se der erro / finalmente, resultados e erro sem tratamento */
|
|
{
|
|
const char* pj = "/tmp/tb_harness_try.json";
|
|
FILE* f = fopen(pj, "wb");
|
|
if (f) {
|
|
fputs("{\"format\":\"tinyblocks-project\",\"version\":2,\"cur_tab\":0,\"tabs\":[{\"name\":\"Erros\",\"composite\":false,\"comp_id\":-1,\"color\":0,\"blocks\":["
|
|
"{\"i\":0,\"type\":\"Events.WhenRun\",\"x\":40,\"y\":40,\"next\":1},"
|
|
"{\"i\":1,\"type\":\"Errors.Try\",\"parent\":0,\"prel\":0,\"next\":7,\"sub\":[2,3,5]},"
|
|
"{\"i\":2,\"type\":\"Errors.Raise\",\"parent\":1,\"prel\":1,\"next\":6,\"in_text\":[\"deu ruim\"]},"
|
|
"{\"i\":6,\"type\":\"IO.Print\",\"parent\":2,\"prel\":0,\"in_text\":[\"nao roda\",\"\"]},"
|
|
"{\"i\":3,\"type\":\"IO.Print\",\"parent\":1,\"prel\":2,\"args\":[-1,4],\"in_text\":[\"pegou\",\"\"]},"
|
|
"{\"i\":4,\"type\":\"Errors.Caught\",\"parent\":3,\"prel\":5},"
|
|
"{\"i\":5,\"type\":\"IO.Print\",\"parent\":1,\"prel\":3,\"in_text\":[\"no finalmente\",\"\"]},"
|
|
"{\"i\":7,\"type\":\"IO.Print\",\"parent\":1,\"prel\":0,\"next\":8,\"args\":[-1,9],\"in_text\":[\"resultado\",\"\"]},"
|
|
"{\"i\":9,\"type\":\"Errors.UnwrapOr\",\"parent\":7,\"prel\":5,\"args\":[10,-1],\"in_text\":[\"\",\"77\"]},"
|
|
"{\"i\":10,\"type\":\"Errors.Attempt\",\"parent\":9,\"prel\":4,\"args\":[11]},"
|
|
"{\"i\":11,\"type\":\"Errors.Unwrap\",\"parent\":10,\"prel\":4,\"args\":[12]},"
|
|
"{\"i\":12,\"type\":\"Errors.Err\",\"parent\":11,\"prel\":4,\"in_text\":[\"x\"]},"
|
|
"{\"i\":8,\"type\":\"Errors.Raise\",\"parent\":7,\"prel\":0,\"next\":13,\"in_text\":[\"sem tente\"]},"
|
|
"{\"i\":13,\"type\":\"IO.Print\",\"parent\":8,\"prel\":0,\"in_text\":[\"nunca\",\"\"]}"
|
|
"],\"top\":[0]}],\"user_blocks\":[],\"variables\":[]}", f);
|
|
fclose(f);
|
|
}
|
|
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(pj);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
if (find("Descartar", R_ANY, 0, &x, &y)) click(x, y);
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(ws_has("tente") && ws_has("se der erro") && ws_has("finalmente"),
|
|
"bloco tente / se der erro / finalmente com três bocas");
|
|
flag();
|
|
for (int i = 0; i < 3; i++) frame(0, 0, 0, 0, 0, 0, NULL);
|
|
CHECK(stage_has("deu ruim") && !stage_has("nao roda"), "erro pula o resto do tente e vai para o se der erro");
|
|
CHECK(stage_has("no finalmente"), "finalmente roda depois");
|
|
CHECK(stage_has("77"), "tente obter + desembrulhe + valor de ... ou: erro vira valor (Result)");
|
|
CHECK(stage_has("[ERRO] sem tente") && !stage_has("nunca"), "erro sem tente para o script e aparece no palco");
|
|
remove(pj);
|
|
}
|
|
|
|
/* 25. Grupos (como no Unreal): agrupar a pilha e mover tudo pelo título */
|
|
{
|
|
float hx0, hy0;
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
if (need("quando a bandeira for clicado", R_WS, 0, &hx0, &hy0)) {
|
|
drag(hx0, hy0, hx0 + 40, hy0 + 160); /* longe da barra de abas */
|
|
need("quando a bandeira for clicado", R_WS, 0, &hx0, &hy0);
|
|
frame(hx0, hy0, 0, 0, 1, 0, NULL); /* botão direito na pilha */
|
|
frame(hx0, hy0, 0, 0, 0, 0, NULL);
|
|
if (need("Agrupar esta pilha", R_ANY, 0, &x, &y)) click(x, y);
|
|
for (int i = 0; i < 12; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type("Principal");
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
CHECK(find("Principal", R_WS, 0, &x, &y), "Agrupar esta pilha cria o grupo com título");
|
|
float tx = x, ty = y;
|
|
drag(tx, ty, tx + 120, ty + 70); /* arrasta pelo título */
|
|
float nx, ny;
|
|
CHECK(find("quando a bandeira for clicado", R_WS, 0, &nx, &ny) &&
|
|
fabsf(nx - (hx0 + 120)) < 2 && fabsf(ny - (hy0 + 70)) < 2,
|
|
"arrastar o título do grupo move a pilha junto");
|
|
CHECK(find("Principal", R_WS, 0, &x, &y) && fabsf(x - (tx + 120)) < 2,
|
|
"o grupo vai junto com a pilha");
|
|
|
|
/* salvar e abrir de novo mantém o grupo */
|
|
const char* gp = "/tmp/tb_harness_grp.json";
|
|
remove(gp);
|
|
if (need("Salvar", R_FLY, 0, &x, &y)) click(x, y);
|
|
for (int i = 0; i < 40; i++) key(TB_KEY_BACKSPACE, 0, 0);
|
|
type(gp);
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
FILE* f = fopen(gp, "rb");
|
|
char buf[65536] = "";
|
|
if (f) { size_t n = fread(buf, 1, sizeof(buf) - 1, f); buf[n] = 0; fclose(f); }
|
|
CHECK(strstr(buf, "\"groups\"") && strstr(buf, "Principal"), "projeto salvo guarda os grupos");
|
|
}
|
|
}
|
|
|
|
/* 27. Dois blocos definidos na mesma aba: os dois aparecem em Meus Blocos */
|
|
{
|
|
const char* nomes[2] = { "render", "draw button" };
|
|
for (int k = 0; k < 2; k++) {
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
ax_do(ax_need(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_BUTTON, "Criar um Bloco"), TB_A11Y_ACT_ACTIVATE);
|
|
type(nomes[k]); /* o foco abre no nome do bloco */
|
|
key(TB_KEY_RETURN, 0, 0);
|
|
}
|
|
if (need("Meus Blocos", R_CAT, 0, &x, &y)) click(x, y);
|
|
int mine = ax_in(ax_in(0, TB_A11Y_LIST, "Paleta"), TB_A11Y_GROUP, "Meus Blocos");
|
|
CHECK(ax_in(mine, TB_A11Y_BLOCK, "render") >= 0 && ax_in(mine, TB_A11Y_BLOCK, "draw button") >= 0,
|
|
"dois blocos definidos aparecem na paleta");
|
|
}
|
|
|
|
/* 28. Interface de acessibilidade: estrutura, estados, eventos, acoes */
|
|
{
|
|
frame(0, 0, 0, 0, 0, 0, NULL);
|
|
int menu = ax_in(0, TB_A11Y_TOOLBAR, "Menu");
|
|
CHECK(menu >= 0 && ax_in(menu, TB_A11Y_BUTTON, "Abrir") >= 0 && ax_in(menu, TB_A11Y_BUTTON, "Salvar") >= 0 &&
|
|
ax_in(menu, TB_A11Y_BUTTON, "Config") >= 0 && ax_in(menu, TB_A11Y_BUTTON, "Carregar library...") >= 0,
|
|
"a11y: barra de menu com os botões");
|
|
CHECK(ax_in(0, TB_A11Y_PANE, "Blocos") >= 0 && ax_in(0, TB_A11Y_PANE, "Scripts") >= 0 &&
|
|
ax_in(0, TB_A11Y_PANE, "Palco") >= 0 && ax_in(0, TB_A11Y_PANE, "Saída") >= 0,
|
|
"a11y: as quatro áreas são painéis");
|
|
|
|
int run = ax_in(ax_in(0, TB_A11Y_PANE, "Palco"), TB_A11Y_BUTTON, "Executar");
|
|
uint32_t run_id = run >= 0 ? N(run)->id : 0;
|
|
char d[256];
|
|
CHECK(run >= 0 && !strcmp(tb_a11y_describe(A(), run, d, sizeof(d)), "Executar, botão"),
|
|
"a11y: o narrador diz \"Executar, botão\"");
|
|
|
|
/* categoria: ativar seleciona (e gera evento de estado) */
|
|
int cats = ax_in(0, TB_A11Y_TAB_LIST, "Categorias");
|
|
ax_do(ax_in(cats, TB_A11Y_TAB, "Controle"), TB_A11Y_ACT_ACTIVATE);
|
|
int ctl = ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Categorias"), TB_A11Y_TAB, "Controle");
|
|
bool ev_state = false;
|
|
for (int i = 0; i < tb_a11y_event_count(A()); i++) {
|
|
const TinyBlocks_A11yEvent* e = tb_a11y_event(A(), i);
|
|
if (e->kind == TB_A11Y_EV_STATE && e->node == ctl) ev_state = true;
|
|
}
|
|
CHECK(ctl >= 0 && (N(ctl)->states & TB_A11Y_SELECTED) && ev_state,
|
|
"a11y: ativar a categoria a seleciona (evento de estado)");
|
|
int sel = 0;
|
|
for (int k = 0; tb_a11y_find(A(), cats, TB_A11Y_TAB, NULL, k) >= 0; k++)
|
|
if (N(tb_a11y_find(A(), cats, TB_A11Y_TAB, NULL, k))->states & TB_A11Y_SELECTED) sel++;
|
|
CHECK(sel == 1, "a11y: uma categoria selecionada por vez");
|
|
run = ax_in(0, TB_A11Y_BUTTON, "Executar");
|
|
CHECK(run >= 0 && N(run)->id == run_id, "a11y: ids estáveis entre quadros");
|
|
|
|
/* blocos da paleta fora da vista ficam OFFSCREEN, mas estão na árvore */
|
|
int pal = ax_in(0, TB_A11Y_LIST, "Paleta");
|
|
int far = ax_in(pal, TB_A11Y_GROUP, "Meus Blocos");
|
|
CHECK(far >= 0 && (N(far)->states & TB_A11Y_OFFSCREEN) && ax_in(pal, TB_A11Y_GROUP, "Controle") >= 0 &&
|
|
!(N(ax_in(pal, TB_A11Y_GROUP, "Controle"))->states & TB_A11Y_OFFSCREEN),
|
|
"a11y: a paleta toda está na árvore; o que não aparece é OFFSCREEN");
|
|
|
|
/* dialogo: abrir pelo botão, evento SHOWN, voltar fecha */
|
|
ax_do(ax_in(0, TB_A11Y_BUTTON, "Config"), TB_A11Y_ACT_ACTIVATE);
|
|
int dlg = ax_in(0, TB_A11Y_DIALOG, "Configurações");
|
|
bool shown = false;
|
|
for (int i = 0; i < tb_a11y_event_count(A()); i++)
|
|
if (tb_a11y_event(A(), i)->kind == TB_A11Y_EV_SHOWN && tb_a11y_event(A(), i)->node == dlg) shown = true;
|
|
CHECK(dlg >= 0 && (N(dlg)->states & TB_A11Y_MODAL) && shown, "a11y: Config abre um diálogo modal (evento)");
|
|
ax_do(ax_in(dlg, TB_A11Y_BUTTON, "Voltar"), TB_A11Y_ACT_ACTIVATE);
|
|
CHECK(ax_in(0, TB_A11Y_DIALOG, "Configurações") < 0, "a11y: Voltar fecha o diálogo");
|
|
|
|
/* menu "+": o botão fica EXPANDED e o menu tem os itens */
|
|
ax_do(ax_in(ax_in(0, TB_A11Y_TAB_LIST, "Abas"), TB_A11Y_BUTTON, "Nova aba"), TB_A11Y_ACT_ACTIVATE);
|
|
int pm = ax_in(0, TB_A11Y_MENU, "Nova aba");
|
|
CHECK(pm >= 0 && ax_in(pm, TB_A11Y_MENU_ITEM, "Editor de Código") >= 0 &&
|
|
(N(ax_in(0, TB_A11Y_BUTTON, "Nova aba"))->states & TB_A11Y_EXPANDED),
|
|
"a11y: o menu \"Nova aba\" abre com os itens");
|
|
ax_do(ax_in(pm, TB_A11Y_MENU_ITEM, "Editor de Código"), TB_A11Y_ACT_ACTIVATE);
|
|
int code = ax_in(0, TB_A11Y_TEXT_FIELD, "Código");
|
|
CHECK(code >= 0 && tb_a11y_focus(A()) == code, "a11y: aba de código é um campo de texto com o foco");
|
|
type("int x;");
|
|
CHECK(!strcmp(ax_value(ax_in(0, TB_A11Y_TEXT_FIELD, "Código")), "int x;"), "a11y: valor = linha do cursor");
|
|
{ /* fecha a aba de codigo (a selecionada) */
|
|
int tabs = ax_in(0, TB_A11Y_TAB_LIST, "Abas"), cur = -1;
|
|
for (int k = 0, t; (t = tb_a11y_find(A(), tabs, TB_A11Y_TAB, NULL, k)) >= 0; k++)
|
|
if (N(t)->states & TB_A11Y_SELECTED) cur = t;
|
|
ax_do(ax_in(cur, TB_A11Y_BUTTON, "Fechar aba"), TB_A11Y_ACT_ACTIVATE);
|
|
CHECK(ax_in(0, TB_A11Y_TEXT_FIELD, "Código") < 0, "a11y: \"Fechar aba\" fecha a aba");
|
|
}
|
|
|
|
/* menu de contexto num bloco */
|
|
int hat = ax_in(ax_in(0, TB_A11Y_TAB_PANEL, NULL), TB_A11Y_BLOCK, "quando a bandeira for clicado");
|
|
CHECK(hat >= 0 && (N(hat)->states & TB_A11Y_OFFSCREEN), "a11y: bloco fora da vista é OFFSCREEN");
|
|
ax_do(hat, TB_A11Y_ACT_MENU); /* rola até ele e abre o menu */
|
|
int cm = ax_in(0, TB_A11Y_MENU, "Menu de contexto");
|
|
CHECK(cm >= 0 && ax_in(cm, TB_A11Y_MENU_ITEM, "Duplicar") >= 0, "a11y: menu de contexto do bloco");
|
|
key(TB_KEY_ESCAPE, 0, 0);
|
|
|
|
/* ponte de texto (um narrador simples) */
|
|
FILE* log = tmpfile();
|
|
if (log) {
|
|
TinyBlocks_A11yBridge b = tb_a11y_log_bridge(log);
|
|
tb_a11y_set_bridge(A(), &b);
|
|
ax_do(ax_in(0, TB_A11Y_BUTTON, "Config"), TB_A11Y_ACT_ACTIVATE);
|
|
ax_do(ax_in(ax_in(0, TB_A11Y_DIALOG, "Configurações"), TB_A11Y_BUTTON, "Voltar"), TB_A11Y_ACT_ACTIVATE);
|
|
tb_a11y_set_bridge(A(), NULL);
|
|
char lb[2048] = "";
|
|
rewind(log);
|
|
size_t n = fread(lb, 1, sizeof(lb) - 1, log);
|
|
lb[n] = 0;
|
|
fclose(log);
|
|
CHECK(strstr(lb, "[a11y] abriu: Configurações, diálogo") != NULL, "a11y: a ponte recebe os eventos");
|
|
}
|
|
}
|
|
|
|
tinyblocks_deinit(&rt);
|
|
printf(fails ? "\n%d FALHA(S)\n" : "\nTUDO OK\n", fails);
|
|
return fails != 0;
|
|
}
|