// At the moment of writing, the only way that the code flow can reach the
// int128_t cast, and not throw, is by retrieving one of the few bigint
// statistics through kea-ctrl-agent. If kea-ctrl-agent ever gets removed, and
-// its HTTP listener embeded in Kea, then the cast to int128_t can be removed as
+// its HTTP listener embedded in Kea, then the cast to int128_t can be removed as
// well, as there is no deserialization of bigints required, although the only
// benefit would be better performance for error cases, so it's arguable.
ElementPtr
EXPECT_EQ("{ }", Element::fromJSON("{ \n \r \t \b \f }")->str());
EXPECT_EQ("[ ]", Element::fromJSON("[ \n \r \f \t \b ]")->str());
+ string number;
+
// 64 min and max
EXPECT_NO_THROW({
- EXPECT_EQ("-9223372036854775808", Element::fromJSON("-9223372036854775808")->str());
+ number = "-9223372036854775808";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
});
EXPECT_NO_THROW({
- EXPECT_EQ("9223372036854775807", Element::fromJSON("9223372036854775807")->str());
+ number = "9223372036854775807";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
});
// Just out of range on 64 bits, they get treated as int128_t under the hood.
EXPECT_NO_THROW({
- EXPECT_EQ("-9223372036854775809", Element::fromJSON("-9223372036854775809")->str());
+ number = "-9223372036854775809";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
});
EXPECT_NO_THROW({
- EXPECT_EQ("9223372036854775808", Element::fromJSON("9223372036854775808")->str());
+ number = "9223372036854775808";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
});
- // 128 min and max
+ // 128 min and max. Min is -2^128 + 1.
+ // This is unlike the usual integers that have -2^n as min.
EXPECT_NO_THROW({
- EXPECT_EQ("-340282366920938463463374607431768211455", Element::fromJSON("-340282366920938463463374607431768211455")->str());
+ number = "-340282366920938463463374607431768211455";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
});
EXPECT_NO_THROW({
- EXPECT_EQ("340282366920938463463374607431768211455", Element::fromJSON("340282366920938463463374607431768211455")->str());
+ number = "340282366920938463463374607431768211455";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
});
// Just out of range on 128 bits, error is expected.
EXPECT_THROW({
- EXPECT_NE("-340282366920938463463374607431768211456", Element::fromJSON("-340282366920938463463374607431768211456")->str());
+ number = "-340282366920938463463374607431768211456";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
}, JSONError);
EXPECT_THROW({
- EXPECT_NE("340282366920938463463374607431768211456", Element::fromJSON("340282366920938463463374607431768211456")->str());
+ number = "340282366920938463463374607431768211456";
+ EXPECT_EQ(number, Element::fromJSON(number)->str());
}, JSONError);
// other number overflows
TEST(Element, mapElement) {
// this function checks the specific functions for ListElements
- ElementPtr el = Element::fromJSON("{ \"name\": \"foo\", \"value1\": \"bar\", \"value2\": { \"number\": 42 } }");
+ ElementPtr el = Element::fromJSON("{ \"name\": \"foo\", "
+ "\"value1\": \"bar\", "
+ "\"value2\": { \"number\": 42 } }");
ConstElementPtr el2;
EXPECT_EQ(el->get("name")->stringValue(), "foo");