List:Commits« Previous MessageNext Message »
From:pharvey Date:January 8 2006 11:16pm
Subject:Connector/ODBC 5 commit: r37 - MYODBCDes/MYODBCDesTest MYODBCDia/MYODBCDiaLib MYODBCDia/MYODBCDiaTest
View as plain text  
Modified:
   MYODBCDes/MYODBCDesTest/MYODBCDesTest.pro
   MYODBCDia/MYODBCDiaLib/MYODBCDia.cpp
   MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.cpp
   MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.pro
Log:
UNICODE:
- diagnostics; improved unit tests

Modified: MYODBCDes/MYODBCDesTest/MYODBCDesTest.pro
===================================================================
--- MYODBCDes/MYODBCDesTest/MYODBCDesTest.pro	2006-01-08 20:03:55 UTC (rev 36)
+++ MYODBCDes/MYODBCDesTest/MYODBCDesTest.pro	2006-01-08 23:16:58 UTC (rev 37)
@@ -9,7 +9,6 @@
 include( ../../defines.pri )
 include( ../../odbc.pri )
 CONFIG          += qtestlib
-# CONFIG          += console
 INCLUDEPATH     += ../../MYODBCC/include
 INCLUDEPATH     += ../../MYODBCDbg/include
 INCLUDEPATH     += ../../MYODBCDia/include

Modified: MYODBCDia/MYODBCDiaLib/MYODBCDia.cpp
===================================================================
--- MYODBCDia/MYODBCDiaLib/MYODBCDia.cpp	2006-01-08 20:03:55 UTC (rev 36)
+++ MYODBCDia/MYODBCDiaLib/MYODBCDia.cpp	2006-01-08 23:16:58 UTC (rev 37)
@@ -119,10 +119,10 @@
 
     if ( nRecNumber < 1 )
         MYODBCDbgReturn( SQL_ERROR );
-    if ( nRecNumber >= getNumber() )
+    if ( nRecNumber > getNumber() )
         MYODBCDbgReturn( SQL_NO_DATA );
 
