This commit is contained in:
Clinv committed 2026-10-24 12:01:52 -03:00
1 parent 7f7fcd545d
commit 4d9a339421
114 files changed
+11383 -1837

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
/* Ayudas comunes de las extensiones de PRUEBA. */
#ifndef PLUG_COMMON_H
#define PLUG_COMMON_H
#include <stdio.h>
#include <stdlib.h>
#include "tahgibu/plugin.h"
static __attribute__((unused)) void mark(const char *what) { /* deja constancia en un archivo para que la prueba compruebe qué se ejecutó */
const char *p = getenv("TGB_TEST_MARK");
if (!p) return;
FILE *f = fopen(p, "a");
if (f) { fputs(what, f); fputc('\n', f); fclose(f); }
}
#endif
+14
View File
@@ -0,0 +1,14 @@
#include "plug_common.h"
TGB_PLUGIN_DECLARE_API_VERSION;
static const tgb_host_api *H;
static int seen_pixels = 0, seen_total = 0;
static void on_event(const tgb_event *ev, void *user) { (void)user; seen_total++; if (ev->type == TGB_EVENT_PIXELS_CHANGED) seen_pixels++; }
static tgb_status cmd_seen(tgb_plugin_handle *self, void *user) { (void)self; (void)user; return seen_pixels > 0 ? TGB_OK : TGB_ERR_PLUGIN; }
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
H = host;
tgb_status s = host->subscribe(self, on_event, NULL);
if (s < 0) return s;
host->register_command(self, "eventos-vistos", cmd_seen, NULL);
info->name = "Escucha eventos"; info->version = "1.0"; info->required_caps = TGB_CAP_EVENTS | TGB_CAP_READ_DOCUMENT;
return TGB_OK;
}
+57
View File
@@ -0,0 +1,57 @@
#include "plug_common.h"
TGB_PLUGIN_DECLARE_API_VERSION;
static const tgb_host_api *H;
static const tgb_color RED = {255, 0, 0, 255};
static tgb_status cmd_cross(tgb_plugin_handle *self, void *user) {
(void)user;
tgb_status s = H->edit_begin(self, 0, 0);
if (s < 0) return s;
int cx = H->doc_width(self) / 2, cy = H->doc_height(self) / 2;
for (int i = -3; i <= 3; i++) { H->put_pixel(self, cx + i, cy, RED); H->put_pixel(self, cx, cy + i, RED); }
return H->edit_end(self);
}
static tgb_status cmd_two_steps(tgb_plugin_handle *self, void *user) {
(void)user;
tgb_status s = H->add_frame(self, H->doc_frame_count(self)); /* paso 1: estructura */
if (s < 0) return s;
s = H->edit_begin(self, 0, 0); /* paso 2: píxeles */
if (s < 0) return s;
H->put_pixel(self, 1, 1, RED);
return H->edit_end(self);
}
static tgb_status cmd_fail_midway(tgb_plugin_handle *self, void *user) {
(void)user;
H->add_frame(self, 0);
if (H->edit_begin(self, 0, 0) == TGB_OK) { H->put_pixel(self, 2, 2, RED); H->edit_end(self); }
return TGB_ERR_PLUGIN; /* falla a mitad: el host debe revertirlo todo */
}
static tgb_status cmd_forget_end(tgb_plugin_handle *self, void *user) {
(void)user;
tgb_status s = H->edit_begin(self, 0, 0);
if (s < 0) return s;
H->put_pixel(self, 3, 3, RED);
return TGB_OK; /* olvida edit_end */
}
static tgb_status cmd_read(tgb_plugin_handle *self, void *user) {
(void)user;
return H->get_pixel(self, 0, 0, 0, 0).a == 0 ? TGB_OK : TGB_ERR_PLUGIN;
}
static tgb_status cmd_outside(tgb_plugin_handle *self, void *user) { (void)user; (void)self; return TGB_OK; }
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
H = host;
mark("init");
if (host->api_version != TGB_PLUGIN_API_VERSION || host->struct_size < sizeof(tgb_host_api)) return TGB_ERR_INCOMPATIBLE;
host->register_command(self, "dibujar-cruz", cmd_cross, NULL);
host->register_command(self, "dos-pasos", cmd_two_steps, NULL);
host->register_command(self, "falla-a-medias", cmd_fail_midway, NULL);
host->register_command(self, "olvida-cerrar", cmd_forget_end, NULL);
host->register_command(self, "lee-pixel", cmd_read, NULL);
host->register_command(self, "no-hace-nada", cmd_outside, NULL);
info->name = "Cruz de prueba";
info->version = "1.0.0";
info->required_caps = TGB_CAP_READ_DOCUMENT | TGB_CAP_EDIT_DOCUMENT;
return TGB_OK;
}
TGB_PLUGIN_EXPORT void tgb_plugin_shutdown(tgb_plugin_handle *self) { (void)self; mark("shutdown"); }
+6
View File
@@ -0,0 +1,6 @@
#include "plug_common.h"
TGB_PLUGIN_DECLARE_API_VERSION;
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
(void)host; (void)self; (void)info;
return TGB_ERR_PLUGIN;
}
+9
View File
@@ -0,0 +1,9 @@
#include "plug_common.h"
TGB_PLUGIN_DECLARE_API_VERSION;
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
(void)host; (void)self;
mark("init-needs-edit");
info->name = "Pide editar"; info->version = "1"; info->required_caps = TGB_CAP_EDIT_DOCUMENT;
return TGB_OK;
}
TGB_PLUGIN_EXPORT void tgb_plugin_shutdown(tgb_plugin_handle *self) { (void)self; mark("shutdown-needs-edit"); }
+3
View File
@@ -0,0 +1,3 @@
#include "plug_common.h"
TGB_PLUGIN_DECLARE_API_VERSION;
int plug_unrelated_symbol(void) { return 42; } /* una biblioteca válida pero sin tgb_plugin_init */
+5
View File
@@ -0,0 +1,5 @@
#include "plug_common.h"
TGB_PLUGIN_DECLARE_API_VERSION;
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
(void)host; (void)self; info->name = NULL; info->required_caps = 0; return TGB_OK;
}
+4
View File
@@ -0,0 +1,4 @@
#include "plug_common.h"
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
(void)host; (void)self; (void)info; mark("init-no-version"); return TGB_OK;
}
+5
View File
@@ -0,0 +1,5 @@
#include "plug_common.h"
TGB_PLUGIN_EXPORT const uint32_t tgb_plugin_api_version = 0; /* compilada para otra API */
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
(void)host; (void)self; (void)info; mark("init-old-api"); return TGB_OK;
}
+12
View File
@@ -0,0 +1,12 @@
#include "plug_common.h"
TGB_PLUGIN_DECLARE_API_VERSION;
static const tgb_host_api *H;
static tgb_status cmd_try_edit(tgb_plugin_handle *self, void *user) { (void)user; return H->edit_begin(self, 0, 0); }
static tgb_status cmd_try_edit_unchecked(tgb_plugin_handle *self, void *user) { (void)user; return H->add_frame(self, 0); }
TGB_PLUGIN_EXPORT tgb_status tgb_plugin_init(const tgb_host_api *host, tgb_plugin_handle *self, tgb_plugin_info *info) {
H = host;
host->register_command(self, "intenta-editar", cmd_try_edit, NULL);
host->register_command(self, "intenta-anadir", cmd_try_edit_unchecked, NULL);
info->name = "Solo lectura"; info->version = "0.1"; info->required_caps = TGB_CAP_READ_DOCUMENT; /* NO pide editar */
return TGB_OK;
}