mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Fixed a few more places where doubles were not serialised to full accuracy
This commit is contained in:
parent
bd07014dcc
commit
306e7e4360
4 changed files with 55 additions and 23 deletions
|
|
@ -175,7 +175,7 @@ public:
|
||||||
int toInt (const ValueUnion& data) const noexcept override { return (int) data.doubleValue; }
|
int toInt (const ValueUnion& data) const noexcept override { return (int) data.doubleValue; }
|
||||||
int64 toInt64 (const ValueUnion& data) const noexcept override { return (int64) data.doubleValue; }
|
int64 toInt64 (const ValueUnion& data) const noexcept override { return (int64) data.doubleValue; }
|
||||||
double toDouble (const ValueUnion& data) const noexcept override { return data.doubleValue; }
|
double toDouble (const ValueUnion& data) const noexcept override { return data.doubleValue; }
|
||||||
String toString (const ValueUnion& data) const override { return String (data.doubleValue, 20); }
|
String toString (const ValueUnion& data) const override { return minimiseLengthOfFloatString (String (data.doubleValue, 15, true)); }
|
||||||
bool toBool (const ValueUnion& data) const noexcept override { return data.doubleValue != 0.0; }
|
bool toBool (const ValueUnion& data) const noexcept override { return data.doubleValue != 0.0; }
|
||||||
bool isDouble() const noexcept override { return true; }
|
bool isDouble() const noexcept override { return true; }
|
||||||
bool isComparable() const noexcept override { return true; }
|
bool isComparable() const noexcept override { return true; }
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,14 @@ public:
|
||||||
/** Writes a JSON-formatted representation of the var object to the given stream.
|
/** Writes a JSON-formatted representation of the var object to the given stream.
|
||||||
If allOnOneLine is true, the result will be compacted into a single line of text
|
If allOnOneLine is true, the result will be compacted into a single line of text
|
||||||
with no carriage-returns. If false, it will be laid-out in a more human-readable format.
|
with no carriage-returns. If false, it will be laid-out in a more human-readable format.
|
||||||
The maximumDecimalPlaces parameter determines the precision of floating point numbers.
|
The maximumDecimalPlaces parameter determines the precision of floating point numbers
|
||||||
|
in scientific notation.
|
||||||
@see toString
|
@see toString
|
||||||
*/
|
*/
|
||||||
static void writeToStream (OutputStream& output,
|
static void writeToStream (OutputStream& output,
|
||||||
const var& objectToFormat,
|
const var& objectToFormat,
|
||||||
bool allOnOneLine = false,
|
bool allOnOneLine = false,
|
||||||
int maximumDecimalPlaces = 20);
|
int maximumDecimalPlaces = 15);
|
||||||
|
|
||||||
/** Returns a version of a string with any extended characters escaped. */
|
/** Returns a version of a string with any extended characters escaped. */
|
||||||
static String escapeString (StringRef);
|
static String escapeString (StringRef);
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,6 @@
|
||||||
#include "containers/juce_PropertySet.cpp"
|
#include "containers/juce_PropertySet.cpp"
|
||||||
#include "containers/juce_ReferenceCountedArray.cpp"
|
#include "containers/juce_ReferenceCountedArray.cpp"
|
||||||
#include "containers/juce_SparseSet.cpp"
|
#include "containers/juce_SparseSet.cpp"
|
||||||
#include "containers/juce_Variant.cpp"
|
|
||||||
#include "files/juce_DirectoryIterator.cpp"
|
#include "files/juce_DirectoryIterator.cpp"
|
||||||
#include "files/juce_File.cpp"
|
#include "files/juce_File.cpp"
|
||||||
#include "files/juce_FileInputStream.cpp"
|
#include "files/juce_FileInputStream.cpp"
|
||||||
|
|
@ -172,6 +171,7 @@
|
||||||
#include "time/juce_RelativeTime.cpp"
|
#include "time/juce_RelativeTime.cpp"
|
||||||
#include "time/juce_Time.cpp"
|
#include "time/juce_Time.cpp"
|
||||||
#include "unit_tests/juce_UnitTest.cpp"
|
#include "unit_tests/juce_UnitTest.cpp"
|
||||||
|
#include "containers/juce_Variant.cpp"
|
||||||
#include "javascript/juce_JSON.cpp"
|
#include "javascript/juce_JSON.cpp"
|
||||||
#include "javascript/juce_Javascript.cpp"
|
#include "javascript/juce_Javascript.cpp"
|
||||||
#include "containers/juce_DynamicObject.cpp"
|
#include "containers/juce_DynamicObject.cpp"
|
||||||
|
|
|
||||||
|
|
@ -1157,32 +1157,63 @@ public:
|
||||||
|
|
||||||
void runTest() override
|
void runTest() override
|
||||||
{
|
{
|
||||||
beginTest ("ValueTree");
|
|
||||||
auto r = getRandom();
|
|
||||||
|
|
||||||
for (int i = 10; --i >= 0;)
|
|
||||||
{
|
{
|
||||||
MemoryOutputStream mo;
|
beginTest ("ValueTree");
|
||||||
auto v1 = createRandomTree (nullptr, 0, r);
|
|
||||||
v1.writeToStream (mo);
|
|
||||||
|
|
||||||
MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
|
auto r = getRandom();
|
||||||
auto v2 = ValueTree::readFromStream (mi);
|
|
||||||
expect (v1.isEquivalentTo (v2));
|
|
||||||
|
|
||||||
MemoryOutputStream zipped;
|
for (int i = 10; --i >= 0;)
|
||||||
{
|
{
|
||||||
GZIPCompressorOutputStream zippedOut (zipped);
|
MemoryOutputStream mo;
|
||||||
v1.writeToStream (zippedOut);
|
auto v1 = createRandomTree (nullptr, 0, r);
|
||||||
|
v1.writeToStream (mo);
|
||||||
|
|
||||||
|
MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
|
||||||
|
auto v2 = ValueTree::readFromStream (mi);
|
||||||
|
expect (v1.isEquivalentTo (v2));
|
||||||
|
|
||||||
|
MemoryOutputStream zipped;
|
||||||
|
{
|
||||||
|
GZIPCompressorOutputStream zippedOut (zipped);
|
||||||
|
v1.writeToStream (zippedOut);
|
||||||
|
}
|
||||||
|
expect (v1.isEquivalentTo (ValueTree::readFromGZIPData (zipped.getData(), zipped.getDataSize())));
|
||||||
|
|
||||||
|
std::unique_ptr<XmlElement> xml1 (v1.createXml());
|
||||||
|
std::unique_ptr<XmlElement> xml2 (v2.createCopy().createXml());
|
||||||
|
expect (xml1->isEquivalentTo (xml2.get(), false));
|
||||||
|
|
||||||
|
auto v4 = v2.createCopy();
|
||||||
|
expect (v1.isEquivalentTo (v4));
|
||||||
}
|
}
|
||||||
expect (v1.isEquivalentTo (ValueTree::readFromGZIPData (zipped.getData(), zipped.getDataSize())));
|
}
|
||||||
|
|
||||||
std::unique_ptr<XmlElement> xml1 (v1.createXml());
|
{
|
||||||
std::unique_ptr<XmlElement> xml2 (v2.createCopy().createXml());
|
beginTest ("Float formatting");
|
||||||
expect (xml1->isEquivalentTo (xml2.get(), false));
|
|
||||||
|
|
||||||
auto v4 = v2.createCopy();
|
ValueTree testVT ("Test");
|
||||||
expect (v1.isEquivalentTo (v4));
|
Identifier number ("number");
|
||||||
|
|
||||||
|
std::map<double, String> tests;
|
||||||
|
tests[1] = "1";
|
||||||
|
tests[1.1] = "1.1";
|
||||||
|
tests[1.01] = "1.01";
|
||||||
|
tests[0.76378] = "7.6378e-1";
|
||||||
|
tests[-10] = "-1e1";
|
||||||
|
tests[10.01] = "1.001e1";
|
||||||
|
tests[0.0123] = "1.23e-2";
|
||||||
|
tests[-3.7e-27] = "-3.7e-27";
|
||||||
|
tests[1e+40] = "1e40";
|
||||||
|
|
||||||
|
for (auto& test : tests)
|
||||||
|
{
|
||||||
|
testVT.setProperty (number, test.first, nullptr);
|
||||||
|
auto lines = StringArray::fromLines (testVT.toXmlString());
|
||||||
|
lines.removeEmptyStrings();
|
||||||
|
auto numLines = lines.size();
|
||||||
|
expect (numLines > 1);
|
||||||
|
expectEquals (lines[numLines - 1], "<Test number=\"" + test.second + "\"/>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue