Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,9 @@ if(BUILD_TESTING)
--ignore-errors negative
--rc branch_coverage=1
COMMAND ${LCOV_EXECUTABLE}
--extract "${AST_COVERAGE_FULL_INFO}" "${CMAKE_SOURCE_DIR}/src/*"
--extract "${AST_COVERAGE_FULL_INFO}"
"${CMAKE_SOURCE_DIR}/src/*"
"${CMAKE_SOURCE_DIR}/ast_tester/*"
--output-file "${AST_COVERAGE_INFO}"
--ignore-errors unused,negative
--rc branch_coverage=1
Expand Down
5 changes: 5 additions & 0 deletions ast_tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ ast_add_test(testresimp INTERNAL_HEADERS)
ast_add_test(testaxis)
ast_add_test(testframe)
ast_add_test(testunitnorm)
ast_add_test(testobjectkeymap)

# --- Tests needing data files ---
configure_file(2dspline_c.dat "${CMAKE_CURRENT_BINARY_DIR}/2dspline_c.dat" COPYONLY)
Expand Down Expand Up @@ -439,6 +440,10 @@ if(HAVE_YAML)
configure_file(tanSipWcs.txt "${CMAKE_CURRENT_BINARY_DIR}/tanSipWcs.txt" COPYONLY)
configure_file(lsst_wcs.txt "${CMAKE_CURRENT_BINARY_DIR}/lsst_wcs.txt" COPYONLY)
configure_file(rotate_seq3d_cartesian.asdf "${CMAKE_CURRENT_BINARY_DIR}/rotate_seq3d_cartesian.asdf" COPYONLY)
configure_file(time_equinox.asdf "${CMAKE_CURRENT_BINARY_DIR}/time_equinox.asdf" COPYONLY)
configure_file(quantity.asdf "${CMAKE_CURRENT_BINARY_DIR}/quantity.asdf" COPYONLY)
configure_file(transforms_1d.asdf "${CMAKE_CURRENT_BINARY_DIR}/transforms_1d.asdf" COPYONLY)
configure_file(transforms_2d.asdf "${CMAKE_CURRENT_BINARY_DIR}/transforms_2d.asdf" COPYONLY)
ast_add_test(testyamlchan)
endif()

Expand Down
79 changes: 79 additions & 0 deletions ast_tester/quantity.asdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ASDF 1.0.0
#ASDF_STANDARD 1.6.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 5.1.0}
history:
extensions:
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/core/extensions/core-1.6.0
manifest_software: !core/software-1.0.0 {name: asdf_standard, version: 1.5.0}
software: !core/software-1.0.0 {name: asdf, version: 5.1.0}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/transform/extensions/transform-1.6.0
manifest_software: !core/software-1.0.0 {name: asdf_transform_schemas, version: 0.6.0}
software: !core/software-1.0.0 {name: asdf-astropy, version: 0.10.0}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/astronomy/gwcs/extensions/gwcs-1.4.0
manifest_software: !core/software-1.0.0 {name: asdf_wcs_schemas, version: 0.5.0}
software: !core/software-1.0.0 {name: gwcs, version: 1.0.3}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/astronomy/extensions/astronomy-1.2.0
manifest_software: !core/software-1.0.0 {name: asdf_standard, version: 1.5.0}
software: !core/software-1.0.0 {name: asdf-astropy, version: 0.10.0}
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://astropy.org/astropy/extensions/units-1.3.0
software: !core/software-1.0.0 {name: asdf-astropy, version: 0.10.0}
wcs: !<tag:stsci.edu:gwcs/wcs-1.4.0>
name: ''
pixel_shape: null
steps:
- !<tag:stsci.edu:gwcs/step-1.3.0>
frame: !<tag:stsci.edu:gwcs/frame2d-1.2.0>
axes_names: [x, y]
axes_order: [0, 1]
axis_physical_types: ['custom:x', 'custom:y']
name: detector
unit: [!unit/unit-1.0.0 pixel, !unit/unit-1.0.0 pixel]
transform: !transform/compose-1.3.0
forward:
- !transform/affine-1.4.0
inputs: [x, y]
matrix: !unit/quantity-1.1.0
unit: !unit/unit-1.0.0
value: !core/ndarray-1.1.0
data:
- [0.6, -0.8]
- [0.8, 0.6]
datatype: float64
shape: [2, 2]
outputs: [x, y]
translation: !unit/quantity-1.1.0
unit: !unit/unit-1.0.0
value: !core/ndarray-1.1.0
data: [100.0, -50.0]
datatype: float64
shape: [2]
- !transform/rotate2d-1.3.0
angle: !unit/quantity-1.1.0 {datatype: float64, unit: !unit/unit-1.0.0 deg,
value: 90.0}
inputs: [x, y]
outputs: [x, y]
inputs: [x, y]
outputs: [x, y]
- !<tag:stsci.edu:gwcs/step-1.3.0>
frame: !<tag:stsci.edu:gwcs/frame2d-1.2.0>
axes_names: [x, y]
axes_order: [0, 1]
axis_physical_types: ['custom:x', 'custom:y']
name: world
unit: [!unit/unit-1.0.0 pixel, !unit/unit-1.0.0 pixel]
transform: null
...
240 changes: 152 additions & 88 deletions ast_tester/testobject.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Test program for the AstObject base class. */

#include "ast.h"
#include <libgen.h>
#include <stdio.h>
Expand All @@ -12,122 +14,184 @@ static const char *baseName( const char *path ) {
return basename( buffer );
}

int main( void ){
const char *routine;
const char *file;
int i;
int line;
char *pickle1;
char *pickle2;
/* Verify that an Object survives a checkdump (astToString followed by
astFromString) round trip, and that the reloaded Object compares equal
to the original. */
static void TestCheckToString( void ) {
AstSkyFrame *sf = astSkyFrame( " " );
int bf_line = __LINE__ + 1;
AstFrame *bf = astFrame( 2, "Domain=SKY" );
AstFrameSet *fs = astConvert( bf, sf, " " );
AstKeyMap *km;
void *p;
AstFrameSet *fs2 = NULL;
char *pickle1 = NULL;
char *pickle2 = NULL;

if( fs ) {
if( !fs ) {
if( astOK )
astError( AST__INTER, "TestCheckToString: astConvert failed.\n" ); /* LCOV_EXCL_LINE */
} else {
pickle1 = astToString( fs );
int fs2_line = __LINE__ + 1;
AstFrameSet *fs2 = astFromString( pickle1 );
fs2 = astFromString( pickle1 );
pickle2 = astToString( fs2 );

if( pickle1 && pickle2 ) {
if( strcmp( pickle1, pickle2 ) && astOK ) {
astError( AST__INTER, "Error 1\n" );
}
if( strcmp( pickle1, pickle2 ) && astOK )
astError( AST__INTER, "TestCheckToString: round-tripped strings differ.\n" ); /* LCOV_EXCL_LINE */
} else if( astOK ) {
astError( AST__INTER, "Error 2\n" );
astError( AST__INTER, "TestCheckToString: astToString returned NULL.\n" ); /* LCOV_EXCL_LINE */
}

if( fs2 && !astEqual( fs, fs2 ) && astOK )
astError( AST__INTER, "TestCheckToString: reloaded Object is not equal to the original.\n" ); /* LCOV_EXCL_LINE */
}

pickle1 = astFree( pickle1 );
pickle2 = astFree( pickle2 );
pickle1 = astFree( pickle1 );
pickle2 = astFree( pickle2 );
sf = astAnnul( sf );
bf = astAnnul( bf );

if( fs2 && !astEqual( fs, fs2 ) && astOK ) {
astError( AST__INTER, "Error 3\n" );
}
if( fs )
fs = astAnnul( fs );

astCreatedAt( bf, &routine, &file, &line );
if( ( !routine || strcmp( routine, "main" ) ) && astOK ) {
astError( AST__INTER, "Error 31\n" );
}
if( ( !file || strcmp( baseName(file), "testobject.c" ) ) && astOK ) {
astError( AST__INTER, "Error 32\n" );
}
if( line != bf_line && astOK ) {
astError( AST__INTER, "Error 33 (line is %d, expected %d)\n", line, bf_line );
}
if( fs2 )
fs2 = astAnnul( fs2 );
}

/* Verify that astCreatedAt reports the routine, file and line at which an
Object was created. */
static void TestCreatedAt( void ) {
const char *routine;
const char *file;
int line;
int bf_line = __LINE__ + 1;
AstFrame *bf = astFrame( 2, "Domain=SKY" );

km = astActiveObjects( NULL, 0, 0 );
if( !km && astOK ) {
astError( AST__INTER, "Error 34\n" );
} else {
int nkey = astMapSize( km );
if( nkey != 3 && astOK ) {
astError( AST__INTER, "Error 35 (nkey is %d)\n", nkey );
}
astCreatedAt( bf, &routine, &file, &line );
if( ( !routine || strcmp( routine, "TestCreatedAt" ) ) && astOK )
astError( AST__INTER, "TestCreatedAt: routine is '%s'.\n", routine ? routine : "<NULL>" ); /* LCOV_EXCL_LINE */
if( ( !file || strcmp( baseName( file ), "testobject.c" ) ) && astOK )
astError( AST__INTER, "TestCreatedAt: file is '%s'.\n", file ? file : "<NULL>" ); /* LCOV_EXCL_LINE */
if( line != bf_line && astOK )
astError( AST__INTER, "TestCreatedAt: line is %d, expected %d.\n", line, bf_line ); /* LCOV_EXCL_LINE */

astSetC( km, "SortBy", "KeyUp" );
for( i=0; i < 3; i++ ){
const char *key = astMapKey( km, i );
if( i == 0 ) {
if( strcmp( key, "Frame" ) && astOK ) {
astError( AST__INTER, "Error 36 (key 0 is '%s')\n", key );
} else if( astMapLength(km,key) != 1 && astOK ) {
astError( AST__INTER, "Error 361 (%d)\n", astMapLength(km,key) );
} else if( ( !astMapGetElemP( km, key, 0, &p ) || ( p != bf ) ) && astOK ) {
astError( AST__INTER, "Error 362\n" );
} else {
astCreatedAt( p, &routine, &file, &line );
if( ( !routine || strcmp( routine, "main" ) ) && astOK ) {
astError( AST__INTER, "Error 363\n" );
}
if( ( !file || strcmp( baseName(file), "testobject.c" ) ) && astOK ) {
astError( AST__INTER, "Error 364\n" );
}
if( line != bf_line && astOK ) {
astError( AST__INTER, "Error 365 (line is %d)\n", line );
}
}
} else if( i == 1 ) {
if( strcmp( key, "FrameSet" ) && astOK ) {
astError( AST__INTER, "Error 37 (key 1 is '%s')\n", key );
} else if( astMapLength(km,key) != 2 && astOK ) {
astError( AST__INTER, "Error 371 (%d)\n", astMapLength(km,key) );
} else if( ( !astMapGetElemP( km, key, 1, &p ) || ( p != fs2 ) ) && astOK ) {
astError( AST__INTER, "Error 372\n" );
} else {
astCreatedAt( p, &routine, &file, &line );
if( ( !routine || strcmp( routine, "main" ) ) && astOK ) {
astError( AST__INTER, "Error 373\n" );
}
if( ( !file || strcmp( baseName(file), "testobject.c" ) ) && astOK ) {
astError( AST__INTER, "Error 374\n" );
}
if( line != fs2_line && astOK ) {
astError( AST__INTER, "Error 375 (line is %d, expected %d)\n", line, fs2_line );
}
}
bf = astAnnul( bf );
}

/* Verify that astActiveObjects reports the Objects active within the
current context, keyed by class, including the creation information for
each one. The objects are created within their own AST context so the
"current" filter yields a deterministic set regardless of any objects
left alive by other tests. */
static void TestActiveObjects( void ) {
AstSkyFrame *sf;
AstFrame *bf;
AstFrameSet *fs;
AstFrameSet *fs2;
AstKeyMap *km;
const char *routine;
const char *file;
const char *key;
int bf_line;
int fs2_line;
int idx;
int jdx;
int found;
int line;
int nkey;
void *p;

astBegin;

sf = astSkyFrame( " " );
bf_line = __LINE__ + 1;
bf = astFrame( 2, "Domain=SKY" );
fs = astConvert( bf, sf, " " );
fs2_line = __LINE__ + 1;
fs2 = astCopy( fs );
km = astActiveObjects( NULL, 0, 1 );

if( !km && astOK ) {
astError( AST__INTER, "TestActiveObjects: astActiveObjects returned NULL.\n" ); /* LCOV_EXCL_LINE */
} else {
nkey = astMapSize( km );
if( nkey != 3 && astOK )
astError( AST__INTER, "TestActiveObjects: nkey is %d, expected 3.\n", nkey ); /* LCOV_EXCL_LINE */

astSetC( km, "SortBy", "KeyUp" );
for( idx = 0; idx < nkey; idx++ ){
key = astMapKey( km, idx );
if( idx == 0 ) {
if( strcmp( key, "Frame" ) && astOK ) {
astError( AST__INTER, "TestActiveObjects: key 0 is '%s'.\n", key ); /* LCOV_EXCL_LINE */
} else if( astMapLength( km, key ) != 1 && astOK ) {
astError( AST__INTER, "TestActiveObjects: Frame count is %d.\n", astMapLength( km, key ) ); /* LCOV_EXCL_LINE */
} else if( ( !astMapGetElemP( km, key, 0, &p ) || ( p != bf ) ) && astOK ) {
astError( AST__INTER, "TestActiveObjects: Frame pointer mismatch.\n" ); /* LCOV_EXCL_LINE */
} else {
astCreatedAt( p, &routine, &file, &line );
if( ( !routine || strcmp( routine, "TestActiveObjects" ) ) && astOK )
astError( AST__INTER, "TestActiveObjects: Frame routine is '%s'.\n", routine ? routine : "<NULL>" ); /* LCOV_EXCL_LINE */
if( ( !file || strcmp( baseName( file ), "testobject.c" ) ) && astOK )
astError( AST__INTER, "TestActiveObjects: Frame file is '%s'.\n", file ? file : "<NULL>" ); /* LCOV_EXCL_LINE */
if( line != bf_line && astOK )
astError( AST__INTER, "TestActiveObjects: Frame line is %d, expected %d.\n", line, bf_line ); /* LCOV_EXCL_LINE */
}
} else if( idx == 1 ) {
if( strcmp( key, "FrameSet" ) && astOK ) {
astError( AST__INTER, "TestActiveObjects: key 1 is '%s'.\n", key ); /* LCOV_EXCL_LINE */
} else if( astMapLength( km, key ) != 2 && astOK ) {
astError( AST__INTER, "TestActiveObjects: FrameSet count is %d.\n", astMapLength( km, key ) ); /* LCOV_EXCL_LINE */
} else {
if( strcmp( key, "SkyFrame" ) && astOK ) {
astError( AST__INTER, "Error 38 (key 2 is '%s')\n", key );
} else if( astMapLength(km,key) != 1 && astOK ) {
astError( AST__INTER, "Error 381 (%d)\n", astMapLength(km,key) );

/* The two FrameSets are both active, but their order within the list is
determined by the order in which the underlying object handles happen
to be allocated, which is not the order of creation. Locate the entry
that corresponds to "fs2" (the FrameSet created in this routine by
astCopy) and verify that its recorded creation information is correct. */
found = 0;
for( jdx = 0; jdx < 2; jdx++ ) {
if( astMapGetElemP( km, key, jdx, &p ) && p == fs2 ) {
found = 1;
astCreatedAt( p, &routine, &file, &line );
if( ( !routine || strcmp( routine, "TestActiveObjects" ) ) && astOK )
astError( AST__INTER, "TestActiveObjects: FrameSet routine is '%s'.\n", routine ? routine : "<NULL>" ); /* LCOV_EXCL_LINE */
if( ( !file || strcmp( baseName( file ), "testobject.c" ) ) && astOK )
astError( AST__INTER, "TestActiveObjects: FrameSet file is '%s'.\n", file ? file : "<NULL>" ); /* LCOV_EXCL_LINE */
if( line != fs2_line && astOK )
astError( AST__INTER, "TestActiveObjects: FrameSet line is %d, expected %d.\n", line, fs2_line ); /* LCOV_EXCL_LINE */
}
}
if( !found && astOK )
astError( AST__INTER, "TestActiveObjects: fs2 not found among the active FrameSets.\n" ); /* LCOV_EXCL_LINE */
}
} else {
if( strcmp( key, "SkyFrame" ) && astOK ) {
astError( AST__INTER, "TestActiveObjects: key 2 is '%s'.\n", key ); /* LCOV_EXCL_LINE */
} else if( astMapLength( km, key ) != 1 && astOK ) {
astError( AST__INTER, "TestActiveObjects: SkyFrame count is %d.\n", astMapLength( km, key ) ); /* LCOV_EXCL_LINE */
}
}
}
km = astAnnul( km );

} else if( astOK ){
astError( AST__INTER, "Error 4\n" );
}

astEnd;
}

int main( void ){
astBegin;

TestCheckToString();
TestCreatedAt();
TestActiveObjects();

astEnd;

if( astOK ) {
printf(" All Object tests passed\n");
return 0;
} else {
printf("Object tests failed\n");
return 1;
}
return astOK ? 0 : 1;
}
Loading
Loading