-    MYODBCDbgReturn( listRecords[nRecNumber]->getDiagRec( psSqlstate,
pnNativeErrorPtr, pszMessageText, nBufferLength, pnTextLengthPtr ) );
+    MYODBCDbgReturn( listRecords[nRecNumber - 1]->getDiagRec( psSqlstate,
pnNativeErrorPtr, pszMessageText, nBufferLength, pnTextLengthPtr ) );
 }
 
 /*!
@@ -196,9 +196,9 @@
         default:
             if ( nRecNumber < 1 )
                 MYODBCDbgReturn( SQL_ERROR );
-            if ( nRecNumber >= getNumber() )
+            if ( nRecNumber > getNumber() )
                 MYODBCDbgReturn( SQL_NO_DATA );
-            MYODBCDbgReturn( listRecords[nRecNumber]->getDiagField( nDiagIdentifier,
pDiagInfoPtr, nBufferLength, pnStringLengthPtr ) );
+            MYODBCDbgReturn( listRecords[nRecNumber - 1]->getDiagField(
nDiagIdentifier, pDiagInfoPtr, nBufferLength, pnStringLengthPtr ) );
     }
 
     MYODBCDbgReturn( SQL_SUCCESS );
@@ -316,7 +316,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%s", listRecords[nRecNumber - 1]->getClassOrigin() );
 }
@@ -326,7 +326,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%d", listRecords[nRecNumber - 1]->getColumnNumber() );
 }
@@ -336,7 +336,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%s", listRecords[nRecNumber - 1]->getConnectionName() );
 }
@@ -346,7 +346,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%s", listRecords[nRecNumber - 1]->getMessageText() );
 }
@@ -356,7 +356,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%s", listRecords[nRecNumber - 1]->getMessage() );
 }
@@ -366,7 +366,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%d", listRecords[nRecNumber - 1]->getNative() );
 }
@@ -376,7 +376,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%d", listRecords[nRecNumber - 1]->getRowNumber() );
 }
@@ -386,7 +386,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%s", listRecords[nRecNumber - 1]->getServerName() );
 }
@@ -396,7 +396,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%s", listRecords[nRecNumber - 1]->getSQLState() );
 }
@@ -406,7 +406,7 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( nRecNumber < 1 );
-    Q_ASSERT( nRecNumber >= getCount() );
+    Q_ASSERT( nRecNumber > getNumber() );
 
     MYODBCDbgReturn3( "%s", listRecords[nRecNumber - 1]->getSubClassOrigin() );
 }
@@ -492,6 +492,7 @@
     pdiarec->setColumnNumber( nColumnNumber );
     pdiarec->setRowNumber( nRowNumber );
     pdiarec->setMessage( stringMessage );
+    listRecords.append( pdiarec );
 
     MYODBCDbgReturn( MYODBCDia_pStates[nState].diag_returncode );
 }
@@ -555,7 +556,7 @@
 {
     MYODBCDbgEnter();
 
-    if ( nRecNumber < 1 || nRecNumber >= getNumber() )
+    if ( nRecNumber < 1 || nRecNumber > getNumber() )
         MYODBCDbgReturn( SQL_ERROR );
 
     delete listRecords.takeAt( nRecNumber - 1 );

Modified: MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.cpp
===================================================================
--- MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.cpp	2006-01-08 20:03:55 UTC (rev 36)
+++ MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.cpp	2006-01-08 23:16:58 UTC (rev 37)
@@ -1,69 +1,111 @@
+#include <QtTest/QtTest>
+#include <QString>
+#include <QFile>
 #include <MYODBCDia.h>
 
-typedef struct tTEST
+class MYODBCDiaTest : public QObject
 {
-    char *      name;
-    int (*pfunc)();
-} TEST;
+    Q_OBJECT
+public:
+    MYODBCDiaTest();
+    ~MYODBCDiaTest();
+    QFile fileDebugOut;
 
-MYODBCDia dia;
+private slots:
+    void alloc();
+    void append();
+    void clear();
+    void cachedNames();
+};
 
-int test1()
+MYODBCDiaTest::MYODBCDiaTest()
 {
-    SQLINTEGER nRecords = 0;
+    fileDebugOut.setFileName( "MYODBCDiaTest.txt" );
+    if ( fileDebugOut.open( QFile::WriteOnly | QFile::Truncate ) ) 
+    {
+        MYODBCDbgInit( &fileDebugOut );
+    }
+    else
+    {
+        MYODBCDbgInit( stdout );
+    }
+}
 
+MYODBCDiaTest::~MYODBCDiaTest()
+{
+    MYODBCDbgFini();
+    fileDebugOut.close();
+}
+
+void MYODBCDiaTest::alloc()
+{
+    MYODBCDia   dia;
+    SQLINTEGER  nRecords = 0;
+
+    /* Should have 0 records available... */
+    QVERIFY( dia.getDiagField( 0, SQL_DIAG_NUMBER, &nRecords, 0, NULL ) ==
SQL_SUCCESS );
+    QVERIFY( nRecords == 0 );
+    QVERIFY( dia.getNumber() == 0 );
+}
+
+void MYODBCDiaTest::append()
+{
+    MYODBCDia   dia;
+    SQLINTEGER  nRecords = 0;
+
+    QVERIFY( dia.doAppend( MYODBC_DIA_01000, 0, "Test of a warning" ) ==
SQL_SUCCESS_WITH_INFO );
+    QVERIFY( dia.doAppend( MYODBC_DIA_HY000, 1, "Test of an error" ) == SQL_ERROR );
+    QVERIFY( dia.doAppend( MYODBC_DIA_01000, 0, NULL ) == SQL_SUCCESS_WITH_INFO );
+    QVERIFY( dia.doAppend( MYODBC_DIA_HY000, 1, NULL ) == SQL_ERROR );
+    QVERIFY( dia.doAppend( MYODBC_DIA_HY000, 1, NULL ) == SQL_ERROR );
+    QVERIFY( dia.doAppend( MYODBC_DIA_HY105, 1, "Test with row and column", 0, 5 ) ==
SQL_ERROR );
+
+    QVERIFY( dia.getDiagField( 0, SQL_DIAG_NUMBER, &nRecords, 0, NULL ) ==
SQL_SUCCESS );
+    QCOMPARE( (long)nRecords, 6L );
+    QCOMPARE( (long)dia.getNumber(), 6L );
+}
+
+void MYODBCDiaTest::clear()
+{
+    MYODBCDia   dia;
+    SQLINTEGER  nRecords = 0;
+
     dia.doAppend( MYODBC_DIA_01000, 0, "Test of a warning" );
     dia.doAppend( MYODBC_DIA_HY000, 1, "Test of an error" );
     dia.doAppend( MYODBC_DIA_01000, 0, NULL );
     dia.doAppend( MYODBC_DIA_HY000, 1, NULL );
     dia.doAppend( MYODBC_DIA_HY000, 1, NULL );
-    dia.doAppend( MYODBC_DIA_HY105, 1, NULL, 0, 5 );
+    dia.doAppend( MYODBC_DIA_HY105, 1, "Test with row and column", 0, 5 );
 
-    dia.getField( 0, SQL_DIAG_NUMBER, &nRecords, 0, NULL );
-    if ( nRecords != 6 )
-    {
-        MYODBCDbgError( "Expected 6 records but found %1", nRecords );
-        return 0;
-    }
+    QVERIFY( dia.getDiagField( 0, SQL_DIAG_NUMBER, &nRecords, 0, NULL ) ==
SQL_SUCCESS );
+    QCOMPARE( (long)nRecords, 6L );
+    QCOMPARE( (long)dia.getNumber(), 6L );
 
     dia.doClear();
 
-    dia.getField( 0, SQL_DIAG_NUMBER, &nRecords, 0, NULL );
-    if ( nRecords != 0 )
-    {
-        MYODBCDbgError( "Expected 0 records but found %1", nRecords );
-        return 0;
-    }
-
-    return 1;
+    QVERIFY( dia.getDiagField( 0, SQL_DIAG_NUMBER, &nRecords, 0, NULL ) ==
SQL_SUCCESS );
+    QCOMPARE( (long)nRecords, 0L );
+    QCOMPARE( (long)dia.getNumber(), 0L );
 }
 
