1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "dbtest_base.cxx"
12 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
13 #include <com/sun/star/sdbc/XColumnLocate.hpp>
14 #include <com/sun/star/sdbc/XConnection.hpp>
15 #include <com/sun/star/sdbc/XResultSet.hpp>
16 #include <com/sun/star/sdbc/XRow.hpp>
17 #include <com/sun/star/sdbc/XStatement.hpp>
18 #include <com/sun/star/util/XCloseable.hpp>
20 using namespace ::com::sun::star
;
21 using namespace ::com::sun::star::sdb
;
22 using namespace ::com::sun::star::sdbc
;
23 using namespace ::com::sun::star::uno
;
29 void testEmptyDBConnection();
30 void testIntegerDatabase();
33 CPPUNIT_TEST_SUITE(FirebirdTest
);
34 CPPUNIT_TEST(testEmptyDBConnection
);
35 CPPUNIT_TEST(testIntegerDatabase
);
36 CPPUNIT_TEST(testTdf132924
);
37 CPPUNIT_TEST_SUITE_END();
41 * Test the loading of an "empty" file, i.e. the embedded database has not yet
42 * been initialised (as occurs when a new .odb is created and opened by base).
44 void FirebirdTest::testEmptyDBConnection()
46 createTempCopy(u
"firebird_empty.odb");
47 uno::Reference
< XOfficeDatabaseDocument
> xDocument
=
48 getDocumentForUrl(maTempFile
.GetURL());
50 getConnectionForDocument(xDocument
);
52 css::uno::Reference
<util::XCloseable
> xCloseable(mxComponent
, css::uno::UNO_QUERY_THROW
);
53 xCloseable
->close(false);
57 * Test reading of integers from a known .odb to verify that the data
58 * can still be read on all systems.
60 void FirebirdTest::testIntegerDatabase()
62 loadFromURL(u
"firebird_integer_ods12.odb");
63 uno::Reference
< XOfficeDatabaseDocument
> xDocument(mxComponent
, UNO_QUERY_THROW
);
65 uno::Reference
< XConnection
> xConnection
=
66 getConnectionForDocument(xDocument
);
68 uno::Reference
< XStatement
> xStatement
= xConnection
->createStatement();
69 CPPUNIT_ASSERT(xStatement
.is());
71 uno::Reference
< XResultSet
> xResultSet
= xStatement
->executeQuery(
72 "SELECT * FROM TESTTABLE");
73 CPPUNIT_ASSERT(xResultSet
.is());
74 CPPUNIT_ASSERT(xResultSet
->next());
76 uno::Reference
< XRow
> xRow(xResultSet
, UNO_QUERY
);
77 CPPUNIT_ASSERT(xRow
.is());
78 uno::Reference
< XColumnLocate
> xColumnLocate(xRow
, UNO_QUERY
);
79 CPPUNIT_ASSERT(xColumnLocate
.is());
81 CPPUNIT_ASSERT_EQUAL(sal_Int16(-30000),
82 xRow
->getShort(xColumnLocate
->findColumn("_SMALLINT")));
83 CPPUNIT_ASSERT_EQUAL(sal_Int32(-2100000000),
84 xRow
->getInt(xColumnLocate
->findColumn("_INT")));
85 CPPUNIT_ASSERT_EQUAL(SAL_CONST_INT64(-9000000000000000000),
86 xRow
->getLong(xColumnLocate
->findColumn("_BIGINT")));
87 CPPUNIT_ASSERT_EQUAL(OUString("5"),
88 xRow
->getString(xColumnLocate
->findColumn("_CHAR")));
89 CPPUNIT_ASSERT_EQUAL(OUString("5"),
90 xRow
->getString(xColumnLocate
->findColumn("_VARCHAR")));
92 CPPUNIT_ASSERT(!xResultSet
->next()); // Should only be one row
94 css::uno::Reference
<util::XCloseable
> xCloseable(mxComponent
, css::uno::UNO_QUERY_THROW
);
95 xCloseable
->close(false);
98 void FirebirdTest::testTdf132924()
100 loadFromURL(u
"tdf132924.odb");
101 uno::Reference
< XOfficeDatabaseDocument
> xDocument(mxComponent
, UNO_QUERY_THROW
);
102 uno::Reference
<XConnection
> xConnection
= getConnectionForDocument(xDocument
);
104 uno::Reference
<XStatement
> xStatement
= xConnection
->createStatement();
105 CPPUNIT_ASSERT(xStatement
.is());
107 uno::Reference
<XResultSet
> xResultSet
= xStatement
->executeQuery("SELECT * FROM AliasTest");
108 CPPUNIT_ASSERT(xResultSet
.is());
109 CPPUNIT_ASSERT(xResultSet
->next());
111 uno::Reference
<XRow
> xRow(xResultSet
, UNO_QUERY
);
112 CPPUNIT_ASSERT(xRow
.is());
113 uno::Reference
<XColumnLocate
> xColumnLocate(xRow
, UNO_QUERY
);
114 CPPUNIT_ASSERT(xColumnLocate
.is());
116 // Without the fix in place, this test would have failed with:
118 // - Actual : The column name 'TestId' is not valid
119 CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xRow
->getShort(xColumnLocate
->findColumn("TestId")));
120 CPPUNIT_ASSERT_EQUAL(OUString("TestName"), xRow
->getString(xColumnLocate
->findColumn("TestName")));
122 css::uno::Reference
<util::XCloseable
> xCloseable(mxComponent
, css::uno::UNO_QUERY_THROW
);
123 xCloseable
->close(false);
126 CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest
);
128 CPPUNIT_PLUGIN_IMPLEMENT();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */