mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 12:39:56 +00:00
c8eeae8d4d
eos() now only returns true _after_ trying to read past the end of the stream. This has a large potential for regressions. Please test! svn-id: r34549
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#include <cxxtest/TestSuite.h>
|
|
|
|
#include "common/stream.h"
|
|
|
|
class ReadLineStreamTestSuite : public CxxTest::TestSuite {
|
|
public:
|
|
void test_readline(void) {
|
|
byte contents[] = { 'a', 'b', '\n', '\n', 'c', '\n' };
|
|
Common::MemoryReadStream ms(contents, sizeof(contents));
|
|
|
|
char buffer[100];
|
|
|
|
TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
|
|
TS_ASSERT(0 == strcmp(buffer, "ab\n"));
|
|
|
|
TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
|
|
TS_ASSERT(0 == strcmp(buffer, "\n"));
|
|
|
|
TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
|
|
TS_ASSERT(0 == strcmp(buffer, "c\n"));
|
|
|
|
TS_ASSERT(!ms.eos());
|
|
|
|
TS_ASSERT(0 == ms.readLine_NEW(buffer, sizeof(buffer)));
|
|
|
|
TS_ASSERT(ms.eos());
|
|
}
|
|
|
|
void test_readline2(void) {
|
|
byte contents[] = { 'a', 'b', '\n', '\n', 'c' };
|
|
Common::MemoryReadStream ms(contents, sizeof(contents));
|
|
|
|
char buffer[100];
|
|
|
|
TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
|
|
TS_ASSERT(0 == strcmp(buffer, "ab\n"));
|
|
|
|
TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
|
|
TS_ASSERT(0 == strcmp(buffer, "\n"));
|
|
|
|
TS_ASSERT(0 != ms.readLine_NEW(buffer, sizeof(buffer)));
|
|
TS_ASSERT(0 == strcmp(buffer, "c"));
|
|
|
|
TS_ASSERT(ms.eos());
|
|
}
|
|
};
|