1"""
2Test some lldb command abbreviations.
3"""
4
5
6import lldb
7import os
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11from lldbsuite.test import lldbplatformutil
12
13
14class TestPaths(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    @no_debug_info_test
19    def test_paths(self):
20        '''Test to make sure no file names are set in the lldb.SBFileSpec objects returned by lldb.SBHostOS.GetLLDBPath() for paths that are directories'''
21        dir_path_types = [lldb.ePathTypeLLDBShlibDir,
22                          lldb.ePathTypeSupportExecutableDir,
23                          lldb.ePathTypeHeaderDir,
24                          lldb.ePathTypePythonDir,
25                          lldb.ePathTypeLLDBSystemPlugins,
26                          lldb.ePathTypeLLDBUserPlugins,
27                          lldb.ePathTypeLLDBTempSystemDir,
28                          lldb.ePathTypeClangDir]
29
30        for path_type in dir_path_types:
31            f = lldb.SBHostOS.GetLLDBPath(path_type)
32            # No directory path types should have the filename set
33            self.assertIsNone(f.GetFilename())
34
35        shlib_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeLLDBShlibDir).GetDirectory()
36        if lldbplatformutil.getHostPlatform() == 'windows':
37            filenames = ['liblldb.dll']
38        elif lldbplatformutil.getHostPlatform() == 'darwin':
39            filenames = ['LLDB', 'liblldb.dylib']
40        else:
41            filenames = ['liblldb.so']
42        self.assertTrue(any([os.path.exists(os.path.join(shlib_dir, f)) for f in
43            filenames]), "shlib_dir = " + shlib_dir)
44
45
46    @no_debug_info_test
47    def test_directory_doesnt_end_with_slash(self):
48        current_directory_spec = lldb.SBFileSpec(os.path.curdir)
49        current_directory_string = current_directory_spec.GetDirectory()
50        self.assertNotEqual(current_directory_string[-1:], '/')
51
52    @skipUnlessPlatform(["windows"])
53    @no_debug_info_test
54    def test_windows_double_slash(self):
55        '''Test to check the path with double slash is handled correctly '''
56        # Create a path and see if lldb gets the directory and file right
57        fspec = lldb.SBFileSpec("C:\\dummy1\\dummy2//unknown_file", True)
58        self.assertEqual(
59            os.path.normpath(
60                fspec.GetDirectory()),
61            os.path.normpath("C:/dummy1/dummy2"))
62        self.assertEqual(fspec.GetFilename(), "unknown_file")
63