test_ssol_atmosphere.c (2971B)
1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) 2 * Copyright (C) 2016, 2018 CNRS 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #include "ssol.h" 18 #include "test_ssol_utils.h" 19 20 static double wl[3] = { 1, 2, 3 }; 21 static double ab[3] = { 1, 0.8, 1.1 }; 22 23 static void 24 get_wlen(const size_t i, double* wlen, double* data, void* ctx) 25 { 26 (void)ctx; 27 *wlen = wl[i]; 28 *data = ab[i]; 29 } 30 31 int 32 main(int argc, char** argv) 33 { 34 struct mem_allocator allocator; 35 struct ssol_device* dev; 36 struct ssol_data extinction, extinction2; 37 struct ssol_atmosphere* atm; 38 struct ssol_spectrum* spectrum; 39 (void) argc, (void) argv; 40 41 mem_init_proxy_allocator(&allocator, &mem_default_allocator); 42 43 CHK(ssol_device_create 44 (NULL, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev) == RES_OK); 45 46 extinction2.type = SSOL_DATA_SPECTRUM; 47 CHK(ssol_spectrum_create(dev, &spectrum) == RES_OK); 48 CHK(ssol_spectrum_setup(spectrum, get_wlen, 2, NULL) == RES_OK); 49 extinction2.type = SSOL_DATA_SPECTRUM; 50 extinction2.value.spectrum = spectrum; 51 52 CHK(ssol_atmosphere_create(NULL, &atm) == RES_BAD_ARG); 53 CHK(ssol_atmosphere_create(dev, NULL) == RES_BAD_ARG); 54 CHK(ssol_atmosphere_create(dev, &atm) == RES_OK); 55 56 CHK(ssol_atmosphere_ref_get(NULL) == RES_BAD_ARG); 57 CHK(ssol_atmosphere_ref_get(atm) == RES_OK); 58 59 CHK(ssol_atmosphere_ref_put(NULL) == RES_BAD_ARG); 60 CHK(ssol_atmosphere_ref_put(atm) == RES_OK); 61 62 extinction.type = SSOL_DATA_REAL; 63 extinction.value.real = 0.1; 64 CHK(ssol_atmosphere_set_extinction(NULL, &extinction) == RES_BAD_ARG); 65 CHK(ssol_atmosphere_set_extinction(atm, NULL) == RES_BAD_ARG); 66 CHK(ssol_atmosphere_set_extinction(atm, &extinction) == RES_OK); 67 CHK(ssol_atmosphere_set_extinction(atm, &extinction) == RES_OK); 68 CHK(ssol_atmosphere_set_extinction(atm, &extinction2) == RES_OK); 69 70 /* extinction values out of range */ 71 extinction.value.real = 2; 72 CHK(ssol_atmosphere_set_extinction(atm, &extinction) == RES_BAD_ARG); 73 CHK(ssol_spectrum_setup(spectrum, get_wlen, 3, NULL) == RES_OK); 74 CHK(ssol_atmosphere_set_extinction(atm, &extinction2) == RES_BAD_ARG); 75 76 CHK(ssol_spectrum_ref_put(extinction2.value.spectrum) == RES_OK); 77 CHK(ssol_device_ref_put(dev) == RES_OK); 78 CHK(ssol_atmosphere_ref_put(atm) == RES_OK); 79 80 check_memory_allocator(&allocator); 81 mem_shutdown_proxy_allocator(&allocator); 82 CHK(mem_allocated_size() == 0); 83 84 return 0; 85 }