Skip to content

Commit

Permalink
dynapi_test: improve finding the tests
Browse files Browse the repository at this point in the history
from an extra builddir
  • Loading branch information
rurban committed Dec 3, 2024
1 parent f7e1011 commit 527956d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
4 changes: 2 additions & 2 deletions doc/dynapi.texi
Original file line number Diff line number Diff line change
Expand Up @@ -14559,9 +14559,9 @@ BL, DXF 97
@item fitpts
2RD*
@item start_tangent
2RD
2RD, DXF 12
@item end_tangent
2RD
2RD, DXF 13

@end vtable
@end indentedblock
Expand Down
4 changes: 2 additions & 2 deletions src/dynapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -11819,9 +11819,9 @@ static const Dwg_DYNAPI_field _dwg_HATCH_PathSeg_fields[] = {
{ "fitpts", "2RD*", sizeof (BITCODE_2RD*), OFF (struct _dwg_HATCH_PathSeg, fitpts),
1,1,0, 0 },
{ "start_tangent", "2RD", sizeof (BITCODE_2RD), OFF (struct _dwg_HATCH_PathSeg, start_tangent),
1,0,0, 0 },
1,0,0, 12 },
{ "end_tangent", "2RD", sizeof (BITCODE_2RD), OFF (struct _dwg_HATCH_PathSeg, end_tangent),
1,0,0, 0 },
1,0,0, 13 },
{NULL, NULL, 0, 0, 0,0,0, 0},
};
/* from typedef struct _dwg_HATCH_PolylinePath: (sorted by offset) */
Expand Down
6 changes: 3 additions & 3 deletions test/unit-testing/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ main (int argc, char *argv[])
if (stat (*ptr, &attrib))
{
char tmp[80];
strcpy (tmp, prefix);
strcat (tmp, "/");
strcat (tmp, *ptr);
strncpy (tmp, prefix, sizeof (tmp));
strncat (tmp, "/", sizeof (prefix) - 1);
strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1);
if (stat (tmp, &attrib))
fprintf (stderr, "Env var INPUT not defined, %s not found\n",
tmp);
Expand Down
39 changes: 26 additions & 13 deletions test/unit-testing/dynapi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "config.h"
#ifdef __APPLE__
# define _DARWIN_C_SOURCE /* for DT_DIR */
#endif
#include <dirent.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
Expand All @@ -45,7 +48,7 @@ test_header (Dwg_Data *dwg)
BITCODE_BD bd;
BITCODE_TV tv;

#line 46 "dynapi_test.c"
#line 51 "dynapi_test.c"
/* @@for test_HEADER@@ */
{
BITCODE_RL size;
Expand Down Expand Up @@ -6095,10 +6098,10 @@ test_header (Dwg_Data *dwg)
dwg_dynapi_header_set_value (dwg, "aspect_ratio", &aspect_ratio, 0);

}
#line 47 "dynapi_test.c.in"
#line 52 "dynapi_test.c.in"
return error;
}
#line 5379 "dynapi_test.c"
#line 6104 "dynapi_test.c"
/* @@for test_OBJECT@@ */
static int test__3DFACE (const Dwg_Object *obj)
{
Expand Down Expand Up @@ -63780,12 +63783,12 @@ static int test_ASSOCARRAYRECTANGULARPARAMETERS (const Dwg_Object *obj)
return failed;
}

#line 53 "dynapi_test.c.in"
#line 58 "dynapi_test.c.in"
static int
test_object (const Dwg_Data *restrict dwg, const Dwg_Object *restrict obj)
{
int error = 0;
#line 62158 "dynapi_test.c"
#line 63791 "dynapi_test.c"
/* @@for if_test_OBJECT@@ */
if (obj->fixedtype == DWG_TYPE__3DFACE)
error += test__3DFACE(obj);
Expand Down Expand Up @@ -65047,7 +65050,7 @@ test_object (const Dwg_Data *restrict dwg, const Dwg_Object *restrict obj)
error += test_ASSOCARRAYPOLARPARAMETERS (obj);
else if (obj->fixedtype == DWG_TYPE_ASSOCARRAYRECTANGULARPARAMETERS)
error += test_ASSOCARRAYRECTANGULARPARAMETERS (obj);
#line 60 "dynapi_test.c.in"
#line 65 "dynapi_test.c.in"
return error + failed;
}

