Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Jan 10, 2025
1 parent 9e30799 commit 84f8a63
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Integration.Vsix.UnitTests/CFamily/CFamilyTestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal class ProjectItemConfig

private static readonly ProjectItemConfig DefaultSetting = new ProjectItemConfig();

internal static Mock<ProjectItem> CreateMockProjectItem(string projectName, ProjectItemConfig projectItemConfig = null)
internal static Mock<ProjectItem> CreateMockProjectItem(string projectName, ProjectItemConfig projectItemConfig = null, string contentType = null)
{
projectItemConfig ??= DefaultSetting;

Expand All @@ -70,6 +70,7 @@ internal static Mock<ProjectItem> CreateMockProjectItem(string projectName, Proj

var vcFileMock = new Mock<VCFile>();
vcFileMock.SetupGet(x => x.ItemType).Returns(projectItemConfig.ItemType);
vcFileMock.SetupGet(x => x.ContentType).Returns(contentType);
vcFileMock.Setup(x => x.GetFileConfigurationForProjectConfiguration(vcConfig)).Returns(vcFileConfigMock.Object);

var projectMock = new ProjectMock(projectName) { Project = vcProjectMock.Object };
Expand Down
116 changes: 115 additions & 1 deletion src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void TryGet_UnsupportedCustomBuild_ReturnsNull()
}

[TestMethod]
public void TryGet_Full_Cmd()
public void TryGet_Full_Cmd_ForCompileAsCppFile()
{
// Arrange
var projectItemConfig = new ProjectItemConfig
Expand All @@ -138,6 +138,7 @@ public void TryGet_Full_Cmd()
["EnableEnhancedInstructionSet"] = "AdvancedVectorExtensions512",
["RuntimeLibrary"] = "MultiThreaded",
["LanguageStandard"] = "stdcpp17",
["LanguageStandard_C"] = "stdc17",
["ExceptionHandling"] = "Sync",
["BasicRuntimeChecks"] = "UninitializedLocalUsageCheck",
["ConformanceMode"] = "true",
Expand All @@ -160,6 +161,119 @@ public void TryGet_Full_Cmd()
Assert.IsFalse(request.IsHeaderFile);
}

[TestMethod]
public void TryGet_Full_Cmd_ForCompileAsCFile()
{
// Arrange
var projectItemConfig = new ProjectItemConfig
{
ItemType = "ClCompile",
FileConfigProperties = new Dictionary<string, string>
{
["PrecompiledHeader"] = "NotUsing",
["CompileAs"] = "CompileAsC",
["CompileAsManaged"] = "false",
["EnableEnhancedInstructionSet"] = "AdvancedVectorExtensions512",
["RuntimeLibrary"] = "MultiThreaded",
["LanguageStandard"] = "stdcpp17",
["LanguageStandard_C"] = "stdc17",
["ExceptionHandling"] = "Sync",
["BasicRuntimeChecks"] = "UninitializedLocalUsageCheck",
["ConformanceMode"] = "true",
["StructMemberAlignment"] = "8Bytes",
["AdditionalOptions"] = "/DA",
}
};

var projectItemMock = CreateMockProjectItem("c:\\foo\\xxx.vcxproj", projectItemConfig);

// Act
var request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.cpp", CreateFileSystemWithClCompiler());

// Assert
request.Should().NotBeNull();
Assert.AreEqual("\"C:\\path\\cl.exe\" /permissive- /TC /std:c17 /EHsc /arch:AVX512 /MT /RTCu /Zp8 /DA \"c:\\dummy\\file.cpp\"", request.CDCommand);
Assert.AreEqual("C:\\path\\includeDir1;C:\\path\\includeDir2;C:\\path\\includeDir3;", request.EnvInclude);
Assert.AreEqual("c:\\dummy\\file.cpp", request.CDFile);
Assert.AreEqual("c:\\foo", request.CDDirectory);
Assert.IsFalse(request.IsHeaderFile);
}


[DataTestMethod]
public void TryGet_Full_Cmd_ForNonCFile()
{
// Arrange
var projectItemConfig = new ProjectItemConfig
{
ItemType = "ClCompile",
FileConfigProperties = new Dictionary<string, string>
{
["PrecompiledHeader"] = "NotUsing",
["CompileAsManaged"] = "false",
["EnableEnhancedInstructionSet"] = "AdvancedVectorExtensions512",
["RuntimeLibrary"] = "MultiThreaded",
["LanguageStandard"] = "stdcpp17",
["LanguageStandard_C"] = "stdc17",
["ExceptionHandling"] = "Sync",
["BasicRuntimeChecks"] = "UninitializedLocalUsageCheck",
["ConformanceMode"] = "true",
["StructMemberAlignment"] = "8Bytes",
["AdditionalOptions"] = "/DA",
}
};

var projectItemMock = CreateMockProjectItem("c:\\foo\\xxx.vcxproj", projectItemConfig, "ANY_NON_CCODE");

// Act
var request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.cpp", CreateFileSystemWithClCompiler());

// Assert
request.Should().NotBeNull();
Assert.AreEqual("\"C:\\path\\cl.exe\" /permissive- /TP /std:c++17 /EHsc /arch:AVX512 /MT /RTCu /Zp8 /DA \"c:\\dummy\\file.cpp\"", request.CDCommand);
Assert.AreEqual("C:\\path\\includeDir1;C:\\path\\includeDir2;C:\\path\\includeDir3;", request.EnvInclude);
Assert.AreEqual("c:\\dummy\\file.cpp", request.CDFile);
Assert.AreEqual("c:\\foo", request.CDDirectory);
Assert.IsFalse(request.IsHeaderFile);
}

[TestMethod]
public void TryGet_Full_Cmd_ForCCodeFile()
{
// Arrange
var projectItemConfig = new ProjectItemConfig
{
ItemType = "ClCompile",
FileConfigProperties = new Dictionary<string, string>
{
["PrecompiledHeader"] = "NotUsing",
["CompileAsManaged"] = "false",
["EnableEnhancedInstructionSet"] = "AdvancedVectorExtensions512",
["RuntimeLibrary"] = "MultiThreaded",
["LanguageStandard"] = "stdcpp17",
["LanguageStandard_C"] = "stdc17",
["ExceptionHandling"] = "Sync",
["BasicRuntimeChecks"] = "UninitializedLocalUsageCheck",
["ConformanceMode"] = "true",
["StructMemberAlignment"] = "8Bytes",
["AdditionalOptions"] = "/DA",
}
};

var projectItemMock = CreateMockProjectItem("c:\\foo\\xxx.vcxproj", projectItemConfig, "CCode");

// Act
var request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.cpp", CreateFileSystemWithClCompiler());

// Assert
request.Should().NotBeNull();
Assert.AreEqual("\"C:\\path\\cl.exe\" /permissive- /TC /std:c17 /EHsc /arch:AVX512 /MT /RTCu /Zp8 /DA \"c:\\dummy\\file.cpp\"", request.CDCommand);
Assert.AreEqual("C:\\path\\includeDir1;C:\\path\\includeDir2;C:\\path\\includeDir3;", request.EnvInclude);
Assert.AreEqual("c:\\dummy\\file.cpp", request.CDFile);
Assert.AreEqual("c:\\foo", request.CDDirectory);
Assert.IsFalse(request.IsHeaderFile);
}

[TestMethod]
public void TryGet_HeaderFileOptions_ReturnsValidConfig()
{
Expand Down

0 comments on commit 84f8a63

Please sign in to comment.