Files
fn_registry/cpp/tests/test_graph_edge_static.cpp
egutierrez b9ffc13caf feat(viz): graph_types modelo extendido + EntityType/RelationType + flags (issue 0049e)
Extiende el modelo agnostico de graph_types.h para soportar shapes/iconos/
filtros/labels/streaming sin acoplar a backend. Migra el unico consumer
(demos_graph) en el mismo cambio.

- GraphNode v2: type_id + shape_override/color_override/size_override +
  flags (NF_PINNED/VISIBLE/SELECTED/HOVERED) + label_idx + user_data.
- GraphEdge v2: type_id + style_override + flags (EF_DIRECTED/VISIBLE).
- EntityType / RelationType: tablas en GraphData (types, rel_types).
- Helpers de resolucion (resolve_node_color/shape/size, resolve_edge_*)
  y constructores ergonomicos (graph_node, graph_edge, entity_type,
  relation_type) — sentinel-based para herencia automatica del tipo.
- graph_renderer v1.4: lee NF_VISIBLE / EF_VISIBLE, resuelve apariencia
  via override → EntityType → fallback indexado por type_id. Skipea
  aristas con endpoints invisibles. Shapes siguen pintandose como
  circulo (0049f cableara el dispatch real).
- graph_force_layout v1.2: pinned ahora vive en flags & NF_PINNED.
- graph_viewport v1.1: hover/seleccion publican NF_HOVERED/SELECTED en
  el grafo (clear-then-set). Drag usa NF_PINNED. Tooltip muestra Type/
  user_data en lugar de community/value/label.
- demos_graph: 8 EntityType (paleta antigua) + 1 RelationType. type_id
  por cluster. user_data = indice numerico del nodo. Apariencia visual
  identica al pre-cambio.
- test_graph_types.cpp: 12 casos cubriendo helpers, defaults, bitmask
  manipulation y resoluciones override-vs-EntityType. test_graph_edge_
  static actualizado al nuevo modelo (ya no tiene .color directo).
- 4 .md de tipos nuevos (graph_node, graph_edge, entity_type,
  relation_type) + GraphData v2.0 actualizado.

Tests: 31/31 ctest verdes (incluye test_visual golden).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 22:44:40 +02:00

66 lines
2.6 KiB
C++

// Smoke test for graph_renderer's vertex-pulling edge buffer layout (issue
// 0049d). El test no toca GL — solo verifica las garantias estructurales que
// el renderer asume:
// 1. EdgeStatic mide 16 bytes (alineacion natural sin padding sorpresa).
// 2. Los offsets de source/target/color/flags son 0/4/8/12.
// 3. La paleta de colores por defecto del fallback (gris 0x88) tiene la
// forma RGBA8 esperada por el shader (R en byte 0).
//
// Render-a-FBO-y-readback queda fuera porque exigirseria un contexto GL en
// el runner de tests; ya hay un golden image gate via test_visual + capture
// en primitives_gallery.
#define CATCH_CONFIG_MAIN
#include "catch_amalgamated.hpp"
#include "viz/graph_renderer.h"
#include "viz/graph_types.h"
#include <cstddef>
#include <cstdint>
// Re-declaramos la struct local a graph_renderer.cpp para chequear su layout
// "en espejo". Si cambia el layout en el .cpp, este test debe actualizarse —
// es intencional: el shader y el VAO setup dependen de estos offsets.
namespace test_layout {
struct EdgeStatic {
uint32_t source;
uint32_t target;
uint32_t color;
uint32_t flags;
};
} // namespace test_layout
TEST_CASE("EdgeStatic mide 16 bytes y tiene offsets contiguos", "[viz][edge_static]") {
using test_layout::EdgeStatic;
REQUIRE(sizeof(EdgeStatic) == 16);
REQUIRE(offsetof(EdgeStatic, source) == 0);
REQUIRE(offsetof(EdgeStatic, target) == 4);
REQUIRE(offsetof(EdgeStatic, color) == 8);
REQUIRE(offsetof(EdgeStatic, flags) == 12);
}
TEST_CASE("Fallback gris 0x88 tiene R en el byte LSB", "[viz][edge_static]") {
// El renderer construye `pack_rgba8(0x88, 0x88, 0x88, 0xFF)` cuando
// `e.color == 0`. El shader hace unpack manual asumiendo R en LSB.
uint32_t gray = pack_rgba8(0x88, 0x88, 0x88, 0xFF);
REQUIRE((gray & 0xFFu) == 0x88u); // R
REQUIRE(((gray >> 8) & 0xFFu) == 0x88u); // G
REQUIRE(((gray >> 16) & 0xFFu) == 0x88u); // B
REQUIRE(((gray >> 24) & 0xFFu) == 0xFFu); // A
}
TEST_CASE("graph_edge() default deja flags=EF_VISIBLE y type_id=0",
"[viz][edge_static]") {
// Modelo extendido (issue 0049e): GraphEdge ya no tiene `color` directo —
// el color sale de RelationType via type_id. Aqui solo validamos los
// defaults del helper para que el renderer pueda dibujar la arista
// (EF_VISIBLE encendido) y que el fallback al RelationType funcione
// con type_id = 0.
GraphEdge e = graph_edge(0, 1, 1.0f);
REQUIRE(e.flags == EF_VISIBLE);
REQUIRE(e.type_id == 0);
REQUIRE(e.style_override == EDGE_USE_TYPE);
REQUIRE(e.weight == 1.0f);
}