Expand All @@ -65057,7 +65060,7 @@ test_sizes (void)
{
int error = 0;
int size1, size2;
#line 63386 "dynapi_test.c"
#line 65063 "dynapi_test.c"
/* @@for test_SIZES@@ */
size1 = sizeof (Dwg_Entity__3DFACE);
size2 = dwg_dynapi_fields_size ("3DFACE");
Expand Down Expand Up @@ -68611,7 +68614,7 @@ test_sizes (void)
"dwg_dynapi_fields_size (\"MLEADER_Content\"): %d\n", size1, size2);
error++;
}
#line 72 "dynapi_test.c.in"
#line 77 "dynapi_test.c.in"
return error;
}

Expand Down Expand Up @@ -68684,10 +68687,20 @@ main (int argc, char *argv[])
if (stat (*ptr, &attrib))
{
char tmp[80];
strncpy (tmp, "../test-data/", sizeof (tmp));
strncat (tmp, *ptr, sizeof (tmp) - sizeof ("../test-data/") - 1);
if (stat (tmp, &attrib))
LOG_ERROR ("Env var INPUT not defined, %s not found", tmp)
const char *prefix = "../test-data/";
strcpy (tmp, prefix);
strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1);
if (stat (tmp, &attrib)) {
/* file not found. try srcdir */
prefix = "../../../test/test-data/";
if (!stat (prefix, &attrib) && S_ISDIR (attrib.st_mode)) {
strcpy (tmp, prefix);
strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1);
error += test_dynapi (tmp);
} else {
LOG_ERROR ("Env var INPUT not defined, %s not found", tmp);
}
}
else
error += test_dynapi (tmp);
}
Expand Down
39 changes: 26 additions & 13 deletions test/unit-testing/dynapi_test.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "config.h"
#ifdef __APPLE__
# define _DARWIN_C_SOURCE /* for DT_DIR */
#endif
#include <dirent.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
Expand All @@ -44,22 +47,22 @@ test_header (Dwg_Data *dwg)
BITCODE_BD bd;
BITCODE_TV tv;

#line 46 "dynapi_test.c"
#line 51 "dynapi_test.c"
/* @@for test_HEADER@@ */
#line 47 "dynapi_test.c.in"
#line 52 "dynapi_test.c.in"
return error;
}
#line 5379 "dynapi_test.c"
#line 6104 "dynapi_test.c"
/* @@for test_OBJECT@@ */

#line 53 "dynapi_test.c.in"
#line 58 "dynapi_test.c.in"
static int
test_object (const Dwg_Data *restrict dwg, const Dwg_Object *restrict obj)
{
int error = 0;
#line 62158 "dynapi_test.c"
#line 63791 "dynapi_test.c"
/* @@for if_test_OBJECT@@ */
#line 60 "dynapi_test.c.in"
#line 65 "dynapi_test.c.in"
return error + failed;
}

Expand All @@ -69,9 +72,9 @@ test_sizes (void)
{
int error = 0;
int size1, size2;
#line 63386 "dynapi_test.c"
#line 65063 "dynapi_test.c"
/* @@for test_SIZES@@ */
#line 72 "dynapi_test.c.in"
#line 77 "dynapi_test.c.in"
return error;
}

Expand Down Expand Up @@ -144,10 +147,20 @@ main (int argc, char *argv[])
if (stat (*ptr, &attrib))
{
char tmp[80];
strncpy (tmp, "../test-data/", sizeof (tmp));
strncat (tmp, *ptr, sizeof (tmp) - sizeof ("../test-data/") - 1);
if (stat (tmp, &attrib))
LOG_ERROR ("Env var INPUT not defined, %s not found", tmp)
const char *prefix = "../test-data/";
strcpy (tmp, prefix);
strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1);
if (stat (tmp, &attrib)) {
/* file not found. try srcdir */
prefix = "../../../test/test-data/";
if (!stat (prefix, &attrib) && S_ISDIR (attrib.st_mode)) {
strcpy (tmp, prefix);
strncat (tmp, *ptr, sizeof (tmp) - sizeof (prefix) - strlen (*ptr) - 1);
error += test_dynapi (tmp);
} else {
LOG_ERROR ("Env var INPUT not defined, %s not found", tmp);
}
}
else
error += test_dynapi (tmp);
}
Expand Down

0 comments on commit 527956d

Please sign in to comment.