| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include <cstdio>
- #include <cstdlib>
- #include <string>
- #include "model/control_registry.h"
- static std::string load_file(const char* path) {
- FILE* fp = fopen(path, "rb");
- if (!fp) { fprintf(stderr, "Cannot open %s\n", path); return {}; }
- fseek(fp, 0, SEEK_END);
- long sz = ftell(fp);
- fseek(fp, 0, SEEK_SET);
- std::string buf(sz, '\0');
- fread(buf.data(), 1, sz, fp);
- fclose(fp);
- return buf;
- }
- int main() {
- uidef::ControlRegistry reg;
- const char* files[] = {
- "assets/controls/abstract-controls.xml",
- "assets/controls/winform-controls.xml",
- "assets/controls/avalonia-controls.xml",
- "assets/controls/webawesome-controls.xml",
- };
- for (auto f : files) {
- std::string data = load_file(f);
- if (data.empty()) { fprintf(stderr, "FAIL: cannot load %s\n", f); return 1; }
- if (!reg.load_control_set(data)) { fprintf(stderr, "FAIL: parse error %s\n", f); return 1; }
- printf("Loaded %s -> %zu controls total\n", f, reg.control_count());
- }
- reg.resolve_inheritance();
- printf("\n=== After inheritance resolution: %zu controls ===\n", reg.control_count());
- auto check = [&](const char* name) {
- auto* def = reg.find(name);
- if (!def) { printf(" NOT FOUND: %s\n", name); return; }
- printf(" %s: type=%s cat=%s inherits=%s attrs=%zu events=%zu container=%d\n",
- def->name.c_str(), def->type.c_str(), def->category.c_str(),
- def->inherits.c_str(), def->attributes.size(), def->events.size(),
- def->is_container);
- };
- check("CommonControl");
- check("Label");
- check("TextBox");
- check("Panel");
- check("wa-button");
- check("AvaloniaTextBox");
- check("ListView");
- check("StackPanel");
- printf("\n=== Categories ===\n");
- for (auto& [cat, names] : reg.by_category()) {
- printf(" %s: %zu controls\n", cat.c_str(), names.size());
- }
- printf("\n=== Structures ===\n");
- for (auto& s : reg.structures()) {
- printf(" %s (type=%s)\n", s.name.c_str(), s.type.c_str());
- }
- // Verify inheritance resolution
- printf("\n=== Inheritance verification ===\n");
- auto* label = reg.find("Label");
- if (label) {
- bool has_visible = false, has_text = false, has_width = false;
- for (auto& a : label->attributes) {
- if (a.name == "visible") has_visible = true;
- if (a.name == "text") has_text = true;
- if (a.name == "width") has_width = true;
- }
- printf(" Label has 'visible' (from CommonControl): %s\n", has_visible ? "YES" : "NO");
- printf(" Label has 'text' (own): %s\n", has_text ? "YES" : "NO");
- printf(" Label has 'width' (from CommonControl): %s\n", has_width ? "YES" : "NO");
- if (!has_visible || !has_text || !has_width) {
- printf(" FAIL: inheritance not resolved correctly!\n");
- return 1;
- }
- }
- auto* wa_button = reg.find("wa-button");
- if (wa_button) {
- bool has_variant = false, has_text = false, has_visible = false;
- for (auto& a : wa_button->attributes) {
- if (a.name == "variant") has_variant = true;
- if (a.name == "text") has_text = true;
- if (a.name == "visible") has_visible = true;
- }
- printf(" wa-button has 'variant' (own): %s\n", has_variant ? "YES" : "NO");
- printf(" wa-button has 'text' (from Button): %s\n", has_text ? "YES" : "NO");
- printf(" wa-button has 'visible' (from CommonControl): %s\n", has_visible ? "YES" : "NO");
- if (!has_variant || !has_text || !has_visible) {
- printf(" FAIL: deep inheritance not resolved correctly!\n");
- return 1;
- }
- }
- printf("\nSUCCESS\n");
- return 0;
- }
|