From e8f23eb82b1954ef2d8524f6f082a72a6755d451 Mon Sep 17 00:00:00 2001 From: "Aaron M. Ucko" Date: Wed, 8 May 2024 16:21:30 -0400 Subject: [PATCH 1/6] Fix compilation errors in single-threaded builds. * Conditionally stub out the tests that require threading (as of 1.4.12) and don't yet have such logic. * include/freetds/thread.h: Never try to add extra checks around stubs. Signed-off-by: Aaron M. Ucko --- include/freetds/thread.h | 2 +- src/odbc/unittests/qn.c | 10 +++++++++- src/tds/unittests/freeze.c | 8 ++++++++ src/tds/unittests/log_elision.c | 8 ++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/freetds/thread.h b/include/freetds/thread.h index e7b746ac1c..d6a5559e3c 100644 --- a/include/freetds/thread.h +++ b/include/freetds/thread.h @@ -331,7 +331,7 @@ static inline int tds_thread_is_current(tds_thread_id th) # define tds_cond_init tds_raw_cond_init # define tds_cond_destroy tds_raw_cond_destroy # define tds_cond_signal tds_raw_cond_signal -# if !ENABLE_EXTRA_CHECKS +# if !ENABLE_EXTRA_CHECKS || !defined(TDS_HAVE_MUTEX) # define TDS_MUTEX_INITIALIZER TDS_RAW_MUTEX_INITIALIZER # define tds_mutex tds_raw_mutex # define tds_mutex_lock tds_raw_mutex_lock diff --git a/src/odbc/unittests/qn.c b/src/odbc/unittests/qn.c index cf344e5ad3..8249c07ae0 100644 --- a/src/odbc/unittests/qn.c +++ b/src/odbc/unittests/qn.c @@ -7,6 +7,7 @@ /* test query notifications */ +#ifdef TDS_HAVE_MUTEX #define SWAP(t,a,b) do { t xyz = a; a = b; b = xyz; } while(0) #define SWAP_CONN() do { SWAP(HENV,env,odbc_env); SWAP(HDBC,dbc,odbc_conn); SWAP(HSTMT,stmt,odbc_stmt);} while(0) @@ -131,4 +132,11 @@ main(void) return 0; } - +#else +int main(int argc, char *argv[]) +{ + printf("Not possible for this platform.\n"); + odbc_test_skipped(); + return 0; +} +#endif diff --git a/src/tds/unittests/freeze.c b/src/tds/unittests/freeze.c index d25b111df8..6ef93fe85a 100644 --- a/src/tds/unittests/freeze.c +++ b/src/tds/unittests/freeze.c @@ -32,6 +32,7 @@ #include #include +#ifdef TDS_HAVE_MUTEX #ifdef _WIN32 #define SHUT_WR SD_SEND #endif @@ -485,3 +486,10 @@ main(void) return 0; } +#else /* !TDS_HAVE_MUTEX */ +int main(int argc, char *argv[]) +{ + printf("Not possible for this platform.\n"); + return 0; // 77? +} +#endif diff --git a/src/tds/unittests/log_elision.c b/src/tds/unittests/log_elision.c index 1d737f9494..4818f07131 100644 --- a/src/tds/unittests/log_elision.c +++ b/src/tds/unittests/log_elision.c @@ -29,6 +29,7 @@ #include #endif /* HAVE_UNISTD_H */ +#ifdef TDS_HAVE_MUTEX enum { LOOP = 100, THREADS = 3, @@ -142,3 +143,10 @@ main(void) return 0; } +#else /* !TDS_HAVE_MUTEX */ +int main(int argc, char *argv[]) +{ + printf("Not possible for this platform.\n"); + return 0; // 77? +} +#endif From 2ba3969b8898a43087ced585ae6458426d5b4eea Mon Sep 17 00:00:00 2001 From: "Aaron M. Ucko" Date: Wed, 17 Jul 2024 12:32:39 -0400 Subject: [PATCH 2/6] unit tests: Start phasing in a central baseline setup. * Introduce a that for now simply ensures that assertions in test-specific code will always be active and pulls in . (Tests that use assertions are still responsible for including themselves, but is generally best included as early as possible.) * Start every common.h with #include and src/tds/unittests/{parsing,tls}.c with #include "common.h". (Every other unit test with an accompanying common.h already had that form.) * Don't directly undefine NDEBUG or include anywhere in */src/unittests. Signed-off-by: Aaron M. Ucko --- include/freetds/utils/test_base.h | 18 ++++++++++++++++++ src/apps/unittests/defncopy.c | 3 +-- src/ctlib/unittests/common.h | 4 +--- src/dblib/unittests/common.h | 4 +--- src/odbc/unittests/all_types.c | 1 - src/odbc/unittests/array_error.c | 1 - src/odbc/unittests/common.h | 4 +--- src/odbc/unittests/peter.c | 1 - src/odbc/unittests/utf8_4.c | 1 - src/replacements/unittests/strings.c | 3 +-- src/replacements/unittests/strsep.c | 3 +-- src/replacements/unittests/strtok_r.c | 2 +- src/tds/unittests/collations.c | 2 -- src/tds/unittests/common.h | 3 +-- src/tds/unittests/parsing.c | 2 +- src/tds/unittests/tls.c | 2 ++ src/tds/unittests/utf8.c | 1 - src/utils/unittests/bytes.c | 4 ++-- src/utils/unittests/challenge.c | 4 ++-- src/utils/unittests/condition.c | 2 +- src/utils/unittests/dlist.c | 4 ++-- src/utils/unittests/mutex1.c | 2 +- src/utils/unittests/passarg.c | 4 ++-- src/utils/unittests/path.c | 4 ++-- src/utils/unittests/smp.c | 4 ++-- 25 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 include/freetds/utils/test_base.h diff --git a/include/freetds/utils/test_base.h b/include/freetds/utils/test_base.h new file mode 100644 index 0000000000..2717997cff --- /dev/null +++ b/include/freetds/utils/test_base.h @@ -0,0 +1,18 @@ +#ifndef _tdsguard_afBM6E9n8CuIFSBHNNblq5 +#define _tdsguard_afBM6E9n8CuIFSBHNNblq5 + +/* + * Base header for FreeTDS unit tests, even those just covering helpers + * from the utils and replacements trees. Should be included first + * (possibly via a common.h) to be certain of preceding . + */ + +/* Ensure assert is always active. */ +#undef NDEBUG +#ifdef assert +# error "Include test_base.h (or common.h) earlier" +#endif + +#include + +#endif /* _tdsguard_afBM6E9n8CuIFSBHNNblq5 */ diff --git a/src/apps/unittests/defncopy.c b/src/apps/unittests/defncopy.c index 5e5abac32c..3b6982d476 100644 --- a/src/apps/unittests/defncopy.c +++ b/src/apps/unittests/defncopy.c @@ -21,8 +21,7 @@ * This tests execute some command using tsql and defncopy to check behaviour */ -#undef NDEBUG -#include +#include #include #include diff --git a/src/ctlib/unittests/common.h b/src/ctlib/unittests/common.h index a928e22cda..ea2b4d608a 100644 --- a/src/ctlib/unittests/common.h +++ b/src/ctlib/unittests/common.h @@ -1,12 +1,10 @@ #ifndef _tdsguard_gWMRTH1fbCWjtfhWbz8PvN_ #define _tdsguard_gWMRTH1fbCWjtfhWbz8PvN_ -#undef NDEBUG +#include #include -#include - #include #include diff --git a/src/dblib/unittests/common.h b/src/dblib/unittests/common.h index 82cce99648..72164fe4b1 100644 --- a/src/dblib/unittests/common.h +++ b/src/dblib/unittests/common.h @@ -2,9 +2,7 @@ #ifndef _tdsguard_daeUPbmgBl59GOSecr8sMB_ #define _tdsguard_daeUPbmgBl59GOSecr8sMB_ -#undef NDEBUG - -#include +#include #include #include diff --git a/src/odbc/unittests/all_types.c b/src/odbc/unittests/all_types.c index 6fe75fde69..f444f88b43 100644 --- a/src/odbc/unittests/all_types.c +++ b/src/odbc/unittests/all_types.c @@ -1,4 +1,3 @@ -#undef NDEBUG #include "common.h" #include #define TDS_DONT_DEFINE_DEFAULT_FUNCTIONS diff --git a/src/odbc/unittests/array_error.c b/src/odbc/unittests/array_error.c index 644ef44f40..30024e5963 100644 --- a/src/odbc/unittests/array_error.c +++ b/src/odbc/unittests/array_error.c @@ -1,4 +1,3 @@ -#undef NDEBUG #include "common.h" #include diff --git a/src/odbc/unittests/common.h b/src/odbc/unittests/common.h index fd50392b9c..e9be322b7a 100644 --- a/src/odbc/unittests/common.h +++ b/src/odbc/unittests/common.h @@ -1,4 +1,4 @@ -#undef NDEBUG +#include #ifdef _WIN32 #define _CRT_SECURE_NO_WARNINGS 1 @@ -6,8 +6,6 @@ #include #endif -#include - #include #include diff --git a/src/odbc/unittests/peter.c b/src/odbc/unittests/peter.c index 94aeb5b7ef..72ee115e99 100644 --- a/src/odbc/unittests/peter.c +++ b/src/odbc/unittests/peter.c @@ -1,4 +1,3 @@ -#undef NDEBUG #include "common.h" #include diff --git a/src/odbc/unittests/utf8_4.c b/src/odbc/unittests/utf8_4.c index 533df25eff..c3a94fd708 100644 --- a/src/odbc/unittests/utf8_4.c +++ b/src/odbc/unittests/utf8_4.c @@ -1,4 +1,3 @@ -#undef NDEBUG #include "common.h" #include #include diff --git a/src/replacements/unittests/strings.c b/src/replacements/unittests/strings.c index 8d9f6364b8..4cc4b0c985 100644 --- a/src/replacements/unittests/strings.c +++ b/src/replacements/unittests/strings.c @@ -17,8 +17,7 @@ * Boston, MA 02111-1307, USA. */ -#undef NDEBUG -#include +#include #include diff --git a/src/replacements/unittests/strsep.c b/src/replacements/unittests/strsep.c index d3d8ef15fc..2eab0c9f29 100644 --- a/src/replacements/unittests/strsep.c +++ b/src/replacements/unittests/strsep.c @@ -17,8 +17,7 @@ * Boston, MA 02111-1307, USA. */ -#undef NDEBUG -#include +#include #ifdef HAVE_STRSEP char *tds_strsep(char **stringp, const char *delim); diff --git a/src/replacements/unittests/strtok_r.c b/src/replacements/unittests/strtok_r.c index f8a159026c..c9b5e41bee 100644 --- a/src/replacements/unittests/strtok_r.c +++ b/src/replacements/unittests/strtok_r.c @@ -19,7 +19,7 @@ #define TDS_INTERNAL_TEST 1 -#include +#include #include #include diff --git a/src/tds/unittests/collations.c b/src/tds/unittests/collations.c index 7566d5b20b..3ddcf98156 100644 --- a/src/tds/unittests/collations.c +++ b/src/tds/unittests/collations.c @@ -16,12 +16,10 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#undef NDEBUG #include "common.h" #include #include -#undef NDEBUG #include #include diff --git a/src/tds/unittests/common.h b/src/tds/unittests/common.h index 8a2393f50d..aced4527e4 100644 --- a/src/tds/unittests/common.h +++ b/src/tds/unittests/common.h @@ -1,8 +1,7 @@ #ifndef _tdsguard_dxzbHKJsR5HKI0Qpzu7Vnq_ #define _tdsguard_dxzbHKJsR5HKI0Qpzu7Vnq_ -#undef NDEBUG -#include +#include #include #include diff --git a/src/tds/unittests/parsing.c b/src/tds/unittests/parsing.c index 9d110b345a..0be191b2f7 100644 --- a/src/tds/unittests/parsing.c +++ b/src/tds/unittests/parsing.c @@ -17,7 +17,7 @@ * Boston, MA 02111-1307, USA. */ -#undef NDEBUG +#include "common.h" /* allows to use some internal functions */ #include "../query.c" diff --git a/src/tds/unittests/tls.c b/src/tds/unittests/tls.c index b2c52a3dd1..3f43f523f4 100644 --- a/src/tds/unittests/tls.c +++ b/src/tds/unittests/tls.c @@ -20,6 +20,8 @@ /* * Check check_hostname function */ +#include "common.h" + #include "../tls.c" #include diff --git a/src/tds/unittests/utf8.c b/src/tds/unittests/utf8.c index 540b69d830..d7a8f191e6 100644 --- a/src/tds/unittests/utf8.c +++ b/src/tds/unittests/utf8.c @@ -16,7 +16,6 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#undef NDEBUG #define TDS_DONT_DEFINE_DEFAULT_FUNCTIONS #include "common.h" diff --git a/src/utils/unittests/bytes.c b/src/utils/unittests/bytes.c index 0a51fa63be..150165024b 100644 --- a/src/utils/unittests/bytes.c +++ b/src/utils/unittests/bytes.c @@ -20,8 +20,8 @@ /* * Purpose: test bytes.h header. */ -#undef NDEBUG -#include + +#include #include #include diff --git a/src/utils/unittests/challenge.c b/src/utils/unittests/challenge.c index 4607a8ada5..8ab3a9d339 100644 --- a/src/utils/unittests/challenge.c +++ b/src/utils/unittests/challenge.c @@ -20,8 +20,8 @@ /* * Purpose: test challenge code. */ -#undef NDEBUG -#include + +#include #include #include diff --git a/src/utils/unittests/condition.c b/src/utils/unittests/condition.c index a8e7fe8372..263b4e1686 100644 --- a/src/utils/unittests/condition.c +++ b/src/utils/unittests/condition.c @@ -17,7 +17,7 @@ * Boston, MA 02111-1307, USA. */ -#include +#include #include diff --git a/src/utils/unittests/dlist.c b/src/utils/unittests/dlist.c index 35fca0e46d..08a286d33d 100644 --- a/src/utils/unittests/dlist.c +++ b/src/utils/unittests/dlist.c @@ -20,8 +20,8 @@ /* * Purpose: test dlist code. */ -#undef NDEBUG -#include + +#include #include #include diff --git a/src/utils/unittests/mutex1.c b/src/utils/unittests/mutex1.c index 49bfd8a546..d41a86c0c5 100644 --- a/src/utils/unittests/mutex1.c +++ b/src/utils/unittests/mutex1.c @@ -17,7 +17,7 @@ * Boston, MA 02111-1307, USA. */ -#include +#include #include diff --git a/src/utils/unittests/passarg.c b/src/utils/unittests/passarg.c index e254d0a9cb..21b218aad3 100644 --- a/src/utils/unittests/passarg.c +++ b/src/utils/unittests/passarg.c @@ -16,8 +16,8 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#undef NDEBUG -#include + +#include #include diff --git a/src/utils/unittests/path.c b/src/utils/unittests/path.c index 15c02ca167..c48653f46f 100644 --- a/src/utils/unittests/path.c +++ b/src/utils/unittests/path.c @@ -20,8 +20,8 @@ /* * Purpose: test path utilities. */ -#undef NDEBUG -#include + +#include #include #include diff --git a/src/utils/unittests/smp.c b/src/utils/unittests/smp.c index e9efff8713..8460930786 100644 --- a/src/utils/unittests/smp.c +++ b/src/utils/unittests/smp.c @@ -20,8 +20,8 @@ /* * Purpose: test smp library. */ -#undef NDEBUG -#include + +#include #include #include From 1835fb397e5eca28eb4bcd4c93aca623d58f1c90 Mon Sep 17 00:00:00 2001 From: "Aaron M. Ucko" Date: Wed, 17 Jul 2024 13:31:26 -0400 Subject: [PATCH 3/6] unit tests: Formally designate entry points as TEST_MAIN(). Define it in the recently introduced (which now includes accordingly) as int main(int argc TDS_UNUSED, char **argv TDS_UNUSED) so that main can have the same signature in tests that ignore any arguments as in tests that consult arguments without yielding any warnings. Use this macro for all tests to pave the way for introducing a central main wrapper around what will then be a test-specific test_main. Signed-off-by: Aaron M. Ucko --- include/freetds/utils/test_base.h | 4 ++++ src/apps/unittests/defncopy.c | 2 +- src/ctlib/unittests/all_types.c | 3 +-- src/ctlib/unittests/array_bind.c | 3 +-- src/ctlib/unittests/blk_in.c | 3 +-- src/ctlib/unittests/blk_in2.c | 3 +-- src/ctlib/unittests/blk_out.c | 3 +-- src/ctlib/unittests/cancel.c | 6 ++---- src/ctlib/unittests/connect_fail.c | 3 +-- src/ctlib/unittests/cs_config.c | 3 +-- src/ctlib/unittests/cs_convert.c | 3 +-- src/ctlib/unittests/cs_diag.c | 3 +-- src/ctlib/unittests/ct_command.c | 3 +-- src/ctlib/unittests/ct_cursor.c | 3 +-- src/ctlib/unittests/ct_cursors.c | 3 +-- src/ctlib/unittests/ct_diagall.c | 3 +-- src/ctlib/unittests/ct_diagclient.c | 3 +-- src/ctlib/unittests/ct_diagserver.c | 3 +-- src/ctlib/unittests/ct_dynamic.c | 3 +-- src/ctlib/unittests/ct_options.c | 3 +-- src/ctlib/unittests/data.c | 3 +-- src/ctlib/unittests/datafmt.c | 3 +-- src/ctlib/unittests/errors.c | 3 +-- src/ctlib/unittests/get_send_data.c | 3 +-- src/ctlib/unittests/lang_ct_param.c | 3 +-- src/ctlib/unittests/long_binary.c | 3 +-- src/ctlib/unittests/row_count.c | 3 +-- src/ctlib/unittests/rpc_ct_param.c | 3 +-- src/ctlib/unittests/rpc_ct_setparam.c | 3 +-- src/ctlib/unittests/rpc_fail.c | 3 +-- src/ctlib/unittests/t0001.c | 3 +-- src/ctlib/unittests/t0002.c | 3 +-- src/ctlib/unittests/t0003.c | 3 +-- src/ctlib/unittests/t0004.c | 3 +-- src/ctlib/unittests/t0005.c | 3 +-- src/ctlib/unittests/t0007.c | 3 +-- src/ctlib/unittests/t0008.c | 3 +-- src/ctlib/unittests/t0009.c | 3 +-- src/ctlib/unittests/variant.c | 3 +-- src/ctlib/unittests/will_convert.c | 3 +-- src/dblib/unittests/batch_stmt_ins_sel.c | 3 +-- src/dblib/unittests/batch_stmt_ins_upd.c | 3 +-- src/dblib/unittests/bcp.c | 3 +-- src/dblib/unittests/bcp2.c | 3 +-- src/dblib/unittests/bcp_getl.c | 3 +-- src/dblib/unittests/cancel.c | 3 +-- src/dblib/unittests/canquery.c | 3 +-- src/dblib/unittests/colinfo.c | 3 +-- src/dblib/unittests/dbmorecmds.c | 3 +-- src/dblib/unittests/dbsafestr.c | 5 ++--- src/dblib/unittests/done_handling.c | 3 +-- src/dblib/unittests/empty_rowsets.c | 3 +-- src/dblib/unittests/hang.c | 6 ++---- src/dblib/unittests/null.c | 5 ++--- src/dblib/unittests/null2.c | 3 +-- src/dblib/unittests/numeric.c | 3 +-- src/dblib/unittests/pending.c | 3 +-- src/dblib/unittests/proc_limit.c | 3 +-- src/dblib/unittests/rpc.c | 3 +-- src/dblib/unittests/setnull.c | 3 +-- src/dblib/unittests/spid.c | 3 +-- src/dblib/unittests/string_bind.c | 3 +-- src/dblib/unittests/t0001.c | 3 +-- src/dblib/unittests/t0002.c | 3 +-- src/dblib/unittests/t0003.c | 3 +-- src/dblib/unittests/t0004.c | 3 +-- src/dblib/unittests/t0005.c | 3 +-- src/dblib/unittests/t0006.c | 3 +-- src/dblib/unittests/t0007.c | 3 +-- src/dblib/unittests/t0008.c | 3 +-- src/dblib/unittests/t0009.c | 3 +-- src/dblib/unittests/t0011.c | 3 +-- src/dblib/unittests/t0012.c | 3 +-- src/dblib/unittests/t0013.c | 3 +-- src/dblib/unittests/t0014.c | 3 +-- src/dblib/unittests/t0015.c | 3 +-- src/dblib/unittests/t0016.c | 3 +-- src/dblib/unittests/t0017.c | 3 +-- src/dblib/unittests/t0018.c | 3 +-- src/dblib/unittests/t0019.c | 3 +-- src/dblib/unittests/t0020.c | 3 +-- src/dblib/unittests/t0022.c | 3 +-- src/dblib/unittests/t0023.c | 3 +-- src/dblib/unittests/text_buffer.c | 3 +-- src/dblib/unittests/thread.c | 6 ++---- src/dblib/unittests/timeout.c | 3 +-- src/odbc/unittests/all_types.c | 3 +-- src/odbc/unittests/array.c | 3 +-- src/odbc/unittests/array_error.c | 3 +-- src/odbc/unittests/array_out.c | 3 +-- src/odbc/unittests/attributes.c | 3 +-- src/odbc/unittests/bcp.c | 3 +-- src/odbc/unittests/binary_test.c | 3 +-- src/odbc/unittests/blob1.c | 3 +-- src/odbc/unittests/cancel.c | 6 ++---- src/odbc/unittests/closestmt.c | 3 +-- src/odbc/unittests/compute.c | 3 +-- src/odbc/unittests/connect.c | 3 +-- src/odbc/unittests/connect2.c | 3 +-- src/odbc/unittests/connection_string_parse.c | 3 +-- src/odbc/unittests/const_params.c | 3 +-- src/odbc/unittests/convert_error.c | 3 +-- src/odbc/unittests/copydesc.c | 3 +-- src/odbc/unittests/cursor1.c | 3 +-- src/odbc/unittests/cursor2.c | 3 +-- src/odbc/unittests/cursor3.c | 3 +-- src/odbc/unittests/cursor4.c | 3 +-- src/odbc/unittests/cursor5.c | 3 +-- src/odbc/unittests/cursor6.c | 3 +-- src/odbc/unittests/cursor7.c | 3 +-- src/odbc/unittests/data.c | 3 +-- src/odbc/unittests/date.c | 3 +-- src/odbc/unittests/descrec.c | 3 +-- src/odbc/unittests/describecol.c | 3 +-- src/odbc/unittests/describecol2.c | 3 +-- src/odbc/unittests/earlybind.c | 3 +-- src/odbc/unittests/empty_query.c | 3 +-- src/odbc/unittests/error.c | 3 +-- src/odbc/unittests/freeclose.c | 6 ++---- src/odbc/unittests/funccall.c | 3 +-- src/odbc/unittests/genparams.c | 3 +-- src/odbc/unittests/getdata.c | 3 +-- src/odbc/unittests/hidden.c | 3 +-- src/odbc/unittests/insert_speed.c | 3 +-- src/odbc/unittests/lang_error.c | 3 +-- src/odbc/unittests/long_error.c | 3 +-- src/odbc/unittests/mars1.c | 3 +-- src/odbc/unittests/moreandcount.c | 3 +-- src/odbc/unittests/moreresults.c | 3 +-- src/odbc/unittests/norowset.c | 3 +-- src/odbc/unittests/oldpwd.c | 3 +-- src/odbc/unittests/paramcore.c | 3 +-- src/odbc/unittests/params.c | 3 +-- src/odbc/unittests/peter.c | 3 +-- src/odbc/unittests/prepare_results.c | 3 +-- src/odbc/unittests/prepare_warn.c | 3 +-- src/odbc/unittests/prepclose.c | 3 +-- src/odbc/unittests/preperror.c | 3 +-- src/odbc/unittests/print.c | 3 +-- src/odbc/unittests/putdata.c | 3 +-- src/odbc/unittests/qn.c | 5 ++--- src/odbc/unittests/raiserror.c | 3 +-- src/odbc/unittests/rebindpar.c | 3 +-- src/odbc/unittests/rowset.c | 3 +-- src/odbc/unittests/rpc.c | 3 +-- src/odbc/unittests/scroll.c | 3 +-- src/odbc/unittests/stats.c | 3 +-- src/odbc/unittests/t0001.c | 3 +-- src/odbc/unittests/t0002.c | 3 +-- src/odbc/unittests/t0003.c | 3 +-- src/odbc/unittests/tables.c | 3 +-- src/odbc/unittests/test64.c | 3 +-- src/odbc/unittests/testodbc.c | 3 +-- src/odbc/unittests/timeout.c | 3 +-- src/odbc/unittests/timeout2.c | 3 +-- src/odbc/unittests/timeout3.c | 6 ++---- src/odbc/unittests/timeout4.c | 6 ++---- src/odbc/unittests/transaction.c | 3 +-- src/odbc/unittests/transaction2.c | 3 +-- src/odbc/unittests/transaction3.c | 2 +- src/odbc/unittests/transaction4.c | 3 +-- src/odbc/unittests/tvp.c | 3 +-- src/odbc/unittests/type.c | 3 +-- src/odbc/unittests/typeinfo.c | 3 +-- src/odbc/unittests/utf8.c | 6 ++---- src/odbc/unittests/utf8_2.c | 3 +-- src/odbc/unittests/utf8_3.c | 3 +-- src/odbc/unittests/utf8_4.c | 3 +-- src/odbc/unittests/warning.c | 3 +-- src/odbc/unittests/wchar.c | 3 +-- src/replacements/unittests/strings.c | 2 +- src/replacements/unittests/strsep.c | 3 +-- src/replacements/unittests/strtok_r.c | 3 +-- src/tds/unittests/charconv.c | 3 +-- src/tds/unittests/collations.c | 3 +-- src/tds/unittests/convert.c | 3 +-- src/tds/unittests/convert_bounds.c | 3 +-- src/tds/unittests/corrupt.c | 3 +-- src/tds/unittests/dataread.c | 3 +-- src/tds/unittests/declarations.c | 3 +-- src/tds/unittests/dynamic1.c | 3 +-- src/tds/unittests/freeze.c | 5 ++--- src/tds/unittests/iconv_fread.c | 3 +-- src/tds/unittests/log_elision.c | 3 +-- src/tds/unittests/nulls.c | 3 +-- src/tds/unittests/numeric.c | 3 +-- src/tds/unittests/parsing.c | 3 +-- src/tds/unittests/portconf.c | 3 +-- src/tds/unittests/readconf.c | 3 +-- src/tds/unittests/strftime.c | 3 +-- src/tds/unittests/t0001.c | 3 +-- src/tds/unittests/t0002.c | 3 +-- src/tds/unittests/t0003.c | 3 +-- src/tds/unittests/t0004.c | 3 +-- src/tds/unittests/t0005.c | 3 +-- src/tds/unittests/t0006.c | 3 +-- src/tds/unittests/t0007.c | 3 +-- src/tds/unittests/t0008.c | 3 +-- src/tds/unittests/tls.c | 6 ++---- src/tds/unittests/toodynamic.c | 3 +-- src/tds/unittests/utf8_1.c | 3 +-- src/tds/unittests/utf8_2.c | 3 +-- src/tds/unittests/utf8_3.c | 3 +-- src/utils/unittests/bytes.c | 3 +-- src/utils/unittests/challenge.c | 3 +-- src/utils/unittests/condition.c | 4 ++-- src/utils/unittests/dlist.c | 3 +-- src/utils/unittests/mutex1.c | 4 ++-- src/utils/unittests/passarg.c | 2 +- src/utils/unittests/path.c | 2 +- src/utils/unittests/smp.c | 2 +- 211 files changed, 229 insertions(+), 436 deletions(-) diff --git a/include/freetds/utils/test_base.h b/include/freetds/utils/test_base.h index 2717997cff..c8cbefdf0c 100644 --- a/include/freetds/utils/test_base.h +++ b/include/freetds/utils/test_base.h @@ -15,4 +15,8 @@ #include +#include + +#define TEST_MAIN() int main(int argc TDS_UNUSED, char **argv TDS_UNUSED) + #endif /* _tdsguard_afBM6E9n8CuIFSBHNNblq5 */ diff --git a/src/apps/unittests/defncopy.c b/src/apps/unittests/defncopy.c index 3b6982d476..cd51d9ff2a 100644 --- a/src/apps/unittests/defncopy.c +++ b/src/apps/unittests/defncopy.c @@ -412,7 +412,7 @@ test_weird_index_names(void) tsql(clean); } -int main(void) +TEST_MAIN() { FILE *f; diff --git a/src/ctlib/unittests/all_types.c b/src/ctlib/unittests/all_types.c index 8431b28f02..96d01b3a7d 100644 --- a/src/ctlib/unittests/all_types.c +++ b/src/ctlib/unittests/all_types.c @@ -61,8 +61,7 @@ static void test_type(TDSSOCKET *tds TDS_UNUSED, TDSCOLUMN *col) tds_free_results(bindinfo); } -int -main(void) +TEST_MAIN() { TDSCONTEXT *tds_ctx; TDSSOCKET *tds; diff --git a/src/ctlib/unittests/array_bind.c b/src/ctlib/unittests/array_bind.c index 71daf5aca1..4fbad661cf 100644 --- a/src/ctlib/unittests/array_bind.c +++ b/src/ctlib/unittests/array_bind.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: array binding of result set */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/blk_in.c b/src/ctlib/unittests/blk_in.c index 3d2e5a7336..82d7359e73 100644 --- a/src/ctlib/unittests/blk_in.c +++ b/src/ctlib/unittests/blk_in.c @@ -184,8 +184,7 @@ do_bind(CS_BLKDESC * blkdesc, int colnum, CS_INT host_format, CS_INT host_type, } -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/blk_in2.c b/src/ctlib/unittests/blk_in2.c index 729f901d98..e7c4defb3c 100644 --- a/src/ctlib/unittests/blk_in2.c +++ b/src/ctlib/unittests/blk_in2.c @@ -34,8 +34,7 @@ hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data) check_call(blk_done, (blk, CS_BLK_ALL, &row)); } -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/blk_out.c b/src/ctlib/unittests/blk_out.c index b3bbff2f5d..c6f517e3ca 100644 --- a/src/ctlib/unittests/blk_out.c +++ b/src/ctlib/unittests/blk_out.c @@ -3,8 +3,7 @@ #include /* Testing: array binding of result set */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/cancel.c b/src/ctlib/unittests/cancel.c index c272d7e515..7f6d4b0594 100644 --- a/src/ctlib/unittests/cancel.c +++ b/src/ctlib/unittests/cancel.c @@ -36,8 +36,7 @@ catch_alrm(int sig_num TDS_UNUSED) } /* Testing: Test asynchronous ct_cancel() */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; @@ -190,8 +189,7 @@ do_fetch(CS_COMMAND * cmd, int *cnt) #else -int -main(void) +TEST_MAIN() { return 0; } diff --git a/src/ctlib/unittests/connect_fail.c b/src/ctlib/unittests/connect_fail.c index 3027ef17c0..0a8bb953dc 100644 --- a/src/ctlib/unittests/connect_fail.c +++ b/src/ctlib/unittests/connect_fail.c @@ -1,7 +1,6 @@ #include "common.h" -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/cs_config.c b/src/ctlib/unittests/cs_config.c index 0544e32a9d..8837136041 100644 --- a/src/ctlib/unittests/cs_config.c +++ b/src/ctlib/unittests/cs_config.c @@ -2,8 +2,7 @@ #include -int -main(void) +TEST_MAIN() { int verbose = 1; CS_CONTEXT *ctx; diff --git a/src/ctlib/unittests/cs_convert.c b/src/ctlib/unittests/cs_convert.c index a653b0b4af..4c2c50d08c 100644 --- a/src/ctlib/unittests/cs_convert.c +++ b/src/ctlib/unittests/cs_convert.c @@ -122,8 +122,7 @@ DoTest( __LINE__);\ } -int -main(void) +TEST_MAIN() { volatile CS_BIGINT one = 1; int verbose = 1; diff --git a/src/ctlib/unittests/cs_diag.c b/src/ctlib/unittests/cs_diag.c index 96dc6f8522..e6c582f01f 100644 --- a/src/ctlib/unittests/cs_diag.c +++ b/src/ctlib/unittests/cs_diag.c @@ -7,8 +7,7 @@ * ct_bind variable * ct_fetch and print results */ -int -main(void) +TEST_MAIN() { int verbose = 1; CS_CONTEXT *ctx; diff --git a/src/ctlib/unittests/ct_command.c b/src/ctlib/unittests/ct_command.c index b3b65a187b..ef09f880bc 100644 --- a/src/ctlib/unittests/ct_command.c +++ b/src/ctlib/unittests/ct_command.c @@ -5,8 +5,7 @@ /* * ct_command with CS_MORE option */ -int -main(void) +TEST_MAIN() { int verbose = 0; CS_CONTEXT *ctx; diff --git a/src/ctlib/unittests/ct_cursor.c b/src/ctlib/unittests/ct_cursor.c index df9b3bd275..90e5e13792 100644 --- a/src/ctlib/unittests/ct_cursor.c +++ b/src/ctlib/unittests/ct_cursor.c @@ -2,8 +2,7 @@ static int update_second_table(CS_COMMAND * cmd2, char *value); -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/ct_cursors.c b/src/ctlib/unittests/ct_cursors.c index 6077a18ff4..319db92930 100644 --- a/src/ctlib/unittests/ct_cursors.c +++ b/src/ctlib/unittests/ct_cursors.c @@ -1,7 +1,6 @@ #include "common.h" -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/ct_diagall.c b/src/ctlib/unittests/ct_diagall.c index cc1f19d001..10285e2627 100644 --- a/src/ctlib/unittests/ct_diagall.c +++ b/src/ctlib/unittests/ct_diagall.c @@ -3,8 +3,7 @@ #include /* Testing: Client and server Messages */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/ct_diagclient.c b/src/ctlib/unittests/ct_diagclient.c index 3266643e3b..4cbb2fcf3c 100644 --- a/src/ctlib/unittests/ct_diagclient.c +++ b/src/ctlib/unittests/ct_diagclient.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: Client Messages */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/ct_diagserver.c b/src/ctlib/unittests/ct_diagserver.c index 5c52aa33b4..1e9f6ef420 100644 --- a/src/ctlib/unittests/ct_diagserver.c +++ b/src/ctlib/unittests/ct_diagserver.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: Server messages limit */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/ct_dynamic.c b/src/ctlib/unittests/ct_dynamic.c index e32cf93291..f5e05ceb3e 100644 --- a/src/ctlib/unittests/ct_dynamic.c +++ b/src/ctlib/unittests/ct_dynamic.c @@ -38,8 +38,7 @@ chk(int check, const char *fmt, ...) exit(1); } -int -main(int argc, char *argv[]) +TEST_MAIN() { int errCode = 1; diff --git a/src/ctlib/unittests/ct_options.c b/src/ctlib/unittests/ct_options.c index ce6f308665..243086025c 100644 --- a/src/ctlib/unittests/ct_options.c +++ b/src/ctlib/unittests/ct_options.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: Set and get options with ct_options */ -int -main(int argc, char *argv[]) +TEST_MAIN() { int verbose = 0; diff --git a/src/ctlib/unittests/data.c b/src/ctlib/unittests/data.c index 81a0fe78b7..7e25ba5249 100644 --- a/src/ctlib/unittests/data.c +++ b/src/ctlib/unittests/data.c @@ -1,8 +1,7 @@ /* Test some data from server. Currently tests MS XML type */ #include "common.h" -int -main(int argc, char *argv[]) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/datafmt.c b/src/ctlib/unittests/datafmt.c index fcf82795ad..fff1659619 100644 --- a/src/ctlib/unittests/datafmt.c +++ b/src/ctlib/unittests/datafmt.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: data truncation behavior of ct_fetch */ -int -main(int argc, char *argv[]) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/errors.c b/src/ctlib/unittests/errors.c index 5ca3a50494..e4f7500e1a 100644 --- a/src/ctlib/unittests/errors.c +++ b/src/ctlib/unittests/errors.c @@ -38,8 +38,7 @@ static CS_CONTEXT *ctx; static CS_CONNECTION *conn; static CS_COMMAND *cmd; -int -main(void) +TEST_MAIN() { int verbose = 1; diff --git a/src/ctlib/unittests/get_send_data.c b/src/ctlib/unittests/get_send_data.c index d9ff33c3fa..3d264e86eb 100644 --- a/src/ctlib/unittests/get_send_data.c +++ b/src/ctlib/unittests/get_send_data.c @@ -5,8 +5,7 @@ static CS_CONNECTION *conn = NULL; /* Testing: Retrieve CS_TEXT_TYPE using ct_bind() */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_COMMAND *cmd; diff --git a/src/ctlib/unittests/lang_ct_param.c b/src/ctlib/unittests/lang_ct_param.c index e77f61e97d..89ca4b8e06 100644 --- a/src/ctlib/unittests/lang_ct_param.c +++ b/src/ctlib/unittests/lang_ct_param.c @@ -8,8 +8,7 @@ static const char *query = static int insert_test(CS_CONNECTION *conn, CS_COMMAND *cmd, int useNames); /* Testing: binding of data via ct_param */ -int -main(int argc, char *argv[]) +TEST_MAIN() { int errCode = 0; diff --git a/src/ctlib/unittests/long_binary.c b/src/ctlib/unittests/long_binary.c index b91ab777ef..dfa67f2124 100644 --- a/src/ctlib/unittests/long_binary.c +++ b/src/ctlib/unittests/long_binary.c @@ -50,8 +50,7 @@ execute_sql(CS_COMMAND * command, const char *sql) return fetch_results(command); } -int -main(int argc, char **argv) +TEST_MAIN() { int verbose = 0; CS_COMMAND *command; diff --git a/src/ctlib/unittests/row_count.c b/src/ctlib/unittests/row_count.c index 4b5dccee04..5b07b0de40 100644 --- a/src/ctlib/unittests/row_count.c +++ b/src/ctlib/unittests/row_count.c @@ -64,8 +64,7 @@ static CS_INT ex_display_results(CS_COMMAND * cmd, char *results); static int test(int final_rows, int no_rows); -int -main(void) +TEST_MAIN() { printf("%s: check row count returned\n", __FILE__); check_call(try_ctlogin, (&ctx, &conn, &cmd, 0)); diff --git a/src/ctlib/unittests/rpc_ct_param.c b/src/ctlib/unittests/rpc_ct_param.c index 42149edca7..0434ca55a8 100644 --- a/src/ctlib/unittests/rpc_ct_param.c +++ b/src/ctlib/unittests/rpc_ct_param.c @@ -15,8 +15,7 @@ typedef struct _ex_column_data EX_COLUMN_DATA; /* Testing: array binding of result set */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/rpc_ct_setparam.c b/src/ctlib/unittests/rpc_ct_setparam.c index 1baf582345..693b63bba4 100644 --- a/src/ctlib/unittests/rpc_ct_setparam.c +++ b/src/ctlib/unittests/rpc_ct_setparam.c @@ -16,8 +16,7 @@ typedef struct _ex_column_data EX_COLUMN_DATA; /* Testing: array binding of result set */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/rpc_fail.c b/src/ctlib/unittests/rpc_fail.c index 7be1c6da33..13fffc5762 100644 --- a/src/ctlib/unittests/rpc_fail.c +++ b/src/ctlib/unittests/rpc_fail.c @@ -1,7 +1,6 @@ #include "common.h" -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/t0001.c b/src/ctlib/unittests/t0001.c index e00212aee7..4395771816 100644 --- a/src/ctlib/unittests/t0001.c +++ b/src/ctlib/unittests/t0001.c @@ -1,7 +1,6 @@ #include "common.h" -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/t0002.c b/src/ctlib/unittests/t0002.c index 011ced86d0..4856e8a88a 100644 --- a/src/ctlib/unittests/t0002.c +++ b/src/ctlib/unittests/t0002.c @@ -7,8 +7,7 @@ static int sp_who(CS_COMMAND *cmd); * ct_bind variable * ct_fetch and print results */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/t0003.c b/src/ctlib/unittests/t0003.c index 2c2709314e..9e9a3eac2a 100644 --- a/src/ctlib/unittests/t0003.c +++ b/src/ctlib/unittests/t0003.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: Retrieve CS_TEXT_TYPE using ct_bind() */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/t0004.c b/src/ctlib/unittests/t0004.c index 998832f02c..73dc0c2b05 100644 --- a/src/ctlib/unittests/t0004.c +++ b/src/ctlib/unittests/t0004.c @@ -8,8 +8,7 @@ CS_RETCODE do_results(CS_COMMAND * cmd, CS_INT * results); #define NUMROWS 5 /* Testing: Test order of ct_results() */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/t0005.c b/src/ctlib/unittests/t0005.c index 1065ace3fc..ec4b88d591 100644 --- a/src/ctlib/unittests/t0005.c +++ b/src/ctlib/unittests/t0005.c @@ -2,8 +2,7 @@ #include "common.h" -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/t0007.c b/src/ctlib/unittests/t0007.c index 2aea865239..f301f3356b 100644 --- a/src/ctlib/unittests/t0007.c +++ b/src/ctlib/unittests/t0007.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: Retrieve CS_TEXT_TYPE using ct_bind() */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/t0008.c b/src/ctlib/unittests/t0008.c index 23f34f54c0..6c06dd7235 100644 --- a/src/ctlib/unittests/t0008.c +++ b/src/ctlib/unittests/t0008.c @@ -7,8 +7,7 @@ * ct_bind variable * ct_fetch and print results */ -int -main(void) +TEST_MAIN() { int verbose = 1; CS_CONTEXT *ctx; diff --git a/src/ctlib/unittests/t0009.c b/src/ctlib/unittests/t0009.c index cdfdd3288e..4d222cd9ac 100644 --- a/src/ctlib/unittests/t0009.c +++ b/src/ctlib/unittests/t0009.c @@ -4,8 +4,7 @@ static CS_RETCODE ex_servermsg_cb(CS_CONTEXT * context, CS_CONNECTION * connecti static int compute_supported = 1; /* Testing: Retrieve compute results */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/variant.c b/src/ctlib/unittests/variant.c index 3970323276..89b2ee868d 100644 --- a/src/ctlib/unittests/variant.c +++ b/src/ctlib/unittests/variant.c @@ -1,8 +1,7 @@ #include "common.h" /* Testing: Retrieving SQL_VARIANT */ -int -main(void) +TEST_MAIN() { CS_CONTEXT *ctx; CS_CONNECTION *conn; diff --git a/src/ctlib/unittests/will_convert.c b/src/ctlib/unittests/will_convert.c index fcf3e2246f..bb9b4c7cb4 100644 --- a/src/ctlib/unittests/will_convert.c +++ b/src/ctlib/unittests/will_convert.c @@ -128,8 +128,7 @@ test(CS_INT from, CS_INT to, CS_BOOL expected) } } -int -main(void) +TEST_MAIN() { int verbose = 0; CS_COMMAND *command; diff --git a/src/dblib/unittests/batch_stmt_ins_sel.c b/src/dblib/unittests/batch_stmt_ins_sel.c index 5902dfd074..da008959ff 100644 --- a/src/dblib/unittests/batch_stmt_ins_sel.c +++ b/src/dblib/unittests/batch_stmt_ins_sel.c @@ -6,8 +6,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/batch_stmt_ins_upd.c b/src/dblib/unittests/batch_stmt_ins_upd.c index 570826b2c9..0517071e20 100644 --- a/src/dblib/unittests/batch_stmt_ins_upd.c +++ b/src/dblib/unittests/batch_stmt_ins_upd.c @@ -6,8 +6,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/bcp.c b/src/dblib/unittests/bcp.c index 3644fa5fb2..05469a7342 100644 --- a/src/dblib/unittests/bcp.c +++ b/src/dblib/unittests/bcp.c @@ -161,8 +161,7 @@ test_bind(DBPROCESS * dbproc) } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/bcp2.c b/src/dblib/unittests/bcp2.c index 752fc051da..3f4e51e022 100644 --- a/src/dblib/unittests/bcp2.c +++ b/src/dblib/unittests/bcp2.c @@ -40,8 +40,7 @@ init(DBPROCESS * dbproc, const char *name) return 0; } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/bcp_getl.c b/src/dblib/unittests/bcp_getl.c index 3e167af165..9bba97de91 100644 --- a/src/dblib/unittests/bcp_getl.c +++ b/src/dblib/unittests/bcp_getl.c @@ -1,8 +1,7 @@ #include "common.h" -int -main(void) +TEST_MAIN() { LOGINREC *c = dblogin(); BCP_SETL(c, TRUE); diff --git a/src/dblib/unittests/cancel.c b/src/dblib/unittests/cancel.c index 2ec285138a..1eb213b49c 100644 --- a/src/dblib/unittests/cancel.c +++ b/src/dblib/unittests/cancel.c @@ -14,8 +14,7 @@ cancel_msg_handler(DBPROCESS * dbproc, DBINT msgno TDS_UNUSED, int msgstate TDS_ return 0; } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/canquery.c b/src/dblib/unittests/canquery.c index c433184d6a..e66baae8f4 100644 --- a/src/dblib/unittests/canquery.c +++ b/src/dblib/unittests/canquery.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/colinfo.c b/src/dblib/unittests/colinfo.c index 73f62e73ae..34074cc9ae 100644 --- a/src/dblib/unittests/colinfo.c +++ b/src/dblib/unittests/colinfo.c @@ -27,8 +27,7 @@ check_contains(const char *value, const char *expected) fprintf(stderr, "Wrong value, got \"%s\" expected to contains \"%s\"\n", value, expected); } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/dbmorecmds.c b/src/dblib/unittests/dbmorecmds.c index 2385e83325..553e31971d 100644 --- a/src/dblib/unittests/dbmorecmds.c +++ b/src/dblib/unittests/dbmorecmds.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { const int rows_to_add = 10; LOGINREC *login; diff --git a/src/dblib/unittests/dbsafestr.c b/src/dblib/unittests/dbsafestr.c index dd25e75149..1c11ebe297 100644 --- a/src/dblib/unittests/dbsafestr.c +++ b/src/dblib/unittests/dbsafestr.c @@ -15,8 +15,7 @@ static const char *unsafestr = "This is a string with ' and \" in it."; /* safestr must be at least strlen(unsafestr) + 3 */ static char safestr[100]; -int -main(int argc TDS_UNUSED, char **argv) +TEST_MAIN() { int len; RETCODE ret; @@ -62,7 +61,7 @@ main(int argc TDS_UNUSED, char **argv) return failed ? 1 : 0; } #else -int main(void) +TEST_MAIN() { fprintf(stderr, "Not supported by MS DBLib\n"); return 0; diff --git a/src/dblib/unittests/done_handling.c b/src/dblib/unittests/done_handling.c index bdfd600c0a..424a45dfba 100644 --- a/src/dblib/unittests/done_handling.c +++ b/src/dblib/unittests/done_handling.c @@ -140,8 +140,7 @@ do_test(const char comment[]) check_state("more results?", print_with, ret); } -int -main(int argc, char *argv[]) +TEST_MAIN() { static const int invalid_column_name = 207; LOGINREC *login; /* Our login information. */ diff --git a/src/dblib/unittests/empty_rowsets.c b/src/dblib/unittests/empty_rowsets.c index 228fb32847..e6fc36ecc4 100644 --- a/src/dblib/unittests/empty_rowsets.c +++ b/src/dblib/unittests/empty_rowsets.c @@ -13,8 +13,7 @@ static void set_failed(int line) } #define set_failed() set_failed(__LINE__) -int -main(int argc, char *argv[]) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/hang.c b/src/dblib/unittests/hang.c index ce30d1d900..0835c565ed 100644 --- a/src/dblib/unittests/hang.c +++ b/src/dblib/unittests/hang.c @@ -140,8 +140,7 @@ test(int close_socket) return 0; } -int -main(int argc, char **argv) +TEST_MAIN() { UNITTEST = argv[0]; read_login_info(argc, argv); @@ -151,8 +150,7 @@ main(int argc, char **argv) } #else -int -main(void) +TEST_MAIN() { fprintf(stderr, "Not possible for this platform.\n"); return 0; diff --git a/src/dblib/unittests/null.c b/src/dblib/unittests/null.c index adfa894d00..ecd29139a5 100644 --- a/src/dblib/unittests/null.c +++ b/src/dblib/unittests/null.c @@ -136,8 +136,7 @@ test(const char *type, int give_err) query("drop table #null"); } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; @@ -185,7 +184,7 @@ main(int argc, char **argv) return failed ? 1 : 0; } #else -int main(void) +TEST_MAIN() { fprintf(stderr, "Not supported by MS DBLib\n"); return 0; diff --git a/src/dblib/unittests/null2.c b/src/dblib/unittests/null2.c index a81fa7796b..81b8bdf152 100644 --- a/src/dblib/unittests/null2.c +++ b/src/dblib/unittests/null2.c @@ -146,8 +146,7 @@ test(const char *type, int give_err) query("drop table #null"); } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; diff --git a/src/dblib/unittests/numeric.c b/src/dblib/unittests/numeric.c index 9f9e7fba44..ff53b57cf7 100644 --- a/src/dblib/unittests/numeric.c +++ b/src/dblib/unittests/numeric.c @@ -167,8 +167,7 @@ test(int bind_type, const char *bind_name, int override_prec, int override_scale #define test(a,b,c,d,e) test(a, #a, b, c, d, e, __LINE__) -int -main(int argc, char **argv) +TEST_MAIN() { read_login_info(argc, argv); diff --git a/src/dblib/unittests/pending.c b/src/dblib/unittests/pending.c index facf2b2a92..8f2abf1770 100644 --- a/src/dblib/unittests/pending.c +++ b/src/dblib/unittests/pending.c @@ -6,8 +6,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/proc_limit.c b/src/dblib/unittests/proc_limit.c index 1a8fc409f3..be6768cf68 100644 --- a/src/dblib/unittests/proc_limit.c +++ b/src/dblib/unittests/proc_limit.c @@ -25,8 +25,7 @@ err_handler(DBPROCESS * dbproc TDS_UNUSED, int severity, int dberr, int oserr, c return INT_CANCEL; } -int -main(int argc, char *argv[]) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc, *dbproc2; diff --git a/src/dblib/unittests/rpc.c b/src/dblib/unittests/rpc.c index e5c7965920..4aba3e0fc7 100644 --- a/src/dblib/unittests/rpc.c +++ b/src/dblib/unittests/rpc.c @@ -167,8 +167,7 @@ bind_param(DBPROCESS *dbproc, struct parameters_t *pb) } } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/setnull.c b/src/dblib/unittests/setnull.c index c3049d096b..daf691e93d 100644 --- a/src/dblib/unittests/setnull.c +++ b/src/dblib/unittests/setnull.c @@ -64,8 +64,7 @@ char_test(const char *null, int bindlen, const char *expected) } } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBINT db_i; diff --git a/src/dblib/unittests/spid.c b/src/dblib/unittests/spid.c index c7ed5f3083..4ffdea2b97 100644 --- a/src/dblib/unittests/spid.c +++ b/src/dblib/unittests/spid.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/string_bind.c b/src/dblib/unittests/string_bind.c index 9e200277c2..427bf8bc73 100644 --- a/src/dblib/unittests/string_bind.c +++ b/src/dblib/unittests/string_bind.c @@ -70,8 +70,7 @@ test_row(int vartype, const char *vartype_name, const char *expected, int line) #define row(bind, expected) test_row(bind, #bind, expected, __LINE__) -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; diff --git a/src/dblib/unittests/t0001.c b/src/dblib/unittests/t0001.c index b6b5c4272a..bc53ed9c82 100644 --- a/src/dblib/unittests/t0001.c +++ b/src/dblib/unittests/t0001.c @@ -8,8 +8,7 @@ int failed = 0; -int -main(int argc, char **argv) +TEST_MAIN() { const int rows_to_add = 50; LOGINREC *login; diff --git a/src/dblib/unittests/t0002.c b/src/dblib/unittests/t0002.c index 0138e463ac..e6e1d8487d 100644 --- a/src/dblib/unittests/t0002.c +++ b/src/dblib/unittests/t0002.c @@ -32,8 +32,7 @@ verify(int i, int testint, char *teststr) printf("Read a row of data -> %d %s\n", testint, teststr); } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/t0003.c b/src/dblib/unittests/t0003.c index cc0b5c3afc..d10f6a2c02 100644 --- a/src/dblib/unittests/t0003.c +++ b/src/dblib/unittests/t0003.c @@ -8,8 +8,7 @@ int failed = 0; -int -main(int argc, char **argv) +TEST_MAIN() { RETCODE rc; const int rows_to_add = 50; diff --git a/src/dblib/unittests/t0004.c b/src/dblib/unittests/t0004.c index f827764412..13de8f3a99 100644 --- a/src/dblib/unittests/t0004.c +++ b/src/dblib/unittests/t0004.c @@ -6,8 +6,7 @@ #include "common.h" #include -int -main(int argc, char **argv) +TEST_MAIN() { const int rows_to_add = 50; LOGINREC *login; diff --git a/src/dblib/unittests/t0005.c b/src/dblib/unittests/t0005.c index 40f3835f31..ae96bd0d46 100644 --- a/src/dblib/unittests/t0005.c +++ b/src/dblib/unittests/t0005.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { const int rows_to_add = 50; LOGINREC *login; diff --git a/src/dblib/unittests/t0006.c b/src/dblib/unittests/t0006.c index 5c07904ee3..411140849d 100644 --- a/src/dblib/unittests/t0006.c +++ b/src/dblib/unittests/t0006.c @@ -35,8 +35,7 @@ get_results(DBPROCESS * dbproc, int start) } -int -main(int argc, char **argv) +TEST_MAIN() { RETCODE rc; const int rows_to_add = 50; diff --git a/src/dblib/unittests/t0007.c b/src/dblib/unittests/t0007.c index 9ca7092eea..67c33a94ee 100644 --- a/src/dblib/unittests/t0007.c +++ b/src/dblib/unittests/t0007.c @@ -60,8 +60,7 @@ hex_buffer(BYTE *binarybuffer, int size, char *textbuf) return textbuf; /* convenience */ } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/t0008.c b/src/dblib/unittests/t0008.c index 58968c363b..ad62a30145 100644 --- a/src/dblib/unittests/t0008.c +++ b/src/dblib/unittests/t0008.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { const int rows_to_add = 48; LOGINREC *login; diff --git a/src/dblib/unittests/t0009.c b/src/dblib/unittests/t0009.c index d3b52e0977..9eb673e8ee 100644 --- a/src/dblib/unittests/t0009.c +++ b/src/dblib/unittests/t0009.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/t0011.c b/src/dblib/unittests/t0011.c index dc4d6fd73e..0a56e4db70 100644 --- a/src/dblib/unittests/t0011.c +++ b/src/dblib/unittests/t0011.c @@ -11,8 +11,7 @@ static int failed = 0; static void insert_row(DBPROCESS * dbproc); static int select_rows(DBPROCESS * dbproc, int bind_type); -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/t0012.c b/src/dblib/unittests/t0012.c index c3fabf5f9b..4d68f2f34f 100644 --- a/src/dblib/unittests/t0012.c +++ b/src/dblib/unittests/t0012.c @@ -35,8 +35,7 @@ ignore_msg_handler(DBPROCESS * dbproc TDS_UNUSED, DBINT msgno TDS_UNUSED, int st } #endif -int -main(int argc, char *argv[]) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/t0013.c b/src/dblib/unittests/t0013.c index 69d9ed88e6..1e46a85eb4 100644 --- a/src/dblib/unittests/t0013.c +++ b/src/dblib/unittests/t0013.c @@ -283,8 +283,7 @@ test(int argc, char **argv, int over4k) return 0; } -int -main(int argc, char **argv) +TEST_MAIN() { int res = test(argc, argv, 0); if (!res) diff --git a/src/dblib/unittests/t0014.c b/src/dblib/unittests/t0014.c index 0c494155df..206904fe5e 100644 --- a/src/dblib/unittests/t0014.c +++ b/src/dblib/unittests/t0014.c @@ -252,8 +252,7 @@ test(int argc, char **argv, int over4k) return 0; } -int -main(int argc, char **argv) +TEST_MAIN() { int res; diff --git a/src/dblib/unittests/t0015.c b/src/dblib/unittests/t0015.c index 361df5f670..bf25d3b731 100644 --- a/src/dblib/unittests/t0015.c +++ b/src/dblib/unittests/t0015.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { const int rows_to_add = 50; LOGINREC *login; diff --git a/src/dblib/unittests/t0016.c b/src/dblib/unittests/t0016.c index 53bffcd903..e2e7fa6c53 100644 --- a/src/dblib/unittests/t0016.c +++ b/src/dblib/unittests/t0016.c @@ -27,8 +27,7 @@ static int compare_files(const char *fn1, const char *fn2); static unsigned count_file_rows(FILE *f); static DBPROCESS *dbproc; -int -main(int argc, char *argv[]) +TEST_MAIN() { LOGINREC *login; char in_file[30]; diff --git a/src/dblib/unittests/t0017.c b/src/dblib/unittests/t0017.c index 4044c8c42b..9ad4fa6b91 100644 --- a/src/dblib/unittests/t0017.c +++ b/src/dblib/unittests/t0017.c @@ -6,8 +6,7 @@ #include "common.h" #include -int -main(int argc, char *argv[]) +TEST_MAIN() { int failed = 0; LOGINREC *login; diff --git a/src/dblib/unittests/t0018.c b/src/dblib/unittests/t0018.c index 09ed121bc3..4f79d6cbda 100644 --- a/src/dblib/unittests/t0018.c +++ b/src/dblib/unittests/t0018.c @@ -8,8 +8,7 @@ int failed = 0; -int -main(int argc, char **argv) +TEST_MAIN() { const int rows_to_add = 50; LOGINREC *login; diff --git a/src/dblib/unittests/t0019.c b/src/dblib/unittests/t0019.c index 111266e67d..ef34682db9 100644 --- a/src/dblib/unittests/t0019.c +++ b/src/dblib/unittests/t0019.c @@ -75,8 +75,7 @@ test(int srctype, const void *srcdata, int srclen, int dsttype, int dstlen) #define TEST(s,out) \ { cur_result = out; cur_line = __LINE__; cur_test = #s; test s; } -int -main(void) +TEST_MAIN() { if (dbinit() == FAIL) return 1; diff --git a/src/dblib/unittests/t0020.c b/src/dblib/unittests/t0020.c index f2b721e430..9ab7c00567 100644 --- a/src/dblib/unittests/t0020.c +++ b/src/dblib/unittests/t0020.c @@ -21,8 +21,7 @@ err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrs return syb_err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr); } -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/t0022.c b/src/dblib/unittests/t0022.c index 9bd6824744..8b96bd3980 100644 --- a/src/dblib/unittests/t0022.c +++ b/src/dblib/unittests/t0022.c @@ -6,8 +6,7 @@ #include "common.h" #include -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/t0023.c b/src/dblib/unittests/t0023.c index e62a7645fa..1711ba4916 100644 --- a/src/dblib/unittests/t0023.c +++ b/src/dblib/unittests/t0023.c @@ -20,8 +20,7 @@ compute_msg_handler(DBPROCESS * dbproc TDS_UNUSED, DBINT msgno TDS_UNUSED, int s return 0; } -int -main(int argc, char *argv[]) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/text_buffer.c b/src/dblib/unittests/text_buffer.c index e9725ee642..325c25c51e 100644 --- a/src/dblib/unittests/text_buffer.c +++ b/src/dblib/unittests/text_buffer.c @@ -5,8 +5,7 @@ #include "common.h" -int -main(int argc, char **argv) +TEST_MAIN() { LOGINREC *login; DBPROCESS *dbproc; diff --git a/src/dblib/unittests/thread.c b/src/dblib/unittests/thread.c index 33ca0072e7..41372ccbe9 100644 --- a/src/dblib/unittests/thread.c +++ b/src/dblib/unittests/thread.c @@ -142,8 +142,7 @@ static TDS_THREAD_PROC_DECLARE(thread_test, arg) return TDS_THREAD_RESULT(0); } -int -main(int argc, char **argv) +TEST_MAIN() { int i; tds_thread th[NUM_THREAD]; @@ -235,8 +234,7 @@ main(int argc, char **argv) #else /* !TDS_HAVE_PTHREAD_MUTEX */ -int -main(int argc, char **argv) +TEST_MAIN() { printf("Not possible for this platform.\n"); return 0; diff --git a/src/dblib/unittests/timeout.c b/src/dblib/unittests/timeout.c index cc4b8ca4b7..4420ed33e8 100644 --- a/src/dblib/unittests/timeout.c +++ b/src/dblib/unittests/timeout.c @@ -276,8 +276,7 @@ test(int per_process) } /* while dbresults */ } -int -main(int argc, char **argv) +TEST_MAIN() { set_malloc_options(); diff --git a/src/odbc/unittests/all_types.c b/src/odbc/unittests/all_types.c index f444f88b43..fb99261370 100644 --- a/src/odbc/unittests/all_types.c +++ b/src/odbc/unittests/all_types.c @@ -58,8 +58,7 @@ static void test_type(TDSSOCKET *tds TDS_UNUSED, TDSCOLUMN *col) } } -int -main(void) +TEST_MAIN() { TDS_DBC *dbc; TDS_ENV *env; diff --git a/src/odbc/unittests/array.c b/src/odbc/unittests/array.c index 62cab3c41a..e316ce76c2 100644 --- a/src/odbc/unittests/array.c +++ b/src/odbc/unittests/array.c @@ -134,8 +134,7 @@ query_test(int prepare, SQLRETURN expected, const char *expected_status) odbc_command_with_result(odbc_stmt, "drop table #tmp1"); } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_conn_additional_params = "ClientCharset=ISO-8859-1;"; diff --git a/src/odbc/unittests/array_error.c b/src/odbc/unittests/array_error.c index 30024e5963..66b0f8ed76 100644 --- a/src/odbc/unittests/array_error.c +++ b/src/odbc/unittests/array_error.c @@ -5,8 +5,7 @@ Test for a bug executing after a not successfully execute */ -int -main(void) +TEST_MAIN() { SQLSMALLINT num_params; SQLLEN sql_nts = SQL_NTS; diff --git a/src/odbc/unittests/array_out.c b/src/odbc/unittests/array_out.c index ea03fb7627..a64ed0b810 100644 --- a/src/odbc/unittests/array_out.c +++ b/src/odbc/unittests/array_out.c @@ -120,8 +120,7 @@ query_test(const char* expected, const char *expected_status) ODBC_FREE(); } -int -main(void) +TEST_MAIN() { int i; diff --git a/src/odbc/unittests/attributes.c b/src/odbc/unittests/attributes.c index 9520a9fd2d..beedc1249f 100644 --- a/src/odbc/unittests/attributes.c +++ b/src/odbc/unittests/attributes.c @@ -267,8 +267,7 @@ get_attr_none(ATTR_PARAMS) } #endif -int -main(void) +TEST_MAIN() { #define TEST_FILE "attributes.in" const char *in_file = FREETDS_SRCDIR "/" TEST_FILE; diff --git a/src/odbc/unittests/bcp.c b/src/odbc/unittests/bcp.c index fbc387a1d4..13edf72deb 100644 --- a/src/odbc/unittests/bcp.c +++ b/src/odbc/unittests/bcp.c @@ -250,8 +250,7 @@ static void special_select(void); static const char table_name[] = "all_types_bcp_unittest"; -int -main(void) +TEST_MAIN() { const char *s; diff --git a/src/odbc/unittests/binary_test.c b/src/odbc/unittests/binary_test.c index 6fe6d5b55d..091352ca4f 100644 --- a/src/odbc/unittests/binary_test.c +++ b/src/odbc/unittests/binary_test.c @@ -100,8 +100,7 @@ test_select(void *buf, SQLINTEGER buflen, SQLLEN * bytes_returned) #define BYTE_AT(n) (((n) * 123) & 0xff) -int -main(void) +TEST_MAIN() { int i; SQLLEN bytes_returned; diff --git a/src/odbc/unittests/blob1.c b/src/odbc/unittests/blob1.c index e9196f421b..9b41e030fa 100644 --- a/src/odbc/unittests/blob1.c +++ b/src/odbc/unittests/blob1.c @@ -229,8 +229,7 @@ free_tests(void) } } -int -main(void) +TEST_MAIN() { SQLRETURN RetCode; SQLHSTMT old_odbc_stmt = SQL_NULL_HSTMT; diff --git a/src/odbc/unittests/cancel.c b/src/odbc/unittests/cancel.c index b76d4e32e9..8582ee1e5a 100644 --- a/src/odbc/unittests/cancel.c +++ b/src/odbc/unittests/cancel.c @@ -186,8 +186,7 @@ Test(bool use_threads, bool return_data) odbc_command("SELECT name FROM sysobjects WHERE 0=1"); } -int -main(void) +TEST_MAIN() { if (tds_mutex_init(&mtx)) return 1; @@ -245,8 +244,7 @@ main(void) } #else -int -main(void) +TEST_MAIN() { printf("Not possible for this platform.\n"); return 0; diff --git a/src/odbc/unittests/closestmt.c b/src/odbc/unittests/closestmt.c index 9b2afc3d22..fb1cbd6663 100644 --- a/src/odbc/unittests/closestmt.c +++ b/src/odbc/unittests/closestmt.c @@ -8,8 +8,7 @@ #define SWAP_STMT(b) do { SQLHSTMT xyz = odbc_stmt; odbc_stmt = b; b = xyz; } while(0) -int -main(void) +TEST_MAIN() { char sql[128]; int i; diff --git a/src/odbc/unittests/compute.c b/src/odbc/unittests/compute.c index 4b3b1c8f29..122b764f6f 100644 --- a/src/odbc/unittests/compute.c +++ b/src/odbc/unittests/compute.c @@ -70,8 +70,7 @@ CheckFetch(const char *c1name, const char *c1, const char *c2) #define CheckFetch main_line = __LINE__; CheckFetch -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/connect.c b/src/odbc/unittests/connect.c index 96ea32342e..831001a746 100644 --- a/src/odbc/unittests/connect.c +++ b/src/odbc/unittests/connect.c @@ -29,8 +29,7 @@ get_entry(const char *key) } #endif -int -main(void) +TEST_MAIN() { char tmp[1024*4]; SQLSMALLINT len; diff --git a/src/odbc/unittests/connect2.c b/src/odbc/unittests/connect2.c index 8befd72ca2..221a0603e1 100644 --- a/src/odbc/unittests/connect2.c +++ b/src/odbc/unittests/connect2.c @@ -59,8 +59,7 @@ set_dbname(const char *dbname) CHKSetConnectAttr(SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER) T(dbname), strlen(dbname)*sizeof(SQLTCHAR), "SI"); } -int -main(void) +TEST_MAIN() { char tmp[1024*3]; diff --git a/src/odbc/unittests/connection_string_parse.c b/src/odbc/unittests/connection_string_parse.c index 48ca5b2c14..08ef42c0bc 100644 --- a/src/odbc/unittests/connection_string_parse.c +++ b/src/odbc/unittests/connection_string_parse.c @@ -137,8 +137,7 @@ CHECK(password_bug_report, CHECK_ERROR(unfinished, "Driver=FreeTDS;Server=1.2.3.4;Port=1433;pwd={p@ssw0rd"); -int -main(void) +TEST_MAIN() { simple_string(); diff --git a/src/odbc/unittests/const_params.c b/src/odbc/unittests/const_params.c index 14cb6981c8..e0d39bcf8b 100644 --- a/src/odbc/unittests/const_params.c +++ b/src/odbc/unittests/const_params.c @@ -2,8 +2,7 @@ /* Test for {?=call store(?,123,'foo')} syntax and run */ -int -main(void) +TEST_MAIN() { SQLINTEGER input, output; SQLINTEGER out1; diff --git a/src/odbc/unittests/convert_error.c b/src/odbc/unittests/convert_error.c index 117eafc5a6..d6b284f495 100644 --- a/src/odbc/unittests/convert_error.c +++ b/src/odbc/unittests/convert_error.c @@ -30,8 +30,7 @@ Test(const char *bind1, SQLSMALLINT type1, const char *bind2, SQLSMALLINT type2) ODBC_FREE(); } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_connect(); diff --git a/src/odbc/unittests/copydesc.c b/src/odbc/unittests/copydesc.c index 89d0c2983f..f6c327881b 100644 --- a/src/odbc/unittests/copydesc.c +++ b/src/odbc/unittests/copydesc.c @@ -19,8 +19,7 @@ check_alloc_type(SQLHDESC hdesc, SQLSMALLINT expected_alloc_type, const char *ex #define check_alloc_type(d,e) check_alloc_type(d, e, #e, __LINE__) -int -main(void) +TEST_MAIN() { SQLHDESC ard, ard2, ard3; SQLINTEGER id; diff --git a/src/odbc/unittests/cursor1.c b/src/odbc/unittests/cursor1.c index 3e8eb90a02..e3f765ce93 100644 --- a/src/odbc/unittests/cursor1.c +++ b/src/odbc/unittests/cursor1.c @@ -133,8 +133,7 @@ Test(int use_sql) Test0(use_sql, "CREATE TABLE #test(i int, c varchar(6))", "INSERT INTO #test(c, i) VALUES('%s', %d)", "SELECT i, c, c + 'xxx' FROM #test"); } -int -main(void) +TEST_MAIN() { odbc_connect(); odbc_check_cursor(); diff --git a/src/odbc/unittests/cursor2.c b/src/odbc/unittests/cursor2.c index 40ee848b1b..352d78c6e7 100644 --- a/src/odbc/unittests/cursor2.c +++ b/src/odbc/unittests/cursor2.c @@ -5,8 +5,7 @@ * 2) Test cursor returns results on language RPCs */ -int -main(void) +TEST_MAIN() { SQLTCHAR sqlstate[6]; SQLTCHAR msg[256]; diff --git a/src/odbc/unittests/cursor3.c b/src/odbc/unittests/cursor3.c index 27327f2dfa..80a9e13c70 100644 --- a/src/odbc/unittests/cursor3.c +++ b/src/odbc/unittests/cursor3.c @@ -1,8 +1,7 @@ /* Tests 2 active statements */ #include "common.h" -int -main(void) +TEST_MAIN() { SQLHSTMT stmt1 = SQL_NULL_HSTMT; SQLHSTMT stmt2 = SQL_NULL_HSTMT; diff --git a/src/odbc/unittests/cursor4.c b/src/odbc/unittests/cursor4.c index a4f16f1fa7..783ae5f668 100644 --- a/src/odbc/unittests/cursor4.c +++ b/src/odbc/unittests/cursor4.c @@ -15,8 +15,7 @@ exec_direct(const char *stmt) CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S"); } -int -main(void) +TEST_MAIN() { char buff[64]; SQLLEN ind; diff --git a/src/odbc/unittests/cursor5.c b/src/odbc/unittests/cursor5.c index d9337c653e..a057bf24b6 100644 --- a/src/odbc/unittests/cursor5.c +++ b/src/odbc/unittests/cursor5.c @@ -24,8 +24,7 @@ doFetch(int dir, int pos, int expected) result = 1; } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_connect(); diff --git a/src/odbc/unittests/cursor6.c b/src/odbc/unittests/cursor6.c index 033bb260c6..401f5ae705 100644 --- a/src/odbc/unittests/cursor6.c +++ b/src/odbc/unittests/cursor6.c @@ -84,8 +84,7 @@ static void Init(void) } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_connect(); diff --git a/src/odbc/unittests/cursor7.c b/src/odbc/unittests/cursor7.c index e3e7f4fa9e..f16f13197e 100644 --- a/src/odbc/unittests/cursor7.c +++ b/src/odbc/unittests/cursor7.c @@ -76,8 +76,7 @@ Init(void) } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_connect(); diff --git a/src/odbc/unittests/data.c b/src/odbc/unittests/data.c index a2dd42f72b..013c7ae0f3 100644 --- a/src/odbc/unittests/data.c +++ b/src/odbc/unittests/data.c @@ -95,8 +95,7 @@ lookup(const char *name, const struct odbc_lookup_int *table) return res == SQL_UNKNOWN_TYPE ? get_int(name) : res; } -int -main(void) +TEST_MAIN() { int cond = 1; diff --git a/src/odbc/unittests/date.c b/src/odbc/unittests/date.c index b0158a6dbf..acd1e81d10 100644 --- a/src/odbc/unittests/date.c +++ b/src/odbc/unittests/date.c @@ -35,8 +35,7 @@ DoTest(int n) CHKCloseCursor("SI"); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/descrec.c b/src/odbc/unittests/descrec.c index 612bf216f4..ab954b4acd 100644 --- a/src/odbc/unittests/descrec.c +++ b/src/odbc/unittests/descrec.c @@ -4,8 +4,7 @@ static char software_version[] = "$Id: descrec.c,v 1.3 2011-07-12 10:16:59 freddy77 Exp $"; static void *no_unused_var_warn[] = { software_version, no_unused_var_warn }; -int -main(void) +TEST_MAIN() { SQLHDESC Descriptor; SQLINTEGER ind; diff --git a/src/odbc/unittests/describecol.c b/src/odbc/unittests/describecol.c index b602403e0d..23d0b8ad8d 100644 --- a/src/odbc/unittests/describecol.c +++ b/src/odbc/unittests/describecol.c @@ -291,8 +291,7 @@ check_attr_none(ATTR_PARAMS) { } -int -main(void) +TEST_MAIN() { int cond = 1; #define TEST_FILE "describecol.in" diff --git a/src/odbc/unittests/describecol2.c b/src/odbc/unittests/describecol2.c index c9b3f884e8..3c3538ed1e 100644 --- a/src/odbc/unittests/describecol2.c +++ b/src/odbc/unittests/describecol2.c @@ -18,8 +18,7 @@ do_check(int c, const char *test, int line) #define check(s) do_check(s, #s, __LINE__) -int -main(void) +TEST_MAIN() { SQLSMALLINT len, type; SQLTCHAR name[128]; diff --git a/src/odbc/unittests/earlybind.c b/src/odbc/unittests/earlybind.c index 8584734694..514a0122cd 100644 --- a/src/odbc/unittests/earlybind.c +++ b/src/odbc/unittests/earlybind.c @@ -1,7 +1,6 @@ #include "common.h" -int -main(void) +TEST_MAIN() { SQLINTEGER id; SQLLEN ind1, ind2; diff --git a/src/odbc/unittests/empty_query.c b/src/odbc/unittests/empty_query.c index 95cb5dba82..99431ade98 100644 --- a/src/odbc/unittests/empty_query.c +++ b/src/odbc/unittests/empty_query.c @@ -3,8 +3,7 @@ /* Check that on queries returning 0 rows and NOCOUNT active SQLExecDirect returns success. * Also SQLFetch should return NO_DATA for these queries. */ -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_connect(); diff --git a/src/odbc/unittests/error.c b/src/odbc/unittests/error.c index a5bf10eb3d..d32016baf3 100644 --- a/src/odbc/unittests/error.c +++ b/src/odbc/unittests/error.c @@ -2,8 +2,7 @@ /* some tests on error reporting */ -int -main(void) +TEST_MAIN() { SQLRETURN RetCode; HSTMT stmt; diff --git a/src/odbc/unittests/freeclose.c b/src/odbc/unittests/freeclose.c index b60b2b9841..c1c0c0bc31 100644 --- a/src/odbc/unittests/freeclose.c +++ b/src/odbc/unittests/freeclose.c @@ -273,8 +273,7 @@ static TDS_THREAD_PROC_DECLARE(fake_thread_proc, arg) return TDS_THREAD_RESULT(0); } -int -main(void) +TEST_MAIN() { SQLLEN sql_nts = SQL_NTS; const char *query; @@ -434,8 +433,7 @@ main(void) } #else -int -main(void) +TEST_MAIN() { printf("Not possible for this platform.\n"); odbc_test_skipped(); diff --git a/src/odbc/unittests/funccall.c b/src/odbc/unittests/funccall.c index bb932a3a2f..06a6e785c8 100644 --- a/src/odbc/unittests/funccall.c +++ b/src/odbc/unittests/funccall.c @@ -5,8 +5,7 @@ static void test_with_conversions(void); static void test_with_dbname(void); -int -main(void) +TEST_MAIN() { SQLINTEGER input, output; SQLLEN ind, ind2, ind3, ind4; diff --git a/src/odbc/unittests/genparams.c b/src/odbc/unittests/genparams.c index e6ab4ac088..0167c74de9 100644 --- a/src/odbc/unittests/genparams.c +++ b/src/odbc/unittests/genparams.c @@ -516,8 +516,7 @@ AllTests(void) } } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_conn_additional_params = "ClientCharset=ISO-8859-1;"; diff --git a/src/odbc/unittests/getdata.c b/src/odbc/unittests/getdata.c index d556651791..3101165e75 100644 --- a/src/odbc/unittests/getdata.c +++ b/src/odbc/unittests/getdata.c @@ -131,8 +131,7 @@ test_split(const char *n_flag) odbc_reset_statement(); } -int -main(void) +TEST_MAIN() { char buf[32]; SQLINTEGER int_buf; diff --git a/src/odbc/unittests/hidden.c b/src/odbc/unittests/hidden.c index fa2c4906f9..ef929757d7 100644 --- a/src/odbc/unittests/hidden.c +++ b/src/odbc/unittests/hidden.c @@ -3,8 +3,7 @@ #include "common.h" -int -main(void) +TEST_MAIN() { SQLSMALLINT cnt = 0; int failed = 0; diff --git a/src/odbc/unittests/insert_speed.c b/src/odbc/unittests/insert_speed.c index 0d71c50202..c2eeda4d21 100644 --- a/src/odbc/unittests/insert_speed.c +++ b/src/odbc/unittests/insert_speed.c @@ -57,8 +57,7 @@ insert_test_man(void) odbc_reset_statement(); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/lang_error.c b/src/odbc/unittests/lang_error.c index 644dce613a..d95490b80a 100644 --- a/src/odbc/unittests/lang_error.c +++ b/src/odbc/unittests/lang_error.c @@ -2,8 +2,7 @@ /* Test if SQLExecDirect return error if a error in row is returned */ -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/long_error.c b/src/odbc/unittests/long_error.c index 542295dab0..e1354572aa 100644 --- a/src/odbc/unittests/long_error.c +++ b/src/odbc/unittests/long_error.c @@ -14,8 +14,7 @@ end static void extract_error(SQLHANDLE handle, SQLSMALLINT type); -int -main(void) +TEST_MAIN() { int i; char cmd[128 + 110*10]; diff --git a/src/odbc/unittests/mars1.c b/src/odbc/unittests/mars1.c index 149fbd939c..e671bfe5f4 100644 --- a/src/odbc/unittests/mars1.c +++ b/src/odbc/unittests/mars1.c @@ -29,8 +29,7 @@ my_attrs(void) SQLSetConnectAttr(odbc_conn, 1224 /*SQL_COPT_SS_MARS_ENABLED*/, (SQLPOINTER) 1 /*SQL_MARS_ENABLED_YES*/, SQL_IS_UINTEGER); } -int -main(void) +TEST_MAIN() { SQLINTEGER len, out; int i; diff --git a/src/odbc/unittests/moreandcount.c b/src/odbc/unittests/moreandcount.c index e7afbf140b..12ac5b2391 100644 --- a/src/odbc/unittests/moreandcount.c +++ b/src/odbc/unittests/moreandcount.c @@ -80,8 +80,7 @@ DoTest(int prepare) ODBC_FREE(); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/moreresults.c b/src/odbc/unittests/moreresults.c index aad26e0a3c..47ec48fa14 100644 --- a/src/odbc/unittests/moreresults.c +++ b/src/odbc/unittests/moreresults.c @@ -38,8 +38,7 @@ Test(bool use_indicator) ODBC_FREE(); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/norowset.c b/src/odbc/unittests/norowset.c index e188deb973..c56f7d99c3 100644 --- a/src/odbc/unittests/norowset.c +++ b/src/odbc/unittests/norowset.c @@ -2,8 +2,7 @@ /* Test that a select following a store procedure execution return results */ -int -main(void) +TEST_MAIN() { char output[256]; SQLLEN dataSize; diff --git a/src/odbc/unittests/oldpwd.c b/src/odbc/unittests/oldpwd.c index 18c8696273..7ec9ead92e 100644 --- a/src/odbc/unittests/oldpwd.c +++ b/src/odbc/unittests/oldpwd.c @@ -9,8 +9,7 @@ my_attrs(void) strcpy(odbc_password, "testpwd$"); } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_set_conn_attr = my_attrs; diff --git a/src/odbc/unittests/paramcore.c b/src/odbc/unittests/paramcore.c index a3c305492e..297c646de8 100644 --- a/src/odbc/unittests/paramcore.c +++ b/src/odbc/unittests/paramcore.c @@ -7,8 +7,7 @@ #define SP_TEXT "{call sp_paramcore_test(?)}" #define OUTSTRING_LEN 20 -int -main(void) +TEST_MAIN() { SQLLEN cb = SQL_NTS; diff --git a/src/odbc/unittests/params.c b/src/odbc/unittests/params.c index 8db70f2ea7..5c02102f0d 100644 --- a/src/odbc/unittests/params.c +++ b/src/odbc/unittests/params.c @@ -75,8 +75,7 @@ Test(int bind_before) return 0; } -int -main(void) +TEST_MAIN() { if (Test(0)) return 1; diff --git a/src/odbc/unittests/peter.c b/src/odbc/unittests/peter.c index 72ee115e99..3698392a23 100644 --- a/src/odbc/unittests/peter.c +++ b/src/odbc/unittests/peter.c @@ -6,8 +6,7 @@ This test on Sybase should not raise an error */ -int -main(void) +TEST_MAIN() { SQLSMALLINT num_params, cols; SQLLEN count; diff --git a/src/odbc/unittests/prepare_results.c b/src/odbc/unittests/prepare_results.c index 54915257df..9aea0c33f5 100644 --- a/src/odbc/unittests/prepare_results.c +++ b/src/odbc/unittests/prepare_results.c @@ -61,8 +61,7 @@ Test(int use_ird) ODBC_FREE(); } -int -main(void) +TEST_MAIN() { SQLSMALLINT count; diff --git a/src/odbc/unittests/prepare_warn.c b/src/odbc/unittests/prepare_warn.c index 3b7aa42237..0089004525 100644 --- a/src/odbc/unittests/prepare_warn.c +++ b/src/odbc/unittests/prepare_warn.c @@ -8,8 +8,7 @@ #include "common.h" -int -main(void) +TEST_MAIN() { #define ARRAY_SIZE 10 SQLCHAR v_dec[ARRAY_SIZE][21]; diff --git a/src/odbc/unittests/prepclose.c b/src/odbc/unittests/prepclose.c index 355bce90b1..88100c8613 100644 --- a/src/odbc/unittests/prepclose.c +++ b/src/odbc/unittests/prepclose.c @@ -90,8 +90,7 @@ Test(int direct, int long_query) return 0; } -int -main(void) +TEST_MAIN() { /* check with short queries */ if (Test(0, 0) || Test(1, 0)) diff --git a/src/odbc/unittests/preperror.c b/src/odbc/unittests/preperror.c index 302050b867..23438b5811 100644 --- a/src/odbc/unittests/preperror.c +++ b/src/odbc/unittests/preperror.c @@ -2,8 +2,7 @@ /* test error on prepared statement, from Nathaniel Talbott test */ -int -main(void) +TEST_MAIN() { SQLLEN cbInString = SQL_NTS; char buf[256]; diff --git a/src/odbc/unittests/print.c b/src/odbc/unittests/print.c index b874049108..db4fd8e85c 100644 --- a/src/odbc/unittests/print.c +++ b/src/odbc/unittests/print.c @@ -91,8 +91,7 @@ test(int odbc3) return 0; } -int -main(void) +TEST_MAIN() { int ret; diff --git a/src/odbc/unittests/putdata.c b/src/odbc/unittests/putdata.c index 5bf128d1eb..9321233337 100644 --- a/src/odbc/unittests/putdata.c +++ b/src/odbc/unittests/putdata.c @@ -225,8 +225,7 @@ Test(int direct) /* TODO test cancel inside SQLExecute */ } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/qn.c b/src/odbc/unittests/qn.c index 8249c07ae0..4db0f411c7 100644 --- a/src/odbc/unittests/qn.c +++ b/src/odbc/unittests/qn.c @@ -26,8 +26,7 @@ static TDS_THREAD_PROC_DECLARE(change_thread_proc, arg TDS_UNUSED) return TDS_THREAD_RESULT(0); } -int -main(void) +TEST_MAIN() { char *sql = NULL; tds_thread th; @@ -133,7 +132,7 @@ main(void) return 0; } #else -int main(int argc, char *argv[]) +TEST_MAIN() { printf("Not possible for this platform.\n"); odbc_test_skipped(); diff --git a/src/odbc/unittests/raiserror.c b/src/odbc/unittests/raiserror.c index 7a4ffce94a..96f5c1aafb 100644 --- a/src/odbc/unittests/raiserror.c +++ b/src/odbc/unittests/raiserror.c @@ -277,8 +277,7 @@ Test2(int nocount, int second_select) odbc_command("DROP PROC #tmp1"); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/rebindpar.c b/src/odbc/unittests/rebindpar.c index 8611a578a2..9bcd2be414 100644 --- a/src/odbc/unittests/rebindpar.c +++ b/src/odbc/unittests/rebindpar.c @@ -65,8 +65,7 @@ Test(int prebind) ODBC_FREE(); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/rowset.c b/src/odbc/unittests/rowset.c index 2da8839031..414be6e1b7 100644 --- a/src/odbc/unittests/rowset.c +++ b/src/odbc/unittests/rowset.c @@ -12,8 +12,7 @@ test_err(int n) } } -int -main(void) +TEST_MAIN() { int i; SQLLEN len; diff --git a/src/odbc/unittests/rpc.c b/src/odbc/unittests/rpc.c index 1f1a84b9fb..f811aa4063 100644 --- a/src/odbc/unittests/rpc.c +++ b/src/odbc/unittests/rpc.c @@ -202,8 +202,7 @@ Test(const char *name) } } -int -main(void) +TEST_MAIN() { const char proc_name[] = "freetds_odbc_rpc_test"; char drop_proc[256] = "DROP PROCEDURE "; diff --git a/src/odbc/unittests/scroll.c b/src/odbc/unittests/scroll.c index 501a700f79..a3af47f5cb 100644 --- a/src/odbc/unittests/scroll.c +++ b/src/odbc/unittests/scroll.c @@ -2,8 +2,7 @@ /* Test cursors */ -int -main(void) +TEST_MAIN() { #define ROWS 3 #define C_LEN 10 diff --git a/src/odbc/unittests/stats.c b/src/odbc/unittests/stats.c index 2e7b584b90..6aafaeeffd 100644 --- a/src/odbc/unittests/stats.c +++ b/src/odbc/unittests/stats.c @@ -95,8 +95,7 @@ set_dbname(const char *dbname) CHKSetConnectAttr(SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER) T(dbname), strlen(dbname)*sizeof(SQLTCHAR), "SI"); } -int -main(void) +TEST_MAIN() { char int_buf[32]; diff --git a/src/odbc/unittests/t0001.c b/src/odbc/unittests/t0001.c index bda246e0e6..82cca2e9c8 100644 --- a/src/odbc/unittests/t0001.c +++ b/src/odbc/unittests/t0001.c @@ -1,7 +1,6 @@ #include "common.h" -int -main(void) +TEST_MAIN() { int i; diff --git a/src/odbc/unittests/t0002.c b/src/odbc/unittests/t0002.c index 7d4f703887..a81e666692 100644 --- a/src/odbc/unittests/t0002.c +++ b/src/odbc/unittests/t0002.c @@ -3,8 +3,7 @@ #define SWAP_STMT() do { SQLHSTMT xyz = odbc_stmt; \ odbc_stmt = old_odbc_stmt; old_odbc_stmt = xyz; } while(0) -int -main(void) +TEST_MAIN() { HSTMT old_odbc_stmt = SQL_NULL_HSTMT; diff --git a/src/odbc/unittests/t0003.c b/src/odbc/unittests/t0003.c index 9fec662a86..5afdc8b525 100644 --- a/src/odbc/unittests/t0003.c +++ b/src/odbc/unittests/t0003.c @@ -47,8 +47,7 @@ DoTest(int prepared) ODBC_FREE(); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/tables.c b/src/odbc/unittests/tables.c index 647e576abc..8e715c0810 100644 --- a/src/odbc/unittests/tables.c +++ b/src/odbc/unittests/tables.c @@ -124,8 +124,7 @@ DoTest(const char *type, int row_returned, int line) #define DoTest(a,b) DoTest(a,b,__LINE__) -int -main(void) +TEST_MAIN() { char type[32]; int mssql2005 = 0; diff --git a/src/odbc/unittests/test64.c b/src/odbc/unittests/test64.c index 79113c340d..5c56e5b15a 100644 --- a/src/odbc/unittests/test64.c +++ b/src/odbc/unittests/test64.c @@ -253,8 +253,7 @@ test_rows(void) free(id_lens); } -int -main(void) +TEST_MAIN() { /* this test is specifically testing for 64 bit platforms where SQLLEN is 64 bit */ if (sizeof(SQLLEN) != 8) { diff --git a/src/odbc/unittests/testodbc.c b/src/odbc/unittests/testodbc.c index c16fb22994..b484239596 100644 --- a/src/odbc/unittests/testodbc.c +++ b/src/odbc/unittests/testodbc.c @@ -423,8 +423,7 @@ RunTests(void) return (!fails); } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; diff --git a/src/odbc/unittests/timeout.c b/src/odbc/unittests/timeout.c index 45e3daa394..69ace1d8fb 100644 --- a/src/odbc/unittests/timeout.c +++ b/src/odbc/unittests/timeout.c @@ -15,8 +15,7 @@ EndTransaction(SQLSMALLINT type) CHKEndTran(SQL_HANDLE_DBC, odbc_conn, type, "S"); } -int -main(void) +TEST_MAIN() { HENV env; HDBC dbc; diff --git a/src/odbc/unittests/timeout2.c b/src/odbc/unittests/timeout2.c index 5639c386e9..b02b060a42 100644 --- a/src/odbc/unittests/timeout2.c +++ b/src/odbc/unittests/timeout2.c @@ -17,8 +17,7 @@ * Test from Ou Liu, cf "Query Time Out", 2006-08-08 */ -int -main(void) +TEST_MAIN() { int i; diff --git a/src/odbc/unittests/timeout3.c b/src/odbc/unittests/timeout3.c index de7c0da55a..8a9a8f2688 100644 --- a/src/odbc/unittests/timeout3.c +++ b/src/odbc/unittests/timeout3.c @@ -129,8 +129,7 @@ static TDS_THREAD_PROC_DECLARE(fake_thread_proc, arg) return TDS_THREAD_RESULT(0); } -int -main(void) +TEST_MAIN() { SQLTCHAR tmp[2048]; char conn[128]; @@ -217,8 +216,7 @@ main(void) } #else /* !TDS_HAVE_MUTEX */ -int -main(void) +TEST_MAIN() { printf("Not possible for this platform.\n"); odbc_test_skipped(); diff --git a/src/odbc/unittests/timeout4.c b/src/odbc/unittests/timeout4.c index 1dcf6ee5c9..deae211bc1 100644 --- a/src/odbc/unittests/timeout4.c +++ b/src/odbc/unittests/timeout4.c @@ -111,8 +111,7 @@ Test(int direct) return 0; } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; @@ -122,8 +121,7 @@ main(void) } #else -int -main(void) +TEST_MAIN() { printf("Not possible for this platform.\n"); odbc_test_skipped(); diff --git a/src/odbc/unittests/transaction.c b/src/odbc/unittests/transaction.c index 00cf987e2b..1b4dc249ad 100644 --- a/src/odbc/unittests/transaction.c +++ b/src/odbc/unittests/transaction.c @@ -88,8 +88,7 @@ Test(bool discard_test) return retcode; } -int -main(void) +TEST_MAIN() { int retcode = 0; diff --git a/src/odbc/unittests/transaction2.c b/src/odbc/unittests/transaction2.c index da3b13bdde..43a9a92cbc 100644 --- a/src/odbc/unittests/transaction2.c +++ b/src/odbc/unittests/transaction2.c @@ -196,8 +196,7 @@ Test(int txn, const char *expected) return 1; } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_connect(); diff --git a/src/odbc/unittests/transaction3.c b/src/odbc/unittests/transaction3.c index 06369107e1..4cc6e05fb6 100644 --- a/src/odbc/unittests/transaction3.c +++ b/src/odbc/unittests/transaction3.c @@ -2,7 +2,7 @@ /* Test commit/rollback with auto commit set to on (the default) */ -int main(void) +TEST_MAIN() { odbc_use_version3 = 1; odbc_connect(); diff --git a/src/odbc/unittests/transaction4.c b/src/odbc/unittests/transaction4.c index c3b057068f..040fd43da0 100644 --- a/src/odbc/unittests/transaction4.c +++ b/src/odbc/unittests/transaction4.c @@ -60,8 +60,7 @@ close_last_socket(void) return 1; } -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; diff --git a/src/odbc/unittests/tvp.c b/src/odbc/unittests/tvp.c index ccf2b331ce..991e355ebc 100644 --- a/src/odbc/unittests/tvp.c +++ b/src/odbc/unittests/tvp.c @@ -573,8 +573,7 @@ TestInitializeLeak(void) } #endif -int -main(void) +TEST_MAIN() { odbc_use_version3 = 1; diff --git a/src/odbc/unittests/type.c b/src/odbc/unittests/type.c index d0a46d83f2..366e2f2035 100644 --- a/src/odbc/unittests/type.c +++ b/src/odbc/unittests/type.c @@ -92,8 +92,7 @@ check_msg(int check, const char *msg) result = 1; } -int -main(void) +TEST_MAIN() { const struct type *p; char buf[16]; diff --git a/src/odbc/unittests/typeinfo.c b/src/odbc/unittests/typeinfo.c index 45b293678a..e806ba8e08 100644 --- a/src/odbc/unittests/typeinfo.c +++ b/src/odbc/unittests/typeinfo.c @@ -193,8 +193,7 @@ DoTest(int version3) odbc_disconnect(); } -int -main(void) +TEST_MAIN() { DoTest(0); diff --git a/src/odbc/unittests/utf8.c b/src/odbc/unittests/utf8.c index 71f75459bd..2e63f7b01f 100644 --- a/src/odbc/unittests/utf8.c +++ b/src/odbc/unittests/utf8.c @@ -72,8 +72,7 @@ TestBinding(int minimun) odbc_reset_statement(); } -int -main(void) +TEST_MAIN() { const char * const*p; SQLINTEGER n; @@ -131,8 +130,7 @@ main(void) #else -int -main(void) +TEST_MAIN() { /* on Windows SQLExecDirect is always converted to SQLExecDirectW by the DM */ printf("Not possible for this platform.\n"); diff --git a/src/odbc/unittests/utf8_2.c b/src/odbc/unittests/utf8_2.c index cc740a0fa3..ad11710228 100644 --- a/src/odbc/unittests/utf8_2.c +++ b/src/odbc/unittests/utf8_2.c @@ -27,8 +27,7 @@ static const column_t columns[] = { { 0, NULL, NULL }, }; -int -main(void) +TEST_MAIN() { char tmp[1024]; char out[TDS_VECTOR_SIZE(column_names)][32]; diff --git a/src/odbc/unittests/utf8_3.c b/src/odbc/unittests/utf8_3.c index a37f49225f..3e95c5297c 100644 --- a/src/odbc/unittests/utf8_3.c +++ b/src/odbc/unittests/utf8_3.c @@ -3,8 +3,7 @@ /* test conversion using SQLGetData */ -int -main(void) +TEST_MAIN() { SQLLEN len; unsigned char buf[30]; diff --git a/src/odbc/unittests/utf8_4.c b/src/odbc/unittests/utf8_4.c index c3a94fd708..831cf36d6f 100644 --- a/src/odbc/unittests/utf8_4.c +++ b/src/odbc/unittests/utf8_4.c @@ -31,8 +31,7 @@ wide_test(const WCHAR* input, size_t input_len, const char *exp, int line) } #endif -int -main(void) +TEST_MAIN() { #ifdef ENABLE_ODBC_WIDE DSTR s = DSTR_INITIALIZER; diff --git a/src/odbc/unittests/warning.c b/src/odbc/unittests/warning.c index bf338bf9fe..7712fdf994 100644 --- a/src/odbc/unittests/warning.c +++ b/src/odbc/unittests/warning.c @@ -54,8 +54,7 @@ Test(const char *query) odbc_reset_statement(); } -int -main(void) +TEST_MAIN() { odbc_connect(); diff --git a/src/odbc/unittests/wchar.c b/src/odbc/unittests/wchar.c index deb86508d5..e38c815cb3 100644 --- a/src/odbc/unittests/wchar.c +++ b/src/odbc/unittests/wchar.c @@ -2,8 +2,7 @@ /* test SQL_C_DEFAULT with NCHAR type */ -int -main(void) +TEST_MAIN() { char buf[102]; SQLLEN ind; diff --git a/src/replacements/unittests/strings.c b/src/replacements/unittests/strings.c index 4cc4b0c985..89b3c675f0 100644 --- a/src/replacements/unittests/strings.c +++ b/src/replacements/unittests/strings.c @@ -42,7 +42,7 @@ size_t tds_strlcat(char *dest, const char *src, size_t len); #include "../strlcat.c" #endif -int main(void) +TEST_MAIN() { char *buf = (char *) malloc(10); diff --git a/src/replacements/unittests/strsep.c b/src/replacements/unittests/strsep.c index 2eab0c9f29..2f97ebdb1c 100644 --- a/src/replacements/unittests/strsep.c +++ b/src/replacements/unittests/strsep.c @@ -79,8 +79,7 @@ test2(void) assert(tds_strsep(&s, "") == NULL); } -int -main(void) +TEST_MAIN() { test("a b c", "", "a b c", NULL); test("a b c", " ", "a", "b", "c", NULL); diff --git a/src/replacements/unittests/strtok_r.c b/src/replacements/unittests/strtok_r.c index c9b5e41bee..cf5a784a97 100644 --- a/src/replacements/unittests/strtok_r.c +++ b/src/replacements/unittests/strtok_r.c @@ -67,8 +67,7 @@ test(const char *s, const char *sep) free(c2); } -int -main(void) +TEST_MAIN() { test("a b\tc", "\t "); test(" x y \t z", " \t"); diff --git a/src/tds/unittests/charconv.c b/src/tds/unittests/charconv.c index 8eb5c65591..464f3cede7 100644 --- a/src/tds/unittests/charconv.c +++ b/src/tds/unittests/charconv.c @@ -301,8 +301,7 @@ big_test(TDSSOCKET *tds) } -int -main(void) +TEST_MAIN() { int i; TDSCONTEXT *ctx = tds_alloc_context(NULL); diff --git a/src/tds/unittests/collations.c b/src/tds/unittests/collations.c index 3ddcf98156..23ba01c125 100644 --- a/src/tds/unittests/collations.c +++ b/src/tds/unittests/collations.c @@ -281,8 +281,7 @@ extract_collations(void) fclose(f); } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; int ret; diff --git a/src/tds/unittests/convert.c b/src/tds/unittests/convert.c index 6e8482706d..2fa4e72721 100644 --- a/src/tds/unittests/convert.c +++ b/src/tds/unittests/convert.c @@ -45,8 +45,7 @@ free_convert(int type, CONV_RESULT *cr) } } -int -main(int argc, char **argv) +TEST_MAIN() { int srctype; int desttype; diff --git a/src/tds/unittests/convert_bounds.c b/src/tds/unittests/convert_bounds.c index 48bbb099ea..53f90fd4a1 100644 --- a/src/tds/unittests/convert_bounds.c +++ b/src/tds/unittests/convert_bounds.c @@ -78,8 +78,7 @@ static const char *bounds[] = { NULL, }; -int -main(void) +TEST_MAIN() { const char **bound; diff --git a/src/tds/unittests/corrupt.c b/src/tds/unittests/corrupt.c index 317a5ce23d..38788be70e 100644 --- a/src/tds/unittests/corrupt.c +++ b/src/tds/unittests/corrupt.c @@ -93,8 +93,7 @@ unfinished_query_test(TDSSOCKET *tds) free(buf); } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/dataread.c b/src/tds/unittests/dataread.c index b34622444a..64e0607010 100644 --- a/src/tds/unittests/dataread.c +++ b/src/tds/unittests/dataread.c @@ -165,8 +165,7 @@ test0(const char *type, ...) exec_query("DROP TABLE #tmp"); } -int -main(void) +TEST_MAIN() { printf("%s: Testing conversion from server\n", __FILE__); if (try_tds_login(&login, &tds, __FILE__, 0) != TDS_SUCCESS) { diff --git a/src/tds/unittests/declarations.c b/src/tds/unittests/declarations.c index 7779c73e54..1134407a61 100644 --- a/src/tds/unittests/declarations.c +++ b/src/tds/unittests/declarations.c @@ -35,8 +35,7 @@ static void test_declaration(TDSSOCKET *tds, TDSCOLUMN *curcol) assert(declaration[0] != 0); } -int -main(void) +TEST_MAIN() { int g_result = 0; TDSCONTEXT *ctx; diff --git a/src/tds/unittests/dynamic1.c b/src/tds/unittests/dynamic1.c index 0ca389ad86..2868165d4f 100644 --- a/src/tds/unittests/dynamic1.c +++ b/src/tds/unittests/dynamic1.c @@ -66,8 +66,7 @@ test(TDSSOCKET * tds, TDSDYNAMIC * dyn, TDS_INT n, const char *s) fatal_error("tds_submit_execute() output error"); } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/freeze.c b/src/tds/unittests/freeze.c index 6ef93fe85a..4a9e08124a 100644 --- a/src/tds/unittests/freeze.c +++ b/src/tds/unittests/freeze.c @@ -462,8 +462,7 @@ test(int mars, void (*real_test)(void)) buf_free(&thread_buf); } -int -main(void) +TEST_MAIN() { int mars; @@ -487,7 +486,7 @@ main(void) return 0; } #else /* !TDS_HAVE_MUTEX */ -int main(int argc, char *argv[]) +TEST_MAIN() { printf("Not possible for this platform.\n"); return 0; // 77? diff --git a/src/tds/unittests/iconv_fread.c b/src/tds/unittests/iconv_fread.c index 4911dc63d6..83e9b79db2 100644 --- a/src/tds/unittests/iconv_fread.c +++ b/src/tds/unittests/iconv_fread.c @@ -35,8 +35,7 @@ static char buf[4096+80]; -int -main(void) +TEST_MAIN() { static const char out_file[] = "iconv_fread.out"; int i; diff --git a/src/tds/unittests/log_elision.c b/src/tds/unittests/log_elision.c index 4818f07131..24e9ae8044 100644 --- a/src/tds/unittests/log_elision.c +++ b/src/tds/unittests/log_elision.c @@ -68,8 +68,7 @@ static TDS_THREAD_PROC_DECLARE(log_func, idx_ptr) return TDS_THREAD_RESULT(0); } -int -main(void) +TEST_MAIN() { int i, ret; tds_thread threads[THREADS]; diff --git a/src/tds/unittests/nulls.c b/src/tds/unittests/nulls.c index 98a72dbbcb..3d614a22be 100644 --- a/src/tds/unittests/nulls.c +++ b/src/tds/unittests/nulls.c @@ -18,8 +18,7 @@ */ #include "common.h" -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/numeric.c b/src/tds/unittests/numeric.c index c4d91b3b35..144f3b7d0a 100644 --- a/src/tds/unittests/numeric.c +++ b/src/tds/unittests/numeric.c @@ -90,8 +90,7 @@ test(const char *src, int prec, int scale, int scale2) test0(src, prec, scale, prec, scale2); } -int -main(void) +TEST_MAIN() { int i; memset(&ctx, 0, sizeof(ctx)); diff --git a/src/tds/unittests/parsing.c b/src/tds/unittests/parsing.c index 0be191b2f7..b34d1a2348 100644 --- a/src/tds/unittests/parsing.c +++ b/src/tds/unittests/parsing.c @@ -64,8 +64,7 @@ test_generic(const char *s, int expected_pos, bool comment, int line) #define test_comment(s, e) test_generic(s, e, true, __LINE__) #define test_quote(s, e) test_generic(s, e, false, __LINE__) -int -main(void) +TEST_MAIN() { tdsdump_open(tds_dir_getenv(TDS_DIR("TDSDUMP"))); diff --git a/src/tds/unittests/portconf.c b/src/tds/unittests/portconf.c index da2ca7e60d..efad98ca9c 100644 --- a/src/tds/unittests/portconf.c +++ b/src/tds/unittests/portconf.c @@ -81,8 +81,7 @@ test0(TDSCONTEXT *ctx, TDSSOCKET *tds, const char *input, const char *expected, } #define test(in, out) test0(ctx, tds, in, out, __LINE__) -int -main(void) +TEST_MAIN() { TDSCONTEXT *ctx = tds_alloc_context(NULL); TDSSOCKET *tds = tds_alloc_socket(ctx, 512); diff --git a/src/tds/unittests/readconf.c b/src/tds/unittests/readconf.c index b0a57b6a1a..2921c2db39 100644 --- a/src/tds/unittests/readconf.c +++ b/src/tds/unittests/readconf.c @@ -57,8 +57,7 @@ test(const char *section, const char *entry, const char *expected) exit(1); } -int -main(void) +TEST_MAIN() { const char *in_file = FREETDS_SRCDIR "/readconf.in"; diff --git a/src/tds/unittests/strftime.c b/src/tds/unittests/strftime.c index 93d3bc0244..f5e5cbbb36 100644 --- a/src/tds/unittests/strftime.c +++ b/src/tds/unittests/strftime.c @@ -43,8 +43,7 @@ test(const TDSDATEREC* dr, int prec, const char *fmt, const char *expected, int free(format); } -int -main(void) +TEST_MAIN() { TDSDATEREC dr; diff --git a/src/tds/unittests/t0001.c b/src/tds/unittests/t0001.c index b3aee56a76..a87c47a523 100644 --- a/src/tds/unittests/t0001.c +++ b/src/tds/unittests/t0001.c @@ -22,8 +22,7 @@ */ #include "common.h" -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/t0002.c b/src/tds/unittests/t0002.c index dab41622e6..8cfa0fa234 100644 --- a/src/tds/unittests/t0002.c +++ b/src/tds/unittests/t0002.c @@ -43,8 +43,7 @@ value_as_string(TDSSOCKET * tds, int col_idx) } /* value_as_string() */ -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/t0003.c b/src/tds/unittests/t0003.c index 42b5aef51b..ef68729286 100644 --- a/src/tds/unittests/t0003.c +++ b/src/tds/unittests/t0003.c @@ -18,8 +18,7 @@ */ #include "common.h" -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/t0004.c b/src/tds/unittests/t0004.c index 31e734f95a..ba1d0239fb 100644 --- a/src/tds/unittests/t0004.c +++ b/src/tds/unittests/t0004.c @@ -30,8 +30,7 @@ varchar_as_string(TDSSOCKET * tds, int col_idx) } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/t0005.c b/src/tds/unittests/t0005.c index 66629cd353..28ed02e285 100644 --- a/src/tds/unittests/t0005.c +++ b/src/tds/unittests/t0005.c @@ -21,8 +21,7 @@ static char *value_as_string(TDSSOCKET * tds, int col_idx); -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/t0006.c b/src/tds/unittests/t0006.c index 59a1e6ab5f..a4d1b85f99 100644 --- a/src/tds/unittests/t0006.c +++ b/src/tds/unittests/t0006.c @@ -21,8 +21,7 @@ static TDSCONTEXT ctx; -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/t0007.c b/src/tds/unittests/t0007.c index 3f25f24753..34aa211211 100644 --- a/src/tds/unittests/t0007.c +++ b/src/tds/unittests/t0007.c @@ -178,8 +178,7 @@ int_values[] = { NULL }; -int -main(void) +TEST_MAIN() { int *type1, *type2; const char **value; diff --git a/src/tds/unittests/t0008.c b/src/tds/unittests/t0008.c index fe15d787c1..0fcff9fab6 100644 --- a/src/tds/unittests/t0008.c +++ b/src/tds/unittests/t0008.c @@ -68,8 +68,7 @@ test(const char *src, const char *intro, const char *cont, int prec, int scale, #define test(a,b,c,d,e,f) test(a,b,c,d,e,f,__LINE__) -int -main(void) +TEST_MAIN() { /* very long string for test buffer overflow */ int i; diff --git a/src/tds/unittests/tls.c b/src/tds/unittests/tls.c index 3f43f523f4..d7e64edb13 100644 --- a/src/tds/unittests/tls.c +++ b/src/tds/unittests/tls.c @@ -74,8 +74,7 @@ test_hostname(X509 *cert, const char *hostname, bool expected) } } -int -main(void) +TEST_MAIN() { BIO *bufio; X509 *cert; @@ -113,8 +112,7 @@ main(void) return got_failure ? 1 : 0; } #else -int -main(void) +TEST_MAIN() { return 0; } diff --git a/src/tds/unittests/toodynamic.c b/src/tds/unittests/toodynamic.c index c5520c2d6e..a867814ac8 100644 --- a/src/tds/unittests/toodynamic.c +++ b/src/tds/unittests/toodynamic.c @@ -30,8 +30,7 @@ fatal_error(const char *msg) exit(1); } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; TDSSOCKET *tds; diff --git a/src/tds/unittests/utf8_1.c b/src/tds/unittests/utf8_1.c index 5a7bdd235f..177dd24d19 100644 --- a/src/tds/unittests/utf8_1.c +++ b/src/tds/unittests/utf8_1.c @@ -177,8 +177,7 @@ test(const char *type, const char *test_name) */ } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; int ret; diff --git a/src/tds/unittests/utf8_2.c b/src/tds/unittests/utf8_2.c index 400ade0ed9..afb4640227 100644 --- a/src/tds/unittests/utf8_2.c +++ b/src/tds/unittests/utf8_2.c @@ -198,8 +198,7 @@ err_handler(const TDSCONTEXT * tds_ctx TDS_UNUSED, TDSSOCKET * tds TDS_UNUSED, T return TDS_INT_CANCEL; } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; int ret; diff --git a/src/tds/unittests/utf8_3.c b/src/tds/unittests/utf8_3.c index 3bfa769707..5eafcba6aa 100644 --- a/src/tds/unittests/utf8_3.c +++ b/src/tds/unittests/utf8_3.c @@ -109,8 +109,7 @@ test(const char *buf) } } -int -main(void) +TEST_MAIN() { TDSLOGIN *login; int ret; diff --git a/src/utils/unittests/bytes.c b/src/utils/unittests/bytes.c index 150165024b..5b02accede 100644 --- a/src/utils/unittests/bytes.c +++ b/src/utils/unittests/bytes.c @@ -51,8 +51,7 @@ assert(val == expected); \ } while(0) -int -main(void) +TEST_MAIN() { /* this structure make sure buffer are properly aligned */ struct { diff --git a/src/utils/unittests/challenge.c b/src/utils/unittests/challenge.c index 8ab3a9d339..1d7729de7a 100644 --- a/src/utils/unittests/challenge.c +++ b/src/utils/unittests/challenge.c @@ -176,8 +176,7 @@ destests(void) } -int -main(void) +TEST_MAIN() { int i; diff --git a/src/utils/unittests/condition.c b/src/utils/unittests/condition.c index 263b4e1686..e638bbc30f 100644 --- a/src/utils/unittests/condition.c +++ b/src/utils/unittests/condition.c @@ -62,7 +62,7 @@ static void check(int cond, const char *msg) } } -int main(void) +TEST_MAIN() { tds_condition cond; tds_thread th; @@ -127,7 +127,7 @@ int main(void) #else -int main(void) +TEST_MAIN() { return 0; } diff --git a/src/utils/unittests/dlist.c b/src/utils/unittests/dlist.c index 08a286d33d..69a58cd320 100644 --- a/src/utils/unittests/dlist.c +++ b/src/utils/unittests/dlist.c @@ -43,8 +43,7 @@ typedef struct #define DLIST_ITEM_TYPE test_item #include -int -main(void) +TEST_MAIN() { test_items list[1]; test_item items[6], *p; diff --git a/src/utils/unittests/mutex1.c b/src/utils/unittests/mutex1.c index d41a86c0c5..4feba3165d 100644 --- a/src/utils/unittests/mutex1.c +++ b/src/utils/unittests/mutex1.c @@ -86,7 +86,7 @@ test(tds_mutex *mtx) tds_mutex_unlock(mtx); } -int main(void) +TEST_MAIN() { tds_mutex local; @@ -113,7 +113,7 @@ int main(void) #else -int main(void) +TEST_MAIN() { return 0; } diff --git a/src/utils/unittests/passarg.c b/src/utils/unittests/passarg.c index 21b218aad3..5e0ae38be2 100644 --- a/src/utils/unittests/passarg.c +++ b/src/utils/unittests/passarg.c @@ -38,7 +38,7 @@ #include #include -int main(void) +TEST_MAIN() { FILE *f; char *pwd = strdup("password"); diff --git a/src/utils/unittests/path.c b/src/utils/unittests/path.c index c48653f46f..7c05758102 100644 --- a/src/utils/unittests/path.c +++ b/src/utils/unittests/path.c @@ -41,7 +41,7 @@ enum { is_windows = 1 }; enum { is_windows = 0 }; #endif -int main(void) +TEST_MAIN() { tds_dir_char *path; size_t len; diff --git a/src/utils/unittests/smp.c b/src/utils/unittests/smp.c index 8460930786..abbd297073 100644 --- a/src/utils/unittests/smp.c +++ b/src/utils/unittests/smp.c @@ -55,7 +55,7 @@ same_int(int n, int expected, int line) #define same_int(n, e) same_int(n, e, __LINE__) -int main(void) +TEST_MAIN() { smp n; smp a; From 3c39ceed2f9bc7080e6ba53fe4e5462c96d8ae40 Mon Sep 17 00:00:00 2001 From: "Aaron M. Ucko" Date: Wed, 17 Jul 2024 14:57:08 -0400 Subject: [PATCH 4/6] Optionally suppress crash dialog boxes for tests on Windows. Consult the environment variable DIAG_SILENT_ABORT (if present), looking for a value starting with Y or y. To that end, adjust TEST_MAIN to call test-specific entry points test_main and incorporate a new tds_test_base library defining a wrapper main that, on Windows, first suppresses any possible source of crash dialog boxes. Signed-off-by: Aaron M. Ucko --- include/freetds/utils/test_base.h | 11 +++++- src/apps/unittests/CMakeLists.txt | 3 +- src/apps/unittests/Makefile.am | 4 +- src/ctlib/unittests/CMakeLists.txt | 8 +++- src/ctlib/unittests/Makefile.am | 4 +- src/dblib/unittests/CMakeLists.txt | 3 +- src/dblib/unittests/Makefile.am | 4 +- src/odbc/unittests/CMakeLists.txt | 9 ++++- src/odbc/unittests/Makefile.am | 7 +++- src/replacements/unittests/CMakeLists.txt | 3 +- src/replacements/unittests/Makefile.am | 3 +- src/tds/unittests/CMakeLists.txt | 3 +- src/tds/unittests/Makefile.am | 4 +- src/utils/unittests/CMakeLists.txt | 7 +++- src/utils/unittests/Makefile.am | 7 +++- src/utils/unittests/test_base.c | 45 +++++++++++++++++++++++ 16 files changed, 107 insertions(+), 18 deletions(-) create mode 100644 src/utils/unittests/test_base.c diff --git a/include/freetds/utils/test_base.h b/include/freetds/utils/test_base.h index c8cbefdf0c..1ff6d85eae 100644 --- a/include/freetds/utils/test_base.h +++ b/include/freetds/utils/test_base.h @@ -17,6 +17,15 @@ #include -#define TEST_MAIN() int main(int argc TDS_UNUSED, char **argv TDS_UNUSED) +/* + * Tests should define test_main in lieu of main so that they can be + * configured to suppress automation-unfriendly crash dialog boxes on + * Windows. To that end, they can use the TEST_MAIN macro, which cleanly + * avoids warnings for the tests that ignore their arguments (but still + * provides the details under conventional names for the remainder). + */ +int test_main(int argc, char **argv); + +#define TEST_MAIN() int test_main(int argc TDS_UNUSED, char **argv TDS_UNUSED) #endif /* _tdsguard_afBM6E9n8CuIFSBHNNblq5 */ diff --git a/src/apps/unittests/CMakeLists.txt b/src/apps/unittests/CMakeLists.txt index 98e5301091..198e890e15 100644 --- a/src/apps/unittests/CMakeLists.txt +++ b/src/apps/unittests/CMakeLists.txt @@ -3,7 +3,8 @@ include_directories(..) foreach(target defncopy) add_executable(a_${target} EXCLUDE_FROM_ALL ${target}.c) set_target_properties(a_${target} PROPERTIES OUTPUT_NAME ${target}) - target_link_libraries(a_${target} replacements tdsutils ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(a_${target} tds_test_base replacements tdsutils + ${lib_NETWORK} ${lib_BASE}) add_test(NAME a_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND a_${target}) add_dependencies(check a_${target}) endforeach(target) diff --git a/src/apps/unittests/Makefile.am b/src/apps/unittests/Makefile.am index 0536c2cc3b..bec1ffec49 100644 --- a/src/apps/unittests/Makefile.am +++ b/src/apps/unittests/Makefile.am @@ -8,6 +8,8 @@ check_PROGRAMS = $(TESTS) defncopy_SOURCES = defncopy.c AM_CPPFLAGS = -I$(top_srcdir)/include -I$(srcdir)/.. -I../ -DFREETDS_TOPDIR=\"$(top_srcdir)\" -LDADD = ../../replacements/libreplacements.la $(LTLIBICONV) $(NETWORK_LIBS) +LDADD = ../../utils/unittests/libtds_test_base.a \ + ../../replacements/libreplacements.la $(LTLIBICONV) \ + $(NETWORK_LIBS) EXTRA_DIST = CMakeLists.txt diff --git a/src/ctlib/unittests/CMakeLists.txt b/src/ctlib/unittests/CMakeLists.txt index 60e722bb77..607aeb8618 100644 --- a/src/ctlib/unittests/CMakeLists.txt +++ b/src/ctlib/unittests/CMakeLists.txt @@ -14,9 +14,13 @@ foreach(target t0001 t0002 t0003 t0004 add_executable(c_${target} EXCLUDE_FROM_ALL ${target}.c) set_target_properties(c_${target} PROPERTIES OUTPUT_NAME ${target}) if (target STREQUAL "all_types") - target_link_libraries(c_${target} c_common ct-static t_common tds replacements tdsutils ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(c_${target} c_common ct-static + t_common tds_test_base tds replacements + tdsutils ${lib_NETWORK} ${lib_BASE}) else() - target_link_libraries(c_${target} c_common ct replacements tdsutils ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(c_${target} c_common tds_test_base ct + replacements tdsutils ${lib_NETWORK} + ${lib_BASE}) endif() add_test(NAME c_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND c_${target}) add_dependencies(check c_${target}) diff --git a/src/ctlib/unittests/Makefile.am b/src/ctlib/unittests/Makefile.am index 426d3e4b14..ec8d316b30 100644 --- a/src/ctlib/unittests/Makefile.am +++ b/src/ctlib/unittests/Makefile.am @@ -91,6 +91,8 @@ AM_LDFLAGS = -no-fast-install else AM_LDFLAGS = -no-install -L../.libs -R "$(abs_builddir)/../.libs" endif -LDADD = libcommon.a ../libct.la ../../replacements/libreplacements.la $(LTLIBICONV) +LDADD = libcommon.a ../../utils/unittests/libtds_test_base.a \ + ../libct.la ../../replacements/libreplacements.la \ + $(LTLIBICONV) CLEANFILES = tdsdump.out EXTRA_DIST = CMakeLists.txt diff --git a/src/dblib/unittests/CMakeLists.txt b/src/dblib/unittests/CMakeLists.txt index e0c4b2b89f..8d2baf2323 100644 --- a/src/dblib/unittests/CMakeLists.txt +++ b/src/dblib/unittests/CMakeLists.txt @@ -8,7 +8,8 @@ foreach(target t0001 t0002 t0003 t0004 t0005 t0006 t0007 t0008 t0009 empty_rowsets string_bind colinfo bcp2 proc_limit) add_executable(d_${target} EXCLUDE_FROM_ALL ${target}.c) set_target_properties(d_${target} PROPERTIES OUTPUT_NAME ${target}) - target_link_libraries(d_${target} d_common sybdb replacements tdsutils ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(d_${target} d_common tds_test_base sybdb + replacements tdsutils ${lib_NETWORK} ${lib_BASE}) add_test(NAME d_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND d_${target}) add_dependencies(check d_${target}) endforeach(target) diff --git a/src/dblib/unittests/Makefile.am b/src/dblib/unittests/Makefile.am index 11987f4c7a..ca739148af 100644 --- a/src/dblib/unittests/Makefile.am +++ b/src/dblib/unittests/Makefile.am @@ -110,7 +110,9 @@ AM_LDFLAGS = -no-fast-install else AM_LDFLAGS = -no-install -L../.libs -R "$(abs_builddir)/../.libs" endif -LDADD = libcommon.a ../libsybdb.la ../../replacements/libreplacements.la $(LTLIBICONV) +LDADD = libcommon.a ../../utils/unittests/libtds_test_base.a \ + ../libsybdb.la ../../replacements/libreplacements.la \ + $(LTLIBICONV) EXTRA_DIST = CMakeLists.txt CLEANFILES = tdsdump.out t0013.out t0014.out t0016.out \ t0016.err t0017.err t0017.out diff --git a/src/odbc/unittests/CMakeLists.txt b/src/odbc/unittests/CMakeLists.txt index c36a39cc3a..a2ed98ae94 100644 --- a/src/odbc/unittests/CMakeLists.txt +++ b/src/odbc/unittests/CMakeLists.txt @@ -47,9 +47,14 @@ foreach(target ${tests}) add_executable(o_${target} EXCLUDE_FROM_ALL ${target}.c) set_target_properties(o_${target} PROPERTIES OUTPUT_NAME ${target}) if (target IN_LIST static_tests) - target_link_libraries(o_${target} o_common tdsodbc_static t_common tds replacements tdsutils ${lib_ODBCINST} ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(o_${target} o_common tds_test_base + tdsodbc_static t_common tds replacements + tdsutils ${lib_ODBCINST} ${lib_NETWORK} + ${lib_BASE}) else() - target_link_libraries(o_${target} o_common replacements tdsutils ${libs} ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(o_${target} o_common tds_test_base + replacements tdsutils ${libs} + ${lib_NETWORK} ${lib_BASE}) endif() if (ENABLE_ODBC_WIDE AND NOT target IN_LIST unicode_tests) set_property(TARGET o_${target} APPEND PROPERTY COMPILE_DEFINITIONS UNICODE=1 _UNICODE=1_) diff --git a/src/odbc/unittests/Makefile.am b/src/odbc/unittests/Makefile.am index dcc4e33b40..6cbd9c778e 100644 --- a/src/odbc/unittests/Makefile.am +++ b/src/odbc/unittests/Makefile.am @@ -153,7 +153,8 @@ cursor7_SOURCES = cursor7.c utf8_SOURCES = utf8.c common.c # this test cannot work using wide characters as use UTF-8 and single byte encoding utf8_CPPFLAGS = $(GLOBAL_CPPFLAGS) -utf8_LDADD = $(ODBC_LDFLAGS) $(NETWORK_LIBS) $(ODBCINST_LDFLAGS) +utf8_LDADD = ../../utils/unittests/libtds_test_base.a \ + $(ODBC_LDFLAGS) $(NETWORK_LIBS) $(ODBCINST_LDFLAGS) utf8_2_SOURCES = utf8_2.c utf8_3_SOURCES = utf8_3.c utf8_4_SOURCES = utf8_4.c @@ -196,7 +197,9 @@ AM_LDFLAGS = -no-fast-install else AM_LDFLAGS = -no-install -L../.libs -R "$(abs_builddir)/../.libs" endif -LDADD = libcommon.a $(ODBC_LDFLAGS) ../../replacements/libreplacements.la $(GLOBAL_LD_ADD) +LDADD = libcommon.a ../../utils/unittests/libtds_test_base.a \ + $(ODBC_LDFLAGS) ../../replacements/libreplacements.la \ + $(GLOBAL_LD_ADD) DISTCLEANFILES = odbc.ini odbcinst.ini EXTRA_DIST = CMakeLists.txt diff --git a/src/replacements/unittests/CMakeLists.txt b/src/replacements/unittests/CMakeLists.txt index 9e7dbebf68..a2878f3998 100644 --- a/src/replacements/unittests/CMakeLists.txt +++ b/src/replacements/unittests/CMakeLists.txt @@ -1,7 +1,8 @@ foreach(target strings strtok_r strsep) add_executable(r_${target} ${target}.c) set_target_properties(r_${target} PROPERTIES OUTPUT_NAME ${target}) - target_link_libraries(r_${target} replacements tdsutils ${lib_BASE}) + target_link_libraries(r_${target} tds_test_base replacements tdsutils + ${lib_BASE}) add_test(NAME r_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND r_${target}) add_dependencies(check r_${target}) endforeach(target) diff --git a/src/replacements/unittests/Makefile.am b/src/replacements/unittests/Makefile.am index 0a1dbe7cda..b5884f22ae 100644 --- a/src/replacements/unittests/Makefile.am +++ b/src/replacements/unittests/Makefile.am @@ -11,6 +11,7 @@ strtok_r_SOURCES = strtok_r.c strsep_SOURCES = strsep.c AM_CPPFLAGS = -I$(top_srcdir)/include -I$(srcdir)/.. -I../ -LDADD = ../../replacements/libreplacements.la $(NETWORK_LIBS) +LDADD = ../../utils/unittests/libtds_test_base.a \ + ../../replacements/libreplacements.la $(NETWORK_LIBS) EXTRA_DIST = CMakeLists.txt diff --git a/src/tds/unittests/CMakeLists.txt b/src/tds/unittests/CMakeLists.txt index f297e8d14b..42e82da885 100644 --- a/src/tds/unittests/CMakeLists.txt +++ b/src/tds/unittests/CMakeLists.txt @@ -8,7 +8,8 @@ foreach(target t0001 t0002 t0003 t0004 t0005 t0006 t0007 t0008 dynamic1 parsing freeze strftime log_elision convert_bounds tls) add_executable(t_${target} EXCLUDE_FROM_ALL ${target}.c) set_target_properties(t_${target} PROPERTIES OUTPUT_NAME ${target}) - target_link_libraries(t_${target} t_common tds replacements tdsutils ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(t_${target} t_common tds_test_base tds + replacements tdsutils ${lib_NETWORK} ${lib_BASE}) if(NOT ${target} STREQUAL "collations") add_test(NAME t_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND t_${target}) endif() diff --git a/src/tds/unittests/Makefile.am b/src/tds/unittests/Makefile.am index b503d71bb0..45fef3994c 100644 --- a/src/tds/unittests/Makefile.am +++ b/src/tds/unittests/Makefile.am @@ -80,7 +80,9 @@ AM_LDFLAGS = -no-fast-install else AM_LDFLAGS = -no-install -L../.libs -R "$(abs_builddir)/../.libs" endif -LDADD = libcommon.a ../libtds.la ../../replacements/libreplacements.la $(LTLIBICONV) $(NETWORK_LIBS) +LDADD = libcommon.a ../../utils/unittests/libtds_test_base.a \ + ../libtds.la ../../replacements/libreplacements.la \ + $(LTLIBICONV) $(NETWORK_LIBS) CLEANFILES = tdsdump.out EXTRA_DIST = CMakeLists.txt diff --git a/src/utils/unittests/CMakeLists.txt b/src/utils/unittests/CMakeLists.txt index 2ce8fd3289..e384044148 100644 --- a/src/utils/unittests/CMakeLists.txt +++ b/src/utils/unittests/CMakeLists.txt @@ -1,5 +1,9 @@ include_directories(..) +add_library(tds_test_base STATIC + test_base.c +) + if(NOT WIN32) set(unix_TESTS challenge) endif(NOT WIN32) @@ -7,7 +11,8 @@ endif(NOT WIN32) foreach(target passarg condition mutex1 dlist bytes smp path ${unix_TESTS}) add_executable(u_${target} EXCLUDE_FROM_ALL ${target}.c) set_target_properties(u_${target} PROPERTIES OUTPUT_NAME ${target}) - target_link_libraries(u_${target} tdsutils ${lib_NETWORK} ${lib_BASE}) + target_link_libraries(u_${target} tds_test_base tdsutils ${lib_NETWORK} + ${lib_BASE}) add_test(NAME u_${target} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND u_${target}) add_dependencies(check u_${target}) endforeach(target) diff --git a/src/utils/unittests/Makefile.am b/src/utils/unittests/Makefile.am index 97acee0b2e..07f6e9f258 100644 --- a/src/utils/unittests/Makefile.am +++ b/src/utils/unittests/Makefile.am @@ -21,6 +21,11 @@ TESTS += challenge$(EXEEXT) challenge_SOURCES= challenge.c endif +noinst_LIBRARIES = libtds_test_base.a +libtds_test_base_a_SOURCES = \ + test_base.c \ + $(NULL) + AM_CPPFLAGS = -I$(top_srcdir)/include -LDADD = ../libtdsutils.la @NETWORK_LIBS@ +LDADD = libtds_test_base.a ../libtdsutils.la @NETWORK_LIBS@ EXTRA_DIST = CMakeLists.txt challenge.c diff --git a/src/utils/unittests/test_base.c b/src/utils/unittests/test_base.c new file mode 100644 index 0000000000..cf6e2da12b --- /dev/null +++ b/src/utils/unittests/test_base.c @@ -0,0 +1,45 @@ +#include + +#ifdef _WIN32 +# include +# include + +static LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep) +{ + /* Always terminate the test. */ + return EXCEPTION_EXECUTE_HANDLER; +} + +static void suppress_diag_popup_messages(void) +{ + /* Check environment variable for silent abort app at error */ + const char* value = getenv("DIAG_SILENT_ABORT"); + if (value && (*value == 'Y' || *value == 'y')) { + /* Windows GPF errors */ + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | + SEM_NOOPENFILEERRORBOX); + + /* Runtime library */ + _set_error_mode(_OUT_TO_STDERR); + + /* Debug library */ + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); + + /* Exceptions(!) */ + SetUnhandledExceptionFilter(seh_handler); + } +} +#endif + +int main(int argc, char ** argv) +{ +#ifdef _WIN32 + suppress_diag_popup_messages(); +#endif + return test_main(argc, argv); +} From c996ac768f25cd1698f67bfb2b54b79306810500 Mon Sep 17 00:00:00 2001 From: "Aaron M. Ucko" Date: Wed, 17 Jul 2024 15:38:03 -0400 Subject: [PATCH 5/6] Centralize test login info (PWD file) handling. Extend the recently introduced tds_test_base library to supply a new COMMON_PWD data structure (mostly based on ctlib tests'), an instance thereof (the only one in practice), functions for working with it, and the default (relative) path to try. Adjust everything else to use this setup rather than a local variant thereof. Let historical variable names such as SERVER continue to work within dblib tests because all online dblib tests need to consult them, but explicitly go through the instance elsewhere, including dblib tests' common.c. Signed-off-by: Aaron M. Ucko --- include/freetds/utils/test_base.h | 33 ++++++++++ src/apps/unittests/defncopy.c | 49 +++------------ src/ctlib/unittests/common.c | 93 +++++++---------------------- src/ctlib/unittests/common.h | 17 ------ src/ctlib/unittests/connect_fail.c | 2 +- src/dblib/unittests/common.c | 96 +++++++----------------------- src/dblib/unittests/common.h | 12 ++-- src/odbc/unittests/cancel.c | 5 +- src/odbc/unittests/common.c | 77 ++++++++++-------------- src/odbc/unittests/common.h | 6 -- src/odbc/unittests/connect.c | 32 +++++++--- src/odbc/unittests/connect2.c | 11 ++-- src/odbc/unittests/freeclose.c | 6 +- src/odbc/unittests/oldpwd.c | 5 +- src/odbc/unittests/qn.c | 8 ++- src/odbc/unittests/stats.c | 4 +- src/odbc/unittests/timeout3.c | 5 +- src/tds/unittests/common.c | 50 +++------------- src/tds/unittests/common.h | 6 -- src/tds/unittests/utf8_1.c | 2 +- src/tds/unittests/utf8_2.c | 2 +- src/tds/unittests/utf8_3.c | 2 +- src/utils/unittests/test_base.c | 93 +++++++++++++++++++++++++++++ 23 files changed, 281 insertions(+), 335 deletions(-) diff --git a/include/freetds/utils/test_base.h b/include/freetds/utils/test_base.h index 1ff6d85eae..1678a7bffc 100644 --- a/include/freetds/utils/test_base.h +++ b/include/freetds/utils/test_base.h @@ -15,6 +15,7 @@ #include +#include #include /* @@ -28,4 +29,36 @@ int test_main(int argc, char **argv); #define TEST_MAIN() int test_main(int argc TDS_UNUSED, char **argv TDS_UNUSED) + +typedef struct +{ + char SERVER[512]; + char DATABASE[512]; + char USER[512]; + char PASSWORD[512]; + char DRIVER[1024]; /* ODBC-only */ + char CHARSET[512]; + int maxlength; + bool fverbose; + bool initialized; + bool tried_env; +} COMMON_PWD; + +extern COMMON_PWD common_pwd; + +#define DEFAULT_PWD_PATH "../../../PWD" + +void reset_login_info(COMMON_PWD * common_pwd); + +/* + * Both return the path used (favoring $TDSPWDFILE in the absence of + * tried_env) on success or NULL on failure (silently in the case of + * try_read_login_info), and defer to any existing settings from + * e.g. the command line. + */ +const char * read_login_info_base(COMMON_PWD * common_pwd, + const char * default_path); +const char * try_read_login_info_base(COMMON_PWD * common_pwd, + const char * default_path); + #endif /* _tdsguard_afBM6E9n8CuIFSBHNNblq5 */ diff --git a/src/apps/unittests/defncopy.c b/src/apps/unittests/defncopy.c index cd51d9ff2a..249687089d 100644 --- a/src/apps/unittests/defncopy.c +++ b/src/apps/unittests/defncopy.c @@ -47,49 +47,14 @@ #include #include -static char USER[512]; -static char SERVER[512]; -static char PASSWORD[512]; -static char DATABASE[512]; - /* content of output file, from command executed */ static char *output; static bool read_login_info(void) { - FILE *in = NULL; - char line[512]; - char *s1, *s2; - - s1 = getenv("TDSPWDFILE"); - if (s1 && s1[0]) - in = fopen(s1, "r"); - if (!in) - in = fopen("../../../PWD", "r"); - if (!in) { - fprintf(stderr, "Can not open PWD file\n\n"); - return false; - } - - while (fgets(line, sizeof(line), in)) { - s1 = strtok(line, "="); - s2 = strtok(NULL, "\n"); - if (!s1 || !s2) { - continue; - } - if (!strcmp(s1, "UID")) { - strcpy(USER, s2); - } else if (!strcmp(s1, "SRV")) { - strcpy(SERVER, s2); - } else if (!strcmp(s1, "PWD")) { - strcpy(PASSWORD, s2); - } else if (!strcmp(s1, "DB")) { - strcpy(DATABASE, s2); - } - } - fclose(in); - return true; + reset_login_info(&common_pwd); + return read_login_info_base(&common_pwd, DEFAULT_PWD_PATH) != NULL; } static void @@ -211,14 +176,14 @@ static char * add_server(char *dest, char *const dest_end) { dest = add_string(dest, dest_end, " -S "); - dest = quote_arg(dest, dest_end, SERVER); + dest = quote_arg(dest, dest_end, common_pwd.SERVER); dest = add_string(dest, dest_end, " -U "); - dest = quote_arg(dest, dest_end, USER); + dest = quote_arg(dest, dest_end, common_pwd.USER); dest = add_string(dest, dest_end, " -P "); - dest = quote_arg(dest, dest_end, PASSWORD); - if (DATABASE[0]) { + dest = quote_arg(dest, dest_end, common_pwd.PASSWORD); + if (common_pwd.DATABASE[0]) { dest = add_string(dest, dest_end, " -D "); - dest = quote_arg(dest, dest_end, DATABASE); + dest = quote_arg(dest, dest_end, common_pwd.DATABASE); } return dest; } diff --git a/src/ctlib/unittests/common.c b/src/ctlib/unittests/common.c index 7a4b7a3853..4c3208f580 100644 --- a/src/ctlib/unittests/common.c +++ b/src/ctlib/unittests/common.c @@ -11,16 +11,9 @@ #include "ctlib.h" #endif -char USER[512]; -char SERVER[512]; -char PASSWORD[512]; -char DATABASE[512]; - -COMMON_PWD common_pwd = {0}; - static const char *BASENAME = NULL; -static const char *PWD = "../../../PWD"; +static const char *PWD = DEFAULT_PWD_PATH; int cslibmsg_cb_invoked = 0; int clientmsg_cb_invoked = 0; @@ -34,46 +27,8 @@ static CS_RETCODE continue_logging_in(CS_CONTEXT ** ctx, CS_CONNECTION ** conn, CS_RETCODE read_login_info(void) { - FILE *in = NULL; - char line[512]; - char *s1, *s2; - - if (common_pwd.initialized) { - strcpy(USER, common_pwd.USER); - strcpy(PASSWORD, common_pwd.PASSWORD); - strcpy(SERVER, common_pwd.SERVER); - strcpy(DATABASE, common_pwd.DATABASE); - return CS_SUCCEED; - } - - s1 = getenv("TDSPWDFILE"); - if (s1 && s1[0]) - in = fopen(s1, "r"); - if (!in) - in = fopen(PWD, "r"); - if (!in) { - fprintf(stderr, "Can not open PWD file \"%s\"\n\n", PWD); - return CS_FAIL; - } - - while (fgets(line, sizeof(line), in)) { - s1 = strtok(line, "="); - s2 = strtok(NULL, "\n"); - if (!s1 || !s2) { - continue; - } - if (!strcmp(s1, "UID")) { - strcpy(USER, s2); - } else if (!strcmp(s1, "SRV")) { - strcpy(SERVER, s2); - } else if (!strcmp(s1, "PWD")) { - strcpy(PASSWORD, s2); - } else if (!strcmp(s1, "DB")) { - strcpy(DATABASE, s2); - } - } - fclose(in); - return CS_SUCCEED; + const char * s = read_login_info_base(&common_pwd, DEFAULT_PWD_PATH); + return s ? CS_SUCCEED : CS_FAIL; } static CS_RETCODE @@ -81,25 +36,30 @@ establish_login(int argc, char **argv) { extern char *optarg; extern int optind; - COMMON_PWD options = {0}; int ch; + reset_login_info(&common_pwd); + BASENAME = basename((char *)argv[0]); /* process command line options (handy for manual testing) */ while ((ch = getopt(argc, argv, "U:P:S:D:f:m:v")) != -1) { switch (ch) { case 'U': - strcpy(options.USER, optarg); + strlcpy(common_pwd.USER, optarg, + sizeof(common_pwd.USER)); break; case 'P': - strcpy(options.PASSWORD, optarg); + strlcpy(common_pwd.PASSWORD, optarg, + sizeof(common_pwd.PASSWORD)); break; case 'S': - strcpy(options.SERVER, optarg); + strlcpy(common_pwd.SERVER, optarg, + sizeof(common_pwd.SERVER)); break; case 'D': - strcpy(options.DATABASE, optarg); + strlcpy(common_pwd.DATABASE, optarg, + sizeof(common_pwd.DATABASE)); break; case 'f': /* override default PWD file */ PWD = strdup(optarg); @@ -120,18 +80,8 @@ establish_login(int argc, char **argv) } read_login_info(); - /* override PWD file with command-line options */ - - if (*options.USER) - strcpy(USER, options.USER); - if (*options.PASSWORD) - strcpy(PASSWORD, options.PASSWORD); - if (*options.SERVER) - strcpy(SERVER, options.SERVER); - if (*options.DATABASE) - strcpy(DATABASE, options.DATABASE); - - return (*USER && *SERVER && *DATABASE)? CS_SUCCEED : CS_FAIL; + return (*common_pwd.USER && *common_pwd.SERVER && *common_pwd.DATABASE) + ? CS_SUCCEED : CS_FAIL; } CS_RETCODE @@ -213,14 +163,16 @@ continue_logging_in(CS_CONTEXT ** ctx, CS_CONNECTION ** conn, CS_COMMAND ** cmd, } return ret; } - ret = ct_con_props(*conn, CS_SET, CS_USERNAME, USER, CS_NULLTERM, NULL); + ret = ct_con_props(*conn, CS_SET, CS_USERNAME, common_pwd.USER, + CS_NULLTERM, NULL); if (ret != CS_SUCCEED) { if (verbose) { fprintf(stderr, "ct_con_props() SET USERNAME failed!\n"); } return ret; } - ret = ct_con_props(*conn, CS_SET, CS_PASSWORD, PASSWORD, CS_NULLTERM, NULL); + ret = ct_con_props(*conn, CS_SET, CS_PASSWORD, common_pwd.PASSWORD, + CS_NULLTERM, NULL); if (ret != CS_SUCCEED) { if (verbose) { fprintf(stderr, "ct_con_props() SET PASSWORD failed!\n"); @@ -235,9 +187,10 @@ continue_logging_in(CS_CONTEXT ** ctx, CS_CONNECTION ** conn, CS_COMMAND ** cmd, return ret; } - printf("connecting as %s to %s.%s\n", USER, SERVER, DATABASE); + printf("connecting as %s to %s.%s\n", + common_pwd.USER, common_pwd.SERVER, common_pwd.DATABASE); - ret = ct_connect(*conn, SERVER, CS_NULLTERM); + ret = ct_connect(*conn, common_pwd.SERVER, CS_NULLTERM); if (ret != CS_SUCCEED) { if (verbose) { fprintf(stderr, "Connection failed!\n"); @@ -262,7 +215,7 @@ continue_logging_in(CS_CONTEXT ** ctx, CS_CONNECTION ** conn, CS_COMMAND ** cmd, return ret; } - sprintf(query, "use %s", DATABASE); + sprintf(query, "use %s", common_pwd.DATABASE); ret = run_command(*cmd, query); if (ret != CS_SUCCEED) diff --git a/src/ctlib/unittests/common.h b/src/ctlib/unittests/common.h index ea2b4d608a..3c45d47953 100644 --- a/src/ctlib/unittests/common.h +++ b/src/ctlib/unittests/common.h @@ -18,23 +18,6 @@ #include -extern char SERVER[512]; -extern char DATABASE[512]; -extern char USER[512]; -extern char PASSWORD[512]; - -typedef struct -{ - int initialized; - char SERVER[512]; - char DATABASE[512]; - char USER[512]; - char PASSWORD[512]; - char fverbose; - int maxlength; -} COMMON_PWD; -extern COMMON_PWD common_pwd; - typedef enum ct_message_type { /** no message saved */ CTMSG_NONE, diff --git a/src/ctlib/unittests/connect_fail.c b/src/ctlib/unittests/connect_fail.c index 0a8bb953dc..98ec9d0d73 100644 --- a/src/ctlib/unittests/connect_fail.c +++ b/src/ctlib/unittests/connect_fail.c @@ -13,7 +13,7 @@ TEST_MAIN() check_call(ct_con_alloc, (ctx, &conn)); check_call(ct_con_props, (conn, CS_SET, CS_USERNAME, (CS_VOID*) "sa", CS_NULLTERM, NULL)); check_call(ct_con_props, (conn, CS_SET, CS_PASSWORD, (CS_VOID*) "invalid", CS_NULLTERM, NULL)); - if (ct_connect(conn, SERVER, CS_NULLTERM) != CS_FAIL) { + if (ct_connect(conn, common_pwd.SERVER, CS_NULLTERM) != CS_FAIL) { fprintf(stderr, "Connection succeeded??\n"); return ret; } diff --git a/src/dblib/unittests/common.c b/src/dblib/unittests/common.c index 329f260869..ae77a4cd82 100644 --- a/src/dblib/unittests/common.c +++ b/src/dblib/unittests/common.c @@ -25,11 +25,6 @@ #define PATH_MAX 256 #endif -char USER[512]; -char SERVER[512]; -char PASSWORD[512]; -char DATABASE[512]; - static char sql_file[PATH_MAX]; static FILE* input_file = NULL; @@ -106,12 +101,11 @@ int read_login_info(int argc, char **argv) { int len; - FILE *in = NULL; int ch; - char *s1; + char *s1 TDS_UNUSED; char filename[PATH_MAX]; - static const char *PWD = "../../../PWD"; - struct { char *username, *password, *servername, *database; char fverbose; } options; + static const char *PWD = DEFAULT_PWD_PATH; + const char *final_filename = NULL; #if defined(HAVE_SETRLIMIT) && defined(RLIMIT_STACK) #define MAX_STACK (8*1024*1024) @@ -124,6 +118,8 @@ read_login_info(int argc, char **argv) } #endif + reset_login_info(&common_pwd); + setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -149,28 +145,30 @@ read_login_info(int argc, char **argv) #endif DIRNAME = dirname(ARGV0); - memset(&options, 0, sizeof(options)); - /* process command line options (handy for manual testing) */ while ((ch = getopt(argc, (char**)argv, "U:P:S:D:f:v")) != -1) { switch (ch) { case 'U': - options.username = strdup(optarg); + strlcpy(common_pwd.USER, optarg, + sizeof(common_pwd.USER)); break; case 'P': - options.password = strdup(optarg); + strlcpy(common_pwd.PASSWORD, optarg, + sizeof(common_pwd.PASSWORD)); break; case 'S': - options.servername = strdup(optarg); + strlcpy(common_pwd.SERVER, optarg, + sizeof(common_pwd.SERVER)); break; case 'D': - options.database = strdup(optarg); + strlcpy(common_pwd.DATABASE, optarg, + sizeof(common_pwd.DATABASE)); break; case 'f': /* override default PWD file */ PWD = strdup(optarg); break; - case 'v': - options.fverbose = 1; /* doesn't normally do anything */ + case 'v': /* doesn't normally do anything */ + common_pwd.fverbose = 1; break; case '?': default: @@ -184,69 +182,21 @@ read_login_info(int argc, char **argv) } } strlcpy(filename, PWD, sizeof(filename)); - - s1 = getenv("TDSPWDFILE"); - if (s1 && s1[0]) - in = fopen(s1, "r"); - if (!in) - in = fopen(filename, "r"); - if (!in) - in = fopen("PWD", "r"); - if (!in) { + if ( !(final_filename = try_read_login_info_base(&common_pwd, + filename)) + && !(final_filename = try_read_login_info_base(&common_pwd, + "PWD")) ) { sprintf(filename, "%s/%s", (DIRNAME) ? DIRNAME : ".", PWD); - - in = fopen(filename, "r"); - } - - if (!in) { - fprintf(stderr, "Can not open %s file\n\n", filename); - } else { - char line[512]; - - while (fgets(line, sizeof(line), in)) { - const char *value; - - s1 = strtok(line, "="); - value = strtok(NULL, "\n"); - if (!s1 || !value) - continue; - if (!strcmp(s1, "UID")) { - strlcpy(USER, value, sizeof(USER)); - } else if (!strcmp(s1, "SRV")) { - strlcpy(SERVER, value, sizeof(SERVER)); - } else if (!strcmp(s1, "PWD")) { - strlcpy(PASSWORD, value, sizeof(PASSWORD)); - } else if (!strcmp(s1, "DB")) { - strlcpy(DATABASE, value, sizeof(DATABASE)); - } - } - fclose(in); - } - - /* apply command-line overrides */ - if (options.username) { - strlcpy(USER, options.username, sizeof(USER)); - free(options.username); - } - if (options.password) { - strlcpy(PASSWORD, options.password, sizeof(PASSWORD)); - free(options.password); - } - if (options.servername) { - strlcpy(SERVER, options.servername, sizeof(SERVER)); - free(options.servername); - } - if (options.database) { - strlcpy(DATABASE, options.database, sizeof(DATABASE)); - free(options.database); + final_filename = read_login_info_base(&common_pwd, filename); } - if (!*SERVER) { + if (!*common_pwd.SERVER) { fprintf(stderr, "no servername provided, quitting.\n"); exit(1); } - printf("found %s.%s for %s in \"%s\"\n", SERVER, DATABASE, USER, filename); + printf("found %s.%s for %s in \"%s\"\n", common_pwd.SERVER, + common_pwd.DATABASE, common_pwd.USER, final_filename); #if 0 dbrecftos(BASENAME); diff --git a/src/dblib/unittests/common.h b/src/dblib/unittests/common.h index 72164fe4b1..af1de7549e 100644 --- a/src/dblib/unittests/common.h +++ b/src/dblib/unittests/common.h @@ -83,10 +83,14 @@ extern int optopt; extern int opterr; extern int optreset; -extern char PASSWORD[512]; -extern char USER[512]; -extern char SERVER[512]; -extern char DATABASE[512]; +/* + * Historical names for widely used values -- common code initializes + * them but then leaves the rest to tests. + */ +static char * const PASSWORD TDS_UNUSED = common_pwd.PASSWORD; +static char * const USER TDS_UNUSED = common_pwd.USER; +static char * const SERVER TDS_UNUSED = common_pwd.SERVER; +static char * const DATABASE TDS_UNUSED = common_pwd.DATABASE; void set_malloc_options(void); int read_login_info(int argc, char **argv); diff --git a/src/odbc/unittests/cancel.c b/src/odbc/unittests/cancel.c index 8582ee1e5a..266bbb29cd 100644 --- a/src/odbc/unittests/cancel.c +++ b/src/odbc/unittests/cancel.c @@ -199,11 +199,12 @@ TEST_MAIN() * is better to do it before connect cause unixODBC cache INIs * the name must be odbcinst.ini cause unixODBC accept only this name */ - if (odbc_driver[0]) { + if (common_pwd.DRIVER[0]) { FILE *f = fopen("odbcinst.ini", "w"); if (f) { - fprintf(f, "[FreeTDS]\nDriver = %s\nThreading = 0\n", odbc_driver); + fprintf(f, "[FreeTDS]\nDriver = %s\nThreading = 0\n", + common_pwd.DRIVER); fclose(f); /* force iODBC */ setenv("ODBCINSTINI", "./odbcinst.ini", 1); diff --git a/src/odbc/unittests/common.c b/src/odbc/unittests/common.c index 0c1d50770d..6a9ec2e489 100644 --- a/src/odbc/unittests/common.c +++ b/src/odbc/unittests/common.c @@ -35,12 +35,6 @@ int odbc_use_version3 = 0; void (*odbc_set_conn_attr)(void) = NULL; const char *odbc_conn_additional_params = NULL; -char odbc_user[512]; -char odbc_server[512]; -char odbc_password[512]; -char odbc_database[512]; -char odbc_driver[1024]; - static int freetds_driver = -1; static int tds_version = -1; static char db_str_version[32]; @@ -78,10 +72,9 @@ static const char *const search_driver[] = { int odbc_read_login_info(void) { - static const char *PWD = "../../../PWD"; + const char *PWD = DEFAULT_PWD_PATH; FILE *in = NULL; - char line[512]; - char *s1, *s2; + char *s1; const char *const *search_p; char path[1024]; int len; @@ -90,37 +83,14 @@ odbc_read_login_info(void) UWORD old_config_mode; #endif + reset_login_info(&common_pwd); + setbuf(stdout, NULL); setbuf(stderr, NULL); - s1 = getenv("TDSPWDFILE"); - if (s1 && s1[0]) - in = fopen(s1, "r"); - if (!in) - in = fopen(PWD, "r"); - if (!in) - in = fopen("PWD", "r"); - - if (!in) { - fprintf(stderr, "Can not open PWD file\n\n"); + PWD = try_read_login_info_base(&common_pwd, PWD); + if ( !PWD && !read_login_info_base(&common_pwd, "PWD") ) return 1; - } - while (fgets(line, 512, in)) { - s1 = strtok(line, "="); - s2 = strtok(NULL, "\n"); - if (!s1 || !s2) - continue; - if (!strcmp(s1, "UID")) { - strcpy(odbc_user, s2); - } else if (!strcmp(s1, "SRV")) { - strcpy(odbc_server, s2); - } else if (!strcmp(s1, "PWD")) { - strcpy(odbc_password, s2); - } else if (!strcmp(s1, "DB")) { - strcpy(odbc_database, s2); - } - } - fclose(in); /* find our driver */ #ifndef _WIN32 @@ -150,7 +120,7 @@ odbc_read_login_info(void) } if (!*search_p) return 0; - strcpy(odbc_driver, path); + strcpy(common_pwd.DRIVER, path); s1 = getenv("TDSINIOVERRIDE"); if (s1 && atoi(s1) == 0) @@ -161,7 +131,10 @@ odbc_read_login_info(void) sprintf(path, "odbc.ini.%d", (int) getpid()); in = fopen(path, "w"); if (in) { - fprintf(in, "[%s]\nDriver = %s\nDatabase = %s\nServername = %s\n", odbc_server, odbc_driver, odbc_database, odbc_server); + fprintf(in, + "[%s]\nDriver = %s\nDatabase = %s\nServername = %s\n", + common_pwd.SERVER, common_pwd.DRIVER, + common_pwd.DATABASE, common_pwd.SERVER); fclose(in); if (ini_override) { setenv("ODBCINI", "./odbc.ini", 1); @@ -173,12 +146,19 @@ odbc_read_login_info(void) #else if (ini_override && SQLGetConfigMode(&old_config_mode)) { ODBC_BUF *odbc_buf = NULL; - LPCTSTR server = (LPCTSTR) T(odbc_server); + LPCTSTR server = (LPCTSTR) T(common_pwd.SERVER); LPCTSTR filename = (LPCTSTR) T("odbc.ini"); SQLSetConfigMode(ODBC_USER_DSN); - SQLWritePrivateProfileString(server, (LPCTSTR) T("Driver"), (void *) T(odbc_driver), filename); - SQLWritePrivateProfileString(server, (LPCTSTR) T("Database"), (LPCTSTR) T(odbc_database), filename); - SQLWritePrivateProfileString(server, (LPCTSTR) T("Servername"), (LPCTSTR) T(odbc_server), filename); + SQLWritePrivateProfileString(server, (LPCTSTR) T("Driver"), + (void *) T(common_pwd.DRIVER), + filename); + SQLWritePrivateProfileString(server, (LPCTSTR) T("Database"), + (LPCTSTR) T(common_pwd.DATABASE), + filename); + SQLWritePrivateProfileString(server, + (LPCTSTR) T("Servername"), + (LPCTSTR) T(common_pwd.SERVER), + filename); SQLSetConfigMode(old_config_mode); ODBC_FREE(); } @@ -263,7 +243,8 @@ odbc_connect(void) printf("odbctest\n--------\n\n"); printf("connection parameters:\nserver: '%s'\nuser: '%s'\npassword: '%s'\ndatabase: '%s'\n", - odbc_server, odbc_user, "????" /* odbc_password */ , odbc_database); + common_pwd.SERVER, common_pwd.USER, + "????" /* common_pwd.PASSWORD */, common_pwd.DATABASE); p = getenv("ODBC_MARS"); if (p && atoi(p) != 0) @@ -272,13 +253,17 @@ odbc_connect(void) (*odbc_set_conn_attr)(); if (!odbc_conn_additional_params) { - CHKConnect(T(odbc_server), SQL_NTS, T(odbc_user), SQL_NTS, T(odbc_password), SQL_NTS, "SI"); + CHKConnect(T(common_pwd.SERVER), SQL_NTS, T(common_pwd.USER), + SQL_NTS, T(common_pwd.PASSWORD), SQL_NTS, "SI"); } else { char *params; SQLSMALLINT len; assert(asprintf(¶ms, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;%s", - odbc_server, odbc_user, odbc_password, odbc_database, odbc_conn_additional_params) >= 0); + common_pwd.SERVER, common_pwd.USER, + common_pwd.PASSWORD, common_pwd.DATABASE, + odbc_conn_additional_params) + >= 0); assert(params); CHKDriverConnect(NULL, T(params), SQL_NTS, (SQLTCHAR *) command, sizeof(command)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SI"); @@ -287,7 +272,7 @@ odbc_connect(void) CHKAllocStmt(&odbc_stmt, "S"); - sprintf(command, "use %s", odbc_database); + sprintf(command, "use %s", common_pwd.DATABASE); printf("%s\n", command); CHKExecDirect(T(command), SQL_NTS, "SI"); diff --git a/src/odbc/unittests/common.h b/src/odbc/unittests/common.h index e9be322b7a..3d9b32a6d7 100644 --- a/src/odbc/unittests/common.h +++ b/src/odbc/unittests/common.h @@ -53,12 +53,6 @@ extern char odbc_err[512]; extern char odbc_sqlstate[6]; -extern char odbc_user[512]; -extern char odbc_server[512]; -extern char odbc_password[512]; -extern char odbc_database[512]; -extern char odbc_driver[1024]; - int odbc_read_login_info(void); void odbc_report_error(const char *msg, int line, const char *file); void odbc_read_error(void); diff --git a/src/odbc/unittests/connect.c b/src/odbc/unittests/connect.c index 831001a746..009bc267b9 100644 --- a/src/odbc/unittests/connect.c +++ b/src/odbc/unittests/connect.c @@ -21,7 +21,8 @@ get_entry(const char *key) static TCHAR buf[256]; entry = NULL; - if (SQLGetPrivateProfileString((LPCTSTR) T(odbc_server), (LPCTSTR) T(key), TEXT(""), + if (SQLGetPrivateProfileString((LPCTSTR) T(common_pwd.SERVER), + (LPCTSTR) T(key), TEXT(""), buf, TDS_VECTOR_SIZE(buf), TEXT("odbc.ini")) > 0) entry = C(buf); @@ -46,11 +47,12 @@ TEST_MAIN() * is better to do it before connect cause uniODBC cache INIs * the name must be odbcinst.ini cause unixODBC accept only this name */ - if (odbc_driver[0]) { + if (common_pwd.DRIVER[0]) { FILE *f = fopen("odbcinst.ini", "w"); if (f) { - fprintf(f, "[FreeTDS]\nDriver = %s\n", odbc_driver); + fprintf(f, "[FreeTDS]\nDriver = %s\n", + common_pwd.DRIVER); fclose(f); /* force iODBC */ setenv("ODBCINSTINI", "./odbcinst.ini", 1); @@ -76,7 +78,8 @@ TEST_MAIN() /* try connect string with using DSN */ printf("connect string DSN connect..\n"); init_connect(); - sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_server, odbc_user, odbc_password, odbc_database); + sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;", common_pwd.SERVER, + common_pwd.USER, common_pwd.PASSWORD, common_pwd.DATABASE); CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SI"); odbc_disconnect(); ++succeeded; @@ -87,7 +90,10 @@ TEST_MAIN() /* this is expected to work with unixODBC */ init_connect(); - sprintf(tmp, "DRIVER=FreeTDS;SERVERNAME=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_server, odbc_user, odbc_password, odbc_database); + sprintf(tmp, + "DRIVER=FreeTDS;SERVERNAME=%s;UID=%s;PWD=%s;DATABASE=%s;", + common_pwd.SERVER, common_pwd.USER, common_pwd.PASSWORD, + common_pwd.DATABASE); rc = CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SIE"); if (rc == SQL_ERROR) { printf("Unable to open data source (ret=%d)\n", rc); @@ -99,9 +105,12 @@ TEST_MAIN() /* this is expected to work with iODBC * (passing shared object name as driver) */ - if (odbc_driver[0]) { + if (common_pwd.DRIVER[0]) { init_connect(); - sprintf(tmp, "DRIVER=%s;SERVERNAME=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_driver, odbc_server, odbc_user, odbc_password, odbc_database); + sprintf(tmp, + "DRIVER=%s;SERVERNAME=%s;UID=%s;PWD=%s;DATABASE=%s;", + common_pwd.DRIVER, common_pwd.SERVER, common_pwd.USER, + common_pwd.PASSWORD, common_pwd.DATABASE); rc = CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SIE"); if (rc == SQL_ERROR) { printf("Unable to open data source (ret=%d)\n", rc); @@ -114,7 +123,10 @@ TEST_MAIN() #ifdef _WIN32 if (get_entry("SERVER")) { init_connect(); - sprintf(tmp, "DRIVER=FreeTDS;SERVER=%s;UID=%s;PWD=%s;DATABASE=%s;", entry, odbc_user, odbc_password, odbc_database); + sprintf(tmp, + "DRIVER=FreeTDS;SERVER=%s;UID=%s;PWD=%s;DATABASE=%s;", + entry, common_pwd.USER, common_pwd.PASSWORD, + common_pwd.DATABASE); if (get_entry("TDS_Version")) sprintf(strchr(tmp, 0), "TDS_Version=%s;", entry); if (get_entry("Port")) @@ -140,7 +152,9 @@ TEST_MAIN() */ printf("connect string DSN connect with a long APP..\n"); init_connect(); - sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;APP=%s", odbc_server, odbc_user, odbc_password, odbc_database, app_name); + sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;APP=%s", + common_pwd.SERVER, common_pwd.USER, + common_pwd.PASSWORD, common_pwd.DATABASE, app_name); CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SI"); odbc_disconnect(); } diff --git a/src/odbc/unittests/connect2.c b/src/odbc/unittests/connect2.c index 221a0603e1..3efbb008ff 100644 --- a/src/odbc/unittests/connect2.c +++ b/src/odbc/unittests/connect2.c @@ -19,7 +19,8 @@ init_connect(void) static void normal_connect(void) { - CHKConnect(T(odbc_server), SQL_NTS, T(odbc_user), SQL_NTS, T(odbc_password), SQL_NTS, "SI"); + CHKConnect(T(common_pwd.SERVER), SQL_NTS, T(common_pwd.USER), SQL_NTS, + T(common_pwd.PASSWORD), SQL_NTS, "SI"); } static void @@ -95,16 +96,18 @@ TEST_MAIN() /* try connect string with using DSN */ printf("SQLDriverConnect before 1..\n"); - sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_server, odbc_user, odbc_password, odbc_database); + sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;", common_pwd.SERVER, + common_pwd.USER, common_pwd.PASSWORD, common_pwd.DATABASE); init_connect(); set_dbname("master"); driver_connect(tmp); - check_dbname(odbc_database); + check_dbname(common_pwd.DATABASE); odbc_disconnect(); /* try connect string with using DSN */ printf("SQLDriverConnect before 2..\n"); - sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;", odbc_server, odbc_user, odbc_password); + sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;", + common_pwd.SERVER, common_pwd.USER, common_pwd.PASSWORD); init_connect(); set_dbname("tempdb"); driver_connect(tmp); diff --git a/src/odbc/unittests/freeclose.c b/src/odbc/unittests/freeclose.c index c1c0c0bc31..56eafb8aff 100644 --- a/src/odbc/unittests/freeclose.c +++ b/src/odbc/unittests/freeclose.c @@ -338,7 +338,11 @@ TEST_MAIN() CHKAllocEnv(&odbc_env, "S"); CHKAllocConnect(&odbc_conn, "S"); - sprintf(tmp, "DRIVER={SQL Server};SERVER=127.0.0.1,%d;UID=%s;PWD=%s;DATABASE=%s;Network=DBMSSOCN;", port, odbc_user, odbc_password, odbc_database); + sprintf(tmp, + "DRIVER={SQL Server};SERVER=127.0.0.1,%d;UID=%s;" + "PWD=%s;DATABASE=%s;Network=DBMSSOCN;", + port, common_pwd.USER, common_pwd.PASSWORD, + common_pwd.DATABASE); printf("connection string: %s\n", tmp); CHKDriverConnect(NULL, T(tmp), SQL_NTS, (SQLTCHAR *) tmp, sizeof(tmp)/sizeof(SQLTCHAR), &len, SQL_DRIVER_NOPROMPT, "SI"); CHKAllocStmt(&odbc_stmt, "S"); diff --git a/src/odbc/unittests/oldpwd.c b/src/odbc/unittests/oldpwd.c index 7ec9ead92e..2fa140a51d 100644 --- a/src/odbc/unittests/oldpwd.c +++ b/src/odbc/unittests/oldpwd.c @@ -5,8 +5,9 @@ static void my_attrs(void) { - SQLSetConnectAttr(odbc_conn, 1226 /*SQL_COPT_SS_OLDPWD */, (SQLPOINTER) odbc_password, SQL_NTS); - strcpy(odbc_password, "testpwd$"); + SQLSetConnectAttr(odbc_conn, 1226 /*SQL_COPT_SS_OLDPWD */, + (SQLPOINTER) common_pwd.PASSWORD, SQL_NTS); + strcpy(common_pwd.PASSWORD, "testpwd$"); } TEST_MAIN() diff --git a/src/odbc/unittests/qn.c b/src/odbc/unittests/qn.c index 4db0f411c7..fcaadadc92 100644 --- a/src/odbc/unittests/qn.c +++ b/src/odbc/unittests/qn.c @@ -43,7 +43,9 @@ TEST_MAIN() return 0; } - sql = odbc_buf_asprintf(&odbc_buf, "ALTER DATABASE %s SET ENABLE_BROKER", odbc_database); + sql = odbc_buf_asprintf(&odbc_buf, + "ALTER DATABASE %s SET ENABLE_BROKER", + common_pwd.DATABASE); odbc_command(sql); odbc_command2("DROP SERVICE FTDS_Service", "SENo"); @@ -72,7 +74,9 @@ TEST_MAIN() odbc_connect(); SWAP_CONN(); - sql = odbc_buf_asprintf(&odbc_buf, "service=FTDS_Service;local database=%s", odbc_database); + sql = odbc_buf_asprintf(&odbc_buf, + "service=FTDS_Service;local database=%s", + common_pwd.DATABASE); CHKSetStmtAttr(SQL_SOPT_SS_QUERYNOTIFICATION_OPTIONS, T(sql), SQL_NTS, "S"); CHKSetStmtAttr(SQL_SOPT_SS_QUERYNOTIFICATION_MSGTEXT, T("Table has changed"), SQL_NTS, "S"); CHKSetStmtAttr(SQL_SOPT_SS_QUERYNOTIFICATION_TIMEOUT, TDS_INT2PTR(60), SQL_IS_UINTEGER, "S"); diff --git a/src/odbc/unittests/stats.c b/src/odbc/unittests/stats.c index 6aafaeeffd..58ea80594b 100644 --- a/src/odbc/unittests/stats.c +++ b/src/odbc/unittests/stats.c @@ -105,7 +105,7 @@ TEST_MAIN() TestProc(NULL, "DATETIME", STR(SQL_TIMESTAMP)); TestTable(NULL, "DATETIME", STR(SQL_TIMESTAMP)); set_dbname("master"); - TestTable(odbc_database, "DATETIME", STR(SQL_TIMESTAMP)); + TestTable(common_pwd.DATABASE, "DATETIME", STR(SQL_TIMESTAMP)); odbc_disconnect(); @@ -116,7 +116,7 @@ TEST_MAIN() TestProc(NULL, "DATETIME", STR(SQL_TYPE_TIMESTAMP)); TestTable(NULL, "DATETIME", STR(SQL_TYPE_TIMESTAMP)); set_dbname("master"); - TestTable(odbc_database, "DATETIME", STR(SQL_TYPE_TIMESTAMP)); + TestTable(common_pwd.DATABASE, "DATETIME", STR(SQL_TYPE_TIMESTAMP)); odbc_disconnect(); diff --git a/src/odbc/unittests/timeout3.c b/src/odbc/unittests/timeout3.c index 8a9a8f2688..5300619372 100644 --- a/src/odbc/unittests/timeout3.c +++ b/src/odbc/unittests/timeout3.c @@ -154,11 +154,12 @@ TEST_MAIN() * it is better to do it before connecting because unixODBC caches INIs * the name must be odbcinst.ini because unixODBC accepts only this name */ - if (odbc_driver[0]) { + if (common_pwd.DRIVER[0]) { FILE *f = fopen("odbcinst.ini", "w"); if (f) { - fprintf(f, "[FreeTDS]\nDriver = %s\n", odbc_driver); + fprintf(f, "[FreeTDS]\nDriver = %s\n", + common_pwd.DRIVER); fclose(f); /* force iODBC */ setenv("ODBCINSTINI", "./odbcinst.ini", 1); diff --git a/src/tds/unittests/common.c b/src/tds/unittests/common.c index ee3130a67f..d35c137a70 100644 --- a/src/tds/unittests/common.c +++ b/src/tds/unittests/common.c @@ -2,50 +2,14 @@ #include "common.h" #include -char USER[512]; -char SERVER[512]; -char PASSWORD[512]; -char DATABASE[512]; -/* TODO use another default ?? */ -char CHARSET[512] = "ISO-8859-1"; - int read_login_info(void); int read_login_info(void) { - FILE *in = NULL; - char line[512]; - char *s1, *s2; - - s1 = getenv("TDSPWDFILE"); - if (s1 && s1[0]) - in = fopen(s1, "r"); - if (!in) - in = fopen("../../../PWD", "r"); - if (!in) { - fprintf(stderr, "Can not open PWD file\n\n"); - return TDS_FAIL; - } - - while (fgets(line, sizeof(line), in)) { - s1 = strtok(line, "="); - s2 = strtok(NULL, "\n"); - if (!s1 || !s2) { - continue; - } - if (!strcmp(s1, "UID")) { - strcpy(USER, s2); - } else if (!strcmp(s1, "SRV")) { - strcpy(SERVER, s2); - } else if (!strcmp(s1, "PWD")) { - strcpy(PASSWORD, s2); - } else if (!strcmp(s1, "DB")) { - strcpy(DATABASE, s2); - } - } - fclose(in); - return TDS_SUCCESS; + reset_login_info(&common_pwd); + const char * s = read_login_info_base(&common_pwd, DEFAULT_PWD_PATH); + return s ? TDS_SUCCESS : TDS_FAIL; } TDSCONTEXT *test_context = NULL; @@ -82,14 +46,14 @@ try_tds_login(TDSLOGIN ** login, TDSSOCKET ** tds, const char *appname, int verb return TDS_FAIL; } appname_copy = strdup(appname); - if (!tds_set_passwd(*login, PASSWORD) - || !tds_set_user(*login, USER) + if (!tds_set_passwd(*login, common_pwd.PASSWORD) + || !tds_set_user(*login, common_pwd.USER) || !appname_copy || !tds_set_app(*login, basename(appname_copy)) || !tds_set_host(*login, "myhost") || !tds_set_library(*login, "TDS-Library") - || !tds_set_server(*login, SERVER) - || !tds_set_client_charset(*login, CHARSET) + || !tds_set_server(*login, common_pwd.SERVER) + || !tds_set_client_charset(*login, common_pwd.CHARSET) || !tds_set_language(*login, "us_english")) { free(appname_copy); fprintf(stderr, "tds_alloc_login() failed.\n"); diff --git a/src/tds/unittests/common.h b/src/tds/unittests/common.h index aced4527e4..267ba27e1a 100644 --- a/src/tds/unittests/common.h +++ b/src/tds/unittests/common.h @@ -21,12 +21,6 @@ #define FREETDS_SRCDIR FREETDS_TOPDIR "/src/tds/unittests" #endif -extern char PASSWORD[512]; -extern char USER[512]; -extern char SERVER[512]; -extern char DATABASE[512]; -extern char CHARSET[512]; - extern TDSCONTEXT *test_context; int try_tds_login(TDSLOGIN ** login, TDSSOCKET ** tds, const char *appname, int verbose); diff --git a/src/tds/unittests/utf8_1.c b/src/tds/unittests/utf8_1.c index 177dd24d19..24e74d080c 100644 --- a/src/tds/unittests/utf8_1.c +++ b/src/tds/unittests/utf8_1.c @@ -184,7 +184,7 @@ TEST_MAIN() int verbose = 0; /* use UTF-8 as our coding */ - strcpy(CHARSET, "UTF-8"); + strcpy(common_pwd.CHARSET, "UTF-8"); ret = try_tds_login(&login, &tds, __FILE__, verbose); if (ret != TDS_SUCCESS) { diff --git a/src/tds/unittests/utf8_2.c b/src/tds/unittests/utf8_2.c index afb4640227..13b4fad7c9 100644 --- a/src/tds/unittests/utf8_2.c +++ b/src/tds/unittests/utf8_2.c @@ -208,7 +208,7 @@ TEST_MAIN() const perr * my_err; /* use ISO8859-1 as our coding */ - strcpy(CHARSET, "ISO8859-1"); + strcpy(common_pwd.CHARSET, "ISO8859-1"); ret = try_tds_login(&login, &tds, __FILE__, verbose); if (ret != TDS_SUCCESS) { diff --git a/src/tds/unittests/utf8_3.c b/src/tds/unittests/utf8_3.c index 5eafcba6aa..340b2a63a7 100644 --- a/src/tds/unittests/utf8_3.c +++ b/src/tds/unittests/utf8_3.c @@ -116,7 +116,7 @@ TEST_MAIN() int verbose = 0; /* use UTF-8 as our coding */ - strcpy(CHARSET, "UTF-8"); + strcpy(common_pwd.CHARSET, "UTF-8"); ret = try_tds_login(&login, &tds, __FILE__, verbose); if (ret != TDS_SUCCESS) { diff --git a/src/utils/unittests/test_base.c b/src/utils/unittests/test_base.c index cf6e2da12b..732e9c7814 100644 --- a/src/utils/unittests/test_base.c +++ b/src/utils/unittests/test_base.c @@ -1,5 +1,9 @@ #include +#include +#include +#include + #ifdef _WIN32 # include # include @@ -43,3 +47,92 @@ int main(int argc, char ** argv) #endif return test_main(argc, argv); } + + +COMMON_PWD common_pwd; + +void +reset_login_info(COMMON_PWD * common_pwd) +{ + common_pwd->SERVER[0] = '\0'; + common_pwd->DATABASE[0] = '\0'; + common_pwd->USER[0] = '\0'; + common_pwd->PASSWORD[0] = '\0'; + common_pwd->DRIVER[0] = '\0'; + /* TODO use another default ?? */ + strcpy(common_pwd->CHARSET, "ISO-8859-1"); + common_pwd->maxlength = 0; + common_pwd->fverbose = false; + common_pwd->initialized = false; + common_pwd->tried_env = false; +} + +const char * +read_login_info_base(COMMON_PWD * common_pwd, const char * default_path) +{ + const char * ret = try_read_login_info_base(common_pwd, default_path); + if ( !ret ) + fprintf(stderr, "Cannot open PWD file %s\n\n", default_path); + return ret; +} + +const char * +try_read_login_info_base(COMMON_PWD * common_pwd, const char * default_path) +{ + FILE *in = NULL; + char line[512]; + char *s1, *s2; + const char *path; + + if (common_pwd->initialized) + return 0; + + if ( !common_pwd->tried_env ) { + common_pwd->tried_env = true; + s1 = getenv("TDSPWDFILE"); + if (s1 && s1[0]) { + in = fopen(s1, "r"); + if (in) + path = s1; + } + } + if ( !in ) { + in = fopen(default_path, "r"); + if (in) { + path = default_path; + } else { + return NULL; + } + } + + while (fgets(line, sizeof(line), in)) { + s1 = strtok(line, "="); + s2 = strtok(NULL, "\n"); + if ( !s1 || !s2 ) { + continue; + } + switch (s1[0]) { + case 'U': + if ( !common_pwd->USER[0] && !strcmp(s1, "UID") ) + strcpy(common_pwd->USER, s2); + break; + case 'S': + if ( !common_pwd->SERVER[0] && !strcmp(s1, "SRV") ) + strcpy(common_pwd->SERVER, s2); + break; + case 'P': + if ( !common_pwd->PASSWORD[0] && !strcmp(s1, "PWD") ) + strcpy(common_pwd->PASSWORD, s2); + break; + case 'D': + if ( !common_pwd->DATABASE[0] && !strcmp(s1, "DB") ) + strcpy(common_pwd->DATABASE, s2); + break; + default: + break; + } + } + fclose(in); + common_pwd->initialized = true; + return path; +} From bbe2948d7514c5fe62666ed845e678fdfb4b0ac0 Mon Sep 17 00:00:00 2001 From: "Aaron M. Ucko" Date: Wed, 17 Jul 2024 16:08:10 -0400 Subject: [PATCH 6/6] Formally address static analyzer concerns. * Add more explicit sanity checks and initializers. * vstrbuild.c (tds_vstrbuild): Use unsigned int for counts that will never be negative. * rpc_ct_setparam.c (ex_display_results): Avoid memory leaks in some error cases. Signed-off-by: Aaron M. Ucko --- src/ctlib/unittests/datafmt.c | 3 +++ src/ctlib/unittests/rpc_ct_setparam.c | 1 + src/ctlib/unittests/t0004.c | 12 ++++++++++++ src/dblib/unittests/t0013.c | 4 ++++ src/dblib/unittests/t0014.c | 5 +++++ src/odbc/prepare_query.c | 2 +- src/tds/vstrbuild.c | 8 ++++---- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/ctlib/unittests/datafmt.c b/src/ctlib/unittests/datafmt.c index fff1659619..c2fe6ed88f 100644 --- a/src/ctlib/unittests/datafmt.c +++ b/src/ctlib/unittests/datafmt.c @@ -59,6 +59,9 @@ TEST_MAIN() fprintf(stderr, "CS_CHAR_TYPE\n"); datafmt.format = CS_FMT_NULLTERM; addr = (char *) malloc(datafmt.maxlength); + } else { + fputs("unexpected data type\n", stderr); + return 1; } fprintf(stderr, "binding column 1 (%s)\n", datafmt.name); diff --git a/src/ctlib/unittests/rpc_ct_setparam.c b/src/ctlib/unittests/rpc_ct_setparam.c index 693b63bba4..35e2a77962 100644 --- a/src/ctlib/unittests/rpc_ct_setparam.c +++ b/src/ctlib/unittests/rpc_ct_setparam.c @@ -335,6 +335,7 @@ int i, j; ret = ct_bind(cmd, (i + 1), &outdatafmt[i], coldata[i].value, &coldata[i].valuelen, & coldata[i].indicator); if (ret != CS_SUCCEED) { + free(coldata[i].value); fprintf(stderr, "ct_bind failed \n"); break; } diff --git a/src/ctlib/unittests/t0004.c b/src/ctlib/unittests/t0004.c index 73dc0c2b05..cafc04515b 100644 --- a/src/ctlib/unittests/t0004.c +++ b/src/ctlib/unittests/t0004.c @@ -114,12 +114,17 @@ do_results(CS_COMMAND * cmd, CS_INT * results) { int result_num; CS_RETCODE results_ret, result_type; +bool done = false; result_num = 0; while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) { printf("result_ret %d result_type %d\n", results_ret, result_type); if (result_type == CS_STATUS_RESULT) continue; + if (done) { + fputs("No further results were expected\n", stderr); + return CS_FAIL; + } if (result_type != results[result_num]) { fprintf(stderr, "ct_results() expected %d received %d\n", results[result_num], result_type); return CS_FAIL; @@ -130,8 +135,15 @@ CS_RETCODE results_ret, result_type; return CS_FAIL; } break; + case CS_CMD_DONE: + done = true; + break; } result_num++; } + if ( !done ) { + fputs("Never saw CS_CMD_DONE\n", stderr); + return CS_FAIL; + } return results_ret; } diff --git a/src/dblib/unittests/t0013.c b/src/dblib/unittests/t0013.c index 1e46a85eb4..8f04991c54 100644 --- a/src/dblib/unittests/t0013.c +++ b/src/dblib/unittests/t0013.c @@ -249,6 +249,10 @@ test(int argc, char **argv, int over4k) } data_ok = 1; + if (rblob == NULL) { + fputs("No blob data received", stderr); + return 7; + } if (memcmp(blob, rblob, numread) != 0) { printf("Saving first blob data row to file: %s\n", argv[2]); if ((fp = fopen(argv[2], "wb")) == NULL) { diff --git a/src/dblib/unittests/t0014.c b/src/dblib/unittests/t0014.c index 206904fe5e..821e540e17 100644 --- a/src/dblib/unittests/t0014.c +++ b/src/dblib/unittests/t0014.c @@ -215,6 +215,11 @@ test(int argc, char **argv, int over4k) } } + if (rblob == NULL) { + fputs("No blob data received", stderr); + return 7; + } + if (i == 0) { printf("Saving first blob data row to file: %s\n", argv[2]); if ((fp = fopen(argv[2], "wb")) == NULL) { diff --git a/src/odbc/prepare_query.c b/src/odbc/prepare_query.c index 6504ae394b..2f57e0731e 100644 --- a/src/odbc/prepare_query.c +++ b/src/odbc/prepare_query.c @@ -443,7 +443,7 @@ continue_parse_prepared_query(struct _hstmt *stmt, SQLPOINTER DataPtr, SQLLEN St } else { memcpy(blob->textvalue + curcol->column_cur_size, DataPtr, len); } - } else { + } else if (len > 0) { memcpy(curcol->column_data + curcol->column_cur_size, DataPtr, len); } diff --git a/src/tds/vstrbuild.c b/src/tds/vstrbuild.c index 32274e941d..e404b1d0b7 100644 --- a/src/tds/vstrbuild.c +++ b/src/tds/vstrbuild.c @@ -84,14 +84,14 @@ tds_vstrbuild(char *buffer, int buflen, int *resultlen, const char *text, int te char *token; const char *sep = "\377"; char *lasts; - int tokcount = 0; + unsigned int tokcount = 0; struct string_linked_list *head = NULL; struct string_linked_list *item = NULL; struct string_linked_list **tail = &head; - int i; + unsigned int i; int state; char **string_array = NULL; - int pnum = 0; + unsigned int pnum = 0; int pdigit; char *paramp = NULL; TDSRET rc = TDS_FAIL; @@ -156,7 +156,7 @@ tds_vstrbuild(char *buffer, int buflen, int *resultlen, const char *text, int te case CALCPARAM: switch (*text) { case '!': - if (pnum <= tokcount) { + if (pnum > 0 && pnum <= tokcount) { paramp = string_array[pnum - 1]; state = OUTPARAM; }