|
| 1 | +// Copyright (c) Ubisoft. All Rights Reserved. |
| 2 | +// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. |
| 3 | + |
| 4 | +using NUnit.Framework; |
| 5 | +using Sharpmake.Generators.VisualStudio; |
| 6 | + |
| 7 | +namespace Sharpmake.UnitTests |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class CsprojTest |
| 11 | + { |
| 12 | + [TestFixture] |
| 13 | + public class GetProjectLinkedFolder |
| 14 | + { |
| 15 | + [Test] |
| 16 | + public void FileUnderSourceRootPath() |
| 17 | + { |
| 18 | + var filePath = "..\\..\\codebase\\helloworld\\program.cs"; |
| 19 | + var projectPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 20 | + var sourceRootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\helloworld"; |
| 21 | + |
| 22 | + var project = new Project() { SourceRootPath = sourceRootPath }; |
| 23 | + |
| 24 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 25 | + |
| 26 | + Assert.AreEqual("", result); |
| 27 | + } |
| 28 | + |
| 29 | + [Test] |
| 30 | + public void FileUnderRootPath() |
| 31 | + { |
| 32 | + var filePath = "..\\..\\codebase\\helloworld\\program.cs"; |
| 33 | + var projectPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 34 | + var sourceRootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\source\\helloworld"; |
| 35 | + var rootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\helloworld"; |
| 36 | + |
| 37 | + var project = new Project() { SourceRootPath = sourceRootPath, RootPath = rootPath }; |
| 38 | + |
| 39 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 40 | + |
| 41 | + Assert.AreEqual("", result); |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + public void RootAndSourcePathCorrectOrder() |
| 46 | + { |
| 47 | + var filePath = "..\\..\\codebase\\helloworld\\program.cs"; |
| 48 | + var projectPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 49 | + var sourceRootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\helloworld"; |
| 50 | + var rootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld"; |
| 51 | + |
| 52 | + var project = new Project() { SourceRootPath = sourceRootPath, RootPath = rootPath }; |
| 53 | + |
| 54 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 55 | + |
| 56 | + Assert.AreNotEqual("codebase\\helloworld", result); |
| 57 | + } |
| 58 | + |
| 59 | + [Test] |
| 60 | + public void FileUnderProjectPath() |
| 61 | + { |
| 62 | + var filePath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld\\program.cs"; |
| 63 | + var projectPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 64 | + var sourceRootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\helloworld"; |
| 65 | + var rootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 66 | + |
| 67 | + var project = new Project() { SourceRootPath = sourceRootPath, RootPath = rootPath }; |
| 68 | + |
| 69 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 70 | + |
| 71 | + Assert.IsNull(result); |
| 72 | + } |
| 73 | + |
| 74 | + [Test] |
| 75 | + public void AbsoluteFilePath() |
| 76 | + { |
| 77 | + var filePath = "c:\\.nuget\\dd\\llvm\\build\\native\\llvm.sharpmake.cs"; |
| 78 | + var projectPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 79 | + var sourceRootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\helloworld"; |
| 80 | + var rootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 81 | + |
| 82 | + var project = new Project() { SourceRootPath = sourceRootPath, RootPath = rootPath }; |
| 83 | + |
| 84 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 85 | + |
| 86 | + Assert.AreEqual(".nuget\\dd\\llvm\\build\\native", result); |
| 87 | + } |
| 88 | + |
| 89 | + [Test] |
| 90 | + public void RelativePathFileOutsideProject() |
| 91 | + { |
| 92 | + var filePath = "..\\..\\..\\..\\code\\platform\\standalone.main.sharpmake.cs"; |
| 93 | + var projectPath = "d:\\versioncontrol\\workspace\\generated\\platform\\sharpmake\\debugsolution"; |
| 94 | + var sourceRootPath = "d:\\versioncontrol\\workspace\\generated\\platform\\sharpmake\\debugsolution"; |
| 95 | + var rootPath = "d:\\versioncontrol\\workspace\\generated\\platform\\sharpmake\\debugsolution"; |
| 96 | + |
| 97 | + var project = new Project() { SourceRootPath = sourceRootPath, RootPath = rootPath }; |
| 98 | + |
| 99 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 100 | + |
| 101 | + Assert.AreEqual("code\\platform", result); |
| 102 | + } |
| 103 | + |
| 104 | + [Test] |
| 105 | + public void AbsolutePathFileInProjectFolder() |
| 106 | + { |
| 107 | + var filePath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld\\program.cs"; |
| 108 | + var projectPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 109 | + var sourceRootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\helloworld"; |
| 110 | + |
| 111 | + var project = new Project() { SourceRootPath = sourceRootPath, RootPath = sourceRootPath }; |
| 112 | + |
| 113 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 114 | + |
| 115 | + Assert.IsNull(result); |
| 116 | + } |
| 117 | + |
| 118 | + [Test] |
| 119 | + public void RelativePathFileInProjectFolder() |
| 120 | + { |
| 121 | + var filePath = "..\\helloworld\\program.cs"; |
| 122 | + var projectPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\projects\\helloworld"; |
| 123 | + var sourceRootPath = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\helloworld"; |
| 124 | + |
| 125 | + var project = new Project() { SourceRootPath = sourceRootPath, RootPath = sourceRootPath }; |
| 126 | + |
| 127 | + var result = CSproj.GetProjectLinkedFolder(filePath, projectPath, project); |
| 128 | + |
| 129 | + Assert.IsNull(result); |
| 130 | + } |
| 131 | + |
| 132 | + [Test] |
| 133 | + public void CasingUnchanged() |
| 134 | + { |
| 135 | + var filePathLowerCase = "..\\..\\codebase\\helloworld\\program.cs"; |
| 136 | + var projectPathLowerCase = "D:\\Git\\Sharpmake\\sharpmake\\samples\\CSharpHelloWorld\\projects\\helloworld"; |
| 137 | + var sourceRootPathLowerCase = "d:\\git\\sharpmake\\sharpmake\\samples\\csharphelloworld\\codebase\\"; |
| 138 | + |
| 139 | + var filePathCamelCase = "..\\..\\CodeBase\\HelloWorld\\Program.cs"; |
| 140 | + var projectPathCamelCase = "D:\\Git\\Sharpmake\\Sharpmake\\Samples\\CSharpHelloWorld\\Projects\\HelloWorld"; |
| 141 | + var sourceRootPathCamelCase = "D:\\Git\\Sharpmake\\Sharpmake\\Samples\\CSharpHelloWorld\\Codebase\\"; |
| 142 | + |
| 143 | + var projectLowerCase = new Project() { SourceRootPath = sourceRootPathLowerCase }; |
| 144 | + var result = CSproj.GetProjectLinkedFolder(filePathLowerCase, projectPathLowerCase, projectLowerCase); |
| 145 | + |
| 146 | + Assert.IsTrue(string.Equals("helloworld", result, System.StringComparison.Ordinal)); |
| 147 | + Assert.IsFalse(string.Equals("HelloWorld", result, System.StringComparison.Ordinal)); |
| 148 | + |
| 149 | + var projectCamelCase = new Project() { SourceRootPath = sourceRootPathCamelCase }; |
| 150 | + result = CSproj.GetProjectLinkedFolder(filePathCamelCase, projectPathCamelCase, projectCamelCase); |
| 151 | + |
| 152 | + Assert.IsTrue(string.Equals("HelloWorld", result, System.StringComparison.Ordinal)); |
| 153 | + Assert.IsFalse(string.Equals("helloworld", result, System.StringComparison.Ordinal)); |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | +} |
0 commit comments