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 12 : class FirebirdTest
26 : : public DBTestBase
27 : {
28 : public:
29 : void testEmptyDBConnection();
30 : void testIntegerDatabase();
31 :
32 : virtual void setUp() SAL_OVERRIDE;
33 :
34 4 : CPPUNIT_TEST_SUITE(FirebirdTest);
35 2 : CPPUNIT_TEST(testEmptyDBConnection);
36 2 : CPPUNIT_TEST(testIntegerDatabase);
37 4 : CPPUNIT_TEST_SUITE_END();
38 : };
39 :
40 4 : void FirebirdTest::setUp()
41 : {
42 4 : DBTestBase::setUp();
43 4 : SvtMiscOptions aMiscOptions;
44 4 : aMiscOptions.SetExperimentalMode(true);
45 4 : }
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 2 : void FirebirdTest::testEmptyDBConnection()
52 : {
53 : uno::Reference< XOfficeDatabaseDocument > xDocument =
54 2 : getDocumentForFileName("firebird_empty.odb");
55 :
56 2 : getConnectionForDocument(xDocument);
57 :
58 2 : closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
59 2 : }
60 :
61 : /**
62 : * Test reading of integers from a known .odb to verify that the data
63 : * can still be read on all systems.
64 : */
65 2 : void FirebirdTest::testIntegerDatabase()
66 : {
67 : uno::Reference< XOfficeDatabaseDocument > xDocument =
68 2 : getDocumentForFileName("firebird_integer_x64le.odb");
69 :
70 : uno::Reference< XConnection > xConnection =
71 4 : getConnectionForDocument(xDocument);
72 :
73 4 : uno::Reference< XStatement > xStatement = xConnection->createStatement();
74 2 : CPPUNIT_ASSERT(xStatement.is());
75 :
76 2 : uno::Reference< XResultSet > xResultSet = xStatement->executeQuery(
77 4 : "SELECT * FROM TESTTABLE");
78 2 : CPPUNIT_ASSERT(xResultSet.is());
79 2 : CPPUNIT_ASSERT(xResultSet->next());
80 :
81 4 : uno::Reference< XRow > xRow(xResultSet, UNO_QUERY);
82 2 : CPPUNIT_ASSERT(xRow.is());
83 4 : uno::Reference< XColumnLocate > xColumnLocate(xRow, UNO_QUERY);
84 2 : CPPUNIT_ASSERT(xColumnLocate.is());
85 :
86 4 : CPPUNIT_ASSERT(sal_Int16(-30000) ==
87 2 : xRow->getShort(xColumnLocate->findColumn("_SMALLINT")));
88 4 : CPPUNIT_ASSERT(sal_Int32(-2100000000) ==
89 2 : xRow->getInt(xColumnLocate->findColumn("_INT")));
90 4 : CPPUNIT_ASSERT(SAL_CONST_INT64(-9000000000000000000) ==
91 2 : xRow->getLong(xColumnLocate->findColumn("_BIGINT")));
92 4 : CPPUNIT_ASSERT(OUString("5") ==
93 2 : xRow->getString(xColumnLocate->findColumn("_CHAR")));
94 4 : CPPUNIT_ASSERT(OUString("5") ==
95 2 : xRow->getString(xColumnLocate->findColumn("_VARCHAR")));
96 :
97 2 : CPPUNIT_ASSERT(!xResultSet->next()); // Should only be one row
98 :
99 4 : closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
100 2 : }
101 :
102 2 : CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest);
103 :
104 8 : CPPUNIT_PLUGIN_IMPLEMENT();
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|