BRL-CAD
test_nmg_copy.c
Go to the documentation of this file.
1 /* T E S T _ N M G _ C O P Y . 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
28 nmg_compare_vertexuse(struct vertexuse *vu1, struct vertexuse *vu2)
29 {
30  int result;
31 
32  result = 0;
33 
34  /* Testing index of vertexuse */
35  if (vu1->index != vu2->index) {
36  bu_log("Error index of vertexuse. vu1: %ld, vu2: %ld\n", vu1->index, vu2->index);
37  result = -1;
38  }
39 
40  return result;
41 }
42 
43 int
44 nmg_compare_edgeuse(struct edgeuse *eu1, struct edgeuse *eu2)
45 {
46  int result;
47 
48  result = 0;
49 
50  /* Testing orientation of edgeuse */
51  if (eu1->orientation != eu2->orientation) {
52  bu_log("Error orientation of edgeuse. eu1: %d, eu2: %d\n", eu1->orientation, eu2->orientation);
53  result = -1;
54  }
55 
56  /* Testing index of edgeuse */
57  if (eu1->index != eu2->index) {
58  bu_log("Error index of edgeuse. eu1: %ld, eu2: %ld\n", eu1->index, eu2->index);
59  result = -1;
60  }
61 
62  return result;
63 }
64 
65 int
66 nmg_compare_loopuse(struct loopuse *lu1, struct loopuse *lu2)
67 {
68  int result;
69 
70  result = 0;
71 
72  /* Testing orientation of loopuse */
73  if (lu1->orientation != lu2->orientation) {
74  bu_log("Error orientation of loopuse. lu1: %d, lu2: %d\n", lu1->orientation, lu2->orientation);
75  result = -1;
76  }
77 
78  /* Testing index of loopuse */
79  if (lu1->index != lu2->index) {
80  bu_log("Error index of loopuse. lu1: %ld, lu2: %ld\n", lu1->index, lu2->index);
81  result = -1;
82  }
83 
84  return result;
85 }
86 
87 int
88 nmg_compare_faceuse(struct faceuse *fu1, struct faceuse *fu2)
89 {
90  int result;
91 
92  int lulen1;
93  int lulen2;
94  struct loopuse *lu1;
95  struct loopuse *lu2;
96 
97  result = 0;
98 
99  /* Testing orientation of faceuse */
100  if (fu1->orientation != fu2->orientation) {
101  bu_log("Error orientation of faceuse. fu1: %d, fu2: %d\n", fu1->orientation, fu2->orientation);
102  result = -1;
103  }
104 
105  /* Testing outside of faceuse */
106  if (fu1->outside != fu2->outside) {
107  bu_log("Error outside of faceuse. fu1: %d, fu2: %d\n", fu1->outside, fu2->outside);
108  result = -1;
109  }
110 
111  /* Testing lu_hd of faceuse */
112  lulen1 = bu_list_len(&fu1->lu_hd);
113  lulen2 = bu_list_len(&fu2->lu_hd);
114 
115  if (lulen1 != lulen2) {
116  bu_log("Error lu_hd's size of faceuse. fu1: %d, fu2: %d\n", lulen1, lulen2);
117  result = -1;
118  return result;
119  }
120 
121  for (BU_LIST_FOR2(lu1, lu2, loopuse, &fu1->lu_hd, &fu2->lu_hd)) {
122  if (nmg_compare_loopuse(lu1, lu2) < 0) {
123  result = -1;
124  }
125  }
126 
127  /* Testing index of faceuse */
128  if (fu1->index != fu2->index) {
129  bu_log("Error index of faceuse. fu1: %ld, fu2: %ld\n", fu1->index, fu2->index);
130  result = -1;
131  }
132 
133  return result;
134 }
135 
136 int
137 nmg_compare_shell_a(struct shell_a *sa1, struct shell_a *sa2)
138 {
139  int result;
140 
141  result = 0;
142 
143  /* Testing min_pt of shell_a */
144  if (!NEAR_EQUAL(sa1->min_pt, sa2->min_pt, SMALL_FASTF)) {
145  bu_log("Error min_pt of shell_a.");
146  result = -1;
147  }
148 
149  /* Testing max_pt of shell_a */
150  if (!NEAR_EQUAL(sa1->max_pt, sa2->max_pt, SMALL_FASTF)) {
151  bu_log("Error max_pt of shell_a.");
152  result = -1;
153  }
154 
155  /* Testing index of shell_a */
156  if (sa1->index != sa2->index) {
157  bu_log("Error index of shell_a. sa1: %ld, sa2: %ld\n", sa1->index, sa2->index);
158  result = -1;
159  }
160 
161  return result;
162 }
163 
164 int
165 nmg_compare_shell(struct shell *s1, struct shell *s2)
166 {
167  int result;
168 
169  int fulen1;
170  int fulen2;
171  struct faceuse *fu1;
172  struct faceuse *fu2;
173 
174  int lulen1;
175  int lulen2;
176  struct loopuse *lu1;
177  struct loopuse *lu2;
178 
179  int eulen1;
180  int eulen2;
181  struct edgeuse *eu1;
182  struct edgeuse *eu2;
183 
184  result = 0;
185 
186  /* Testing shell_a of shell */
187  if (s1->sa_p != (struct shell_a *)NULL && s2->sa_p != (struct shell_a *)NULL) {
188  if (nmg_compare_shell_a(s1->sa_p, s2->sa_p) < 0) {
189  result = -1;
190  }
191  } else {
192  if (s1->sa_p != s2->sa_p) {
193  bu_log("Error shell_a of shell. One is NULL, but other is not NULL\n");
194  result = -1;
195  }
196  }
197 
198  /* Testing fu_hd of shell */
199  fulen1 = bu_list_len(&s1->fu_hd);
200  fulen2 = bu_list_len(&s2->fu_hd);
201 
202  if (fulen1 != fulen2) {
203  bu_log("Error fu_hd's size of shell. s1: %d, s2: %d\n", fulen1, fulen2);
204  result = -1;
205  return result;
206  }
207 
208  for (BU_LIST_FOR2(fu1, fu2, faceuse, &s1->fu_hd, &s2->fu_hd)) {
209  if (nmg_compare_faceuse(fu1, fu2) < 0) {
210  result = -1;
211  }
212  }
213 
214  /* Testing lu_hd of shell */
215  lulen1 = bu_list_len(&s1->lu_hd);
216  lulen2 = bu_list_len(&s2->lu_hd);
217 
218  if (lulen1 != lulen2) {
219  bu_log("Error lu_hd's size of shell. s1: %d, s2: %d\n", lulen1, lulen2);
220  result = -1;
221  return result;
222  }
223 
224  for (BU_LIST_FOR2(lu1, lu2, loopuse, &s1->lu_hd, &s2->lu_hd)) {
225  if (nmg_compare_loopuse(lu1, lu2) < 0) {
226  result = -1;
227  }
228  }
229 
230  /* Testing eu_hd of shell */
231  eulen1 = bu_list_len(&s1->eu_hd);
232  eulen2 = bu_list_len(&s2->eu_hd);
233 
234  if (eulen1 != eulen2) {
235  bu_log("Error eu_hd's size of shell. s1: %d, s2: %d\n", eulen1, eulen2);
236  result = -1;
237  return result;
238  }
239 
240  for (BU_LIST_FOR2(eu1, eu2, edgeuse, &s1->eu_hd, &s2->eu_hd)) {
241  if (nmg_compare_edgeuse(eu1, eu2) < 0) {
242  result = -1;
243  }
244  }
245 
246  /* Testing vu_p of shell */
247  if (s1->vu_p != (struct vertexuse *)NULL && s2->vu_p != (struct vertexuse *)NULL) {
248  if (nmg_compare_vertexuse(s1->vu_p, s2->vu_p) < 0) {
249  result = -1;
250  }
251  } else {
252  if (s1->vu_p != s2->vu_p) {
253  bu_log("Error vu_p of shell. One is NULL, but other is not NULL\n");
254  result = -1;
255  }
256  }
257 
258  /* Testing index of shell */
259  if (s1->index != s2->index) {
260  bu_log("Error index of shell. s1: %ld, s2: %ld\n", s1->index, s2->index);
261  result = -1;
262  }
263 
264  return result;
265 }
266 
267 int
268 nmg_compare_region_a(struct nmgregion_a *ra1, struct nmgregion_a *ra2)
269 {
270  int result;
271 
272  result = 0;
273 
274  /* Testing min_pt of nmgregion_a */
275  if (!NEAR_EQUAL(ra1->min_pt, ra2->min_pt, SMALL_FASTF)) {
276  bu_log("Error min_pt of nmgregion_a.");
277  result = -1;
278  }
279 
280  /* Testing max_pt of nmgregion_a */
281  if (!NEAR_EQUAL(ra1->max_pt, ra2->max_pt, SMALL_FASTF)) {
282  bu_log("Error max_pt of nmgregion_a.");
283  result = -1;
284  }
285 
286  /* Testing index of nmgregion_a */
287  if (ra1->index != ra2->index) {
288  bu_log("Error index of nmgregion_a. ra1: %ld, ra2: %ld\n", ra1->index, ra2->index);
289  result = -1;
290  }
291 
292  return result;
293 }
294 
295 int
296 nmg_compare_region(struct nmgregion *r1, struct nmgregion *r2)
297 {
298  int result;
299 
300  int slen1;
301  int slen2;
302  struct shell *s1;
303  struct shell *s2;
304 
305  result = 0;
306 
307  /* Testing ra_p of nmgregion */
308  if (r1->ra_p != (struct nmgregion_a *)NULL && r2->ra_p != (struct nmgregion_a *)NULL) {
309  if (nmg_compare_region_a(r1->ra_p, r2->ra_p) < 0) {
310  result = -1;
311  }
312  } else {
313  if (r1->ra_p != r2->ra_p) {
314  bu_log("Error nmgregion_a of region. One is NULL, but other is not NULL\n");
315  result = -1;
316  }
317  }
318 
319  /* Testing s_hd of nmgregion */
320  slen1 = bu_list_len(&r1->s_hd);
321  slen2 = bu_list_len(&r2->s_hd);
322 
323  if (slen1 != slen2) {
324  bu_log("Error s_hd's size of region. r1: %d, r2: %d\n", slen1, slen2);
325  result = -1;
326  return result;
327  }
328 
329  for (BU_LIST_FOR2(s1, s2, shell, &r1->s_hd, &r2->s_hd)) {
330  if (nmg_compare_shell(s1, s2) < 0) {
331  result = -1;
332  }
333  }
334 
335  /* Testing index of nmgregion */
336  if (r1->index != r2->index) {
337  bu_log("Error index of region. r1: %ld, r2: %ld\n", r1->index, r2->index);
338  result = -1;
339  }
340 
341  return result;
342 }
343 
344 int
345 test_nmg_clone_model(struct model *m1, struct model *m2)
346 {
347  int result;
348 
349  int rlen1;
350  int rlen2;
351  struct nmgregion *r1;
352  struct nmgregion *r2;
353 
354  result = 0;
355 
356  /* Testing r_hd of model */
357  rlen1 = bu_list_len(&m1->r_hd);
358  rlen2 = bu_list_len(&m2->r_hd);
359 
360  if (rlen1 != rlen2) {
361  bu_log("Error r_hd's size of model. m1: %d, m2: %d\n", rlen1, rlen2);
362  result = -1;
363  return result;
364  }
365 
366  for (BU_LIST_FOR2(r1, r2, nmgregion, &m1->r_hd, &m2->r_hd)) {
367  if (nmg_compare_region(r1, r2) < 0) {
368  result = -1;
369  }
370  }
371 
372  /* Testing manifolds of model */
373  if (m1->manifolds != (char *)NULL && m2->manifolds != (char *)NULL) {
374  if (*m1->manifolds != *m2->manifolds) {
375  bu_log("Error manifolds of model. m1: %ld, m2: %ld\n", *m1->manifolds, *m2->manifolds);
376  result = -1;
377  }
378  } else {
379  if (m1->manifolds != m2->manifolds) {
380  bu_log("Error manifolds of model. One is NULL, but other is not NULL\n");
381  result = -1;
382  }
383  }
384 
385  /* Testing index of model */
386  if (m1->index != m2->index) {
387  bu_log("Error index of model. m1: %ld, m2: %ld\n", m1->index, m2->index);
388  result = -1;
389  }
390 
391  /* Testing maxindex of model */
392  if (m1->maxindex != m2->maxindex) {
393  bu_log("Error maxindex of model. m1: %ld, m2: %ld\n", m1->maxindex, m2->maxindex);
394  result = -1;
395  }
396 
397  return result;
398 }
399 
400 int
402 {
403  int result;
404  struct model *m1;
405  struct model *m2;
406 
407  m1 = nmg_mm();
408  m2 = nmg_clone_model(m1);
409 
410  result = test_nmg_clone_model(m1, m2);
411 
412  nmg_km(m1);
413  nmg_km(m2);
414 
415  return result;
416 }
417 
418 int
420 {
421  int result;
422  struct model *m1;
423  struct model *m2;
424 
425  m1 = nmg_mmr();
426  m2 = nmg_clone_model(m1);
427 
428  result = test_nmg_clone_model(m1, m2);
429 
430  nmg_km(m1);
431  nmg_km(m2);
432 
433  return result;
434 }
435 
436 int
438 {
439  int result;
440  struct model *m1;
441  struct model *m2;
442 
443  m1 = nmg_mmr();
444  nmg_mrsv(m1);
445  m2 = nmg_clone_model(m1);
446 
447  result = test_nmg_clone_model(m1, m2);
448 
449  nmg_km(m1);
450  nmg_km(m2);
451 
452  return result;
453 }
454 
455 int
456 main(int argc, char **argv)
457 {
458  if (argc > 1) {
459  bu_exit(1, "Usage: %s\n", argv[0]);
460  }
461 
462  if (testcase_nmg_mm() < 0) {
463  bu_exit(1, "Test Case by nmg_mm failed!\n");
464  }
465 
466  if (testcase_nmg_mmr() < 0) {
467  bu_exit(1, "Test Case by nmg_mmr failed!\n");
468  }
469 
470  if (testcase_nmg_mrsv() < 0) {
471  bu_exit(1, "Test Case by nmg_mrsv failed!\n");
472  }
473 
474  bu_log("All unit tests succeeded.\n");
475  return 0;
476 }
477 
478 /*
479  * Local Variables:
480  * tab-width: 8
481  * mode: C
482  * indent-tabs-mode: t
483  * c-file-style: "stroustrup"
484  * End:
485  * ex: shiftwidth=4 tabstop=8
486  */
int nmg_compare_shell(struct shell *s1, struct shell *s2)
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int testcase_nmg_mmr()
#define BU_LIST_FOR2(p1, p2, structure, hp1, hp2)
Definition: list.h:392
int testcase_nmg_mm()
#define SMALL_FASTF
Definition: defines.h:342
struct model * nmg_mmr(void)
Definition: nmg_mk.c:268
Header file for the BRL-CAD common definitions.
int nmg_compare_region(struct nmgregion *r1, struct nmgregion *r2)
int nmg_compare_loopuse(struct loopuse *lu1, struct loopuse *lu2)
Definition: test_nmg_copy.c:66
BU_LIST_DEQUEUE & eu1
Definition: nmg_mod.c:3839
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195
int main(int argc, char **argv)
void nmg_km(struct model *m)
Definition: nmg_mk.c:1634
int test_nmg_clone_model(struct model *m1, struct model *m2)
struct nmgregion * nmg_mrsv(struct model *m)
Definition: nmg_mk.c:306
int testcase_nmg_mrsv()
struct model * nmg_mm(void)
Definition: nmg_mk.c:235
int nmg_compare_edgeuse(struct edgeuse *eu1, struct edgeuse *eu2)
Definition: test_nmg_copy.c:44
int nmg_compare_region_a(struct nmgregion_a *ra1, struct nmgregion_a *ra2)
int bu_list_len(const struct bu_list *hd)
int nmg_compare_shell_a(struct shell_a *sa1, struct shell_a *sa2)
int nmg_compare_vertexuse(struct vertexuse *vu1, struct vertexuse *vu2)
Definition: test_nmg_copy.c:28
struct model * nmg_clone_model(const struct model *original)
Definition: nmg_copy.c:714
eu2
Definition: nmg_mod.c:3875
int nmg_compare_faceuse(struct faceuse *fu1, struct faceuse *fu2)
Definition: test_nmg_copy.c:88