diff --git a/.gitignore b/.gitignore index cb83e1b..834b8a9 100644 --- a/.gitignore +++ b/.gitignore @@ -46,11 +46,4 @@ access* *.err # sample programs -ulog_test -exceptions_tests -buffer_test -multi_context_test -queue_test -transaction_test -sample_fml_table.h - +*test diff --git a/tests/clients/field_test.bcl b/tests/clients/field_test.bcl new file mode 100644 index 0000000..585d58e --- /dev/null +++ b/tests/clients/field_test.bcl @@ -0,0 +1,121 @@ +/* $Id$ + + Sample Tuxedo client using ATMI++ libray. + + */ +#include +#include +#include +#include +#include +#include +#include +#include "atmi/atmi++.hpp" + +#include "sample_fml_table.h" + +template< class T, FLDID32 F = 0 > +class _field: public atmi::Tfield { + public: + _field(): atmi::Tfield(F){ + } + + _field( FLDID32 id ): atmi::Tfield(id){ + } + + T operator=( T v ){ + atmi::Tfield::value = v; + + return atmi::Tfield::value ; + } +}; + +typedef _field prenom_t; +typedef _field empid_t; +typedef _field void_t; + +class fields { + public: + fields(){ + prenom = "hello world" ; + std::cout << __FUNCTION__ << ": " << prenom << std::endl ; + } + + private: + prenom_t prenom ; +}; + + +class field_empid: public atmi::Tfield { + public: + field_empid(): atmi::Tfield(EMPID){ + } + +}; + +// program main ------------------------------------------------- + +int main ( int argc, char **argv ) { + + auto status = EXIT_FAILURE; + try { + + std::cout << "field sample program (" << atmi::cpp_atmi_version() <<")." << std::endl; + + std::cout << std::endl << "---------------------------" << std::endl << std::endl; + + { + std::cout << "TEST >>>> IMPID field ID: " << std::endl; + + atmi::Tfield empid_(EMPID); + std::auto_ptr empid_ptr(new atmi::Tfield); + std::cout << empid_ptr->name() << "(PTR): " << empid_ptr->what() << std::endl; + + atmi::Tfield empid; + empid = 10; + std::cout << empid.name() << ": " << empid << std::endl << " " << empid.what() << std::endl; + + std::cout << "TEST >>>> succesful" << std::endl ; + } + + { + std::cout << "TEST >>>> IMPID field name: " << std::endl; + + atmi::Tfield empid("EMPID"); + empid = 10; + std::cout << empid.name() << ": " << empid << std::endl << " " << empid.what() << std::endl; + + std::cout << "TEST >>>> succesful" << std::endl ; + } + + std::cout << std::endl << "---------------------------" << std::endl << std::endl; + + { + std::cout << "TEST >>>> Tfields type mismatch detection: " << std::endl; + + try { + atmi::Tfield empid(EMPID); + }catch ( std::exception &err ){ + std::cerr << "field test failed. " << err.what() << std::endl; + } + + try { + atmi::Tfield empid("EMPID"); + }catch ( std::exception &err ){ + std::cerr << "field test failed. " << err.what() << std::endl; + } + + std::cout << "TEST >>>> succesful" << std::endl ; + } + + std::cout << std::endl << "---------------------------" << std::endl << std::endl; + + std::cout << "END of field sample program" << std::endl ; + status = EXIT_SUCCESS; + + } catch ( std::exception &err ) { + std::cerr << "field test failed. " << err.what() << std::endl; + } + + return status; +}