test_data_id.c (1121B)
1 2 #include "resource.h" 3 #include "lens.h" 4 #include <stdio.h> 5 6 struct test_struct { 7 struct { 8 char ca, cb; 9 int bleh; 10 } s; 11 float a; 12 float mat4[MAT4_ELEMS]; 13 float b; 14 }; 15 16 static void test_data_ids() 17 { 18 printf("test_data_ids\n"); 19 struct resource_manager r; 20 struct resource_id id; 21 struct test_struct *ts; 22 struct data_id a_id, b_id; 23 float a, b; 24 int ret; 25 // 2 item case 26 init_resource_manager(&r, sizeof(struct test_struct), 1, 2, "test_struct"); 27 init_id(&id); 28 29 ts = new_resource(&r, &id); 30 assert(ts); 31 32 new_resource_data_id(&a_id, &r, id, DATA_ID_FLOAT, struct test_struct, a); 33 new_ptr_data_id(&b_id, &a, DATA_ID_FLOAT); 34 35 ts->a = 1337.0; 36 ts->b = 123.0; 37 38 assert(get_data_id_float(&a_id, &a)); 39 40 assert(a == 1337.0); 41 a = 123.0; 42 43 assert(get_data_id_float(&b_id, &b)); 44 assert(b == 123.0); 45 46 destroy_resource(&r, &id); 47 ret = get_data_id_float(&a_id, &a); 48 assert(ret == 0); 49 assert(is_resource_destroyed(&r, &a_id.res_id.id)); 50 51 b = 0.0; 52 assert(get_data_id_float(&b_id, &b)); 53 assert(b == 123.0); 54 55 destroy_resource_manager(&r); 56 } 57 58 int main(int argc, char *argv[]) 59 { 60 test_data_ids(); 61 62 return 0; 63 }