2008-09-06 16:46:28 +00:00
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
|
|
|
#include "common/stream.h"
|
|
|
|
|
|
|
|
class ReadLineStreamTestSuite : public CxxTest::TestSuite {
|
|
|
|
public:
|
2009-04-20 19:26:50 +00:00
|
|
|
void test_readline() {
|
2008-09-06 16:46:28 +00:00
|
|
|
byte contents[] = { 'a', 'b', '\n', '\n', 'c', '\n' };
|
|
|
|
Common::MemoryReadStream ms(contents, sizeof(contents));
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-06 16:46:28 +00:00
|
|
|
char buffer[100];
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2009-12-30 23:00:55 +00:00
|
|
|
TS_ASSERT_DIFFERS((char *)0, ms.readLine(buffer, sizeof(buffer)));
|
2009-05-19 11:22:49 +00:00
|
|
|
TS_ASSERT_EQUALS(0, strcmp(buffer, "ab\n"));
|
2008-09-06 16:46:28 +00:00
|
|
|
|
2009-12-30 23:00:55 +00:00
|
|
|
TS_ASSERT_DIFFERS((char *)0, ms.readLine(buffer, sizeof(buffer)));
|
2009-05-19 11:22:49 +00:00
|
|
|
TS_ASSERT_EQUALS(0, strcmp(buffer, "\n"));
|
2008-09-06 16:46:28 +00:00
|
|
|
|
2009-12-30 23:00:55 +00:00
|
|
|
TS_ASSERT_DIFFERS((char *)0, ms.readLine(buffer, sizeof(buffer)));
|
2009-05-19 11:22:49 +00:00
|
|
|
TS_ASSERT_EQUALS(0, strcmp(buffer, "c\n"));
|
2008-09-06 16:46:28 +00:00
|
|
|
|
2008-09-14 22:28:53 +00:00
|
|
|
TS_ASSERT(!ms.eos());
|
|
|
|
|
2009-12-30 23:00:55 +00:00
|
|
|
TS_ASSERT_EQUALS((char *)0, ms.readLine(buffer, sizeof(buffer)));
|
2008-09-14 22:28:53 +00:00
|
|
|
|
2008-09-06 16:46:28 +00:00
|
|
|
TS_ASSERT(ms.eos());
|
|
|
|
}
|
|
|
|
|
2009-04-20 19:26:50 +00:00
|
|
|
void test_readline2() {
|
2008-09-06 16:46:28 +00:00
|
|
|
byte contents[] = { 'a', 'b', '\n', '\n', 'c' };
|
|
|
|
Common::MemoryReadStream ms(contents, sizeof(contents));
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-06 16:46:28 +00:00
|
|
|
char buffer[100];
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2009-12-30 23:00:55 +00:00
|
|
|
TS_ASSERT_DIFFERS((char *)0, ms.readLine(buffer, sizeof(buffer)));
|
2009-05-19 11:22:49 +00:00
|
|
|
TS_ASSERT_EQUALS(0, strcmp(buffer, "ab\n"));
|
2008-09-06 16:46:28 +00:00
|
|
|
|
2009-12-30 23:00:55 +00:00
|
|
|
TS_ASSERT_DIFFERS((char *)0, ms.readLine(buffer, sizeof(buffer)));
|
2009-05-19 11:22:49 +00:00
|
|
|
TS_ASSERT_EQUALS(0, strcmp(buffer, "\n"));
|
2008-09-06 16:46:28 +00:00
|
|
|
|
2009-12-30 23:00:55 +00:00
|
|
|
TS_ASSERT_DIFFERS((char *)0, ms.readLine(buffer, sizeof(buffer)));
|
2009-05-19 11:22:49 +00:00
|
|
|
TS_ASSERT_EQUALS(0, strcmp(buffer, "c"));
|
2008-09-06 16:46:28 +00:00
|
|
|
|
|
|
|
TS_ASSERT(ms.eos());
|
|
|
|
}
|
|
|
|
};
|