26int64 juce_fileSetPosition (
void* handle, int64 pos);
50 jassert (buffer !=
nullptr && bytesToRead >= 0);
52 auto num = readInternal (buffer, (
size_t) bytesToRead);
53 currentPosition += (int64) num;
65 return currentPosition;
73 if (pos != currentPosition)
74 currentPosition = juce_fileSetPosition (fileHandle, pos);
76 return currentPosition == pos;
82struct FileInputStreamTests :
public UnitTest
84 FileInputStreamTests()
85 :
UnitTest (
"FileInputStream",
"Streams")
88 void runTest()
override
90 const MemoryBlock data (
"abcdefghijklmnopqrstuvwxyz", 26);
91 File f (File::createTempFile (
".txt"));
92 f.appendData (data.getData(), data.getSize());
93 FileInputStream stream (f);
97 expectEquals (stream.getPosition(), (int64) 0);
98 expectEquals (stream.getTotalLength(), (int64) data.getSize());
99 expectEquals (stream.getNumBytesRemaining(), stream.getTotalLength());
100 expect (! stream.isExhausted());
102 size_t numBytesRead = 0;
103 MemoryBlock readBuffer (data.getSize());
105 while (numBytesRead < data.getSize())
107 numBytesRead += (size_t) stream.read (&readBuffer[numBytesRead], 3);
109 expectEquals (stream.getPosition(), (int64) numBytesRead);
110 expectEquals (stream.getNumBytesRemaining(), (int64) (data.getSize() - numBytesRead));
111 expect (stream.isExhausted() == (numBytesRead == data.getSize()));
114 expectEquals (stream.getPosition(), (int64) data.getSize());
115 expectEquals (stream.getNumBytesRemaining(), (int64) 0);
116 expect (stream.isExhausted());
118 expect (readBuffer == data);
122 stream.setPosition (0);
123 expectEquals (stream.getPosition(), (int64) 0);
124 expectEquals (stream.getTotalLength(), (int64) data.getSize());
125 expectEquals (stream.getNumBytesRemaining(), stream.getTotalLength());
126 expect (! stream.isExhausted());
129 const int numBytesToSkip = 5;
131 while (numBytesRead < data.getSize())
133 stream.skipNextBytes (numBytesToSkip);
134 numBytesRead += numBytesToSkip;
135 numBytesRead = std::min (numBytesRead, data.getSize());
137 expectEquals (stream.getPosition(), (int64) numBytesRead);
138 expectEquals (stream.getNumBytesRemaining(), (int64) (data.getSize() - numBytesRead));
139 expect (stream.isExhausted() == (numBytesRead == data.getSize()));
142 expectEquals (stream.getPosition(), (int64) data.getSize());
143 expectEquals (stream.getNumBytesRemaining(), (int64) 0);
144 expect (stream.isExhausted());
150static FileInputStreamTests fileInputStreamTests;
Represents a local file or directory.
int64 getSize() const
Returns the size of the file in bytes.
This is a base class for classes that perform a unit test.