|
@@ -0,0 +1,72 @@
|
|
|
+#include "tests/FileReaderTests.h"
|
|
|
+
|
|
|
+#include "io/FileReader.h"
|
|
|
+#include "test/Test.h"
|
|
|
+
|
|
|
+static constexpr const char* TEST_FILE = "../src/tests/resources/test";
|
|
|
+
|
|
|
+static void testReadChar() {
|
|
|
+ Core::FileReader r;
|
|
|
+ CORE_TEST_ERROR(r.open(TEST_FILE));
|
|
|
+ Core::String8<128> s;
|
|
|
+ while(true) {
|
|
|
+ int c = 0;
|
|
|
+ if(r.readChar(c) != Core::Error::NONE) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ CORE_TEST_ERROR(s.append(static_cast<c32>(c)));
|
|
|
+ }
|
|
|
+ CORE_TEST_STRING("abc\nBaum\n", s);
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadChars() {
|
|
|
+ Core::FileReader r;
|
|
|
+ CORE_TEST_ERROR(r.open(TEST_FILE));
|
|
|
+ char buffer[128];
|
|
|
+ CORE_TEST_EQUAL(Core::Error::END_OF_FILE,
|
|
|
+ r.readChars(buffer, sizeof(buffer)));
|
|
|
+ CORE_TEST_STRING("abc\nBaum\n", buffer);
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadCharsOverflow() {
|
|
|
+ Core::FileReader r;
|
|
|
+ CORE_TEST_ERROR(r.open(TEST_FILE));
|
|
|
+ char buffer[6];
|
|
|
+ CORE_TEST_ERROR(r.readChars(buffer, sizeof(buffer)));
|
|
|
+ CORE_TEST_STRING("abc\nB", buffer);
|
|
|
+}
|
|
|
+
|
|
|
+static void testMoveConstruct() {
|
|
|
+ Core::FileReader r;
|
|
|
+ CORE_TEST_ERROR(r.open(TEST_FILE));
|
|
|
+ Core::FileReader r2 = Core::move(r);
|
|
|
+ CORE_TEST_STRING("", r.getPath());
|
|
|
+ CORE_TEST_STRING(TEST_FILE, r2.getPath());
|
|
|
+
|
|
|
+ int c = 0;
|
|
|
+ CORE_TEST_EQUAL(Core::Error::INVALID_STATE, r.readChar(c));
|
|
|
+ CORE_TEST_ERROR(r2.readChar(c));
|
|
|
+ CORE_TEST_EQUAL('a', c);
|
|
|
+}
|
|
|
+
|
|
|
+static void testMoveAssignment() {
|
|
|
+ Core::FileReader r;
|
|
|
+ CORE_TEST_ERROR(r.open(TEST_FILE));
|
|
|
+ Core::FileReader r2;
|
|
|
+ r2 = Core::move(r);
|
|
|
+ CORE_TEST_STRING("", r.getPath());
|
|
|
+ CORE_TEST_STRING(TEST_FILE, r2.getPath());
|
|
|
+
|
|
|
+ int c = 0;
|
|
|
+ CORE_TEST_EQUAL(Core::Error::INVALID_STATE, r.readChar(c));
|
|
|
+ CORE_TEST_ERROR(r2.readChar(c));
|
|
|
+ CORE_TEST_EQUAL('a', c);
|
|
|
+}
|
|
|
+
|
|
|
+void Core::FileReaderTests::test() {
|
|
|
+ testReadChar();
|
|
|
+ testReadChars();
|
|
|
+ testReadCharsOverflow();
|
|
|
+ testMoveConstruct();
|
|
|
+ testMoveAssignment();
|
|
|
+}
|