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