pixbufloader_test.cc (1263B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include <gdk-pixbuf/gdk-pixbuf.h> 7 #include <gdk/gdk.h> 8 #include <glib.h> 9 #include <stdlib.h> 10 11 int main(int argc, char* argv[]) { 12 if (argc != 3) { 13 fprintf(stderr, "Usage: %s <loaders.cache> <image.jxl>\n", argv[0]); 14 return 1; 15 } 16 17 const char* loaders_cache = argv[1]; 18 const char* filename = argv[2]; 19 const int kDoOverwrite = 1; 20 setenv("GDK_PIXBUF_MODULE_FILE", loaders_cache, kDoOverwrite); 21 22 // XDG_DATA_HOME is the path where we look for the mime cache. 23 // XDG_DATA_DIRS directories are used in addition to XDG_DATA_HOME. 24 setenv("XDG_DATA_HOME", ".", kDoOverwrite); 25 setenv("XDG_DATA_DIRS", "", kDoOverwrite); 26 27 if (!gdk_init_check(nullptr, nullptr)) { 28 fprintf(stderr, "This test requires a DISPLAY\n"); 29 // Signals ctest that we should mark this test as skipped. 30 return 254; 31 } 32 GError* error = nullptr; 33 GdkPixbuf* pb = gdk_pixbuf_new_from_file(filename, &error); 34 if (pb != nullptr) { 35 g_object_unref(pb); 36 return 0; 37 } else { 38 fprintf(stderr, "Error loading file: %s\n", filename); 39 g_assert_no_error(error); 40 return 1; 41 } 42 }