133 lines
3.7 KiB
C
133 lines
3.7 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "../bridge/photokit_bridge.h"
|
|
|
|
static export_progress_t stub_progress_slots[16];
|
|
static int stub_progress_slot_count = 16;
|
|
static int stub_progress_slots_null = 0;
|
|
|
|
static char *alloc_json(const char *s) {
|
|
size_t len = strlen(s);
|
|
char *copy = (char *)malloc(len + 1);
|
|
memcpy(copy, s, len);
|
|
copy[len] = '\0';
|
|
return copy;
|
|
}
|
|
|
|
static int stub_access_rc = 0;
|
|
static const char *stub_albums_json = "{\"albums\":[]}";
|
|
static const char *stub_assets_json = "{\"assets\":[]}";
|
|
static const char *stub_tree_json = "{\"collections\":[]}";
|
|
static int stub_albums_null = 0;
|
|
static int stub_assets_null = 0;
|
|
static int stub_tree_null = 0;
|
|
static int stub_cancelled = 0;
|
|
static const char *stub_export_preview_json = NULL;
|
|
static const char *stub_export_original_json = NULL;
|
|
|
|
static char *maybe_alloc_json(const char *s) {
|
|
if (!s) return NULL;
|
|
return alloc_json(s);
|
|
}
|
|
|
|
void photos_test_set_access(int rc) { stub_access_rc = rc; }
|
|
void photos_test_set_albums(const char *json) { stub_albums_json = json; stub_albums_null = 0; }
|
|
void photos_test_set_assets(const char *json) { stub_assets_json = json; stub_assets_null = 0; }
|
|
void photos_test_set_tree(const char *json) { stub_tree_json = json; stub_tree_null = 0; }
|
|
void photos_test_set_albums_null(void) { stub_albums_null = 1; }
|
|
void photos_test_set_assets_null(void) { stub_assets_null = 1; }
|
|
void photos_test_set_tree_null(void) { stub_tree_null = 1; }
|
|
|
|
int photos_request_access(void) { return stub_access_rc; }
|
|
|
|
char *photos_list_albums_json(void) {
|
|
if (stub_albums_null) return NULL;
|
|
return alloc_json(stub_albums_json);
|
|
}
|
|
|
|
char *photos_list_assets_json(const char *album_id) {
|
|
(void)album_id;
|
|
if (stub_assets_null) return NULL;
|
|
return alloc_json(stub_assets_json);
|
|
}
|
|
|
|
char *photos_export_preview_json(const char *asset_id, const char *output_dir, int target_size, int quality, int index, int slot_index) {
|
|
(void)asset_id;
|
|
(void)output_dir;
|
|
(void)target_size;
|
|
(void)quality;
|
|
(void)index;
|
|
(void)slot_index;
|
|
return maybe_alloc_json(stub_export_preview_json);
|
|
}
|
|
|
|
char *photos_export_original_json(const char *asset_id, const char *output_dir, int index, int slot_index) {
|
|
(void)asset_id;
|
|
(void)output_dir;
|
|
(void)index;
|
|
(void)slot_index;
|
|
return maybe_alloc_json(stub_export_original_json);
|
|
}
|
|
|
|
char *photos_list_tree_json(void) {
|
|
if (stub_tree_null) return NULL;
|
|
return alloc_json(stub_tree_json);
|
|
}
|
|
|
|
void photos_free_string(char *value) {
|
|
if (value) free(value);
|
|
}
|
|
|
|
void photos_request_cancel(void) {
|
|
stub_cancelled = 1;
|
|
}
|
|
|
|
int photos_request_is_cancelled(void) {
|
|
return stub_cancelled;
|
|
}
|
|
|
|
void photos_test_set_export_preview_json(const char *json) {
|
|
stub_export_preview_json = json;
|
|
}
|
|
|
|
void photos_test_set_export_preview_json_null(void) {
|
|
stub_export_preview_json = NULL;
|
|
}
|
|
|
|
void photos_test_set_export_original_json(const char *json) {
|
|
stub_export_original_json = json;
|
|
}
|
|
|
|
void photos_test_set_export_original_json_null(void) {
|
|
stub_export_original_json = NULL;
|
|
}
|
|
|
|
export_progress_t *photos_get_progress_slots(void) {
|
|
if (stub_progress_slots_null) return NULL;
|
|
return stub_progress_slots;
|
|
}
|
|
|
|
export_progress_t photos_get_progress_slot(export_progress_t *slots, int index) {
|
|
export_progress_t result = {0, 0.0, 0, 0};
|
|
if (index >= 0 && index < 16) {
|
|
result = slots[index];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int photos_get_progress_slot_count(void) {
|
|
return stub_progress_slot_count;
|
|
}
|
|
|
|
void photos_reset_progress_slots(void) {
|
|
memset(stub_progress_slots, 0, sizeof(stub_progress_slots));
|
|
}
|
|
|
|
void photos_test_set_progress_slot_count(int count) {
|
|
stub_progress_slot_count = count;
|
|
}
|
|
|
|
void photos_test_set_progress_slots_null(int val) {
|
|
stub_progress_slots_null = val;
|
|
}
|