mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-18 04:52:22 +02:00
Removed default template value for DIGITS, because Arduino 1.0.5 refused it
This commit is contained in:
@ -29,6 +29,11 @@ namespace ArduinoJson
|
||||
items[itemCount++].set(value);
|
||||
}
|
||||
|
||||
void add(double value)
|
||||
{
|
||||
add<2>(value);
|
||||
}
|
||||
|
||||
template<int DIGITS>
|
||||
void add(double value)
|
||||
{
|
||||
|
@ -42,6 +42,11 @@ namespace ArduinoJson
|
||||
itemCount++;
|
||||
}
|
||||
|
||||
void add(const char* key, double value)
|
||||
{
|
||||
add<2>(key, value);
|
||||
}
|
||||
|
||||
using JsonObjectBase::printTo;
|
||||
|
||||
private:
|
||||
|
@ -47,7 +47,7 @@ namespace ArduinoJson
|
||||
content.asString.set(value);
|
||||
}
|
||||
|
||||
template<int DIGITS=2>
|
||||
template<int DIGITS>
|
||||
void set(double value)
|
||||
{
|
||||
printToImpl = &printDoubleTo<DIGITS>;
|
||||
|
@ -55,7 +55,13 @@ namespace JsonGeneratorTests
|
||||
jsonIs("[\"hello\",\"world\"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDouble)
|
||||
TEST_METHOD(OneDoubleDefaultDigits)
|
||||
{
|
||||
addValue(3.14159265358979323846);
|
||||
jsonIs("[3.14]");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDoubleFourDigits)
|
||||
{
|
||||
addValue<4>(3.14159265358979323846);
|
||||
jsonIs("[3.1416]");
|
||||
|
@ -49,12 +49,18 @@ namespace JsonGeneratorTests
|
||||
jsonIs("{\"key\":1}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDouble)
|
||||
TEST_METHOD(OneDoubleFourDigits)
|
||||
{
|
||||
addValue<4>("key", 3.14159265358979323846);
|
||||
jsonIs("{\"key\":3.1416}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneDoubleDefaultDigits)
|
||||
{
|
||||
addValue("key", 3.14159265358979323846);
|
||||
jsonIs("{\"key\":3.14}");
|
||||
}
|
||||
|
||||
TEST_METHOD(OneNull)
|
||||
{
|
||||
addValue("key", (char*) 0);
|
||||
|
@ -74,12 +74,6 @@ namespace JsonGeneratorTests
|
||||
assertResultIs("\"\\t\"");
|
||||
}
|
||||
|
||||
TEST_METHOD(DoubleDefaultDigits)
|
||||
{
|
||||
write(3.14159265358979323846);
|
||||
assertResultIs("3.14");
|
||||
}
|
||||
|
||||
TEST_METHOD(DoubleZeroDigits)
|
||||
{
|
||||
write<0>(3.14159265358979323846);
|
||||
@ -116,15 +110,6 @@ namespace JsonGeneratorTests
|
||||
assertResultIs("314");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void write(T value)
|
||||
{
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
JsonValue jsonValue;
|
||||
jsonValue.set(value);
|
||||
returnValue = jsonValue.printTo(sb);
|
||||
}
|
||||
|
||||
template<int DIGITS>
|
||||
void write(double value)
|
||||
{
|
||||
@ -134,6 +119,15 @@ namespace JsonGeneratorTests
|
||||
returnValue = jsonValue.printTo(sb);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void write(T value)
|
||||
{
|
||||
StringBuilder sb(buffer, sizeof(buffer));
|
||||
JsonValue jsonValue;
|
||||
jsonValue.set(value);
|
||||
returnValue = jsonValue.printTo(sb);
|
||||
}
|
||||
|
||||
void assertResultIs(const char* expected)
|
||||
{
|
||||
Assert::AreEqual(expected, buffer);
|
||||
|
Reference in New Issue
Block a user