test_senc2d_invalid_scenes.c (3792B)
1 /* Copyright (C) |Meso|Star> 2016-2020 (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 /* This test has been created using the sg3_geometry_dump_as_C_code feature 17 * of star-geometry. It uses output from test_sg3_cube_on_cube. */ 18 19 #define _POSIX_C_SOURCE 200112L /* snprintf */ 20 21 #include "senc2d.h" 22 #include "test_senc2d_utils.h" 23 24 #include <rsys/double2.h> 25 26 #include <stdio.h> 27 28 /* 29 2 squares with some edges overlapping 30 */ 31 32 /* Dump of star-geometry-2d 'invalid'. */ 33 static const unsigned invalid_vertices_count = 6; 34 static const double invalid_vertices[12] = 35 { 36 0, 0, 37 1, 0, 38 0, 1, 39 1, 1, 40 2, 0, 41 2, 1 42 }; 43 static const unsigned invalid_segments_count = 7; 44 static const unsigned invalid_segments[14] = 45 { 46 0, 2, 47 2, 3, 48 3, 1, 49 1, 0, 50 2, 5, 51 5, 4, 52 4, 0 53 }; 54 static const unsigned invalid_properties[21] = 55 { 56 0, 1, 0, 57 0, 1, 0, 58 0, 1, 0, 59 0, 1, 0, 60 0, 1, 0, 61 0, 1, 0, 62 0, 1, 0 63 }; 64 65 static const unsigned degenerated_segments_count = 1; 66 static const unsigned degenerated_vertices_count = 2; 67 static const unsigned degenerated[2] = { 0, 0 }; 68 static const double degenerated_vertices[9] = { 0, 0 }; 69 static const unsigned degenerated_properties[3] = { 0, 0, 0 }; 70 71 int 72 main(int argc, char** argv) 73 { 74 struct mem_allocator allocator; 75 struct senc2d_device* dev = NULL; 76 struct senc2d_scene* scn = NULL; 77 struct context ctx = CONTEXT_NULL__; 78 unsigned count, scount, s, e; 79 struct senc2d_enclosure* enc; 80 (void)argc, (void)argv; 81 82 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 83 OK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)); 84 85 /* Degenerated segment: duplicated vertex */ 86 ctx.positions = degenerated_vertices; 87 ctx.indices = degenerated; 88 ctx.properties = degenerated_properties; 89 BA(senc2d_scene_create(dev, 90 SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, 91 degenerated_segments_count, get_indices, get_media_from_properties, 92 degenerated_vertices_count, get_position, &ctx, &scn)); 93 94 /* Degenerated scene: overlapping segments */ 95 ctx.positions = invalid_vertices; 96 ctx.indices = invalid_segments; 97 ctx.properties = invalid_properties; 98 OK(senc2d_scene_create(dev, 99 SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, 100 invalid_segments_count, get_indices, get_media_from_properties, 101 invalid_vertices_count, get_position, &ctx, &scn)); 102 103 OK(senc2d_scene_get_segments_count(scn, &scount)); 104 FOR_EACH(s, 0, scount) { 105 unsigned ids[2]; 106 BO(senc2d_scene_get_segment_enclosures(scn, s, ids)); 107 } 108 BO(senc2d_scene_get_enclosure_count(scn, &count)); 109 BO(senc2d_scene_get_enclosure(scn, 0, &enc)); 110 111 OK(senc2d_scene_get_overlapping_segments_count(scn, &count)); 112 FOR_EACH(e, 0, count) { 113 OK(senc2d_scene_get_overlapping_segment(scn, e, &s)); 114 ASSERT(s < scount); 115 } 116 CHK(count == 4); 117 OK(senc2d_scene_get_overlapping_segment(scn, 0, &s)); 118 BA(senc2d_scene_get_overlapping_segment(scn, count, &s)); 119 120 OK(senc2d_scene_ref_put(scn)); 121 OK(senc2d_device_ref_put(dev)); 122 123 check_memory_allocator(&allocator); 124 mem_shutdown_proxy_allocator(&allocator); 125 CHK(mem_allocated_size() == 0); 126 return 0; 127 } 128