diff --git a/support/testing/tests/package/br2-external/gumbo-parser/Config.in b/support/testing/tests/package/br2-external/gumbo-parser/Config.in new file mode 100644 index 0000000000..28a97c1dfe --- /dev/null +++ b/support/testing/tests/package/br2-external/gumbo-parser/Config.in @@ -0,0 +1 @@ +source "$BR2_EXTERNAL_GUMBO_PARSER_PATH/package/gumbo-parser-test/Config.in" diff --git a/support/testing/tests/package/br2-external/gumbo-parser/external.desc b/support/testing/tests/package/br2-external/gumbo-parser/external.desc new file mode 100644 index 0000000000..4bda9627e9 --- /dev/null +++ b/support/testing/tests/package/br2-external/gumbo-parser/external.desc @@ -0,0 +1 @@ +name: GUMBO_PARSER diff --git a/support/testing/tests/package/br2-external/gumbo-parser/external.mk b/support/testing/tests/package/br2-external/gumbo-parser/external.mk new file mode 100644 index 0000000000..bdc8b2fc79 --- /dev/null +++ b/support/testing/tests/package/br2-external/gumbo-parser/external.mk @@ -0,0 +1 @@ +include $(sort $(wildcard $(BR2_EXTERNAL_GUMBO_PARSER_PATH)/package/*/*.mk)) diff --git a/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/Config.in b/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/Config.in new file mode 100644 index 0000000000..714d3e0198 --- /dev/null +++ b/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/Config.in @@ -0,0 +1,7 @@ +config BR2_PACKAGE_GUMBO_PARSER_TEST + bool "gumbo-parser-test" + depends on BR2_PACKAGE_GUMBO_PARSER + help + Test program for gumbo-parser library. + This package builds a simple test program that demonstrates + basic HTML parsing functionality using gumbo-parser. diff --git a/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/gumbo-parser-test.mk b/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/gumbo-parser-test.mk new file mode 100644 index 0000000000..111f1977bf --- /dev/null +++ b/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/gumbo-parser-test.mk @@ -0,0 +1,19 @@ +################################################################################ +# +# gumbo-parser-test +# +################################################################################ + +GUMBO_PARSER_TEST_DEPENDENCIES = gumbo-parser + +define GUMBO_PARSER_TEST_BUILD_CMDS + $(TARGET_CC) $(TARGET_CFLAGS) -o $(@D)/gumbo_test \ + $(GUMBO_PARSER_TEST_PKGDIR)/gumbo_test.c \ + $(TARGET_LDFLAGS) -lgumbo +endef + +define GUMBO_PARSER_TEST_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/gumbo_test $(TARGET_DIR)/usr/bin/gumbo_test +endef + +$(eval $(generic-package)) diff --git a/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/gumbo_test.c b/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/gumbo_test.c new file mode 100644 index 0000000000..f9c9ca4a91 --- /dev/null +++ b/support/testing/tests/package/br2-external/gumbo-parser/package/gumbo-parser-test/gumbo_test.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +static void search_for_title(GumboNode* node) { + if (node->type != GUMBO_NODE_ELEMENT) { + return; + } + + if (node->v.element.tag == GUMBO_TAG_TITLE) { + GumboNode* text = node->v.element.children.data[0]; + if (text->type == GUMBO_NODE_TEXT) { + printf("Found title: %s\n", text->v.text.text); + } + return; + } + + GumboVector* children = &node->v.element.children; + for (unsigned int i = 0; i < children->length; ++i) { + search_for_title(children->data[i]); + } +} + +int main() { + const char* html = "Test HTML

Hello World

"; + + GumboOutput* output = gumbo_parse(html); + + if (output == NULL) { + printf("HTML parsing failed\n"); + return 1; + } + + printf("HTML parsing successful\n"); + search_for_title(output->root); + + gumbo_destroy_output(&kGumboDefaultOptions, output); + return 0; +} diff --git a/support/testing/tests/package/test_gumbo_parser.py b/support/testing/tests/package/test_gumbo_parser.py new file mode 100644 index 0000000000..efa8ec91a7 --- /dev/null +++ b/support/testing/tests/package/test_gumbo_parser.py @@ -0,0 +1,27 @@ +import os + +import infra.basetest + + +class TestGumboParser(infra.basetest.BRTest): + br2_external = [infra.filepath("tests/package/br2-external/gumbo-parser")] + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_PACKAGE_GUMBO_PARSER=y + BR2_PACKAGE_GUMBO_PARSER_TEST=y + BR2_TARGET_ROOTFS_CPIO=y + # BR2_TARGET_ROOTFS_TAR is not set + """ + + def test_run(self): + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv5", + kernel="builtin", + options=["-initrd", cpio_file]) + self.emulator.login() + + # Run the test program and check output + out, ret = self.emulator.run("/usr/bin/gumbo_test") + self.assertEqual(ret, 0) + self.assertIn("HTML parsing successful", "\n".join(out)) + self.assertIn("Found title: Test HTML", "\n".join(out))