solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit 68bb68d306b16badba07149ae513ea205d4f3eca
parent 93c9896cbfd71e5caeb4aa9dd086deb73d994037
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  6 Jan 2017 10:38:15 +0100

Test the -D CLI option

Diffstat:
Msrc/solstice_args.c | 4++--
Msrc/test_solstice_args.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/solstice_args.c b/src/solstice_args.c @@ -108,7 +108,7 @@ parse_sun_dir_list(const char* str, struct solstice_args* args) } strncpy(buf, str, sizeof(buf)); - tk = strtok_r(buf, ",", &ctx); + tk = strtok_r(buf, ":", &ctx); while(tk) { struct solstice_args_polar polar; double tmp[2]; @@ -123,7 +123,7 @@ parse_sun_dir_list(const char* str, struct solstice_args* args) polar.elevation = tmp[1]; sa_push(args->sun_dirs, polar); - tk = strtok_r(NULL, ",", &ctx); + tk = strtok_r(NULL, ":", &ctx); } args->nsun_dirs += sa_size(args->sun_dirs); diff --git a/src/test_solstice_args.c b/src/test_solstice_args.c @@ -138,6 +138,7 @@ test_rendering(void) cmd = cmd_create(0, "test", "-r", "pos=0,10,1:::::", NULL); CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK); CHECK(d3_eq(args.camera.pos, d3(tmp, 0, 10, 1)), 1); + solstice_args_release(&args); cmd_delete(cmd); cmd = cmd_create(0, "test", "-r", "img=32X32", NULL); @@ -157,11 +158,61 @@ test_rendering(void) cmd_delete(cmd); } +static void +test_sun_dirs(void) +{ + struct solstice_args args = SOLSTICE_ARGS_NULL; + char** cmd = NULL; + + cmd = cmd_create(0, "test", "-D", "0,1", NULL); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK); + CHECK(args.nsun_dirs, 1); + CHECK(args.sun_dirs[0].azimuth, 0); + CHECK(args.sun_dirs[0].elevation, 1); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "1.2,3.4:3.14,0.123:", RES_OK); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK); + CHECK(args.nsun_dirs, 2); + CHECK(args.sun_dirs[0].azimuth, 1.2); + CHECK(args.sun_dirs[0].elevation, 3.4); + CHECK(args.sun_dirs[1].azimuth, 3.14); + CHECK(args.sun_dirs[1].elevation, 0.123); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "1.2,3.4:3.14,0.123:2.01,23.1", RES_OK); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK); + CHECK(args.nsun_dirs, 3); + CHECK(args.sun_dirs[0].azimuth, 1.2); + CHECK(args.sun_dirs[0].elevation, 3.4); + CHECK(args.sun_dirs[1].azimuth, 3.14); + CHECK(args.sun_dirs[1].elevation, 0.123); + CHECK(args.sun_dirs[2].azimuth, 2.01); + CHECK(args.sun_dirs[2].elevation, 23.1); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "1.2,3.4,5", NULL); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "1.2,3.4:1", NULL); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "1.2,3.4:5.2,A", NULL); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_BAD_ARG); + cmd_delete(cmd); +} + int main(int argc, char** argv) { (void)argc, (void)argv; test_rendering(); + test_sun_dirs(); CHECK(mem_allocated_size(), 0); return 0;