test_sdis_radiative_env.c (3463B)
1 /* Copyright (C) 2016-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "sdis.h" 17 #include "test_sdis_utils.h" 18 19 #include <rsys/rsys.h> 20 21 /******************************************************************************* 22 * Helper function 23 ******************************************************************************/ 24 static double 25 radenv_get_temperature 26 (const struct sdis_radiative_ray* ray, 27 struct sdis_data* data) 28 { 29 (void)ray, (void)data; 30 return 300; 31 } 32 33 static double 34 radenv_get_reference_temperature 35 (const struct sdis_radiative_ray* ray, 36 struct sdis_data* data) 37 { 38 (void)ray, (void)data; 39 return 300; 40 } 41 42 static void 43 check_api(struct sdis_device* sdis) 44 { 45 struct sdis_radiative_env_shader shader = SDIS_RADIATIVE_ENV_SHADER_NULL; 46 struct sdis_radiative_env_shader shader2 = SDIS_RADIATIVE_ENV_SHADER_NULL; 47 struct sdis_radiative_env* radenv = NULL; 48 struct sdis_data* data = NULL; 49 50 CHK(sdis != NULL); 51 BA(sdis_radiative_env_create(NULL, &shader, NULL, &radenv)); 52 BA(sdis_radiative_env_create(sdis, NULL, NULL, &radenv)); 53 OK(sdis_radiative_env_create(sdis, &shader, NULL, &radenv)); 54 55 BA(sdis_radiative_env_get_shader(NULL, &shader2)); 56 BA(sdis_radiative_env_get_shader(radenv, NULL)); 57 OK(sdis_radiative_env_get_shader(radenv, &shader2)); 58 59 CHK(shader2.temperature == shader.temperature); 60 CHK(shader2.reference_temperature == shader.reference_temperature); 61 62 CHK(sdis_radiative_env_get_data(radenv) == NULL); 63 64 BA(sdis_radiative_env_ref_get(NULL)); 65 OK(sdis_radiative_env_ref_get(radenv)); 66 BA(sdis_radiative_env_ref_put(NULL)); 67 OK(sdis_radiative_env_ref_put(radenv)); 68 OK(sdis_radiative_env_ref_put(radenv)); 69 70 shader.temperature = radenv_get_temperature; 71 shader.reference_temperature = radenv_get_reference_temperature; 72 73 OK(sdis_data_create(sdis, sizeof(uint32_t), ALIGNOF(uint32_t), NULL, &data)); 74 *((uint32_t*)sdis_data_get(data)) = 0xD3CAFBAD; 75 76 OK(sdis_radiative_env_create(sdis, &shader, data, &radenv)); 77 OK(sdis_data_ref_put(data)); 78 79 OK(sdis_radiative_env_get_shader(radenv, &shader2)); 80 81 CHK(shader2.temperature == shader.temperature); 82 CHK(shader2.reference_temperature == shader.reference_temperature); 83 84 CHK(sdis_radiative_env_get_data(radenv) == data); 85 data = sdis_radiative_env_get_data(radenv); 86 CHK(*((uint32_t*)sdis_data_get(data)) == 0xD3CAFBAD); 87 88 OK(sdis_radiative_env_ref_put(radenv)); 89 } 90 91 /******************************************************************************* 92 * The test 93 ******************************************************************************/ 94 int 95 main(int argc, char** argv) 96 { 97 struct sdis_device* sdis = NULL; 98 (void)argc, (void)argv; 99 100 OK(sdis_device_create(&SDIS_DEVICE_CREATE_ARGS_DEFAULT, &sdis)); 101 102 check_api(sdis); 103 104 OK(sdis_device_ref_put(sdis)); 105 CHK(mem_allocated_size() == 0); 106 return 0; 107 }