List:Commits« Previous MessageNext Message »
From:jwinstead Date:March 22 2007 9:23pm
Subject:Connector/ODBC 3.51 commit: r259 - in trunk/test: . include timestamp
View as plain text  
Modified:
   trunk/test/
   trunk/test/Makefile.am
   trunk/test/include/odbctap.h
   trunk/test/timestamp/my_ts.c
Log:
Rewrite the timestamp test to use odbctap.h, and include it in 'make test'.

Also add odbctap.h to EXTRA_DIST so it is included in source tarballs.



Property changes on: trunk/test
___________________________________________________________________
Name: svn:ignore
   - dbtest
.deps
.libs
Makefile
Makefile.in
my_basics
my_blob
my_bulk
my_catalog
my_col_length
my_connect
my_cursor
my_dyn_cursor
my_error
my_keys
my_param
my_position
my_relative
my_result
my_scroll
mytest
mytest2
mytest3
mytest32
my_tran
my_tran_ext
my_unixodbc
my_use_result
odbc.ini
odbcinst.ini

   + dbtest
.deps
.libs
Makefile
Makefile.in
my_basics
my_blob
my_bulk
my_catalog
my_col_length
my_connect
my_cursor
my_dyn_cursor
my_error
my_keys
my_param
my_position
my_relative
my_result
my_scroll
mytest
mytest2
mytest3
mytest32
my_tran
my_tran_ext
my_ts
my_unixodbc
my_use_result
odbc.ini
odbcinst.ini


Modified: trunk/test/Makefile.am
===================================================================
--- trunk/test/Makefile.am	2007-03-21 20:47:23 UTC (rev 258)
+++ trunk/test/Makefile.am	2007-03-22 20:23:24 UTC (rev 259)
@@ -40,6 +40,7 @@
 my_tran_ext \
 my_catalog \
 my_error \
+my_ts \
 mytest32 \
 my_use_result
 fancy_tests= \
@@ -76,6 +77,7 @@
 my_tran_ext_SOURCES=	tran_ext/my_tran_ext.c
 my_catalog_SOURCES=	catalog/my_catalog.c
 my_error_SOURCES=	error/my_error.c
+my_ts_SOURCES=		timestamp/my_ts.c
 my_use_result_SOURCES=	use_result/my_use_result.c
 dbtest_SOURCES=		db_test/db_test.c
 mytest_SOURCES=		test/mytest.c
@@ -144,6 +146,7 @@
 	odbc.ini.in \
 	odbcinst.ini.in \
 	include/mytest3.h \
+	include/odbctap.h \
 	Makefile.ini \
 	test.vpj \
 	test.pro \
@@ -173,8 +176,7 @@
 	imyodbc/myodbc.c \
 	thread/my_thread.c \
 	thread_coredump/thread-coredump.c \
-	thread_test/thread_test.c \
-	timestamp/my_ts.c
+	thread_test/thread_test.c
 
 # ----------------------------------------------------------------------
 # We want to rebuild the "test.ini" file each time, as it might

Modified: trunk/test/include/odbctap.h
===================================================================
--- trunk/test/include/odbctap.h	2007-03-21 20:47:23 UTC (rev 258)
+++ trunk/test/include/odbctap.h	2007-03-22 20:23:24 UTC (rev 259)
@@ -152,7 +152,42 @@
 
 
 /**
+  Verify that a string (char *) matches an expected value.
+
+  @param a     The string to compare
+  @param b     The string to compare against
+  @param c     The number of characters to compare
 */
+#define is_str(a, b, c) \
+do { \
+  char *val_a= (char *)(a), *val_b= (char *)(b); \
+  int val_len= (int)(c); \
+  if (strncmp(val_a, val_b, val_len) != 0) { \
+    printf("# %s ('%*s') != '%*s' in %s on line %d\n", \
+           #a, val_len, val_a, val_len, val_b, __FILE__, __LINE__); \
+    return FAIL; \
+  } \
+} while (0);
+
+
+/**
+  Verify that a number (long integer) matches an expected value.
+
+  @param a     The number to compare
+  @param b     The number to compare against
+*/
+#define is_num(a, b) \
+do { \
+  if (a != b) { \
+    printf("# %s (%ld) != %ld in %s on line %d\n", \
+           #a, (long)a, (long)b, __FILE__, __LINE__); \
+    return FAIL; \
+  } \
+} while (0);
+
+
+/**
+*/
 void print_diag(SQLRETURN rc, SQLSMALLINT htype, SQLHANDLE handle,
                 const char *text, const char *file, int line)
 {

Modified: trunk/test/timestamp/my_ts.c
===================================================================
--- trunk/test/timestamp/my_ts.c	2007-03-21 20:47:23 UTC (rev 258)
+++ trunk/test/timestamp/my_ts.c	2007-03-22 20:23:24 UTC (rev 259)
@@ -1,177 +1,122 @@
-/***************************************************************************
-                          my_ts.c  -  description
-                             ---------------------
-    begin                : Mon Jan 7, 2002
-    copyright            : (C) Copyright -    author               : venu ( venu@stripped )
- ***************************************************************************/
+/*
+  Copyright (C) 1995-2006 MySQL AB
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-#include "mytest3.h"
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of version 2 of the GNU General Public License as
+  published by the Free Software Foundation.
 
-/********************************************************
-* timestamp demo..
-*********************************************************/
-void my_ts(SQLHDBC hdbc, SQLHSTMT hstmt)
-{
-    SQLRETURN        rc;
-    SQLCHAR          szTs[50];
-    TIMESTAMP_STRUCT ts;
-    SQLINTEGER       pclen;
+  There are special exceptions to the terms and conditions of the GPL
+  as it is applied to this software. View the full text of the exception
+  in file LICENSE.exceptions in the top-level directory of this software
+  distribution.
 
-    /* drop table 'myodbc3_demo_result' if it already exists */
-    SQLExecDirect(hstmt,"DROP TABLE my_ts",SQL_NTS);
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
 
-    /* commit the transaction */
-    rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT); 
-    mycon(hdbc,rc);
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
 
-    /* create the table 'myodbc3_demo_result' */
-    rc = SQLExecDirect(hstmt,"CREATE TABLE my_ts(ts timestamp)",SQL_NTS);
-    mystmt(hstmt,rc);
+#include "odbctap.h"
 
-    rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
-    mycon(hdbc,rc);    
 
-    /* insert using SQL_C_CHAR to SQL_TIMESTAMP */    
-    strcpy(szTs,"2002-01-07 10:20:49.06");
-    rc = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,
-                          SQL_C_CHAR,SQL_TIMESTAMP,
-                          0,0,&szTs,sizeof(szTs),NULL);
-    mystmt(hstmt,rc);
+DECLARE_TEST(my_ts)
+{
+  SQLCHAR          szTs[50];
+  TIMESTAMP_STRUCT ts;
+  SQLLEN           len;
 
-    rc = SQLExecDirect(hstmt,"INSERT INTO my_ts(ts) values(?)",SQL_NTS);
-    mystmt(hstmt,rc);
+  ok_sql(hstmt, "DROP TABLE IF EXISTS my_ts");
+  ok_sql(hstmt, "CREATE TABLE my_ts (ts TIMESTAMP)");
 
-    SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
-    SQLFreeStmt(hstmt,SQL_CLOSE);
+  /* insert using SQL_C_CHAR to SQL_TIMESTAMP */
+  strcpy((char *)szTs, "2002-01-07 10:20:49.06");
+  ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
+                                  SQL_C_CHAR, SQL_TIMESTAMP,
+                                  0, 0, szTs, sizeof(szTs), NULL));
+  ok_sql(hstmt, "INSERT INTO my_ts (ts) VALUES (?)");
 
+  ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_RESET_PARAMS));
+  ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE));
 
-    /* insert using SQL_C_TIMESTAMP to SQL_TIMESTAMP */    
-    ts.year = 2002;
-    ts.month=01;
-    ts.day=07;
-    ts.hour=19;
-    ts.minute=47;
-    ts.second=59;
-    ts.fraction=04;
-    rc = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,
-                          SQL_C_TIMESTAMP,SQL_TIMESTAMP,
-                          0,0,&ts,sizeof(ts),NULL);
-    mystmt(hstmt,rc);
+  /* insert using SQL_C_TIMESTAMP to SQL_TIMESTAMP */
+  ts.year= 2002;
+  ts.month= 1;
+  ts.day= 7;
+  ts.hour= 19;
+  ts.minute= 47;
+  ts.second= 59;
+  ts.fraction= 4;
+  ok_stmt(hstmt, SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
+                                  SQL_C_TIMESTAMP, SQL_TIMESTAMP,
+                                  0, 0, &ts, sizeof(ts), NULL));
 
-    rc = SQLExecDirect(hstmt,"INSERT INTO my_ts(ts) values(?)",SQL_NTS);
-    mystmt(hstmt,rc);
+  ok_sql(hstmt, "INSERT INTO my_ts (ts) VALUES (?)");
 
-    SQLFreeStmt(hstmt,SQL_RESET_PARAMS);
-    SQLFreeStmt(hstmt,SQL_CLOSE);
+  ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_RESET_PARAMS));
+  ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_CLOSE));
 
-    /* commit the transaction */
-    rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT); 
-    mycon(hdbc,rc);
+  /* now fetch and verify the results .. */
+  ok_sql(hstmt, "SELECT * FROM my_ts");
 
-    strcpy(szTs,"");
-    /* now fetch and verify the results .. */        
-    rc = SQLExecDirect(hstmt,"SELECT * from my_ts",SQL_NTS);
-    mystmt(hstmt,rc);
+  /* now fetch first row */
+  ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 1));
 
-    /* now fetch first row */
-    rc = SQLFetchScroll(hstmt,SQL_FETCH_ABSOLUTE,1);
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, szTs, sizeof(szTs), &len));
+  is_str(szTs, "2002-01-07 10:20:49", len);
+  printf("# row1 using SQL_C_CHAR: %s (%ld)\n", szTs, len);
 
