forked from bblanchon/ArduinoJson
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);
|
items[itemCount++].set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add(double value)
|
||||||
|
{
|
||||||
|
add<2>(value);
|
||||||
|
}
|
||||||
|
|
||||||
template<int DIGITS>
|
template<int DIGITS>
|
||||||
void add(double value)
|
void add(double value)
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,11 @@ namespace ArduinoJson
|
|||||||
itemCount++;
|
itemCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add(const char* key, double value)
|
||||||
|
{
|
||||||
|
add<2>(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
using JsonObjectBase::printTo;
|
using JsonObjectBase::printTo;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -47,7 +47,7 @@ namespace ArduinoJson
|
|||||||
content.asString.set(value);
|
content.asString.set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int DIGITS=2>
|
template<int DIGITS>
|
||||||
void set(double value)
|
void set(double value)
|
||||||
{
|
{
|
||||||
printToImpl = &printDoubleTo<DIGITS>;
|
printToImpl = &printDoubleTo<DIGITS>;
|
||||||
|
@ -55,7 +55,13 @@ namespace JsonGeneratorTests
|
|||||||
jsonIs("[\"hello\",\"world\"]");
|
jsonIs("[\"hello\",\"world\"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(OneDouble)
|
TEST_METHOD(OneDoubleDefaultDigits)
|
||||||
|
{
|
||||||
|
addValue(3.14159265358979323846);
|
||||||
|
jsonIs("[3.14]");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(OneDoubleFourDigits)
|
||||||
{
|
{
|
||||||
addValue<4>(3.14159265358979323846);
|
addValue<4>(3.14159265358979323846);
|
||||||
jsonIs("[3.1416]");
|
jsonIs("[3.1416]");
|
||||||
|
@ -49,12 +49,18 @@ namespace JsonGeneratorTests
|
|||||||
jsonIs("{\"key\":1}");
|
jsonIs("{\"key\":1}");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(OneDouble)
|
TEST_METHOD(OneDoubleFourDigits)
|
||||||
{
|
{
|
||||||
addValue<4>("key", 3.14159265358979323846);
|
addValue<4>("key", 3.14159265358979323846);
|
||||||
jsonIs("{\"key\":3.1416}");
|
jsonIs("{\"key\":3.1416}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(OneDoubleDefaultDigits)
|
||||||
|
{
|
||||||
|
addValue("key", 3.14159265358979323846);
|
||||||
|
jsonIs("{\"key\":3.14}");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_METHOD(OneNull)
|
TEST_METHOD(OneNull)
|
||||||
{
|
{
|
||||||
addValue("key", (char*) 0);
|
addValue("key", (char*) 0);
|
||||||
|
@ -74,12 +74,6 @@ namespace JsonGeneratorTests
|
|||||||
assertResultIs("\"\\t\"");
|
assertResultIs("\"\\t\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(DoubleDefaultDigits)
|
|
||||||
{
|
|
||||||
write(3.14159265358979323846);
|
|
||||||
assertResultIs("3.14");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_METHOD(DoubleZeroDigits)
|
TEST_METHOD(DoubleZeroDigits)
|
||||||
{
|
{
|
||||||
write<0>(3.14159265358979323846);
|
write<0>(3.14159265358979323846);
|
||||||
@ -116,15 +110,6 @@ namespace JsonGeneratorTests
|
|||||||
assertResultIs("314");
|
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>
|
template<int DIGITS>
|
||||||
void write(double value)
|
void write(double value)
|
||||||
{
|
{
|
||||||
@ -134,6 +119,15 @@ namespace JsonGeneratorTests
|
|||||||
returnValue = jsonValue.printTo(sb);
|
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)
|
void assertResultIs(const char* expected)
|
||||||
{
|
{
|
||||||
Assert::AreEqual(expected, buffer);
|
Assert::AreEqual(expected, buffer);
|
||||||
|
Reference in New Issue
Block a user