00001 // 00002 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney 00003 // Distributed under the Boost Software License, Version 1.0. 00004 // (See accompanying file LICENSE_1_0.txt or copy at 00005 // http://www.boost.org/LICENSE_1_0.txt) 00006 // 00007 00008 // 00009 #if defined(SOCI_HEADERS_BURIED) 00010 # include <soci/core/soci.h> 00011 # include <soci/backends/odbc/soci-odbc.h> 00012 # include <soci/core/test/common-tests.h> 00013 #else 00014 # include <soci.h> 00015 # include <soci-odbc.h> 00016 # include <test/common-tests.h> 00017 #endif 00018 // 00019 #include <iostream> 00020 #include <string> 00021 #include <cassert> 00022 #include <ctime> 00023 #include <cmath> 00024 00025 using namespace soci; 00026 using namespace soci::tests; 00027 00028 std::string connectString; 00029 backend_factory const &backEnd = odbc; 00030 00031 00032 // DDL Creation objects for common tests 00033 struct table_creator_one : public table_creator_base 00034 { 00035 table_creator_one(session & sql) 00036 : table_creator_base(sql) 00037 { 00038 sql << "create table soci_test(id integer, val integer, c char, " 00039 "str varchar(20), sh smallint, ul numeric(20), d float, " 00040 "tm datetime, i1 integer, i2 integer, i3 integer, " 00041 "name varchar(20))"; 00042 } 00043 }; 00044 00045 struct table_creator_two : public table_creator_base 00046 { 00047 table_creator_two(session & sql) 00048 : table_creator_base(sql) 00049 { 00050 sql << "create table soci_test(num_float float, num_int integer," 00051 " name varchar(20), sometime datetime, chr char)"; 00052 } 00053 }; 00054 00055 struct table_creator_three : public table_creator_base 00056 { 00057 table_creator_three(session & sql) 00058 : table_creator_base(sql) 00059 { 00060 sql << "create table soci_test(name varchar(100) not null, " 00061 "phone varchar(15))"; 00062 } 00063 }; 00064 00065 // 00066 // Support for SOCI Common Tests 00067 // 00068 00069 class test_context : public test_context_base 00070 { 00071 public: 00072 test_context(backend_factory const &backEnd, 00073 std::string const &connectString) 00074 : test_context_base(backEnd, connectString) {} 00075 00076 table_creator_base* table_creator_1(session& s) const 00077 { 00078 return new table_creator_one(s); 00079 } 00080 00081 table_creator_base* table_creator_2(session& s) const 00082 { 00083 return new table_creator_two(s); 00084 } 00085 00086 table_creator_base* table_creator_3(session& s) const 00087 { 00088 return new table_creator_three(s); 00089 } 00090 00091 std::string to_date_time(std::string const &datdt_string) const 00092 { 00093 return "convert(datetime, \'" + datdt_string + "\', 120)"; 00094 } 00095 }; 00096 00097 int main(int argc, char** argv) 00098 { 00099 00100 #ifdef _MSC_VER 00101 // Redirect errors, unrecoverable problems, and assert() failures to STDERR, 00102 // instead of debug message window. 00103 // This hack is required to run asser()-driven tests by Buildbot. 00104 // NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside. 00105 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); 00106 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); 00107 #endif //_MSC_VER 00108 00109 if (argc == 2) 00110 { 00111 connectString = argv[1]; 00112 } 00113 else 00114 { 00115 connectString = "FILEDSN=./test-mssql.dsn"; 00116 } 00117 try 00118 { 00119 test_context tc(backEnd, connectString); 00120 common_tests tests(tc); 00121 tests.run(); 00122 std::cout << "\nOK, all tests passed.\n"; 00123 } 00124 catch (soci::odbc_soci_error const & e) 00125 { 00126 std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl 00127 << "Native Error Code: " << e.native_error_code() << std::endl 00128 << "SOCI Message: " << e.what() << std::endl 00129 << "ODBC Message: " << e.odbc_error_message() << std::endl; 00130 } 00131 catch (soci::soci_error const & e) 00132 { 00133 std::cout << "SOCIERROR: " << e.what() << '\n'; 00134 } 00135 catch (std::exception const & e) 00136 { 00137 std::cout << "STD::EXECEPTION " << e.what() << '\n'; 00138 } 00139 }
Generated on Sun Oct 3 2010 17:42:16 for EXTRAS-SOCI by Doxygen 1.7.1