LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / dbaccess / qa / unit / hsql_binary_import.cxx
blob4eac0cdc4130f8b1d198f3521e594682da739e4d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "dbtest_base.cxx"
12 #include <osl/process.h>
13 #include <cppunit/plugin/TestPlugIn.h>
14 #include <com/sun/star/sdbc/XRow.hpp>
15 #include <cppunit/extensions/HelperMacros.h>
16 #include <officecfg/Office/Common.hxx>
18 class HsqlBinaryImportTest : public DBTestBase
20 public:
21 void testBinaryImport();
23 virtual void setUp() override;
25 CPPUNIT_TEST_SUITE(HsqlBinaryImportTest);
27 CPPUNIT_TEST(testBinaryImport);
29 CPPUNIT_TEST_SUITE_END();
32 void HsqlBinaryImportTest::setUp()
34 DBTestBase::setUp();
35 osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData);
38 void HsqlBinaryImportTest::testBinaryImport()
40 bool oldValue = officecfg::Office::Common::Misc::ExperimentalMode::get();
42 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
43 comphelper::ConfigurationChanges::create());
44 officecfg::Office::Common::Misc::ExperimentalMode::set(true, xChanges);
45 xChanges->commit();
48 // the migration requires the file to be writable
49 utl::TempFile const temp(createTempCopy(u"hsqldb_migration_test.odb"));
50 uno::Reference<XOfficeDatabaseDocument> const xDocument = getDocumentForUrl(temp.GetURL());
52 uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
53 // at this point migration is already done
55 uno::Reference<XStatement> statement = xConnection->createStatement();
57 uno::Reference<XResultSet> xRes
58 = statement->executeQuery("SELECT \"ID\", \"Power_value\", \"Power_name\", \"Retired\", "
59 "\"Birth_date\" FROM \"TestTable\" ORDER BY \"ID\"");
60 uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW);
62 // assert first row
63 CPPUNIT_ASSERT(xRes->next());
64 constexpr sal_Int16 idExpected = 1;
65 CPPUNIT_ASSERT_EQUAL(idExpected, xRow->getShort(1));
66 CPPUNIT_ASSERT_EQUAL(OUString{ "45.32" }, xRow->getString(2)); // numeric
67 CPPUNIT_ASSERT_EQUAL(OUString{ "laser eye" }, xRow->getString(3)); // varchar
68 CPPUNIT_ASSERT(xRow->getBoolean(4)); // boolean
70 css::util::Date date = xRow->getDate(5);
72 CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 15 }, date.Day);
73 CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 1 }, date.Month);
74 CPPUNIT_ASSERT_EQUAL(sal_Int16{ 1996 }, date.Year);
76 // assert second row
77 CPPUNIT_ASSERT(xRes->next());
78 constexpr sal_Int16 secondIdExpected = 2;
79 CPPUNIT_ASSERT_EQUAL(secondIdExpected, xRow->getShort(1)); // ID
80 CPPUNIT_ASSERT_EQUAL(OUString{ "54.12" }, xRow->getString(2)); // numeric
81 CPPUNIT_ASSERT_EQUAL(OUString{ "telekinesis" }, xRow->getString(3)); // varchar
82 CPPUNIT_ASSERT(!xRow->getBoolean(4)); // boolean
84 date = xRow->getDate(5);
85 CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 26 }, date.Day);
86 CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 2 }, date.Month);
87 CPPUNIT_ASSERT_EQUAL(sal_Int16{ 1998 }, date.Year);
89 closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
90 if (!oldValue)
92 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
93 comphelper::ConfigurationChanges::create());
94 officecfg::Office::Common::Misc::ExperimentalMode::set(false, xChanges);
95 xChanges->commit();
99 CPPUNIT_TEST_SUITE_REGISTRATION(HsqlBinaryImportTest);
101 CPPUNIT_PLUGIN_IMPLEMENT();