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 <svtools/miscopt.hxx>
19 #include <config_firebird.h>
21 using namespace ::com::sun::star
;
22 using namespace ::com::sun::star::sdb
;
23 using namespace ::com::sun::star::sdbc
;
24 using namespace ::com::sun::star::uno
;
30 void testEmptyDBConnection();
31 void testIntegerDatabase();
33 CPPUNIT_TEST_SUITE(FirebirdTest
);
34 CPPUNIT_TEST(testEmptyDBConnection
);
35 CPPUNIT_TEST(testIntegerDatabase
);
36 CPPUNIT_TEST_SUITE_END();
40 * Test the loading of an "empty" file, i.e. the embedded database has not yet
41 * been initialised (as occurs when a new .odb is created and opened by base).
43 void FirebirdTest::testEmptyDBConnection()
45 auto const tmp
= createTempCopy("firebird_empty.odb");
46 uno::Reference
< XOfficeDatabaseDocument
> xDocument
=
47 getDocumentForUrl(tmp
.GetURL());
49 getConnectionForDocument(xDocument
);
51 closeDocument(uno::Reference
<lang::XComponent
>(xDocument
, uno::UNO_QUERY
));
55 * Test reading of integers from a known .odb to verify that the data
56 * can still be read on all systems.
58 void FirebirdTest::testIntegerDatabase()
60 uno::Reference
< XOfficeDatabaseDocument
> xDocument
=
61 getDocumentForFileName("firebird_integer_ods12.odb");
63 uno::Reference
< XConnection
> xConnection
=
64 getConnectionForDocument(xDocument
);
66 uno::Reference
< XStatement
> xStatement
= xConnection
->createStatement();
67 CPPUNIT_ASSERT(xStatement
.is());
69 uno::Reference
< XResultSet
> xResultSet
= xStatement
->executeQuery(
70 "SELECT * FROM TESTTABLE");
71 CPPUNIT_ASSERT(xResultSet
.is());
72 CPPUNIT_ASSERT(xResultSet
->next());
74 uno::Reference
< XRow
> xRow(xResultSet
, UNO_QUERY
);
75 CPPUNIT_ASSERT(xRow
.is());
76 uno::Reference
< XColumnLocate
> xColumnLocate(xRow
, UNO_QUERY
);
77 CPPUNIT_ASSERT(xColumnLocate
.is());
79 CPPUNIT_ASSERT_EQUAL(sal_Int16(-30000),
80 xRow
->getShort(xColumnLocate
->findColumn("_SMALLINT")));
81 CPPUNIT_ASSERT_EQUAL(sal_Int32(-2100000000),
82 xRow
->getInt(xColumnLocate
->findColumn("_INT")));
83 CPPUNIT_ASSERT_EQUAL(SAL_CONST_INT64(-9000000000000000000),
84 xRow
->getLong(xColumnLocate
->findColumn("_BIGINT")));
85 CPPUNIT_ASSERT_EQUAL(OUString("5"),
86 xRow
->getString(xColumnLocate
->findColumn("_CHAR")));
87 CPPUNIT_ASSERT_EQUAL(OUString("5"),
88 xRow
->getString(xColumnLocate
->findColumn("_VARCHAR")));
90 CPPUNIT_ASSERT(!xResultSet
->next()); // Should only be one row
92 closeDocument(uno::Reference
<lang::XComponent
>(xDocument
, uno::UNO_QUERY
));
95 CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest
);
97 CPPUNIT_PLUGIN_IMPLEMENT();
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */