Browse Source

Adding some tests

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
1d4c06fadd
2 changed files with 63 additions and 3 deletions
  1. 2 3
      include/anki/util/Filesystem.h
  2. 61 0
      tests/util/Filesystem.cpp

+ 2 - 3
include/anki/util/Filesystem.h

@@ -30,12 +30,11 @@ ANKI_USE_RESULT Error removeDirectory(const CString& dir);
 ANKI_USE_RESULT Error createDirectory(const CString& dir);
 
 /// Get the home directory.
-/// Write the home directory to @a buff. The @a buffSize is the size of the 
-/// @a buff. If the @buffSize is not enough the function will throw 
+/// Write the home directory to @a buff. The @a buffSize is the size of the
+/// @a buff. If the @buffSize is not enough the function will throw
 /// an exception.
 ANKI_USE_RESULT Error getHomeDirectory(
 	GenericMemoryPoolAllocator<U8> alloc, String& out);
-
 /// @}
 
 } // end namespace anki

+ 61 - 0
tests/util/Filesystem.cpp

@@ -0,0 +1,61 @@
+// Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include "tests/framework/Framework.h"
+#include "anki/util/Filesystem.h"
+#include "anki/util/File.h"
+
+ANKI_TEST(Util, FileExists)
+{
+	// Create file
+	File file;
+	ANKI_TEST_EXPECT_NO_ERR(file.open("./tmp", File::OpenFlag::WRITE));
+	file.close();
+
+	// Check
+	ANKI_TEST_EXPECT_EQ(fileExists("./tmp"), true);
+}
+
+ANKI_TEST(Util, Directory)
+{
+	// Destroy previous
+	if(directoryExists("./dir"))
+	{
+		ANKI_TEST_EXPECT_NO_ERR(removeDirectory("./dir"));
+	}
+
+	// Create simple directory
+	ANKI_TEST_EXPECT_NO_ERR(createDirectory("./dir"));
+	File file;
+	ANKI_TEST_EXPECT_NO_ERR(file.open("./dir/tmp", File::OpenFlag::WRITE));
+	file.close();
+	ANKI_TEST_EXPECT_EQ(fileExists("./dir/tmp"), true);
+
+	ANKI_TEST_EXPECT_NO_ERR(removeDirectory("./dir"));
+	ANKI_TEST_EXPECT_EQ(fileExists("./dir/tmp"), false);
+	ANKI_TEST_EXPECT_EQ(directoryExists("./dir"), false);
+
+	// A bit more complex
+	ANKI_TEST_EXPECT_NO_ERR(createDirectory("./dir"));
+	ANKI_TEST_EXPECT_NO_ERR(createDirectory("./dir/rid"));
+	ANKI_TEST_EXPECT_NO_ERR(file.open("./dir/rid/tmp", File::OpenFlag::WRITE));
+	file.close();
+	ANKI_TEST_EXPECT_EQ(fileExists("./dir/rid/tmp"), true);
+
+	ANKI_TEST_EXPECT_NO_ERR(removeDirectory("./dir"));
+	ANKI_TEST_EXPECT_EQ(fileExists("./dir/rid/tmp"), false);
+	ANKI_TEST_EXPECT_EQ(directoryExists("./dir/rid"), false);
+	ANKI_TEST_EXPECT_EQ(directoryExists("./dir"), false);
+}
+
+ANKI_TEST(Util, HomeDir)
+{
+	HeapAllocator<char> alloc(allocAligned, nullptr);
+	StringAuto out(alloc);
+
+	ANKI_TEST_EXPECT_NO_ERR(getHomeDirectory(alloc, out));
+	printf("home dir %s\n", &out[0]);
+	ANKI_TEST_EXPECT_GT(out.getLength(), 0);
+}