generated-main.c 807 B

12345678910111213141516171819202122232425262728
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<gio/gio.h>
  4. #include"generated-resources.h"
  5. #define EXPECTED "This is a generated resource.\n"
  6. int main(int argc, char **argv) {
  7. GResource *res = generated_resources_get_resource();
  8. GError *err = NULL;
  9. GBytes *data = g_resources_lookup_data("/com/example/myprog/res3.txt",
  10. G_RESOURCE_LOOKUP_FLAGS_NONE, &err);
  11. if(data == NULL) {
  12. fprintf(stderr, "Data lookup failed: %s\n", err->message);
  13. return 1;
  14. }
  15. if(strcmp(g_bytes_get_data(data, NULL), EXPECTED) != 0) {
  16. fprintf(stderr, "Resource contents are wrong:\n %s\n",
  17. (const char*)g_bytes_get_data(data, NULL));
  18. return 1;
  19. }
  20. fprintf(stdout, "All ok.\n");
  21. g_bytes_unref(data);
  22. g_resource_unref(res);
  23. return 0;
  24. }