Skip to content

Commit 860d612

Browse files
committed
test SDAI_Select assignment operator
1 parent 2685dbc commit 860d612

File tree

2 files changed

+91
-7
lines changed

2 files changed

+91
-7
lines changed

src/clstepcore/test/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
22
#c++ tests for clstepcore
33

4-
INCLUDE_DIRECTORIES( ${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor ${SC_SOURCE_DIR}/src/clutils
5-
${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/base )
4+
INCLUDE_DIRECTORIES(${SC_SOURCE_DIR}/src/cldai ${SC_SOURCE_DIR}/src/cleditor ${SC_SOURCE_DIR}/src/clutils
5+
${SC_SOURCE_DIR}/src/clstepcore ${SC_SOURCE_DIR}/src/base)
66

77
function(add_stepcore_test name libs)
8-
SC_ADDEXEC( tst_${name} test_${name}.cc "${libs}" "TESTABLE" )
8+
SC_ADDEXEC(tst_${name} test_${name}.cc "${libs}" "TESTABLE")
99
add_test( NAME build_cpp_${name}
1010
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
1111
COMMAND ${CMAKE_COMMAND} --build .
@@ -14,9 +14,10 @@ function(add_stepcore_test name libs)
1414
add_test( NAME test_${name}
1515
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
1616
COMMAND $<TARGET_FILE:tst_${name}> )
17-
set_tests_properties( build_cpp_${name} PROPERTIES LABELS cpp_unit_stepcore DEPENDS stepcore )
18-
set_tests_properties( test_${name} PROPERTIES LABELS cpp_unit_stepcore DEPENDS build_cpp_${name} )
17+
set_tests_properties(build_cpp_${name} PROPERTIES LABELS cpp_unit_stepcore DEPENDS stepcore)
18+
set_tests_properties(test_${name} PROPERTIES LABELS cpp_unit_stepcore DEPENDS build_cpp_${name})
1919
endfunction(add_stepcore_test name libs)
2020

21-
add_stepcore_test( "SupertypesIterator" "stepcore;steputils;stepeditor;stepdai;base" ) #all these libs are necessary?
22-
add_stepcore_test( "operators_STEPattribute" "stepcore;steputils;stepeditor;stepdai;base" )
21+
add_stepcore_test("SupertypesIterator" "stepcore;steputils;stepeditor;stepdai;base") #all these libs are necessary?
22+
add_stepcore_test("operators_STEPattribute" "stepcore;steputils;stepeditor;stepdai;base")
23+
add_stepcore_test("operators_SDAI_Select" "stepcore;steputils;stepeditor;stepdai;base")
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/** \file test_operators_SDAI_Select.cc
2+
* tests for SDAI_Select operators
3+
* currently only implements a test for operator=
4+
* TODO implement others
5+
*/
6+
7+
#include <iostream>
8+
9+
#include "ExpDict.h"
10+
#include "baseType.h"
11+
#include "sdaiSelect.h"
12+
13+
using namespace std;
14+
15+
class TestSdaiSelect: public SDAI_Select {
16+
public:
17+
TestSdaiSelect( SelectTypeDescriptor * s, TypeDescriptor * t, BASE_TYPE b, SDAI_String v, ErrorDescriptor e ):
18+
SDAI_Select( s, t ) {
19+
base_type = b;
20+
val = v;
21+
_error = e;
22+
}
23+
TestSdaiSelect(): SDAI_Select() {}
24+
TestSdaiSelect & operator=( const TestSdaiSelect & other ) {
25+
SDAI_Select::operator=( other );
26+
return *this;
27+
}
28+
SDAI_Select& operator=( const SDAI_Select& other ) {
29+
SDAI_Select::operator=( other );
30+
return *this;
31+
}
32+
33+
/// \return true for match
34+
bool compare( SelectTypeDescriptor * s, TypeDescriptor * t, BASE_TYPE b, SDAI_String * v, ErrorDescriptor * e ) {
35+
bool pass = _type == s;
36+
pass &= underlying_type == t;
37+
pass &= base_type == b;
38+
pass &= val == v->c_str();
39+
pass &= ( _error.severity() == e->severity() ) && ( _error.debug_level() == e->debug_level() );
40+
return pass;
41+
}
42+
43+
// dummy implementations of pure virtual funcs
44+
const TypeDescriptor* AssignEntity( SDAI_Application_instance * /*i*/ ) { return (TypeDescriptor *)0; }
45+
SDAI_Select* NewSelect(){ return (SDAI_Select *)0; }
46+
BASE_TYPE ValueType() const { return sdaiBOOLEAN; }
47+
void STEPwrite_content( std::ostream& /*o*/, const char* /*a*/ ) const {}
48+
Severity StrToVal_content( const char* /*a*/, InstMgr* /*m*/ ) { return SEVERITY_NULL; }
49+
Severity STEPread_content(std::istream& i, InstMgr* m, const char* c, int n, const char* d) {
50+
(void)i; (void)m; (void)c; (void)n; (void)d; return SEVERITY_NULL;
51+
}
52+
};
53+
/// \return true for success
54+
bool testOperatorEq() {
55+
Schema * sch = 0;
56+
SelectTypeDescriptor s( 5, "a", sdaiBOOLEAN, sch, "b" );
57+
TypeDescriptor t;
58+
BASE_TYPE b = sdaiAGGR;
59+
SDAI_String v( "test string" );
60+
ErrorDescriptor e( SEVERITY_MAX, 99 );
61+
TestSdaiSelect s1( &s, &t, b, v, e );
62+
TestSdaiSelect s2;
63+
64+
s2 = s1;
65+
if( s2.compare( &s, &t, b, &v, &e ) ) {
66+
return true;
67+
} else {
68+
cerr << __FILE__ << ":" << __LINE__ << " - error: test for SDAI_Select::operator= failed" << endl;
69+
return false;
70+
}
71+
}
72+
73+
int main( int /*argc*/, char ** /*argv*/ ) {
74+
bool pass = true;
75+
pass &= testOperatorEq();
76+
//TODO test other operators
77+
cerr << "FIXME this test is incomplete!" << endl;
78+
if( pass ) {
79+
exit( EXIT_SUCCESS );
80+
} else {
81+
exit( EXIT_FAILURE );
82+
}
83+
}

0 commit comments

Comments
 (0)