Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 :
10 : #include "dbtest_base.cxx"
11 :
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 :
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;
24 :
25 6 : class FirebirdTest
26 : : public DBTestBase
27 : {
28 : public:
29 : void testEmptyDBConnection();
30 : void testIntegerDatabase();
31 :
32 : virtual void setUp() SAL_OVERRIDE;
33 :
34 2 : CPPUNIT_TEST_SUITE(FirebirdTest);
35 1 : CPPUNIT_TEST(testEmptyDBConnection);
36 1 : CPPUNIT_TEST(testIntegerDatabase);
37 2 : CPPUNIT_TEST_SUITE_END();
38 : };
39 :
40 2 : void FirebirdTest::setUp()
41 : {
42 2 : DBTestBase::setUp();
43 2 : SvtMiscOptions aMiscOptions;
44 2 : aMiscOptions.SetExperimentalMode(true);
45 2 : }
46 :
47 : /**
48 : * Test the loading of an "empty" file, i.e. the embedded database has not yet
49 : * been initialised (as occurs when a new .odb is created and opened by base).
50 : */
51 1 : void FirebirdTest::testEmptyDBConnection()
52 : {
53 : uno::Reference< XOfficeDatabaseDocument > xDocument =
54 1 : getDocumentForFileName("firebird_empty.odb");
55 :
56 1 : getConnectionForDocument(xDocument);
57 1 : }
58 :
59 : /**
60 : * Test reading of integers from a known .odb to verify that the data
61 : * can still be read on all systems.
62 : */
63 1 : void FirebirdTest::testIntegerDatabase()
64 : {
65 : uno::Reference< XOfficeDatabaseDocument > xDocument =
66 1 : getDocumentForFileName("firebird_integer_x64le.odb");
67 :
68 : uno::Reference< XConnection > xConnection =
69 2 : getConnectionForDocument(xDocument);
70 :
71 2 : uno::Reference< XStatement > xStatement = xConnection->createStatement();
72 1 : CPPUNIT_ASSERT(xStatement.is());
73 :
74 1 : uno::Reference< XResultSet > xResultSet = xStatement->executeQuery(
75 2 : "SELECT * FROM TESTTABLE");
76 1 : CPPUNIT_ASSERT(xResultSet.is());
77 1 : CPPUNIT_ASSERT(xResultSet->next());
78 :
79 2 : uno::Reference< XRow > xRow(xResultSet, UNO_QUERY);
80 1 : CPPUNIT_ASSERT(xRow.is());
81 2 : uno::Reference< XColumnLocate > xColumnLocate(xRow, UNO_QUERY);
82 1 : CPPUNIT_ASSERT(xColumnLocate.is());
83 :
84 2 : CPPUNIT_ASSERT(sal_Int16(-30000) ==
85 1 : xRow->getShort(xColumnLocate->findColumn("_SMALLINT")));
86 2 : CPPUNIT_ASSERT(sal_Int32(-2100000000) ==
87 1 : xRow->getInt(xColumnLocate->findColumn("_INT")));
88 2 : CPPUNIT_ASSERT(SAL_CONST_INT64(-9000000000000000000) ==
89 1 : xRow->getLong(xColumnLocate->findColumn("_BIGINT")));
90 2 : CPPUNIT_ASSERT(OUString("5") ==
91 1 : xRow->getString(xColumnLocate->findColumn("_CHAR")));
92 2 : CPPUNIT_ASSERT(OUString("5") ==
93 1 : xRow->getString(xColumnLocate->findColumn("_VARCHAR")));
94 :
95 2 : CPPUNIT_ASSERT(!xResultSet->next()); // Should only be one row
96 1 : }
97 :
98 1 : CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest);
99 :
100 4 : CPPUNIT_PLUGIN_IMPLEMENT();
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|