BRL-CAD
test_nmg_mk.c
Go to the documentation of this file.
1 /* T E S T _ N M G _ M K . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 
23 #include <string.h>
24 
25 #include "raytrace.h"
26 
27 int
29 {
30  int result;
31  struct model *m;
32 
33  result = 0;
34  m = nmg_mm();
35 
36  /* test m */
37  if (m->index != 0) {
38  bu_log("Error index of model in nmg_mm %ld\n", m->index);
39  result = -1;
40  }
41 
42  if (m->maxindex != 1) {
43  bu_log("Error maxindex of model in nmg_mm %ld\n", m->maxindex);
44  result = -1;
45  }
46 
47  if (m->magic != NMG_MODEL_MAGIC) {
48  bu_log("Error magic of model in nmg_mm, it should be NMG_MODEL_MAGIC\n");
49  result = -1;
50  }
51 
52  if (m->manifolds != NULL) {
53  bu_log("Error manifolds of model in nmg_mm, it should be NULL\n");
54  result = -1;
55  }
56 
57  nmg_km(m);
58  return result;
59 }
60 
61 int
63 {
64  int result;
65  struct model *m;
66  struct nmgregion *r;
67 
68  result = 0;
69  m = nmg_mmr();
70  r = BU_LIST_FIRST(nmgregion, &m->r_hd);
71 
72  /* test m */
73  if (m->maxindex != 2) {
74  bu_log("Error maxindex of model in nmg_mmr %ld\n", m->maxindex);
75  result = -1;
76  }
77 
78  /* test r */
79  if (r == NULL) {
80  bu_log("Error r_hd of model in nmg_mmr");
81  nmg_km(m);
82  result = -1;
83  return result;
84  }
85 
86  if (r->index != 1) {
87  bu_log("Error index of region in nmg_mmr %ld\n", r->index);
88  result = -1;
89  }
90 
91  if (r->l.magic != NMG_REGION_MAGIC) {
92  bu_log("Error magic of region in nmg_mmr, it should be NMG_REGION_MAGIC\n");
93  result = -1;
94  }
95 
96  nmg_km(m);
97  return result;
98 }
99 
100 int
102 {
103  int result;
104  struct model *m;
105  struct nmgregion *r;
106 
107  result = 0;
108  m = nmg_mmr();
109  r = nmg_mrsv(m);
110 
111  /* test m */
112  if (m->maxindex != 6) {
113  bu_log("Error maxindex of model in nmg_mrsv %ld\n", m->maxindex);
114  result = -1;
115  }
116 
117  /* test r */
118  if (r == NULL) {
119  bu_log("Error r_hd of model in nmg_mrsv");
120  nmg_km(m);
121  result = -1;
122  return result;
123  }
124 
125  if (r->index != 2) {
126  bu_log("Error index of region in nmg_mrsv %ld\n", r->index);
127  result = -1;
128  }
129 
130  if (r->l.magic != NMG_REGION_MAGIC) {
131  bu_log("Error magic of region in nmg_mrsv, it should be NMG_REGION_MAGIC\n");
132  result = -1;
133  }
134 
135  nmg_km(m);
136  return result;
137 }
138 
139 int
141 {
142  int result;
143  struct model *m;
144  struct nmgregion *r;
145  struct shell *s;
146 
147  result = 0;
148  m = nmg_mmr();
149  r = BU_LIST_FIRST(nmgregion, &m->r_hd);
150  s = nmg_msv(r);
151 
152  /* test m */
153  if (m->maxindex != 5) {
154  bu_log("Error maxindex of model in nmg_msv %ld\n", m->maxindex);
155  result = -1;
156  }
157 
158  /* test s */
159  if (s == NULL) {
160  bu_log("Error r_hd of model in nmg_msv");
161  nmg_km(m);
162  result = -1;
163  return result;
164  }
165 
166  if (s->index != 2) {
167  bu_log("Error index of shell in nmg_msv %ld\n", s->index);
168  result = -1;
169  }
170 
171  if (s->l.magic != NMG_SHELL_MAGIC) {
172  bu_log("Error magic of shell in nmg_msv, it should be NMG_SHELL_MAGIC\n");
173  result = -1;
174  }
175 
176  nmg_km(m);
177  return result;
178 }
179 
180 int
181 main(int argc, char **argv)
182 {
183  if (argc > 1) {
184  bu_exit(1, "Usage: %s\n", argv[0]);
185  }
186 
187  if (test_nmg_mm() < 0) {
188  bu_exit(1, "Test for nmg_mm failed!\n");
189  }
190 
191  if (test_nmg_mmr() < 0) {
192  bu_exit(1, "Test for nmg_mmr failed!\n");
193  }
194 
195  if (test_nmg_mrsv() < 0) {
196  bu_exit(1, "Test for nmg_mrsv failed!\n");
197  }
198 
199  if (test_nmg_msv() < 0) {
200  bu_exit(1, "Test for nmg_msv failed!\n");
201  }
202 
203  bu_log("All unit tests succeeded.\n");
204  return 0;
205 }
206 
207 /*
208  * Local Variables:
209  * tab-width: 8
210  * mode: C
211  * indent-tabs-mode: t
212  * c-file-style: "stroustrup"
213  * End:
214  * ex: shiftwidth=4 tabstop=8
215  */
#define NMG_MODEL_MAGIC
Definition: magic.h:133
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int test_nmg_mrsv(void)
Definition: test_nmg_mk.c:101
#define NMG_SHELL_MAGIC
Definition: magic.h:142
if lu s
Definition: nmg_mod.c:3860
int test_nmg_mmr(void)
Definition: test_nmg_mk.c:62
struct model * nmg_mmr(void)
Definition: nmg_mk.c:268
Header file for the BRL-CAD common definitions.
int test_nmg_mm(void)
Definition: test_nmg_mk.c:28
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195
void nmg_km(struct model *m)
Definition: nmg_mk.c:1634
int test_nmg_msv(void)
Definition: test_nmg_mk.c:140
#define NMG_REGION_MAGIC
Definition: magic.h:137
struct shell * nmg_msv(struct nmgregion *r)
Definition: nmg_mk.c:423
struct nmgregion * nmg_mrsv(struct model *m)
Definition: nmg_mk.c:306
struct model * nmg_mm(void)
Definition: nmg_mk.c:235
int main(int argc, char **argv)
Definition: test_nmg_mk.c:181
#define BU_LIST_FIRST(structure, hp)
Definition: list.h:312