[options] Change RelativeDate and Multichoice index type to uint16_t.

From size_t because clang thinks that std::is_same_v<size_t, time64> is
true and we need to differentiate the handling of the two.
This commit is contained in:
John Ralls 2022-07-17 15:16:10 -07:00
parent 0b2d14ee72
commit cf2870b71a
9 changed files with 90 additions and 84 deletions

View File

@ -527,7 +527,7 @@ gnc_option_test_book_destroy(QofBook* book)
%ignore GncOptionDateValue(GncOptionDateValue&&);
%ignore GncOptionDateValue::operator=(const GncOptionDateValue&);
%ignore GncOptionDateValue::operator=(GncOptionDateValue&&);
%ignore GncOptionDateValue::set_value(size_t); // Used only by dialog-options
%ignore GncOptionDateValue::set_value(uint16_t); // Used only by dialog-options
%ignore operator<<(std::ostream&, const GncOption&);
%ignore operator<<(std::ostream&, const RelativeDatePeriod);
%ignore operator>>(std::istream&, GncOption&);
@ -779,9 +779,9 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
%header %{
static std::vector<SCM> reldate_values{};
inline size_t index_of(RelativeDatePeriod per)
inline uint16_t index_of(RelativeDatePeriod per)
{
return static_cast<size_t>(per) + 1;
return static_cast<uint16_t>(per) + 1;
}
static void init_reldate_values()
@ -891,7 +891,7 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
inline static SCM scm_relative_date_from_period(RelativeDatePeriod period)
{
init_reldate_values();
return reldate_values[static_cast<size_t>(period) + 1];
return reldate_values[static_cast<uint16_t>(period) + 1];
}
inline static bool scm_date_absolute(SCM date)
@ -940,7 +940,7 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
scm_to_multichoices(const SCM new_value,
const GncOptionMultichoiceValue& option)
{
static const auto size_t_max = std::numeric_limits<std::size_t>::max();
static const auto uint16_t_max = std::numeric_limits<uint16_t>::max();
static const char* empty{""};
auto scm_to_str = [](auto item)->const char* {
if (scm_is_integer(item))
@ -962,14 +962,14 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
{
auto item{scm_list_ref(new_value, scm_from_size_t(i))};
auto index{option.permissible_value_index(scm_to_str(item))};
if (index < size_t_max)
if (index < uint16_t_max)
vec.push_back(index);
}
}
else
{
auto index{option.permissible_value_index(scm_to_str(new_value))};
if (index < size_t_max)
if (index < uint16_t_max)
vec.push_back(index);
}
return vec;

View File

@ -22,6 +22,7 @@
* *
\********************************************************************/
%include "constraints.i"
%include <stdint.i>
typedef void * gpointer; // Not sure why SWIG doesn't figure this out.
%typemap(newfree) gchar * "g_free($1);"
@ -173,7 +174,6 @@ typedef char gchar;
#elif defined(SWIGPYTHON) /* Typemaps for Python */
%import "glib.h"
%include <stdint.i>
%apply int { gint };
%apply unsigned int { guint };

View File

@ -1095,12 +1095,12 @@ public:
void set_ui_item_from_option(GncOption& option) noexcept override
{
auto widget{GTK_COMBO_BOX(get_widget())};
gtk_combo_box_set_active(widget, option.get_value<size_t>());
gtk_combo_box_set_active(widget, option.get_value<uint16_t>());
}
void set_option_from_ui_item(GncOption& option) noexcept override
{
auto widget{GTK_COMBO_BOX(get_widget())};
option.set_value<size_t>(static_cast<size_t>(gtk_combo_box_get_active(widget)));
option.set_value<uint16_t>(static_cast<uint16_t>(gtk_combo_box_get_active(widget)));
}
};
@ -1240,13 +1240,13 @@ RelativeDateEntry::RelativeDateEntry(GncOption& option)
void
RelativeDateEntry::set_entry_from_option(GncOption& option)
{
gtk_combo_box_set_active(GTK_COMBO_BOX(m_entry), option.get_value<size_t>());
gtk_combo_box_set_active(GTK_COMBO_BOX(m_entry), option.get_value<uint16_t>());
}
void
RelativeDateEntry::set_option_from_entry(GncOption& option)
{
option.set_value<size_t>(gtk_combo_box_get_active(GTK_COMBO_BOX(m_entry)));
option.set_value<uint16_t>(gtk_combo_box_get_active(GTK_COMBO_BOX(m_entry)));
}
void
@ -2383,7 +2383,7 @@ public:
GncOptionGtkUIItem{widget, GncOptionUIType::RADIOBUTTON} {}
void set_ui_item_from_option(GncOption& option) noexcept override
{
auto index{option.get_value<size_t>()};
auto index{option.get_value<uint16_t>()};
auto list{gtk_container_get_children(GTK_CONTAINER(get_widget()))};
auto box{GTK_WIDGET(list->data)};
g_list_free(list);
@ -2397,7 +2397,7 @@ public:
}
else
{
PERR("Invalid Radio Button Selection %lu", index);
PERR("Invalid Radio Button Selection %hu", index);
g_list_free(list);
return;
}
@ -2412,7 +2412,7 @@ public:
{
auto index{g_object_get_data(G_OBJECT(get_widget()),
"gnc_radiobutton_index")};
option.set_value<size_t>(GPOINTER_TO_INT(index));
option.set_value<uint16_t>(GPOINTER_TO_INT(index));
}
};

