|
| 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