소스 검색

Add initial path tests

Daniele Bartolini 10 년 전
부모
커밋
cc0ae6676f
1개의 변경된 파일65개의 추가작업 그리고 1개의 파일을 삭제
  1. 65 1
      src/core/unit_tests.cpp

+ 65 - 1
src/core/unit_tests.cpp

@@ -12,6 +12,7 @@
 #include "math_utils.h"
 #include "math_utils.h"
 #include "memory.h"
 #include "memory.h"
 #include "murmur.h"
 #include "murmur.h"
+#include "path.h"
 #include "sjson.h"
 #include "sjson.h"
 #include "string_utils.h"
 #include "string_utils.h"
 #include "temp_allocator.h"
 #include "temp_allocator.h"
@@ -19,7 +20,6 @@
 
 
 namespace crown
 namespace crown
 {
 {
-
 static void test_array()
 static void test_array()
 {
 {
 	memory_globals::init();
 	memory_globals::init();
@@ -132,6 +132,69 @@ static void test_sjson()
 	memory_globals::shutdown();
 	memory_globals::shutdown();
 }
 }
 
 
+static void test_path()
+{
+#if CROWN_PLATFORM_POSIX
+	{
+		const bool a = path::is_absolute("/home/foo");
+		CE_ENSURE(a == true);
+		const bool b = path::is_absolute("home/foo");
+		CE_ENSURE(b == false);
+	}
+	{
+		const bool a = path::is_relative("/home/foo");
+		CE_ENSURE(a == false);
+		const bool b = path::is_relative("home/foo");
+		CE_ENSURE(b == true);
+	}
+	{
+		const bool a = path::is_root("/");
+		CE_ENSURE(a == true);
+		const bool b = path::is_root("/home");
+		CE_ENSURE(b == false);
+	}
+#else
+	{
+		const bool a = path::is_absolute("C:\\Users\\foo");
+		CE_ENSURE(a == true);
+		const bool b = path::is_absolute("Users\\foo");
+		CE_ENSURE(b == false);
+	}
+	{
+		const bool a = path::is_relative("D:\\Users\\foo");
+		CE_ENSURE(a == false);
+		const bool b = path::is_relative("Users\\foo");
+		CE_ENSURE(b == true);
+	}
+	{
+		const bool a = path::is_root("E:\\");
+		CE_ENSURE(a == true);
+		const bool b = path::is_root("E:\\Users");
+		CE_ENSURE(b == false);
+	}
+#endif // CROWN_PLATFORM_POSIX
+	{
+		const char* p = path::basename("");
+		CE_ENSURE(strcmp(p, "") == 0);
+		const char* q = path::basename("/");
+		CE_ENSURE(strcmp(q, "") == 0);
+		const char* r = path::basename("boot.config");
+		CE_ENSURE(strcmp(r, "boot.config") == 0);
+		const char* s = path::basename("foo/boot.config");
+		CE_ENSURE(strcmp(s, "boot.config") == 0);
+		const char* t = path::basename("/foo/boot.config");
+		CE_ENSURE(strcmp(t, "boot.config") == 0);
+	}
+	{
+		const char* p = path::extension("");
+		CE_ENSURE(p == NULL);
+		const char* q = path::extension("boot");
+		CE_ENSURE(q == NULL);
+		const char* r = path::extension("boot.bar.config");
+		CE_ENSURE(strcmp(r, "config") == 0);
+	}
+}
+
 static void run_unit_tests()
 static void run_unit_tests()
 {
 {
 	test_array();
 	test_array();
@@ -139,6 +202,7 @@ static void run_unit_tests()
 	test_murmur();
 	test_murmur();
 	test_json();
 	test_json();
 	test_sjson();
 	test_sjson();
+	test_path();
 }
 }
 
 
 } // namespace crown
 } // namespace crown