// Copyright 2022, FOSS-VG Developers and Contributers // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU Affero General Public License as published // by the Free Software Foundation, version 3. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // version 3 along with this program. // If not, see https://www.gnu.org/licenses/agpl-3.0.en.html #include #include "assert.hpp" #include "tinyutf8/tinyutf8.h" #include "../lib/file.hpp" int main(){ std::cout << "################################################################################" << std::endl; std::cout << "File tests" << std::endl; std::cout << "################################################################################" << std::endl; File* file; //readByte test file = File::open("resources/unicode_data/normal_utf-8", 'r').value; uint8_t byte = file->readByte().value; ASSERT(byte == 'T'); std::cout << "Passed read byte test." << std::endl; //read test std::vector bytes = file->read(5).value; //cursorPosition has already moved forward by one ASSERT(bytes == std::vector({'e', 's', 't', ' ', 's'})); std::cout << "Passed read test." << std::endl; //readString test tiny_utf8::string data = file->readString(5).value; ASSERT(data == "tring"); std::cout << "Passed read string test." << std::endl; file->close(); delete file; //Write Tests File *writeFile; File *readFile; //writeByte test writeFile = File::open("resources/unicode_data/writeTest", 'w').value; writeFile->writeByte('a'); writeFile->close(); readFile = File::open("resources/unicode_data/writeTest", 'r').value; uint8_t testByte = readFile->readByte().value; ASSERT(testByte == 'a'); std::cout << "Passed write byte test." << std::endl; //write test writeFile->open(); writeFile->write(std::vector({'a', 'b', 'c'})); writeFile->close(); readFile->cursorPosition = 0; tiny_utf8::string testBytes = readFile->readString(3).value; ASSERT(testBytes == "abc"); std::cout << "Passed write test." << std::endl; writeFile->open(); writeFile->writeString(tiny_utf8::string("Hallo")); writeFile->close(); readFile->cursorPosition = 0; tiny_utf8::string testString = readFile->readString(5).value; ASSERT(testString == "Hallo"); std::cout << "Passed write string test." << std::endl; }