Skip to content

Commit f148fc7

Browse files
committed
add files to test binary indexing - incomplete
1 parent 6e4fcaf commit f148fc7

File tree

11 files changed

+234
-10
lines changed

11 files changed

+234
-10
lines changed

src/clstepcore/SingleLinkList.inline.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
#include <SingleLinkList.h>
1414
#include <iostream>
1515

16-
SingleLinkNode *
17-
SingleLinkNode::NextNode() const {
16+
SingleLinkNode * SingleLinkNode::NextNode() const {
1817
return next;
1918
}
2019

src/test/scl2html/scl2html.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int PrintAttrsHTML( const EntityDescriptor * ent, ofstream & outhtml ) {
115115
while( attrDesc != 0 ) {
116116
attrCount++;
117117
outhtml << "<LI>" << attrDesc->Name() << " : ";
118-
if( ( SDAI_Logical )( attrDesc->Optional() ) == SCLLOG( LTrue ) ) {
118+
if( attrDesc->Optional().operator==( LTrue ) ) {
119119
outhtml << "optional ";
120120
}
121121
PrintAttrTypeWithAnchor( attrDesc->ReferentType(), outhtml );

src/test/treg/treg.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void PopulateEntity( STEPentity * ent ) {
3939
const AttrDescriptor * attrDesc = attr->aDesc;
4040
cout << " attribute " << attrDesc->Name();
4141
cout << " [" << attrDesc->TypeName() << "] = ";
42-
int needOutput = 1; // true if we need to output the value
42+
bool needOutput = true; // true if we need to output the value
4343
// that is, if it's anything but 'none'
4444

4545
// Here's how we do this... set up a string stream to put the value
@@ -66,18 +66,23 @@ void PopulateEntity( STEPentity * ent ) {
6666
valstr << se->element_at( rand() % se->no_elements() );
6767
}
6868
break;
69+
case BINARY_TYPE: //FIXME we really need to query the number of bits (does scl/fedex_plus even support this?!)
70+
cout << "(binary) ";
71+
valstr << "\"1";
72+
valstr.setf(ios::hex,ios::basefield);
73+
valstr << rand() % 100 << '\"';
74+
SDAI_Binary b;
75+
break;
6976
default: // for other stuff like aggregates and selects, just leave
7077
cout << "none (" << attrDesc->NonRefType(); // 'em blank...
7178
cout << ")" << endl;
72-
needOutput = 0;
79+
needOutput = false;
7380
}
7481
valstr << ends; // flush and null-terminate the stream
75-
/*** char *val = valstr.str(); ***/ // fix stream into char* string
76-
char * val = &( valstr.str()[0] );
7782
if( needOutput ) {
78-
cout << val << endl;
83+
cout << valstr.str() << endl;
7984
}
80-
attr->StrToVal( val ); // and assign
85+
attr->StrToVal( valstr.str().c_str() ); // and assign
8186

8287
attr = ent->NextAttribute();
8388
}

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ FILE(GLOB UNITARY_SCHEMAS "${CMAKE_CURRENT_SOURCE_DIR}/unitary_schemas/*.exp")
66
FOREACH(UNITARY_SCHEMA ${UNITARY_SCHEMAS})
77
GET_FILENAME_COMPONENT(SCHEMA_NAME ${UNITARY_SCHEMA} NAME_WE)
88
# setting test_name
9-
SET(TEST_NAME test${SCHEMA_NAME})
9+
SET(TEST_NAME test_unit_${SCHEMA_NAME})
1010
# add test
1111
ADD_TEST(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/check-express ${UNITARY_SCHEMA})
1212
set_tests_properties( ${TEST_NAME} PROPERTIES LABELS unitary_schemas )
1313
ENDFOREACH(UNITARY_SCHEMA ${UNITARY_SCHEMAS})
1414

1515
add_subdirectory(p21)
16+
add_subdirectory(cpp)

test/cpp/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
3+
#c++ tests
4+
5+
add_subdirectory(schema_dependent)
6+
# add_subdirectory(stepcore)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
#c++ tests that depend on a particular schema
3+
4+
# ${name} is used for the C++ file name (${name}.cc), and as the suffix for the target and test names
5+
# ${sdai_lib} is the name of the schema lib that is used
6+
# ${args} are additional args for the test command
7+
FUNCTION( add_schema_dependent_test name sdai_lib args )
8+
add_executable( tst_${name} "${name}.cc" )
9+
set_target_properties( tst_${name} PROPERTIES COMPILE_FLAGS "-I${SCL_SOURCE_DIR}/src/cldai -I${SCL_SOURCE_DIR}/src/cleditor -I${SCL_SOURCE_DIR}/src/clutils -I${CMAKE_BINARY_DIR}/${sdai_lib} -I${SCL_SOURCE_DIR}/src/clstepcore" )
10+
set_target_properties( tst_${name} PROPERTIES EXCLUDE_FROM_ALL ON )
11+
target_link_libraries( tst_${name} sdai_${sdai_lib} )
12+
add_test( NAME test_${name}
13+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
14+
COMMAND tst_${name} ${args} )
15+
set_tests_properties( test_${name} PROPERTIES DEPENDS build_cpp_sdai_${sdai_lib} LABELS cpp )
16+
ENDFUNCTION( add_schema_dependent_test name sdai_lib args )
17+
18+
add_schema_dependent_test( "binary_index_derived" "binary_index" "${SCL_SOURCE_DIR}/test/p21/test_binary_index.p21" )
19+
add_schema_dependent_test( "stepAttrListSegfault" "binary_index" "${SCL_SOURCE_DIR}/test/p21/test_binary_index.p21" )
20+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
extern void SchemaInit( class Registry & );
3+
#include "scl_version_string.h"
4+
#include <STEPfile.h>
5+
#include <sdai.h>
6+
#include <STEPattribute.h>
7+
#include <ExpDict.h>
8+
#include <Registry.h>
9+
#include <errordesc.h>
10+
#include <algorithm>
11+
#include <string>
12+
#include <unistd.h>
13+
14+
#include "SdaiTEST_BINARY_INDEX.h"
15+
16+
//FIXME incomplete
17+
int main( int argc, char * argv[] ) {
18+
19+
if ( argc != 2 ) {
20+
cerr << "Wrong number of args. Use: " << argv[0] << " file.stp" << endl;
21+
exit(1);
22+
}
23+
24+
Registry registry( SchemaInit );
25+
InstMgr instance_list;
26+
STEPfile sfile( registry, instance_list, "", false );
27+
28+
sfile.ReadExchangeFile( argv[1] );
29+
sfile.Error().PrintContents(cout);
30+
31+
Severity readSev = sfile.Error().severity();
32+
33+
// Keeps track of the last processed ent id
34+
int search_index = 0;
35+
36+
const EntityDescriptor* ed = registry.FindEntity("Buynary");
37+
AttrDescItr aditr( ed->ExplicitAttr() );
38+
const AttrDescriptor * attrDesc = aditr.NextAttrDesc();
39+
while( attrDesc != 0 ) {
40+
if( attrDesc->Derived() == LTrue ) {
41+
cout << "attr: " << attrDesc->Name() << " initializer: " << ((Derived_attribute*) attrDesc)->initializer_() << endl;
42+
//how to find the value of an attribute for an entity?
43+
}
44+
attrDesc = aditr.NextAttrDesc();
45+
}
46+
47+
SdaiBuynary* ent;
48+
while ( ENTITY_NULL != (ent = (SdaiBuynary*) instance_list.GetApplication_instance("Buynary",search_index) ) ) {
49+
// Loop over the Buynarys in the file
50+
cout << "Ent #" << ent->StepFileId() << endl;
51+
SDAI_Binary b = ent->bin_();
52+
int cnt = ent->AttributeCount();
53+
cout << "bin " << b.asStr() << endl;
54+
cout << "count " << cnt << endl;
55+
STEPattributeList &sal = ent->attributes;
56+
STEPattribute sa;
57+
// AttrDescItr adi( ent->attributes );
58+
// while 0 != (
59+
for( int i = 0; i < cnt; i++ ) {
60+
sa = sal[i];
61+
if( ( sa.aDesc->Derived() == LTrue ) && ( sa.aDesc->BaseType() == sdaiBINARY ) ) {
62+
cout << "derived: " << sa.ptr.b->asStr() << endl;
63+
} else {
64+
cout << "not derived: " << sa.ptr.b->asStr() << endl;
65+
}
66+
}
67+
MgrNode* mnode = instance_list.FindFileId( ent->StepFileId() );
68+
search_index = instance_list.GetIndex( mnode ) + 1;
69+
}
70+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
2+
extern void SchemaInit( class Registry & );
3+
#include "scl_version_string.h"
4+
#include <STEPfile.h>
5+
#include <sdai.h>
6+
#include <STEPattribute.h>
7+
#include <ExpDict.h>
8+
#include <Registry.h>
9+
#include <errordesc.h>
10+
#include <algorithm>
11+
#include <string>
12+
#include <unistd.h>
13+
14+
#include "SdaiTEST_BINARY_INDEX.h"
15+
16+
/* TODO: simplify this as much as possible
17+
* This segfault will probably occur with the STEPattributeList base class, SingleLinkList, as well - and without a schema lib.
18+
*/
19+
int main( int argc, char * argv[] ) {
20+
21+
if ( argc != 2 ) {
22+
cerr << "Wrong number of args. Use: " << argv[0] << " file.stp" << endl;
23+
exit(1);
24+
}
25+
26+
Registry registry( SchemaInit );
27+
InstMgr instance_list;
28+
STEPfile sfile( registry, instance_list, "", false );
29+
30+
sfile.ReadExchangeFile( argv[1] );
31+
sfile.Error().PrintContents(cout);
32+
33+
Severity readSev = sfile.Error().severity();
34+
35+
// Keeps track of the last processed ent id
36+
int search_index = 0;
37+
38+
const EntityDescriptor* ed = registry.FindEntity("Buynary");
39+
AttrDescItr aditr( ed->ExplicitAttr() );
40+
const AttrDescriptor * attrDesc = aditr.NextAttrDesc();
41+
while( attrDesc != 0 ) {
42+
if( attrDesc->Derived() == LTrue ) {
43+
cout << "attr: " << attrDesc->Name() << " initializer: " << ((Derived_attribute*) attrDesc)->initializer_() << endl;
44+
//how to find the value of an attribute for an entity?
45+
}
46+
attrDesc = aditr.NextAttrDesc();
47+
}
48+
49+
SdaiBuynary* ent;
50+
while ( ENTITY_NULL != (ent = (SdaiBuynary*) instance_list.GetApplication_instance("Buynary",search_index) ) ) {
51+
// Loop over the Buynarys in the file
52+
cout << "Ent #" << ent->StepFileId() << endl;
53+
SDAI_Binary b = ent->bin_();
54+
int cnt = ent->AttributeCount();
55+
cout << "bin " << b.asStr() << endl;
56+
cout << "count " << cnt << endl;
57+
58+
STEPattributeList sal = ent->attributes; //commenting this line out prevents the segfault
59+
60+
MgrNode* mnode = instance_list.FindFileId( ent->StepFileId() );
61+
search_index = instance_list.GetIndex( mnode ) + 1;
62+
}
63+
/* attr: lasthalf initializer: bin[5:8]
64+
* Ent #1
65+
* bin 15A
66+
* count 1
67+
*
68+
* Program received signal SIGSEGV, Segmentation fault.
69+
* 0x000000000067f768 in ?? ()
70+
* (gdb) bt
71+
* #0 0x000000000067f768 in ?? ()
72+
* #1 0x00007ffff778962d in SingleLinkList::Empty (this=0x6755b8)
73+
* at /opt/step/scl/src/clstepcore/SingleLinkList.inline.cc:32
74+
* #2 0x00007ffff77895b8 in SingleLinkList::~SingleLinkList (this=0x6755b8, __in_chrg=<optimized out>)
75+
* at /opt/step/scl/src/clstepcore/SingleLinkList.inline.cc:26
76+
* #3 0x00007ffff7788f64 in STEPattributeList::~STEPattributeList (this=0x6755b8, __in_chrg=<optimized out>)
77+
* at /opt/step/scl/src/clstepcore/STEPattributeList.cc:27
78+
* #4 0x00007ffff77778e0 in SDAI_Application_instance::~SDAI_Application_instance (this=0x6755a0,
79+
* __in_chrg=<optimized out>) at /opt/step/scl/src/clstepcore/sdaiApplication_instance.cc:42
80+
* #5 0x00007ffff7bdb163 in SdaiBuynary::~SdaiBuynary (this=0x6755a0, __in_chrg=<optimized out>)
81+
* at /opt/step/scl/build/binary_index/SdaiTEST_BINARY_INDEX.cc:46
82+
* #6 0x00007ffff7bdb1b6 in SdaiBuynary::~SdaiBuynary (this=0x6755a0, __in_chrg=<optimized out>)
83+
* at /opt/step/scl/build/binary_index/SdaiTEST_BINARY_INDEX.cc:46
84+
* #7 0x00007ffff79c8656 in MgrNode::~MgrNode (this=0x67f790, __in_chrg=<optimized out>)
85+
* at /opt/step/scl/src/cleditor/mgrnode.cc:69
86+
* #8 0x00007ffff79c86ee in MgrNode::~MgrNode (this=0x67f790, __in_chrg=<optimized out>)
87+
* at /opt/step/scl/src/cleditor/mgrnode.cc:75
88+
* #9 0x00007ffff79c8efd in MgrNodeArray::DeleteEntries (this=0x637940)
89+
* at /opt/step/scl/src/cleditor/mgrnodearray.cc:84
90+
* #10 0x00007ffff79c8d7f in MgrNodeArray::~MgrNodeArray (this=0x637940, __in_chrg=<optimized out>)
91+
* at /opt/step/scl/src/cleditor/mgrnodearray.cc:60
92+
* #11 0x00007ffff79c8dde in MgrNodeArray::~MgrNodeArray (this=0x637940, __in_chrg=<optimized out>)
93+
* at /opt/step/scl/src/cleditor/mgrnodearray.cc:61
94+
* #12 0x00007ffff79c7554 in InstMgr::~InstMgr (this=0x7fffffffe030, __in_chrg=<optimized out>)
95+
* at /opt/step/scl/src/cleditor/instmgr.cc:58
96+
* #13 0x0000000000402133 in main (argc=2, argv=0x7fffffffe1f8)
97+
* at /opt/step/scl/test/cpp/schema_dependent/binary_index_derived.cc:25
98+
*/
99+
100+
}

test/p21/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ set_tests_properties( test_good_schema_name test_good_schema_name_asn test_misma
5252
PROPERTIES DEPENDS build_cpp_sdai_AP214E3_2010 LABELS exchange_file )
5353

5454
set_tests_properties( test_mismatch_schema_name test_missing_and_required_strict PROPERTIES WILL_FAIL TRUE )
55+
56+
#currently, this test is forced to fail - the file is written with a '$', but p21read reports no errors or warnings. The WILL_FAIL property can be removed when p21read reports an error or when it stores the correct data
57+
add_test( test_binary_index "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/p21read_sdai_binary_index" ${CMAKE_CURRENT_SOURCE_DIR}/test_binary_index.p21 )
58+
set_tests_properties( test_binary_index PROPERTIES DEPENDS build_cpp_sdai_binary_index WILL_FAIL TRUE LABELS exchange_file )

test/p21/test_binary_index.p21

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ISO-10303-21;
2+
HEADER;
3+
FILE_DESCRIPTION(('SCL test file'),'2;1');
4+
FILE_NAME('test_binary_index.stp','2012-01-19T',('mp'),(''),'0','1','2');
5+
FILE_SCHEMA(('test_binary_index'));
6+
ENDSEC;
7+
DATA;
8+
#1=BUYNARY("15A");
9+
ENDSEC;
10+
END-ISO-10303-21;

0 commit comments

Comments
 (0)