View File

@ -465,7 +465,7 @@ GncOptionDateValue::get_default_value() const noexcept
/* Use asserts for pre- and post-conditions to deliberately crash if they're not
* met as the program design should prevent that from happening.
*/
size_t
uint16_t
GncOptionDateValue::get_period_index() const noexcept
{
assert (m_period != RelativeDatePeriod::ABSOLUTE);
@ -475,7 +475,7 @@ GncOptionDateValue::get_period_index() const noexcept
return item - m_period_set.begin();
}
size_t
uint16_t
GncOptionDateValue::get_default_period_index() const noexcept
{
assert(m_period != RelativeDatePeriod::ABSOLUTE);
@ -487,7 +487,7 @@ GncOptionDateValue::get_default_period_index() const noexcept
}
void
GncOptionDateValue::set_value(size_t index) noexcept
GncOptionDateValue::set_value(uint16_t index) noexcept
{
assert(!m_period_set.empty());
assert(index < m_period_set.size());
@ -495,7 +495,7 @@ GncOptionDateValue::set_value(size_t index) noexcept
m_period = m_period_set[index];
}
size_t
uint16_t
GncOptionDateValue::permissible_value_index(const char* key) const noexcept
{
auto index = std::find_if(m_period_set.begin(), m_period_set.end(),
@ -800,11 +800,11 @@ GncOptionMultichoiceValue::serialize() const noexcept
bool
GncOptionMultichoiceValue::deserialize(const std::string& str) noexcept
{
static const auto size_t_max = std::numeric_limits<std::size_t>::max();
static const auto uint16_t_max = std::numeric_limits<uint16_t>::max();
if (str.empty())
return false;
size_t pos{};
uint16_t pos{};
while (pos < str.size())
{
auto endpos{str.find(' ', pos)};
@ -812,7 +812,7 @@ GncOptionMultichoiceValue::deserialize(const std::string& str) noexcept
endpos = str.size();
//need a null-terminated char* to pass to permissible_value_index
auto index{permissible_value_index(str.substr(pos, endpos).c_str())};
if (index == size_t_max)
if (index == uint16_t_max)
return false;
m_value.push_back(index);
pos = endpos + 1;
@ -870,7 +870,7 @@ GncOptionDateValue::deserialize(const std::string& str) noexcept
if (type_str == "absolute")
{
// Need a cast to disambiguate from time64.
set_value(static_cast<size_t>(std::stoll(period_str)));
set_value(static_cast<uint16_t>(std::stoll(period_str)));
return true;
}
else if (type_str == "relative ")
@ -914,7 +914,7 @@ template GncOptionValue<std::string>::GncOptionValue(const GncOptionValue<std::s
template GncOptionValue<const QofQuery*>::GncOptionValue(const GncOptionValue<const QofQuery*>&);
template GncOptionValue<const GncOwner*>::GncOptionValue(const GncOptionValue<const GncOwner*>&);
template GncOptionValue<RelativeDatePeriod>::GncOptionValue(const GncOptionValue<RelativeDatePeriod>&);
template GncOptionValue<size_t>::GncOptionValue(const GncOptionValue<size_t>&);
template GncOptionValue<uint16_t>::GncOptionValue(const GncOptionValue<uint16_t>&);
template GncOptionValue<GncOptionAccountList>::GncOptionValue(const GncOptionValue<GncOptionAccountList>&);
template GncOptionValue<GncMultichoiceOptionIndexVec>::GncOptionValue(const GncOptionValue<GncMultichoiceOptionIndexVec>&);
template GncOptionValue<GncOptionReportPlacementVec>::GncOptionValue(const GncOptionValue<GncOptionReportPlacementVec>&);
@ -928,7 +928,7 @@ template void GncOptionValue<std::string>::set_value(std::string);
template void GncOptionValue<const QofQuery*>::set_value(const QofQuery*);
template void GncOptionValue<const GncOwner*>::set_value(const GncOwner*);
template void GncOptionValue<RelativeDatePeriod>::set_value(RelativeDatePeriod);
template void GncOptionValue<size_t>::set_value(size_t);
template void GncOptionValue<uint16_t>::set_value(uint16_t);
template void GncOptionValue<GncOptionAccountList>::set_value(GncOptionAccountList);
template void GncOptionValue<GncMultichoiceOptionIndexVec>::set_value(GncMultichoiceOptionIndexVec);
template void GncOptionValue<GncOptionReportPlacementVec>::set_value(GncOptionReportPlacementVec);
@ -942,7 +942,7 @@ template void GncOptionValue<std::string>::set_default_value(std::string);
template void GncOptionValue<const QofQuery*>::set_default_value(const QofQuery*);
template void GncOptionValue<const GncOwner*>::set_default_value(const GncOwner*);
template void GncOptionValue<RelativeDatePeriod>::set_default_value(RelativeDatePeriod);
template void GncOptionValue<size_t>::set_default_value(size_t);
template void GncOptionValue<uint16_t>::set_default_value(uint16_t);
template void GncOptionValue<GncOptionAccountList>::set_default_value(GncOptionAccountList);
template void GncOptionValue<GncMultichoiceOptionIndexVec>::set_default_value(GncMultichoiceOptionIndexVec);
template void GncOptionValue<GncOptionReportPlacementVec>::set_default_value(GncOptionReportPlacementVec);
@ -956,7 +956,7 @@ template void GncOptionValue<std::string>::reset_default_value();
template void GncOptionValue<const QofQuery*>::reset_default_value();
template void GncOptionValue<const GncOwner*>::reset_default_value();
template void GncOptionValue<RelativeDatePeriod>::reset_default_value();
template void GncOptionValue<size_t>::reset_default_value();
template void GncOptionValue<uint16_t>::reset_default_value();
template void GncOptionValue<GncOptionAccountList>::reset_default_value();
template void GncOptionValue<GncMultichoiceOptionIndexVec>::reset_default_value();
template void GncOptionValue<GncOptionReportPlacementVec>::reset_default_value();

View File

@ -77,7 +77,7 @@ struct OptionClassifier
#ifndef SWIG
auto constexpr size_t_max = std::numeric_limits<std::size_t>::max();
auto constexpr uint16_t_max = std::numeric_limits<uint16_t>::max();
#endif
/** @class GncOptionValue
@ -424,7 +424,7 @@ operator>> (std::istream& iss, OptType& opt)
using GncMultichoiceOptionEntry = std::tuple<const std::string,
const std::string,
GncOptionMultichoiceKeyType>;
using GncMultichoiceOptionIndexVec = std::vector<std::size_t>;
using GncMultichoiceOptionIndexVec = std::vector<uint16_t>;
using GncMultichoiceOptionChoices = std::vector<GncMultichoiceOptionEntry>;
/** @class GncOptionMultichoiceValue
@ -457,7 +457,7 @@ public:
if (value)
{
if (auto index = find_key(value);
index != size_t_max)
index != uint16_t_max)
{
m_value.push_back(index);
m_default_value.push_back(index);
@ -467,7 +467,7 @@ public:
GncOptionMultichoiceValue(const char* section, const char* name,
const char* key, const char* doc_string,
size_t index,
uint16_t index,
GncMultichoiceOptionChoices&& choices,
GncOptionUIType ui_type = GncOptionUIType::MULTICHOICE) :
OptionClassifier{section, name, key, doc_string},
@ -516,7 +516,7 @@ public:
return c_list_string;
}
size_t get_index() const
uint16_t get_index() const
{
if (m_value.size() > 0)
return m_value[0];
@ -535,7 +535,7 @@ public:
bool validate(const std::string& value) const noexcept
{
auto index = find_key(value);
return index != size_t_max;
return index != uint16_t_max;
}
bool validate(const GncMultichoiceOptionIndexVec& indexes) const noexcept
@ -549,7 +549,7 @@ public:
void set_value(const std::string& value)
{
auto index = find_key(value);
if (index != size_t_max)
if (index != uint16_t_max)
{
m_value.clear();
m_value.push_back(index);
@ -558,7 +558,7 @@ public:
throw std::invalid_argument("Value not a valid choice.");
}
void set_value(size_t index)
void set_value(uint16_t index)
{
if (index < m_choices.size())
{
@ -572,7 +572,7 @@ public:
void set_default_value(const std::string& value)
{
auto index = find_key(value);
if (index != size_t_max)
if (index != uint16_t_max)
{
m_value.clear();
m_value.push_back(index);
@ -583,7 +583,7 @@ public:
throw std::invalid_argument("Value not a valid choice.");
}
void set_default_value(size_t index)
void set_default_value(uint16_t index)
{
if (index < m_choices.size())
{
@ -610,19 +610,19 @@ public:
else
throw std::invalid_argument("One of the supplied indexes was out of range.");
}
std::size_t num_permissible_values() const noexcept
uint16_t num_permissible_values() const noexcept
{
return m_choices.size();
}
std::size_t permissible_value_index(const char* key) const noexcept
uint16_t permissible_value_index(const char* key) const noexcept
{
return find_key(key);
}
const char* permissible_value(std::size_t index) const
const char* permissible_value(uint16_t index) const
{
return std::get<0>(m_choices.at(index)).c_str();
}
const char* permissible_value_name(std::size_t index) const
const char* permissible_value_name(uint16_t index) const
{
return std::get<1>(m_choices.at(index)).c_str();
}
@ -634,7 +634,7 @@ public:
std::string serialize() const noexcept;
bool deserialize(const std::string& str) noexcept;
private:
std::size_t find_key (const std::string& key) const noexcept
uint16_t find_key (const std::string& key) const noexcept
{
auto iter = std::find_if(m_choices.begin(), m_choices.end(),
[key](auto choice) {
@ -642,7 +642,7 @@ private:
if (iter != m_choices.end())
return iter - m_choices.begin();
else
return size_t_max;
return uint16_t_max;
}
GncOptionUIType m_ui_type;
@ -682,7 +682,7 @@ operator>> <GncOptionMultichoiceValue>(std::istream& iss,
if (!str.empty())
{
auto index = opt.permissible_value_index(str.c_str());
if (index != size_t_max)
if (index != uint16_t_max)
values.push_back(index);
else
{
@ -983,8 +983,8 @@ public:
time64 get_default_value() const noexcept;
RelativeDatePeriod get_period() const noexcept { return m_period; }
RelativeDatePeriod get_default_period() const noexcept { return m_default_period; }
size_t get_period_index() const noexcept;
size_t get_default_period_index() const noexcept;
uint16_t get_period_index() const noexcept;
uint16_t get_default_period_index() const noexcept;
std::ostream& out_stream(std::ostream& oss) const noexcept;
std::istream& in_stream(std::istream& iss);
bool validate(RelativeDatePeriod value);
@ -1007,7 +1007,7 @@ public:
m_date = time;
}
}
void set_value(size_t index) noexcept;
void set_value(uint16_t index) noexcept;
void set_default_value(RelativeDatePeriod value) {
if (validate(value))
{
@ -1022,16 +1022,16 @@ public:
m_date = m_default_date = time;
}
}
std::size_t num_permissible_values() const noexcept
uint16_t num_permissible_values() const noexcept
{
return m_period_set.size();
}
std::size_t permissible_value_index(const char* key) const noexcept;
const char* permissible_value(std::size_t index) const
uint16_t permissible_value_index(const char* key) const noexcept;
const char* permissible_value(uint16_t index) const
{
return gnc_relative_date_storage_string(m_period_set.at(index));
}
const char* permissible_value_name(std::size_t index) const
const char* permissible_value_name(uint16_t index) const
{
return gnc_relative_date_display_string(m_period_set.at(index));
}

View File

@ -59,14 +59,16 @@ GncOption::get_value() const
if constexpr (is_same_decayed_v<ValueType,
RelativeDatePeriod>)
return option.get_period();
if constexpr (std::is_same_v<ValueType, size_t>)
if constexpr (std::is_same_v<ValueType, time64>)
return option.get_value();
if constexpr (std::is_same_v<ValueType, uint16_t>)
return option.get_period_index();
return ValueType{};
}
if constexpr (is_same_decayed_v<decltype(option),
GncOptionMultichoiceValue>)
{
if constexpr (std::is_same_v<ValueType, size_t>)
if constexpr (std::is_same_v<ValueType, uint16_t>)
return option.get_index();
if constexpr (is_same_decayed_v<ValueType,
GncMultichoiceOptionIndexVec>)
@ -90,7 +92,9 @@ GncOption::get_default_value() const
if constexpr (is_same_decayed_v<ValueType,
RelativeDatePeriod>)
return option.get_default_period();
if constexpr (std::is_same_v<ValueType, size_t>)
if constexpr (std::is_same_v<ValueType, time64>)
return option.get_value();
if constexpr (std::is_same_v<ValueType, uint16_t>)
return option.get_default_period_index();
return ValueType{};
}
@ -115,7 +119,8 @@ GncOption::set_value(ValueType value)
(is_same_decayed_v<decltype(option),
GncOptionDateValue> &&
(is_same_decayed_v<ValueType, RelativeDatePeriod> ||
std::is_same_v<ValueType, size_t>)))
std::is_same_v<ValueType, time64> ||
std::is_same_v<ValueType, uint16_t>)))
option.set_value(value);
if constexpr (is_same_decayed_v<decltype(option),
GncOptionMultichoiceValue>)
@ -124,7 +129,7 @@ GncOption::set_value(ValueType value)
GncMultichoiceOptionIndexVec>)
option.set_multiple(value);
else if constexpr
(std::is_same_v<ValueType, size_t> ||
(std::is_same_v<ValueType, uint16_t> ||
is_same_decayed_v<ValueType, std::string> ||
std::is_same_v<std::remove_cv<ValueType>, char*>)
option.set_value(value);
@ -141,7 +146,8 @@ GncOption::set_default_value(ValueType value)
(is_same_decayed_v<decltype(option.get_value()), ValueType>||
(is_same_decayed_v<decltype(option), GncOptionDateValue> &&
(is_same_decayed_v<ValueType, RelativeDatePeriod> ||
std::is_same_v<ValueType, size_t>)))
std::is_same_v<ValueType, time64> ||
std::is_same_v<ValueType, uint16_t>)))
option.set_default_value(value);
if constexpr (is_same_decayed_v<decltype(option),
GncOptionMultichoiceValue>)
@ -150,7 +156,7 @@ GncOption::set_default_value(ValueType value)
GncMultichoiceOptionIndexVec>)
option.set_default_multiple(value);
else if constexpr
(std::is_same_v<ValueType, size_t> ||
(std::is_same_v<ValueType, uint16_t> ||
is_same_decayed_v<ValueType, std::string> ||
std::is_same_v<std::remove_cv<ValueType>, char*>)
option.set_default_value(value);
@ -317,38 +323,38 @@ GncOption::validate(ValueType value) const
}, *m_option);
}
std::size_t
std::uint16_t
GncOption::num_permissible_values() const
{
return std::visit(
[] (const auto& option) -> size_t {
[] (const auto& option) -> uint16_t {
if constexpr (is_same_decayed_v<decltype(option),
GncOptionMultichoiceValue> ||
is_same_decayed_v<decltype(option),
GncOptionDateValue>)
return option.num_permissible_values();
else
return size_t_max;
return uint16_t_max;
}, *m_option);
}
std::size_t
std::uint16_t
GncOption::permissible_value_index(const char* value) const
{
return std::visit(
[&value] (const auto& option) -> size_t {
[&value] (const auto& option) -> uint16_t {
if constexpr (is_same_decayed_v<decltype(option),
GncOptionMultichoiceValue> ||
is_same_decayed_v<decltype(option),
GncOptionDateValue>)
return option.permissible_value_index(value);
else
return size_t_max;
return uint16_t_max;
}, *m_option);
}
const char*
GncOption::permissible_value(std::size_t index) const
GncOption::permissible_value(std::uint16_t index) const
{
return std::visit([index] (const auto& option) -> const char* {
if constexpr (std::is_same_v<std::decay_t<decltype(option)>,
@ -362,7 +368,7 @@ GncOption::permissible_value(std::size_t index) const
}
const char*
GncOption::permissible_value_name(std::size_t index) const
GncOption::permissible_value_name(std::uint16_t index) const
{
return std::visit([index] (const auto& option) -> const char* {
if constexpr (std::is_same_v<std::decay_t<decltype(option)>,
@ -459,7 +465,7 @@ template bool GncOption::get_value<bool>() const;
template int GncOption::get_value<int>() const;
template int64_t GncOption::get_value<int64_t>() const;
template double GncOption::get_value<double>() const;
template size_t GncOption::get_value<size_t>() const;
template uint16_t GncOption::get_value<uint16_t>() const;
template const char* GncOption::get_value<const char*>() const;
template std::string GncOption::get_value<std::string>() const;
template const QofInstance* GncOption::get_value<const QofInstance*>() const;
@ -495,7 +501,7 @@ template void GncOption::set_value(const QofInstance*);
template void GncOption::set_value(gnc_commodity*);
template void GncOption::set_value(const Account*);
template void GncOption::set_value(RelativeDatePeriod);
template void GncOption::set_value(size_t);
template void GncOption::set_value(uint16_t);
template void GncOption::set_value(GncOptionAccountList);
template void GncOption::set_value(GncMultichoiceOptionIndexVec);
template void GncOption::set_value(GncOptionReportPlacementVec);
@ -510,7 +516,7 @@ template void GncOption::set_default_value(std::string);
template void GncOption::set_default_value(const QofInstance*);
template void GncOption::set_default_value(const Account*);
template void GncOption::set_default_value(RelativeDatePeriod);
template void GncOption::set_default_value(size_t);
template void GncOption::set_default_value(uint16_t);
template void GncOption::set_default_value(GncOptionAccountList);
template void GncOption::set_default_value(GncMultichoiceOptionIndexVec);
template void GncOption::set_default_value(GncOptionReportPlacementVec);

View File

@ -171,13 +171,13 @@ public:
/** Not implemented for GncOptionValue. */
template <typename ValueType> bool validate(ValueType value) const;
/** Implemented only for GncOptionMultiselectValue. */
std::size_t num_permissible_values() const;
uint16_t num_permissible_values() const;
/** Implemented only for GncOptionMultiselectValue. */
std::size_t permissible_value_index(const char* value) const;
uint16_t permissible_value_index(const char* value) const;
/** Implemented only for GncOptionMultiselectValue. */
const char* permissible_value(std::size_t index) const;
const char* permissible_value(uint16_t index) const;
/** Implemented only for GncOptionMultiselectValue. */
const char* permissible_value_name(std::size_t index) const;
const char* permissible_value_name(uint16_t index) const;
/** Implemented only for GncOptionAccountListValue. */
GList* account_type_list() const noexcept;
bool is_alternate() const noexcept;

View File

@ -783,7 +783,7 @@ TEST_F(GncMultichoiceOption, test_permissible_value_stuff)
std::out_of_range);
EXPECT_THROW({ auto result = m_option.permissible_value_name(9); },
std::out_of_range);
EXPECT_EQ(std::numeric_limits<std::size_t>::max(),
EXPECT_EQ(std::numeric_limits<uint16_t>::max(),
m_option.permissible_value_index("xyzzy"));
}
@ -842,14 +842,14 @@ TEST_F(GncListOption, test_set_value)
m_option.set_value(GncMultichoiceOptionIndexVec{1, 3});
EXPECT_STREQ("multiple values",
m_option.get_value<std::string>().c_str());
EXPECT_EQ(1U, m_option.get_value<size_t>());
EXPECT_EQ(1U, m_option.get_value<uint16_t>());
auto vec{m_option.get_value<GncMultichoiceOptionIndexVec>()};
ASSERT_EQ(2U, vec.size());
EXPECT_EQ(1U, vec[0]);
EXPECT_EQ(3U, vec[1]);
});
EXPECT_THROW({ m_option.set_value(GncMultichoiceOptionIndexVec{2, 5}); }, std::invalid_argument);
EXPECT_EQ(1U, m_option.get_value<size_t>());
EXPECT_EQ(1U, m_option.get_value<uint16_t>());
}
TEST_F(GncListOption, test_list_out)
@ -1066,15 +1066,15 @@ TEST_F(GncDateOptionList, test_set_and_get_relative)
m_option.set_value(RelativeDatePeriod::START_THIS_MONTH);
EXPECT_EQ(time1, m_option.get_value<time64>());
EXPECT_EQ(RelativeDatePeriod::START_THIS_MONTH, m_option.get_value<RelativeDatePeriod>());
size_t index(std::find(c_begin_dates.begin(), c_begin_dates.end(),
uint16_t index(std::find(c_begin_dates.begin(), c_begin_dates.end(),
RelativeDatePeriod::START_THIS_MONTH) - c_begin_dates.begin());
EXPECT_EQ(index, m_option.get_value<size_t>());
EXPECT_EQ(index, m_option.get_value<uint16_t>());
// And check that nothing happens when we try to set m_option to an end date
m_option.set_value(RelativeDatePeriod::END_THIS_MONTH);
EXPECT_EQ(RelativeDatePeriod::START_THIS_MONTH, m_option.get_value<RelativeDatePeriod>());
m_option.set_value(static_cast<size_t>(5));
m_option.set_value(static_cast<uint16_t>(5));
EXPECT_EQ(RelativeDatePeriod::START_CAL_YEAR, m_option.get_value<RelativeDatePeriod>());
EXPECT_EQ(5u, m_option.get_value<size_t>());
EXPECT_EQ(5u, m_option.get_value<uint16_t>());
}
TEST_F(GncDateOption, test_stream_out)
@ -1326,4 +1326,4 @@ TEST(GncOption, test_create)
EXPECT_EQ(wide, swide);
EXPECT_EQ(high, shigh);
}
}

View File

@ -282,12 +282,12 @@ TEST_F(GncOptionDBTest, test_register_start_date_option)
* gnc-optiondb.cpp.
*/
EXPECT_EQ(static_cast<unsigned int>(std::distance(begin_dates.begin(), index)),
m_db->find_option("foo", "bar")->get_value<size_t>());
m_db->find_option("foo", "bar")->get_value<uint16_t>());
m_db->set_option("foo", "bar", RelativeDatePeriod::END_THIS_MONTH);
EXPECT_EQ(RelativeDatePeriod::START_THIS_MONTH,
m_db->find_option("foo", "bar")->get_value<RelativeDatePeriod>());
m_db->set_option("foo", "bar", static_cast<size_t>(5));
EXPECT_EQ(5u, m_db->find_option("foo", "bar")->get_value<size_t>());
m_db->set_option("foo", "bar", static_cast<uint16_t>(5));
EXPECT_EQ(5u, m_db->find_option("foo", "bar")->get_value<uint16_t>());
}