Linkloader improvement: mclinker.
Change-Id: I8805e39ccbc2ee204234fb3e71c70c906f3990bb
diff --git a/unittests/PathTest.cpp b/unittests/PathTest.cpp
new file mode 100644
index 0000000..8906d02
--- /dev/null
+++ b/unittests/PathTest.cpp
@@ -0,0 +1,140 @@
+//===- PathTest.cpp -------------------------------------------------------===//
+//
+// The MCLinker Project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "PathTest.h"
+#include "mcld/Support/FileSystem.h"
+#include <string>
+
+//
+using namespace mcld;
+using namespace mcld::sys::fs;
+using namespace mcldtest;
+
+
+// Constructor can do set-up work for all test here.
+PathTest::PathTest()
+{
+ // create testee. modify it if need
+ m_pTestee = new Path();
+}
+
+// Destructor can do clean-up work that doesn't throw exceptions here.
+PathTest::~PathTest()
+{
+ delete m_pTestee;
+}
+
+// SetUp() will be called immediately before each test.
+void PathTest::SetUp()
+{
+}
+
+// TearDown() will be called immediately after each test.
+void PathTest::TearDown()
+{
+}
+
+//==========================================================================//
+// Testcases
+//
+TEST_F( PathTest, should_exist ) {
+ const std::string root = "/etc/hosts";
+ m_pTestee->assign(root);
+ EXPECT_TRUE(exists(*m_pTestee));
+
+ delete m_pTestee;
+ m_pTestee = new Path(root);
+ EXPECT_TRUE(exists(*m_pTestee));
+}
+
+TEST_F( PathTest, should_not_exist ) {
+ const std::string root = "/luck";
+ m_pTestee->assign(root);
+ EXPECT_FALSE(exists(*m_pTestee));
+
+ delete m_pTestee;
+ m_pTestee = new Path(root);
+ EXPECT_FALSE(exists(*m_pTestee));
+}
+
+TEST_F( PathTest, should_is_directory ) {
+// const std::string root = "/proj/mtk03931/temp/pndk-luba/../";
+ const std::string root = "../././..";
+ m_pTestee->assign(root);
+ EXPECT_TRUE(exists(*m_pTestee));
+ EXPECT_TRUE(is_directory(*m_pTestee));
+ delete m_pTestee;
+ m_pTestee = new Path(root);
+ EXPECT_TRUE(exists(*m_pTestee));
+ EXPECT_TRUE(is_directory(*m_pTestee));
+}
+
+TEST_F( PathTest, should_not_is_directory ) {
+ const std::string root = "/luck";
+ m_pTestee->assign(root);
+ EXPECT_FALSE(exists(*m_pTestee));
+ EXPECT_FALSE(is_directory(*m_pTestee));
+ delete m_pTestee;
+ m_pTestee = new Path(root);
+ EXPECT_FALSE(exists(*m_pTestee));
+ EXPECT_FALSE(is_directory(*m_pTestee));
+}
+
+TEST_F( PathTest, should_equal ) {
+ const std::string root = "aaa/bbb/../../ccc/";
+ m_pTestee->assign(root);
+
+ Path* p2 = new Path("ccc///////");
+
+ EXPECT_TRUE(*m_pTestee==*p2);
+
+ delete m_pTestee;
+ m_pTestee = new Path(root);
+ EXPECT_TRUE(*m_pTestee==*m_pTestee);
+ delete p2;
+}
+
+TEST_F( PathTest, should_not_equal ) {
+ const std::string root = "aa/";
+ Path* p2=new Path("aaa//");
+// p2->assign(root);
+ m_pTestee->assign(root);
+ EXPECT_TRUE(*m_pTestee!=*p2);
+
+ delete m_pTestee;
+ m_pTestee = new Path(root);
+ EXPECT_TRUE(*m_pTestee!=*p2);
+ delete p2;
+}
+
+TEST_F( PathTest, append_success ) {
+
+ const std::string root = "aa/";
+ m_pTestee->assign(root);
+ m_pTestee->append("aaa");
+ std::string a("aa/aaa");
+ EXPECT_TRUE(m_pTestee->native()=="aa/aaa");
+ delete m_pTestee;
+ m_pTestee = new Path("aa/");
+ m_pTestee->append("/aaa");
+ EXPECT_TRUE(m_pTestee->string()=="aa/aaa");
+ delete m_pTestee;
+ m_pTestee = new Path("aa");
+ m_pTestee->append("/aaa");
+ EXPECT_TRUE(m_pTestee->string()=="aa/aaa");
+ delete m_pTestee;
+ m_pTestee = new Path("aa");
+ m_pTestee->append("aaa");
+ EXPECT_TRUE(m_pTestee->string()=="aa/aaa");
+}
+
+TEST_F( PathTest, should_become_generic_string ) {
+ m_pTestee->assign("/etc/../dev/../usr//lib//");
+ EXPECT_STREQ("/usr/lib/", m_pTestee->generic_string().c_str());
+}
+