EXPECT_EQ(min, x.getMin());
EXPECT_EQ(value, x.get());
EXPECT_EQ(max, x.getMax());
+ EXPECT_FALSE(x.unspecified());
// requested values below min should return allowed min value
EXPECT_EQ(min, x.get(min - 5));
EXPECT_EQ(42, y.getMin()); // min, default and max are equal to 42
EXPECT_EQ(42, y.get()); // it returns ...
EXPECT_EQ(42, y.getMax()); // the exact value...
+ EXPECT_FALSE(x.unspecified());
// requested values below or above are ignore
EXPECT_EQ(42, y.get(5)); // all...
EXPECT_EQ(42, y.get(80)); // time!
}
+TEST(TripletTest, unspecified) {
+ Triplet<uint32_t> x;
+ // When using the constructor without parameters, the triplet
+ // value is unspecified.
+ EXPECT_EQ(0, x.getMin());
+ EXPECT_EQ(0, x.get());
+ EXPECT_EQ(0, x.getMax());
+ EXPECT_TRUE(x.unspecified());
+
+ // For the triplet which has unspecified value we can call accessors
+ // without an exception.
+ uint32_t exp_unspec = 0;
+ EXPECT_EQ(exp_unspec, x);
+
+ x = 72;
+ // Check if the new value has been assigned.
+ EXPECT_EQ(72, x.getMin());
+ EXPECT_EQ(72, x.get());
+ EXPECT_EQ(72, x.getMax());
+ // Triplet is now specified.
+ EXPECT_FALSE(x.unspecified());
+}
+
// Triplets must be easy to use.
// Simple to/from int conversions must be done on the fly.
TEST(TripletTest, operator) {
EXPECT_EQ(4, foo.getMin());
EXPECT_EQ(5, foo.get());
EXPECT_EQ(6, foo.getMax());
+ EXPECT_FALSE(foo.unspecified());
// assignment operator: uint32_t => triplet
Triplet<uint32_t> y(0);
min_ = other;
default_ = other;
max_ = other;
+ // The value is now specified because we just assigned one.
+ unspecified_ = false;
return (*this);
}
return (default_);
}
+ /// @brief Constructor without parameters.
+ ///
+ /// Marks value in @c Triplet unspecified.
+ Triplet()
+ : min_(0), default_(0), max_(0),
+ unspecified_(true) {
+ }
+
/// @brief Sets a fixed value.
///
/// This constructor assigns a fixed (i.e. no range, just a single value)
///
/// @param value A number to be assigned as min, max and default value.
Triplet(T value)
- :min_(value), default_(value), max_(value) {
+ : min_(value), default_(value), max_(value),
+ unspecified_(false) {
}
/// @brief Sets the default value and thresholds
///
/// @throw BadValue if min <= def <= max rule is violated
Triplet(T min, T def, T max)
- :min_(min), default_(def), max_(max) {
+ : min_(min), default_(def), max_(max),
+ unspecified_(false) {
if ( (min_ > def) || (def > max_) ) {
isc_throw(BadValue, "Invalid triplet values.");
}
/// @brief Returns a maximum allowed value
T getMax() const { return (max_); }
+ /// @brief Check if the value has been specified.
+ ///
+ /// @return true if the value hasn't been specified, or false otherwise.
+ bool unspecified() const {
+ return (unspecified_);
+ }
+
private:
/// @brief the minimum value
/// @brief the maximum value
T max_;
+
+ /// @brief Indicates whether the value is unspecified.
+ bool unspecified_;
};