-    rc = SQLGetData(hstmt,1,SQL_C_CHAR,szTs,sizeof(szTs),&pclen);
-    mystmt(hstmt,rc);
-    printMessage("\n row1 using SQL_C_CHAR:%s(%d)\n",szTs,pclen);
+  ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 1));
 
-    rc = SQLFetchScroll(hstmt,SQL_FETCH_ABSOLUTE,1);
-    mystmt(hstmt,rc);
-    ts.fraction= 0;
+  ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &len));
+  is_num(ts.year,  2002);
+  is_num(ts.month, 1);
+  is_num(ts.day,   7);
+  is_num(ts.hour,  10);
+  is_num(ts.minute,20);
+  is_num(ts.second,49);
+  printf("# row1 using SQL_C_TIMESTAMP: %d-%d-%d %d:%d:%d.%d (%ld)\n",
+         ts.year, ts.month,ts.day, ts.hour, ts.minute, ts.second, ts.fraction,
+         len);
 
-    rc = SQLGetData(hstmt,1,SQL_C_TIMESTAMP,&ts,sizeof(ts),&pclen);
-    mystmt(hstmt,rc);
-    printMessage("\n row1 using SQL_C_TIMESTAMP:%d-%d-%d %d:%d:%d.%d(%d)\n",
-           ts.year,ts.month,
-           ts.day,ts.hour,ts.minute,
-           ts.second,ts.fraction,pclen);
+  ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 2));
 
+  ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_CHAR, szTs, sizeof(szTs), &len));
+  is_str(szTs, "2002-01-07 19:47:59", len);
+  printf("# row2 using SQL_C_CHAR: %s(%ld)\n", szTs, len);
 
-    /* now fetch second row */
-    rc = SQLFetchScroll(hstmt,SQL_FETCH_ABSOLUTE,2);
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 2));
 
-    rc = SQLGetData(hstmt,1,SQL_C_CHAR,szTs,sizeof(szTs),&pclen);
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt, SQLGetData(hstmt, 1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &len));
+  is_num(ts.year,  2002);
+  is_num(ts.month, 1);
+  is_num(ts.day,   7);
+  is_num(ts.hour,  19);
+  is_num(ts.minute,47);
+  is_num(ts.second,59);
+  printf("# row2 using SQL_C_TIMESTAMP: %d-%d-%d %d:%d:%d.%d (%ld)\n",
+         ts.year, ts.month,ts.day, ts.hour, ts.minute, ts.second, ts.fraction,
+         len);
 
-    rc = SQLFetchScroll(hstmt,SQL_FETCH_ABSOLUTE,2);
-    mystmt(hstmt,rc);
 
-    rc = SQLGetData(hstmt,1,SQL_C_TIMESTAMP,&ts,sizeof(ts),&pclen);
-    mystmt(hstmt,rc);
-    printMessage("\n row2 using SQL_C_TIMESTAMP:%d-%d-%d %d:%d:%d.%d(%d)\n",
-           ts.year,ts.month,
-           ts.day,ts.hour,ts.minute,
-           ts.second,ts.fraction,pclen);
+  expect_stmt(hstmt, SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 3),
+              SQL_NO_DATA_FOUND);
 
+  ok_stmt(hstmt, SQLFreeStmt(hstmt,SQL_UNBIND));
+  ok_stmt(hstmt,  SQLFreeStmt(hstmt,SQL_CLOSE));
 
-    rc = SQLFetchScroll(hstmt,SQL_FETCH_ABSOLUTE,3);
-    mystmt_err(hstmt,rc==SQL_NO_DATA_FOUND,rc);
+  ok_sql(hstmt, "DROP TABLE IF EXISTS my_ts");
 
-    SQLFreeStmt(hstmt,SQL_UNBIND);
-    SQLFreeStmt(hstmt,SQL_CLOSE);
+  return OK;
 }
 
-/********************************************************
-* main routine                                          *
-*********************************************************/
-int main(int argc, char *argv[])
-{
-    SQLHENV    henv;
-    SQLHDBC    hdbc; 
-    SQLHSTMT   hstmt;
-    SQLINTEGER narg;
 
-    printMessageHeader();
+BEGIN_TESTS
+  ADD_TEST(my_ts)
+END_TESTS
 
-    /*
-     * if connection string supplied through arguments, overrite
-     * the default one..
-    */
-    for (narg = 1; narg < argc; narg++)
-    {
-        if ( narg == 1 )
-            mydsn = argv[1];
-        else if ( narg == 2 )
-            myuid = argv[2];
-        else if ( narg == 3 )
-            mypwd = argv[3];
-    }   
 
-    /* 
-     * connect to MySQL server
-    */
-    myconnect(&henv,&hdbc,&hstmt); 
-
-    /* 
-     * simple timestamp conversion demo
-    */
-    my_ts(hdbc, hstmt);
-
-    /* 
-     * disconnect from the server, by freeing all resources
-    */
-    mydisconnect(&henv,&hdbc,&hstmt);
-
-    printMessageFooter( 1 );
-
-    return(0);
-} 
-
-
-
+RUN_TESTS

Thread
Connector/ODBC 3.51 commit: r259 - in trunk/test: . include timestampjwinstead22 Mar