1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a unit-test, and removed constness from a couple more return types.

This commit is contained in:
Julian Storer 2011-09-13 15:09:21 +01:00
parent bd9a32c757
commit dce7cd9cd1
16 changed files with 79 additions and 53 deletions

View file

@ -133,11 +133,6 @@ void AbstractFifo::finishedRead (int numRead) noexcept
//==============================================================================
#if JUCE_UNIT_TESTS
#include "../unit_tests/juce_UnitTest.h"
#include "../maths/juce_Random.h"
#include "../threads/juce_Thread.h"
class AbstractFifoTests : public UnitTest
{
public:

View file

@ -901,11 +901,6 @@ File File::createTempFile (const String& fileNameEnding)
//==============================================================================
#if JUCE_UNIT_TESTS
#include "../unit_tests/juce_UnitTest.h"
#include "../maths/juce_Random.h"
#include "juce_MemoryMappedFile.h"
class FileTests : public UnitTest
{
public:

View file

@ -525,10 +525,6 @@ void JSON::writeToStream (OutputStream& output, const var& data, const bool allO
//==============================================================================
#if JUCE_UNIT_TESTS
#include "../unit_tests/juce_UnitTest.h"
#include "../maths/juce_Random.h"
class JSONTests : public UnitTest
{
public:

View file

@ -95,10 +95,6 @@ int64 MemoryInputStream::getPosition()
//==============================================================================
#if JUCE_UNIT_TESTS
#include "../unit_tests/juce_UnitTest.h"
#include "../maths/juce_Random.h"
#include "juce_MemoryOutputStream.h"
class MemoryStreamTests : public UnitTest
{
public:

View file

@ -103,17 +103,17 @@ void MemoryOutputStream::writeRepeatedByte (uint8 byte, int howMany)
}
}
const MemoryBlock& MemoryOutputStream::getMemoryBlock() const noexcept
MemoryBlock MemoryOutputStream::getMemoryBlock() const
{
if (data.getSize() > size)
static_cast <char*> (data.getData()) [size] = 0;
return data;
return MemoryBlock (getData(), getDataSize());
}
const void* MemoryOutputStream::getData() const noexcept
{
return getMemoryBlock().getData();
if (data.getSize() > size)
static_cast <char*> (data.getData()) [size] = 0;
return data.getData();
}
bool MemoryOutputStream::setPosition (int64 newPosition)
@ -160,7 +160,8 @@ String MemoryOutputStream::toString() const
OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputStream& streamToRead)
{
return stream << streamToRead.getMemoryBlock();
stream.write (streamToRead.getData(), streamToRead.getDataSize());
return stream;
}
END_JUCE_NAMESPACE

View file

@ -97,8 +97,8 @@ public:
*/
String toString() const;
/** Returns the memory block that is being used internally to hold the data. */
const MemoryBlock& getMemoryBlock() const noexcept;
/** Returns a copy of the stream's data as a memory block. */
MemoryBlock getMemoryBlock() const;
//==============================================================================
/** If the stream is writing to a user-supplied MemoryBlock, this will trim any excess

View file

@ -2095,10 +2095,6 @@ void String::Concatenator::append (const String& s)
//==============================================================================
#if JUCE_UNIT_TESTS
#include "../unit_tests/juce_UnitTest.h"
#include "../maths/juce_Random.h"
#include "juce_StringArray.h"
class StringTests : public UnitTest
{
public:

View file

@ -63,8 +63,6 @@ String ChildProcess::readAllProcessOutput()
//==============================================================================
#if JUCE_UNIT_TESTS
#include "../unit_tests/juce_UnitTest.h"
class ChildProcessTests : public UnitTest
{
public:

View file

@ -333,8 +333,6 @@ void SpinLock::enter() const noexcept
//==============================================================================
#if JUCE_UNIT_TESTS
#include "../unit_tests/juce_UnitTest.h"
class AtomicTests : public UnitTest
{
public:

View file

@ -195,4 +195,58 @@ bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
return false;
}
//==============================================================================
#if JUCE_UNIT_TESTS
class GZIPTests : public UnitTest
{
public:
GZIPTests() : UnitTest ("GZIP") {}
void runTest()
{
beginTest ("GZIP");
Random rng;
for (int i = 100; --i >= 0;)
{
MemoryOutputStream original, compressed, uncompressed;
{
GZIPCompressorOutputStream zipper (&compressed, rng.nextInt (10), false);
for (int j = rng.nextInt (100); --j >= 0;)
{
MemoryBlock data (rng.nextInt (2000) + 1);
for (int k = data.getSize(); --k >= 0;)
data[k] = (char) rng.nextInt (255);
original.write (data.getData(), data.getSize());
zipper .write (data.getData(), data.getSize());
}
}
{
MemoryInputStream compressedInput (compressed.getData(), compressed.getDataSize(), false);
GZIPDecompressorInputStream unzipper (compressedInput);
uncompressed.writeFromInputStream (unzipper, -1);
}
expectEquals ((int) uncompressed.getDataSize(),
(int) original.getDataSize());
if (original.getDataSize() == uncompressed.getDataSize())
expect (memcmp (uncompressed.getData(),
original.getData(),
original.getDataSize()) == 0);
}
}
};
static GZIPTests gzipTests;
#endif
END_JUCE_NAMESPACE

View file

@ -294,7 +294,7 @@ void FileBrowserComponent::setFileFilter (const FileFilter* const newFileFilter)
}
}
const String FileBrowserComponent::getActionVerb() const
String FileBrowserComponent::getActionVerb() const
{
return isSaveMode() ? TRANS("Save") : TRANS("Open");
}

View file

@ -153,7 +153,7 @@ public:
E.g. if browsing in "load file" mode, this will be "Open", if in "save file"
mode, it'll be "Save", etc.
*/
virtual const String getActionVerb() const;
virtual String getActionVerb() const;
/** Returns true if the saveMode flag was set when this component was created.
*/

View file

@ -205,7 +205,6 @@ public:
return columnComponents [owner.getHeader().getIndexOfColumnId (columnId, true)];
}
private:
TableListBox& owner;
OwnedArray<Component> columnComponents;
@ -269,7 +268,6 @@ TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
TableListBox::~TableListBox()
{
header = nullptr;
}
void TableListBox::setModel (TableListBoxModel* const newModel)
@ -332,8 +330,8 @@ bool TableListBox::isAutoSizeMenuOptionShown() const
return autoSizeOptionsShown;
}
const Rectangle<int> TableListBox::getCellPosition (const int columnId, const int rowNumber,
const bool relativeToComponentTopLeft) const
Rectangle<int> TableListBox::getCellPosition (const int columnId, const int rowNumber,
const bool relativeToComponentTopLeft) const
{
Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
@ -479,8 +477,8 @@ void TableListBoxModel::deleteKeyPressed (int) {}
void TableListBoxModel::returnKeyPressed (int) {}
void TableListBoxModel::listWasScrolled() {}
const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/) { return String::empty; }
var TableListBoxModel::getDragSourceDescription (const SparseSet<int>&) { return var::null; }
String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/) { return String::empty; }
var TableListBoxModel::getDragSourceDescription (const SparseSet<int>&) { return var::null; }
Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
{
@ -489,5 +487,4 @@ Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component
return nullptr;
}
END_JUCE_NAMESPACE

View file

@ -146,7 +146,7 @@ public:
/** Returns a tooltip for a particular cell in the table.
*/
virtual const String getCellTooltip (int rowNumber, int columnId);
virtual String getCellTooltip (int rowNumber, int columnId);
//==============================================================================
/** Override this to be informed when rows are selected or deselected.
@ -275,8 +275,8 @@ public:
If relativeToComponentTopLeft is false, the co-ords are relative to the
top-left of the table's top-left cell.
*/
const Rectangle<int> getCellPosition (int columnId, int rowNumber,
bool relativeToComponentTopLeft) const;
Rectangle<int> getCellPosition (int columnId, int rowNumber,
bool relativeToComponentTopLeft) const;
/** Returns the component that currently represents a given cell.
If the component for this cell is off-screen or if the position is out-of-range,