Files
fn_registry/cpp/tests/CMakeLists.txt
T
egutierrez 1861205504 feat(viz): graph_labels render con LabelPolicy + ImDrawList (issue 0049j)
graph_labels_draw pinta etiquetas de nodos sobre el FBO del graph_renderer
via ImDrawList. Politica configurable: always-on para selected/hovered/
pinned, top-N por size*(degree+1), culling por viewport AABB y
min_node_pixel_size. Cap duro = max_visible + |always_*|.

API:
- graph_labels_draw(graph, viewport_state, policy, cb, user)
- graph_labels_draw_at(...)  — variante con rect explicito
- graph_labels_select(...)   — helper puro testeable
- graph_compute_degrees(...) — O(E)

Splitting en dos TUs:
- graph_labels.cpp          — funciones draw (depende de ImGui)
- graph_labels_select.cpp   — helpers puros para tests sin ImGui

12 tests en test_graph_labels (culling, max_visible cap, min_pixel_size,
always_* gating por viewport, top-N por score, edge cases). Todos verdes.

Integrado en demos_graph con UI: toggle Labels, sliders Max visible /
Font / Min px, checkboxes Selected/Hovered/Pinned. Golden de
graph_viewport regenerado.

Cierra issue 0049j.
2026-04-29 23:53:32 +02:00

157 lines
7.9 KiB
CMake

# cpp/tests — Catch2 unit tests for primitives.
#
# Catch2 amalgamated is compiled once as a STATIC LIB. Each test binary is
# its own executable so we can mix tests that use ImGui-context and tests
# that are pure logic without polluting symbols.
add_library(catch2 STATIC
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/catch2/catch_amalgamated.cpp)
target_include_directories(catch2 PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/catch2)
target_compile_features(catch2 PUBLIC cxx_std_17)
# Helper: register a test executable.
# add_fn_test(<name> <sources...>)
# By default links Catch2 + the cpp/functions include path. Tests that need
# real symbols (linking against fn_framework etc.) can call
# target_link_libraries(${name} PRIVATE fn_framework imgui ...) afterwards.
function(add_fn_test name)
add_executable(${name} ${ARGN})
target_link_libraries(${name} PRIVATE catch2)
target_include_directories(${name} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../functions
${CMAKE_CURRENT_SOURCE_DIR}/../framework)
add_test(NAME ${name} COMMAND ${name})
endfunction()
# --- Tests reales (logica pura, no necesitan ImGui context) ----------------
add_fn_test(test_tween_curves test_tween_curves.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/tween_curves.cpp)
add_fn_test(test_pie_chart_math test_pie_chart_math.cpp)
add_fn_test(test_kpi_card_math test_kpi_card_math.cpp)
add_fn_test(test_bar_chart_math test_bar_chart_math.cpp)
# Issue 0045 — tests de la logica pura extraida.
add_fn_test(test_sql_parse test_sql_parse.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/sql_parse.cpp)
add_fn_test(test_process_state_machine test_process_state_machine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/process_state_machine.cpp)
add_fn_test(test_file_poll_diff test_file_poll_diff.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/file_poll_diff.cpp)
# --- Placeholders para primitivos UI (logica visual cubierta en 0048) ------
add_fn_test(test_tokens test_tokens.cpp)
add_fn_test(test_button test_button.cpp)
add_fn_test(test_select test_select.cpp)
add_fn_test(test_text_input test_text_input.cpp)
add_fn_test(test_badge test_badge.cpp)
add_fn_test(test_kpi_card test_kpi_card.cpp)
add_fn_test(test_pie_chart test_pie_chart.cpp)
add_fn_test(test_bar_chart test_bar_chart.cpp)
add_fn_test(test_tree_view test_tree_view.cpp)
add_fn_test(test_modal_dialog test_modal_dialog.cpp)
add_fn_test(test_toolbar test_toolbar.cpp)
add_fn_test(test_toast test_toast.cpp)
add_fn_test(test_empty_state test_empty_state.cpp)
add_fn_test(test_page_header test_page_header.cpp)
add_fn_test(test_dashboard_panel test_dashboard_panel.cpp)
add_fn_test(test_dashboard_grid test_dashboard_grid.cpp)
add_fn_test(test_sparkline test_sparkline.cpp)
add_fn_test(test_table_view test_table_view.cpp)
add_fn_test(test_icon_button test_icon_button.cpp)
# --- Issue 0049c — graph renderer Tier 1 (RGBA8 + auto-pause helper) -------
add_fn_test(test_graph_pack_rgba8 test_graph_pack_rgba8.cpp)
add_fn_test(test_graph_should_pause test_graph_should_pause.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_force_layout.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_layouts.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
# --- Issue 0049d — vertex pulling edge buffer (logica solo, sin GL) --------
add_fn_test(test_graph_edge_static test_graph_edge_static.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
# --- Issue 0049e — modelo de grafo extendido (GraphNode/GraphEdge + tipos) --
add_fn_test(test_graph_types test_graph_types.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
# --- Issue 0049g — graph_sources: lector de operations.db ------------------
add_fn_test(test_graph_sources test_graph_sources.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_sources.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
target_link_libraries(test_graph_sources PRIVATE SQLite::SQLite3)
# --- Issue 0049i — graph_layouts (radial / hierarchical / fixed / etc) -----
add_fn_test(test_graph_layouts test_graph_layouts.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_layouts.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
# --- Issue 0049j — graph_labels (LabelPolicy + select pure logic) ---------
add_fn_test(test_graph_labels test_graph_labels.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_labels_select.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
# --- Issue 0049i — graph_viewport selection helpers (logica pura sin GL) ---
# Solo cubre graph_viewport_selection.cpp; el widget completo se prueba en
# primitives_gallery + golden image diff. graph_viewport.h incluye ImVec2,
# por eso anadimos cpp/vendor/imgui al include path.
add_fn_test(test_graph_viewport test_graph_viewport.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_viewport_selection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
target_include_directories(test_graph_viewport PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/imgui)
# --- Issue 0049h — graph_force_layout_gpu (compute + spatial hash) ----------
# El test crea una ventana GLFW oculta a 4.3 core; si glfwInit/window/context
# fallan (CI sin DISPLAY, Mesa sin compute), el test SKIPea. Linkamos contra
# glfw + OpenGL para que se resuelvan los simbolos en cualquier caso.
add_fn_test(test_graph_force_layout_gpu test_graph_force_layout_gpu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_force_layout_gpu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_force_layout.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_layouts.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/gfx/gl_loader.cpp)
if(WIN32)
target_link_libraries(test_graph_force_layout_gpu PRIVATE glfw opengl32)
else()
find_package(OpenGL REQUIRED)
target_link_libraries(test_graph_force_layout_gpu PRIVATE glfw OpenGL::GL)
endif()
# --- Issue 0049f — atlas de iconos Tabler para graph_renderer ---------------
# graph_icons.cpp incluye gl_loader.h y referencia gl* — el atlas se puede
# construir sin contexto via FN_GRAPH_ICONS_SKIP_GL=1 (set por el test), pero
# las funciones GL siguen siendo simbolos a resolver en link. Linkamos contra
# OpenGL::GL (Linux) u opengl32 (Win cross) para que el linker quede contento.
add_fn_test(test_graph_icons test_graph_icons.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_icons.cpp)
target_include_directories(test_graph_icons PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/imgui)
target_compile_definitions(test_graph_icons PRIVATE
FN_CPP_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/..")
if(WIN32)
target_link_libraries(test_graph_icons PRIVATE opengl32)
else()
find_package(OpenGL REQUIRED)
target_link_libraries(test_graph_icons PRIVATE OpenGL::GL)
endif()
# --- Visual golden-image diff (issue 0048) ---------------------------------
# El binario primitives_gallery se compila con --capture; el test compara los
# PNGs generados con los goldens en cpp/tests/golden/. Si no hay goldens o el
# entorno no tiene GL, el test SKIPea.
add_fn_test(test_visual
test_visual.cpp
png_diff.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/stb/stb_image_impl.cpp)
target_include_directories(test_visual PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/stb)
target_compile_definitions(test_visual PRIVATE
"FN_TEST_GOLDEN_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/golden\""
"FN_TEST_GALLERY_BIN=\"$<TARGET_FILE:primitives_gallery>\""
"FN_TEST_TMP_DIR=\"${CMAKE_BINARY_DIR}/tests/visual_actual\""
# CMAKE_SOURCE_DIR aqui es cpp/, queremos la raiz del repo (un nivel arriba).
"FN_TEST_REPO_ROOT=\"${CMAKE_SOURCE_DIR}/..\"")
# Asegura que primitives_gallery existe antes de correr el test.
add_dependencies(test_visual primitives_gallery)