diff --git a/src/libsysprof-analyze/tests/meson.build b/src/libsysprof-analyze/tests/meson.build index c328c977..7ffd5b01 100644 --- a/src/libsysprof-analyze/tests/meson.build +++ b/src/libsysprof-analyze/tests/meson.build @@ -14,6 +14,7 @@ libsysprof_analyze_testsuite_c_args = [ libsysprof_analyze_testsuite = { 'test-capture-model' : {'skip': true}, 'test-list-files' : {'skip': true}, + 'test-print-file' : {'skip': true}, 'test-symbolize' : {'skip': true}, } diff --git a/src/libsysprof-analyze/tests/test-print-file.c b/src/libsysprof-analyze/tests/test-print-file.c new file mode 100644 index 00000000..ec593088 --- /dev/null +++ b/src/libsysprof-analyze/tests/test-print-file.c @@ -0,0 +1,60 @@ +/* test-print-file.c + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include + +int +main (int argc, + char *argv[]) +{ + g_autoptr(SysprofDocumentFile) file = NULL; + g_autoptr(SysprofDocument) document = NULL; + g_autoptr(GListModel) files = NULL; + g_autoptr(GError) error = NULL; + g_autoptr(GBytes) bytes = NULL; + + if (argc < 3) + { + g_printerr ("usage: %s CAPTURE_FILE EMBEDDED_FILE_PATH\n", argv[0]); + return 1; + } + + if (!(document = sysprof_document_new (argv[1], &error))) + { + g_printerr ("Failed to open capture: %s\n", error->message); + return 1; + } + + file = sysprof_document_lookup_file (document, argv[2]); + + if (file == NULL) + { + g_printerr ("File \"%s\" not found.\n", argv[2]); + return 1; + } + + bytes = sysprof_document_file_dup_bytes (file); + + write (STDOUT_FILENO, + g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes)); + + return 0; +}