TEST_F(FileSystemTest, mktree) { Path test_subdir_path(get_test_dir_name() / get_test_dir_name()); if (!FileSystem().mktree(test_subdir_path)) { throw Exception(); } ASSERT_TRUE(FileSystem().exists(test_subdir_path)); }
void FileSystem::mount(const std::string &mount_point, const std::string &path, bool is_zip_file) { if (is_zip_file) mount(mount_point, FileSystem(new FileSystemProvider_Zip(ZipArchive(path)))); else mount(mount_point, FileSystem(new FileSystemProvider_File(path))); }
TEST_F(FileSystemTest, lstat) { if (!FileSystem().symlink(get_test_file_name(), get_test_link_name())) { throw Exception(); } auto_Object<Stat> stbuf = FileSystem().lstat(get_test_link_name()); ASSERT_TRUE(stbuf->ISLNK()); }
TEST_F(FileSystemTest, exists) { if (!FileSystem().exists(get_test_file_name())) { throw Exception(); } ASSERT_FALSE(FileSystem().exists(Path("some other file.txt"))); }
void TestApp::test_vfs() { Console::write_line(" Header: virtual_file_system.h"); Console::write_line(" Class: FileSystem"); test_vfs_internal(" File based #1", FileSystem("../../", false)); test_vfs_internal(" Zip based #1", FileSystem("../IOData/test.zip", true)); }
TEST_F(FileSystemTest, open) { auto_Object<File> file = FileSystem().open(get_test_file_name()); File* no_file = FileSystem().open(Path("nofile.txt"), O_RDONLY); if (no_file != NULL) { File::dec_ref(*no_file); ASSERT_TRUE(false); } }
TEST_F(FileSystemTest, touch) { if (!FileSystem().touch(get_test_file_name())) { throw Exception(); } if (FileSystem().touch(get_test_dir_name() / get_test_file_name())) { ASSERT_TRUE(false); } }
TEST_F(FileSystemTest, statvfs) { FileSystem().mkdir(get_test_dir_name()); struct statvfs stbuf; if (!FileSystem().statvfs(get_test_dir_name(), stbuf)) { throw Exception(); } ASSERT_GT(stbuf.f_bsize, 0u); ASSERT_GT(stbuf.f_blocks, 0); ASSERT_GT(stbuf.f_bfree, 0); ASSERT_GE(stbuf.f_blocks, stbuf.f_bfree); }
TEST_F(FileSystemTest, utime) { DateTime atime = DateTime::now(), mtime = DateTime::now(); if (FileSystem().utime(get_test_file_name(), atime, mtime)) { auto_Object<Stat> stbuf = FileSystem().stat(get_test_file_name()); ASSERT_LE(stbuf->get_atime() - atime, Time::NS_IN_S); ASSERT_LE(stbuf->get_mtime() - mtime, Time::NS_IN_S); } else { throw Exception(); } }
TEST_F(FileSystemTest, readlink) { if (!FileSystem().symlink(get_test_file_name(), get_test_link_name())) { throw Exception(); } Path target_path; if (FileSystem().readlink(get_test_link_name(), target_path)) { ASSERT_EQ(target_path, get_test_file_name()); } else { throw Exception(); } }
TEST_F(FileSystemTest, utime_win32) { DateTime atime = DateTime::now(); DateTime mtime = DateTime::now(); DateTime ctime = DateTime::now(); if (FileSystem().utime(get_test_file_name(), atime, mtime, ctime)) { auto_Object<Stat> stbuf = FileSystem().stat(get_test_file_name()); ASSERT_LE(stbuf->get_atime() - atime, Time::NS_IN_S); ASSERT_LE(stbuf->get_mtime() - mtime, Time::NS_IN_S); ASSERT_LE(stbuf->get_ctime() - ctime, Time::NS_IN_S); } else if (Exception::get_last_error_code() != ENOTSUP) { throw Exception(); } }
TEST_F(FileSystemTest, chown) { auto_Object<Stat> stbuf = FileSystem().stat(get_test_file_name()); ASSERT_TRUE( FileSystem().chown(get_test_file_name(), stbuf->get_uid()) ); ASSERT_TRUE( FileSystem().chown( get_test_file_name(), stbuf->get_uid(), stbuf->get_gid() ) ); }
void ACBaseImpl::CreateServices() { NEX_NEW(FileSystem()); NEX_NEW(PluginRegistry()); NEX_NEW(WindowManager()); NEX_NEW(BackgroundStreamerImpl()); CreateExtendedInterfacesImpl(); }
void SFile::Close( SFile * file ) { if ( !file ) return; FileSystem( ).Close( file->m_fileptr ); SAFE_DELETE( file ); }
void FontFamily_Impl::font_face_load(const FontDescription &desc, const std::string &typeface_name, float pixel_ratio) { #if defined(WIN32) std::shared_ptr<FontEngine> engine = std::make_shared<FontEngine_Win32>(desc, typeface_name, pixel_ratio); font_cache.push_back(Font_Cache(engine)); font_cache.back().glyph_cache->set_texture_group(texture_group); font_cache.back().pixel_ratio = pixel_ratio; #elif defined(__APPLE__) std::shared_ptr<FontEngine> engine = std::make_shared<FontEngine_Cocoa>(desc, typeface_name, pixel_ratio); font_cache.push_back(Font_Cache(engine)); font_cache.back().glyph_cache->set_texture_group(texture_group); font_cache.back().pixel_ratio = pixel_ratio; #elif defined(__ANDROID__) throw Exception("automatic typeface to ttf file selection is not supported on android"); #else // Obtain the best matching font file from fontconfig. FontConfig &fc = FontConfig::instance(); std::string font_file_path = fc.match_font(typeface_name, desc); std::string path = PathHelp::get_fullpath(font_file_path, PathHelp::path_type_file); auto filename = PathHelp::get_filename(font_file_path, PathHelp::path_type_file); auto fs = FileSystem(path); IODevice file = fs.open_file(filename); DataBuffer font_databuffer; font_databuffer.set_size(file.get_size()); file.read(font_databuffer.get_data(), font_databuffer.get_size()); font_face_load(desc, font_databuffer, pixel_ratio); #endif }
TEST_F(FileSystemTest, creat) { File* file = FileSystem().creat(get_test_file_name()); if (file != NULL) { File::dec_ref(*file); } else { throw Exception(); } }
TEST_F(FileSystemTest, rmtree) { if (!FileSystem().mkdir(get_test_dir_name())) { throw Exception(); } if (!FileSystem().mkdir(get_test_dir_name() / get_test_dir_name())) { throw Exception(); } if (!FileSystem().touch(get_test_dir_name() / get_test_file_name())) { throw Exception(); } if (!FileSystem().rmtree(get_test_dir_name())) { throw Exception(); } ASSERT_FALSE(FileSystem().exists(get_test_dir_name())); }
Texture::Texture(std::string _fileName) : m_texID(0), m_usingFallback(false), m_hasAlpha(false) { glGenTextures(1, &m_texID); SDL_Surface* texture = IMG_Load((_fileName).c_str()); if(!texture) { // Attempt to load a fallback texture that should be guaranteed to exist if( !(texture = IMG_Load(FileSystem().fallbackTexture().c_str())) ) { throw std::invalid_argument(" Could not load fallback material "); } m_usingFallback = true; std::cerr << SDL_GetError() << ", using fallback material\n"; } // ---------------------------------------------------------------------- // Additional error checks from http://content.gpwiki.org/SDL%3aTutorials%3aUsing_SDL_with_OpenGL // ---------------------------------------------------------------------- // Warn if the image is not a power of 2 if((texture->w & (texture->w-1)) != 0) { std::cerr << _fileName << " : Non-power of 2 width \n"; } if((texture->h & (texture->h-1)) != 0) { std::cerr << _fileName << " : Non-power of 2 height \n"; } GLenum texFormat; GLint numColours = texture->format->BytesPerPixel; if(numColours == 4) // Alpha { texFormat = GL_RGBA; m_hasAlpha = true; } else if(numColours== 3) // No alpha { texFormat = GL_RGB; m_hasAlpha = false; } else { throw std::runtime_error("Invalid image format (Must be RGB or RGBA)"); } glBindTexture(GL_TEXTURE_2D, m_texID); glTexImage2D(GL_TEXTURE_2D, 0 , numColours, texture->w, texture->h, 0, texFormat, GL_UNSIGNED_BYTE, texture->pixels); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); m_texHeight = texture->h; m_texWidth = texture->w; SDL_FreeSurface(texture); }
TEST_F(FileSystemTest, realpath) { Path realpath; if (!FileSystem().realpath(get_test_file_name(), realpath)) { throw Exception(); } ASSERT_FALSE(realpath.empty()); ASSERT_NE(get_test_file_name(), realpath); ASSERT_LT(get_test_file_name().size(), realpath.size()); }
TEST_F(FileSystemTest, stat) { DateTime now = DateTime::now(); auto_Object<Stat> stbuf = FileSystem().stat(get_test_file_name()); ASSERT_NE(stbuf->get_atime(), DateTime::INVALID_DATE_TIME); ASSERT_LE(stbuf->get_atime(), now); ASSERT_NE(stbuf->get_ctime(), DateTime::INVALID_DATE_TIME); ASSERT_LE(stbuf->get_ctime(), now); ASSERT_NE(stbuf->get_mtime(), DateTime::INVALID_DATE_TIME); ASSERT_LE(stbuf->get_mtime(), now); ASSERT_EQ(stbuf->get_nlink(), 1); ASSERT_EQ(stbuf->get_size(), 0); ASSERT_TRUE(stbuf->ISREG()); }
unsigned long SFile::ReadFileCache(void * fileptr, void * buffer, unsigned long bytestoread, int nPos, unsigned long * bytesread ) { if ( !fileptr || !buffer ) return 0; int nReadCount = FileSystem( ).ReadFileCache( buffer, bytestoread, nPos, fileptr ); if ( bytesread ) *bytesread = nReadCount; return nReadCount; }
bool SFile::OpenEx( /*SArchive * archive,*/ const char * filename, unsigned long flags, SFile * * file ) { if ( !file ) return false; FileHandle_t fileHandle = FileSystem().Open( filename, "rb" ); if ( fileHandle == FILESYSTEM_INVALID_HANDLE ) { return false; } *file = new SFile; (*file)->m_fileptr = fileHandle; (*file)->m_actualname = SStrDupA(filename); return true; }
TEST_F(FileLogTest, write) { ASSERT_FALSE(FileSystem().exists(get_test_file_path())); FileLog file_log(get_test_file_path()); static_cast<Log&>(file_log).write("test", Log::Level::DEBUG); ASSERT_TRUE(FileSystem().exists(get_test_file_path())); }
void TearDown() { FileSystem().unlink(get_test_file_path()); }
TEST_F(FileSystemTest, chmod) { auto_Object<Stat> stbuf = FileSystem().stat(get_test_file_name()); ASSERT_TRUE( FileSystem().chmod(get_test_file_name(), stbuf->get_mode()) ); }
TEST_F(FileSystemTest, access) { ASSERT_TRUE(FileSystem().access(get_test_file_name(), F_OK)); }
void TearDown() { FileSystem().rmtree(get_test_dir_name()); FileSystem().unlink(get_test_file_name()); FileSystem().unlink(get_test_link_name()); }
// ::testing::Test void SetUp() { TearDown(); FileSystem().touch(get_test_file_name()); }
int main() { GDT::init(); Console::init(); IDT::init(); ExceptionHandler::init_dispatcher(); IRQ::init(); InterruptHandler::init_dispatcher(); /* -- EXAMPLE OF AN EXCEPTION HANDLER -- */ class DBZ_Handler : public ExceptionHandler { public: virtual void handle_exception(REGS * _regs) { Console::puts("DIVISION BY ZERO!\n"); for(;;); } } dbz_handler; ExceptionHandler::register_handler(0, &dbz_handler); /* -- INITIALIZE MEMORY -- */ /* NOTE: We don't have paging enabled in this MP. */ /* NOTE2: This is not an exercise in memory management. The implementation of the memory management is accordingly *very* primitive! */ /* ---- Initialize a frame pool; details are in its implementation */ FramePool system_frame_pool; SYSTEM_FRAME_POOL = &system_frame_pool; /* ---- Create a memory pool of 256 frames. */ MemPool memory_pool(SYSTEM_FRAME_POOL, 256); MEMORY_POOL = &memory_pool; /* -- INITIALIZE THE TIMER (we use a very simple timer).-- */ /* Question: Why do we want a timer? We have it to make sure that we enable interrupts correctly. If we forget to do it, the timer "dies". */ SimpleTimer timer(100); /* timer ticks every 10ms. */ InterruptHandler::register_handler(0, &timer); /* The Timer is implemented as an interrupt handler. */ #ifdef _USES_SCHEDULER_ /* -- SCHEDULER -- IF YOU HAVE ONE -- */ Scheduler system_scheduler; SYSTEM_SCHEDULER = &system_scheduler; #endif #ifdef _USES_DISK_ /* -- DISK DEVICE -- IF YOU HAVE ONE -- */ BlockingDisk system_disk = BlockingDisk(MASTER, SYSTEM_DISK_SIZE); SYSTEM_DISK = &system_disk; #endif //#ifdef _USES_FILESYSTEM_ /* -- FILE SYSTEM -- IF YOU HAVE ONE -- */ FileSystem file_system= FileSystem(); FILE_SYSTEM = &file_system; //#endif /* NOTE: The timer chip starts periodically firing as soon as we enable interrupts. It is important to install a timer handler, as we would get a lot of uncaptured interrupts otherwise. */ /* -- ENABLE INTERRUPTS -- */ machine_enable_interrupts(); /* -- MOST OF WHAT WE NEED IS SETUP. THE KERNEL CAN START. */ Console::puts("Hello World!\n"); /* -- LET'S CREATE SOME THREADS... */ Console::puts("CREATING THREAD 1...\n"); char * stack1 = new char[1024]; thread1 = new Thread(fun1, stack1, 1024); Console::puts("DONE\n"); Console::puts("CREATING THREAD 2..."); char * stack2 = new char[1024*2];//allow for testing file system with larger buffers thread2 = new Thread(fun2, stack2, 1024); Console::puts("DONE\n"); Console::puts("CREATING THREAD 3..."); char * stack3 = new char[1024*10]; thread3 = new Thread(fun3, stack3, 1024); Console::puts("DONE\n"); Console::puts("CREATING THREAD 4..."); char * stack4 = new char[1024]; thread4 = new Thread(fun4, stack4, 1024); Console::puts("DONE\n"); #ifdef _USES_SCHEDULER_ /* WE ADD thread2 - thread4 TO THE READY QUEUE OF THE SCHEDULER. */ SYSTEM_SCHEDULER->add(thread2); SYSTEM_SCHEDULER->add(thread3); SYSTEM_SCHEDULER->add(thread4); #endif /* -- KICK-OFF THREAD1 ... */ Console::puts("STARTING THREAD 1 ...\n"); Thread::dispatch_to(thread1); /* -- AND ALL THE REST SHOULD FOLLOW ... */ assert(FALSE); /* WE SHOULD NEVER REACH THIS POINT. */ /* -- WE DO THE FOLLOWING TO KEEP THE COMPILER HAPPY. */ return 1; }
TEST_F(FileSystemTest, unlink) { if (!FileSystem().unlink(get_test_file_name())) { throw Exception(); } }