-int main()
+void MYODBCDiaTest::cachedNames()
 {
-    TEST tests[2]=
-    {
-        {"test1", test1},
-        {NULL, NULL}
-    };
-    int n;
+    MYODBCDia   dia;
 
-    MYODBCDbgInit( stderr );
+    /* default... */
+    dia.doAppend( MYODBC_DIA_01000, 0, "Test of a warning" );
+    /* set with value... */
+    dia.setConnectionName( "MyConnection" );
+    dia.doAppend( MYODBC_DIA_HY000, 1, "Test of an error" );
+    /* set with null (should automatically be upgraded to "")... */
+    dia.setConnectionName( QString::null );
+    dia.doAppend( MYODBC_DIA_01000, 0, NULL );
 
-    for ( n = 0; tests[n].name; n++ )
-    {
-        printf( "%-40s", tests[n].name ); 
-        if ( tests[n].pfunc() )
-            printf( "[  OK  ]\n" );
-        else
-        {
-            printf( "[FAILED]\n" ); 
-            exit( 1 );
-        }
-    }
+    QCOMPARE( dia.getConnectionName( 1 ), QString( "" ) );
+    QCOMPARE( dia.getConnectionName( 2 ), QString( "MyConnection" ) );
+    QCOMPARE( dia.getConnectionName( 3 ), QString( "" ) );
+}
 
-    MYODBCDbgFini();
+QTEST_MAIN( MYODBCDiaTest )
+#include "MYODBCDiaTest.moc"
 
-    return 0;
-}  
-
-

Modified: MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.pro
===================================================================
--- MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.pro	2006-01-08 20:03:55 UTC (rev 36)
+++ MYODBCDia/MYODBCDiaTest/MYODBCDiaTest.pro	2006-01-08 23:16:58 UTC (rev 37)
@@ -8,7 +8,7 @@
 include( ../../config.pri )
 include( ../../defines.pri )
 include( ../../odbc.pri )
-CONFIG          += console
+CONFIG          += qtestlib
 INCLUDEPATH     += ../../MYODBCC/include
 INCLUDEPATH     += ../../MYODBCDbg/include
 INCLUDEPATH	+= ../include

Thread
Connector/ODBC 5 commit: r37 - MYODBCDes/MYODBCDesTest MYODBCDia/MYODBCDiaLib MYODBCDia/MYODBCDiaTestpharvey9 Jan