mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix up and test the int specialization of GncOptionRangeValue.
Not sure yet that a double one is really needed.
This commit is contained in:
parent
39b7c9c74d
commit
ff7b263a5f
@ -250,6 +250,10 @@ private:
|
||||
ValueType m_validation_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Used for numeric ranges and plot sizes.
|
||||
*/
|
||||
|
||||
template <typename ValueType>
|
||||
class GncOptionRangeValue :
|
||||
public OptionClassifier, public OptionUIItem
|
||||
@ -263,7 +267,7 @@ public:
|
||||
OptionUIItem(GncOptionUIType::NUMBER_RANGE),
|
||||
m_value{value >= min && value <= max ? value : min},
|
||||
m_default_value{value >= min && value <= max ? value : min},
|
||||
m_min{min}, m_step{step} {}
|
||||
m_min{min}, m_max{max}, m_step{step} {}
|
||||
|
||||
GncOptionRangeValue<ValueType>(const GncOptionRangeValue<ValueType>&) = default;
|
||||
GncOptionRangeValue<ValueType>(GncOptionRangeValue<ValueType>&&) = default;
|
||||
@ -444,7 +448,7 @@ using GncOptionVariant = std::variant<GncOptionValue<std::string>,
|
||||
GncOptionValue<std::vector<GncGUID>>,
|
||||
GncOptionMultichoiceValue,
|
||||
GncOptionRangeValue<int>,
|
||||
GncOptionRangeValue<GncNumeric>,
|
||||
GncOptionRangeValue<double>,
|
||||
GncOptionValidatedValue<QofInstance*>,
|
||||
GncOptionDateValue>;
|
||||
|
||||
|
@ -212,6 +212,41 @@ TEST_F(GncOptionUI, test_set_option_ui_item)
|
||||
EXPECT_EQ(&ui_item, m_option.get_ui_item()->m_widget);
|
||||
}
|
||||
|
||||
class GncOptionRangeTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
GncOptionRangeTest() :
|
||||
m_intoption{"foo", "bar", "baz", "Phony Option", 15, 1, 30, 1},
|
||||
m_doubleoption{"waldo", "pepper", "salt", "Phonier Option",
|
||||
1.5, 1.0, 3.0, 0.1} {}
|
||||
|
||||
GncOptionRangeValue<int> m_intoption;
|
||||
GncOptionRangeValue<double> m_doubleoption;
|
||||
};
|
||||
|
||||
using GncRangeOption = GncOptionRangeTest;
|
||||
|
||||
TEST_F(GncRangeOption, test_initialization)
|
||||
{
|
||||
EXPECT_EQ(15, m_intoption.get_value());
|
||||
EXPECT_EQ(1.5, m_doubleoption.get_value());
|
||||
EXPECT_EQ(15, m_intoption.get_default_value());
|
||||
EXPECT_EQ(1.5, m_doubleoption.get_default_value());
|
||||
}
|
||||
|
||||
TEST_F(GncRangeOption, test_setter)
|
||||
{
|
||||
EXPECT_THROW({ m_intoption.set_value(45); }, std::invalid_argument);
|
||||
EXPECT_NO_THROW({ m_intoption.set_value(20); });
|
||||
EXPECT_EQ(20, m_intoption.get_value());
|
||||
EXPECT_EQ(15, m_intoption.get_default_value());
|
||||
EXPECT_THROW({ m_doubleoption.set_value(4.5); }, std::invalid_argument);
|
||||
EXPECT_NO_THROW({ m_doubleoption.set_value(2.0); });
|
||||
EXPECT_EQ(2.0, m_doubleoption.get_value());
|
||||
EXPECT_EQ(1.5, m_doubleoption.get_default_value());
|
||||
}
|
||||
|
||||
|
||||
class GncOptionMultichoiceTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -37,6 +37,7 @@
|
||||
(test-gnc-make-text-option)
|
||||
(test-gnc-make-multichoice-option)
|
||||
(test-gnc-make-date-option)
|
||||
(test-gnc-make-number-range-option)
|
||||
(test-end "test-gnc-optiondb-scheme"))
|
||||
|
||||
(define (test-gnc-make-text-option)
|
||||
@ -88,10 +89,23 @@
|
||||
(let* ((option-db (gnc-option-db-new))
|
||||
(date-opt (gnc-register-date-interval-option option-db "foo" "bar"
|
||||
"baz" "Phony Option"))
|
||||
(a-time (gnc-dmy2time64 2019 07 11)))
|
||||
(a-time (gnc-dmy2time64 11 07 2019)))
|
||||
(test-equal (current-time) (GncOptionDB-lookup-option
|
||||
(GncOptionDBPtr-get option-db) "foo" "bar"))
|
||||
(GncOptionDB-set-option-time64 (GncOptionDBPtr-get option-db) "foo" "bar" a-time)
|
||||
(test-equal a-time (GncOptionDB-lookup-option
|
||||
(GncOptionDBPtr-get option-db) "foo" "bar"))
|
||||
(test-end "test-gnc-test-date-option")))
|
||||
|
||||
(define (test-gnc-make-number-range-option)
|
||||
(test-begin "test-gnc-number-range-option")
|
||||
(let* ((option-db (gnc-option-db-new))
|
||||
(number-opt (gnc-register-number-range-option option-db "foo" "bar"
|
||||
"baz" "Phony Option"
|
||||
15 5 30 1)))
|
||||
(test-equal 15 (GncOptionDB-lookup-option
|
||||
(GncOptionDBPtr-get option-db) "foo" "bar"))
|
||||
(GncOptionDB-set-option-int (GncOptionDBPtr-get option-db) "foo" "bar" 20)
|
||||
(test-equal 20 (GncOptionDB-lookup-option
|
||||
(GncOptionDBPtr-get option-db) "foo" "bar")))
|
||||
(test-end "test-gnc-number-range-option"))
|
||||
|
Loading…
Reference in New Issue
Block a user