summaryrefslogtreecommitdiff
path: root/dbaccess/qa/unit/tdf119625.cxx
blob: bbbe232a292deb95bd4c91270af241157d4d01ee (plain)
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
/* -*- 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 <hsqlimport.hxx>

#include <osl/process.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <test/unoapi_test.hxx>
#include <svtools/miscopt.hxx>
#include <com/sun/star/util/Time.hpp>

using namespace dbahsql;

class Tdf119625Test : public DBTestBase
{
public:
    void testTime();

    virtual void setUp() override;

    CPPUNIT_TEST_SUITE(Tdf119625Test);

    CPPUNIT_TEST(testTime);

    CPPUNIT_TEST_SUITE_END();
};

void Tdf119625Test::setUp()
{
    DBTestBase::setUp();
    SvtMiscOptions aMiscOptions;
    osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData);
}

namespace
{
struct expect_t
{
    sal_Int16 id;
    sal_Int16 h, m, s;
};
}

/* The values here assume that our results are in UTC.  However,
   tdf#119675 "Firebird: Migration: User dialog to set treatment of
   datetime and time values during migration" is going to change the
   final result of migration. If that change is implemented below
   the level we are testing, this test will have to allow for or set
   the destination timezone.
 */
static const expect_t expect[]
    = { { 0, 15, 10, 10 }, { 1, 23, 30, 30 }, { 2, 5, 0, 0 },  { 3, 4, 30, 0 },
        { 4, 3, 15, 10 },  { 5, 5, 0, 0 },    { 6, 3, 22, 22 } };

void Tdf119625Test::testTime()
{
    SvtMiscOptions aMiscOptions;
    bool oldValue = aMiscOptions.IsExperimentalMode();

    aMiscOptions.SetExperimentalMode(true);

    // the migration requires the file to be writable
    utl::TempFile const temp(createTempCopy("tdf119625.odb"));
    uno::Reference<XOfficeDatabaseDocument> const xDocument = getDocumentForUrl(temp.GetURL());

    uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
    // at this point migration is already done
    /* In the presence of tdf#119625, terminal already has messages

           *value exceeds the range for a valid time
           caused by
           'isc_dsql_execute'

           warn:dbaccess:22435:22435:dbaccess/source/filter/hsqldb/hsqlimport.cxx:373: Error during migration

       In this case, we do not expect anything good from the following
       code, but I (tje, 2018-09-04) do not know how to detect this
       situation.  In particular, the migration has been observed to
       create the destination table (but truncated after the first
       row), and xConnection.is() returns true.
    */

    // select basically everything from the .odb
    uno::Reference<XStatement> statement = xConnection->createStatement();
    const OUString sql{ "  SELECT id, tst_dt, tst_d, tst_t "
                        "    FROM tst_data "
                        "ORDER BY id" };

    uno::Reference<XResultSet> xRes = statement->executeQuery(sql);
    uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW);

    // check result
    for (auto& e : expect)
    {
        CPPUNIT_ASSERT(xRes->next());
        CPPUNIT_ASSERT_EQUAL(xRow->getShort(1), e.id);
        auto time_got = xRow->getTime(4);
        auto time_expected = com::sun::star::util::Time(0, e.s, e.m, e.h, false);
        auto equal_times = time_got == time_expected;
        CPPUNIT_ASSERT(equal_times);
    }
    CPPUNIT_ASSERT(!xRes->next());

    closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
    if (!oldValue)
        aMiscOptions.SetExperimentalMode(false);
}

CPPUNIT_TEST_SUITE_REGISTRATION(Tdf119625Test);

CPPUNIT_PLUGIN_IMPLEMENT();