TEST(TestMemFile, EmptyFileInCache) { StaticContentCache::TheFileCache = std::make_shared<FileCache>(); StaticContentCache::TheFileCache->write("/no/content/entry"); MemFile mf; // The file itself... ASSERT_FALSE(mf.open("/no/content/entry", "r")); // ... and one of the automatically-created "directory" entries. ASSERT_FALSE(mf.open("/no/content", "r")); }
TEST(TestMemFile, RealFileInCache) { string temp_fn; ASSERT_TRUE(makeTempFile("123abc", &temp_fn)); StaticContentCache::TheFileCache = std::make_shared<FileCache>(); StaticContentCache::TheFileCache->write("/content", temp_fn.c_str()); MemFile mf; ASSERT_TRUE(mf.open("/content", "r")); ASSERT_EQ(mf.getc(), '1'); ASSERT_EQ(mf.getc(), '2'); ASSERT_EQ(mf.getc(), '3'); ASSERT_EQ(mf.getc(), 'a'); ASSERT_EQ(mf.getc(), 'b'); ASSERT_EQ(mf.getc(), 'c'); ASSERT_EQ(mf.getc(), EOF); ASSERT_TRUE(mf.close()); ASSERT_EQ(unlink(temp_fn.c_str()), 0); }
TEST(TestMemFile, NotInCache) { StaticContentCache::TheFileCache = std::make_shared<FileCache>(); MemFile mf; ASSERT_FALSE(mf.open("/not/even/there", "r")); }
TEST(TestMemFile, BadOpenModes) { MemFile mf; ASSERT_FALSE(mf.open("/some/file1", "+")); ASSERT_FALSE(mf.open("/some/file2", "a")); ASSERT_FALSE(mf.open("/some/file3", "w")); }
TEST(TestMemFile, BadReadFromCache) { StaticContentCache::TheFileCache = std::make_shared<FileCache>(); MemFile mf; ASSERT_FALSE(mf.open("/some/random/file", "r")); }
TEST(TestMemFile, NotInCache) { StaticContentCache::TheFileCache = FileCachePtr(new FileCache()); MemFile mf; ASSERT_FALSE(mf.open("/not/even/there", "r")); }
TEST(TestMemFile, BadReadFromCache) { StaticContentCache::TheFileCache = FileCachePtr(new FileCache()); MemFile mf; ASSERT_FALSE(mf.open("/some/random/file", "r")); }