| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2021 StatPro Italia srl |
| 5 | |
| 6 | This file is part of QuantLib, a free-software/open-source library |
| 7 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 | |
| 9 | QuantLib is free software: you can redistribute it and/or modify it |
| 10 | under the terms of the QuantLib license. You should have received a |
| 11 | copy of the license along with this program; if not, please email |
| 12 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 | <http://quantlib.org/license.shtml>. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 18 | */ |
| 19 | |
| 20 | #include "settings.hpp" |
| 21 | #include "utilities.hpp" |
| 22 | #include <ql/settings.hpp> |
| 23 | |
| 24 | using namespace QuantLib; |
| 25 | using namespace boost::unit_test_framework; |
| 26 | |
| 27 | |
| 28 | void SettingsTest::testNotificationsOnDateChange() { |
| 29 | BOOST_TEST_MESSAGE("Testing notifications on evaluation-date change..." ); |
| 30 | |
| 31 | #ifdef QL_HIGH_RESOLUTION_DATE |
| 32 | |
| 33 | Date d1(11, February, 2021, 9, 17, 0); |
| 34 | Date d2(11, February, 2021, 10, 21, 0); |
| 35 | |
| 36 | #else |
| 37 | |
| 38 | Date d1(11, February, 2021); |
| 39 | Date d2(12, February, 2021); |
| 40 | |
| 41 | #endif |
| 42 | |
| 43 | Settings::instance().evaluationDate() = d1; |
| 44 | |
| 45 | Flag flag; |
| 46 | flag.registerWith(h: Settings::instance().evaluationDate()); |
| 47 | |
| 48 | // Set to same date, no notification |
| 49 | Settings::instance().evaluationDate() = d1; |
| 50 | |
| 51 | if (flag.isUp()) |
| 52 | BOOST_ERROR("unexpected notification" ); |
| 53 | |
| 54 | // Set to different date, notification expected |
| 55 | Settings::instance().evaluationDate() = d2; |
| 56 | |
| 57 | if (!flag.isUp()) |
| 58 | BOOST_ERROR("missing notification" ); |
| 59 | } |
| 60 | |
| 61 | test_suite* SettingsTest::suite() { |
| 62 | auto* suite = BOOST_TEST_SUITE("SettingsTest tests" ); |
| 63 | suite->add(QUANTLIB_TEST_CASE(&SettingsTest::testNotificationsOnDateChange)); |
| 64 | return suite; |
| 65 | } |
| 66 | |