Add a Local Test binary, to enable local TerminalApp testing (#2294)

In #1164 we learned that our CI doesn't support WinRT testing. This made us all sad. Since that merged, we haven't really added any TerminalApp tests, because it's a little too hard. You'd have to uncomment the entire file, and if the list of types changed you'd have to manually update the sxs manifest and appxmanifest.

Since that was all insane, I created a new Terminal App unittesting project without those problems.
1. The project is not named *Unit*Test*, so the CI won't run it, but it will run locally.
2. The project will auto-generate its SxS manifest, using the work from #1987. 
3. We'll use the SxS manifest from step 2 to generate an AppxManifest for running packaged tests.


* This is the start of me trying to enable local unittesting again

  * We've got a new unittests project that isn't named *unit*test*

  * We're manually generating the SxS manifest for it. B/C we need to use it at runtime, we need to manually combine it into one manifest file

  * the runas:UAP thing still doesn't work. We'll investigate.

* This shockingly works

but I'm still stuck with:
```
Summary of Errors Outside of Tests:
Error: TAEF: [HRESULT: 0x80270254] Failed to create the test host process for
out of process test execution. (The
IApplicationActivationManager::ActivateApplication call failed while using a
default host. TAEF's ETW logs which are gathered with the /enableEtwLogging
switch should contain events from relevant providers that may help to diagnose
the failure.)
```

* Cleaning this all up for review.

  Frankly just pushing to see if it'll work in CI

* Couple things I noticed in the diff from master

* Apply @dhowett-msft's suggestions from code review
This commit is contained in:
Mike Griese 2019-08-13 08:23:28 -05:00 committed by GitHub
parent 138d3b81c8
commit ac97e5d082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 568 additions and 177 deletions

View File

@ -243,6 +243,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TerminalAppLib", "src\casca
{CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907} = {CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LocalTests_TerminalApp", "src\cascadia\LocalTests_TerminalApp\TerminalApp.LocalTests.vcxproj", "{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}"
ProjectSection(ProjectDependencies) = postProject
{CA5CAD1A-9A12-429C-B551-8562EC954746} = {CA5CAD1A-9A12-429C-B551-8562EC954746}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
AuditMode|ARM64 = AuditMode|ARM64
@ -1087,6 +1092,24 @@ Global
{CA5CAD1A-9A12-429C-B551-8562EC954746}.Release|x64.Build.0 = Release|x64
{CA5CAD1A-9A12-429C-B551-8562EC954746}.Release|x86.ActiveCfg = Release|Win32
{CA5CAD1A-9A12-429C-B551-8562EC954746}.Release|x86.Build.0 = Release|Win32
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.AuditMode|ARM64.Build.0 = AuditMode|ARM64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.AuditMode|x64.ActiveCfg = AuditMode|x64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.AuditMode|x64.Build.0 = AuditMode|x64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.AuditMode|x86.ActiveCfg = AuditMode|Win32
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.AuditMode|x86.Build.0 = AuditMode|Win32
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Debug|ARM64.ActiveCfg = Debug|ARM64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Debug|ARM64.Build.0 = Debug|ARM64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Debug|x64.ActiveCfg = Debug|x64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Debug|x64.Build.0 = Debug|x64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Debug|x86.ActiveCfg = Debug|Win32
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Debug|x86.Build.0 = Debug|Win32
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Release|ARM64.ActiveCfg = Release|ARM64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Release|ARM64.Build.0 = Release|ARM64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Release|x64.ActiveCfg = Release|x64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Release|x64.Build.0 = Release|x64
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Release|x86.ActiveCfg = Release|Win32
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1147,6 +1170,7 @@ Global
{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73} = {89CDCC5C-9F53-4054-97A4-639D99F169CD}
{CA5CAD1A-9333-4D05-B12A-1905CBF112F9} = {59840756-302F-44DF-AA47-441A9D673202}
{CA5CAD1A-9A12-429C-B551-8562EC954746} = {59840756-302F-44DF-AA47-441A9D673202}
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506} = {59840756-302F-44DF-AA47-441A9D673202}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3140B1B7-C8EE-43D1-A772-D82A7061A271}

View File

@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "../TerminalApp/ColorScheme.h"
using namespace Microsoft::Console;
using namespace TerminalApp;
using namespace WEX::Logging;
using namespace WEX::TestExecution;
namespace TerminalAppLocalTests
{
// Unfortunately, these tests _WILL NOT_ work in our CI, until we have a lab
// machine available that can run Windows version 18362.
class SettingsTests
{
// Use a custom manifest to ensure that we can activate winrt types from
// our test. This property will tell taef to manually use this as the
// sxs manifest during this test class. It includes all the cppwinrt
// types we've defined, so if your test is crashing for an unknown
// reason, make sure it's included in that file.
// If you want to do anything XAML-y, you'll need to run yor test in a
// packaged context. See TabTests.cpp for more details on that.
BEGIN_TEST_CLASS(SettingsTests)
TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.LocalTests.manifest")
END_TEST_CLASS()
TEST_METHOD(TryCreateWinRTType);
};
void SettingsTests::TryCreateWinRTType()
{
winrt::Microsoft::Terminal::Settings::TerminalSettings settings{};
VERIFY_IS_NOT_NULL(settings);
auto oldFontSize = settings.FontSize();
settings.FontSize(oldFontSize + 5);
auto newFontSize = settings.FontSize();
VERIFY_ARE_NOT_EQUAL(oldFontSize, newFontSize);
}
}

View File

@ -0,0 +1,110 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "../TerminalApp/ColorScheme.h"
#include "../TerminalApp/Tab.h"
using namespace Microsoft::Console;
using namespace TerminalApp;
using namespace WEX::Logging;
using namespace WEX::TestExecution;
namespace TerminalAppLocalTests
{
// Unfortunately, these tests _WILL NOT_ work in our CI, until we have a lab
// machine available that can run Windows version 18362.
class TabTests
{
// For this set of tests, we need to activate some XAML content. To do
// that, we need to be able to activate Xaml Islands(XI), using the Xaml
// Hosting APIs. Because XI looks at the manifest of the exe running, we
// can't just use the TerminalApp.Unit.Tests.manifest as our
// ActivationContext. XI is going to inspect `te.exe`s manifest to try
// and find the maxversiontested property, but te.exe hasn't set that.
// Instead, this test will run as a UAP application, as a packaged
// centenial (win32) app. We'll specify our own AppxManifest, so that
// we'll be able to also load all the dll's for the types we've defined
// (and want to use here). This does come with a minor caveat, as
// deploying the appx takes a bit, so use sparingly (though it will
// deploy once per class when used like this.)
BEGIN_TEST_CLASS(TabTests)
TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.LocalTests.AppxManifest.xml")
END_TEST_CLASS()
// These four tests act as canary tests. If one of them fails, then they
// can help you identify if something much lower in the stack has
// failed.
TEST_METHOD(TryInitXamlIslands);
TEST_METHOD(TryCreateLocalWinRTType);
TEST_METHOD(TryCreateXamlObjects);
TEST_METHOD(TryCreateTab);
TEST_CLASS_SETUP(ClassSetup)
{
winrt::init_apartment(winrt::apartment_type::single_threaded);
// Initialize the Xaml Hosting Manager
_manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread();
_source = winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource{};
return true;
}
private:
winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _manager{ nullptr };
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr };
};
void TabTests::TryInitXamlIslands()
{
// Ensures that XAML Islands was initialized correctly
VERIFY_IS_NOT_NULL(_manager);
VERIFY_IS_NOT_NULL(_source);
}
void TabTests::TryCreateLocalWinRTType()
{
// Verify we can create a WinRT type we authored
// Just creating it is enough to know that everything is working.
winrt::Microsoft::Terminal::Settings::TerminalSettings settings{};
VERIFY_IS_NOT_NULL(settings);
auto oldFontSize = settings.FontSize();
settings.FontSize(oldFontSize + 5);
auto newFontSize = settings.FontSize();
VERIFY_ARE_NOT_EQUAL(oldFontSize, newFontSize);
}
void TabTests::TryCreateXamlObjects()
{
// Verify we can create a some XAML objects
// Just creating all of them is enough to know that everything is working.
winrt::Windows::UI::Xaml::Controls::UserControl controlRoot;
VERIFY_IS_NOT_NULL(controlRoot);
winrt::Windows::UI::Xaml::Controls::Grid root;
VERIFY_IS_NOT_NULL(root);
winrt::Windows::UI::Xaml::Controls::SwapChainPanel swapChainPanel;
VERIFY_IS_NOT_NULL(swapChainPanel);
winrt::Windows::UI::Xaml::Controls::Primitives::ScrollBar scrollBar;
VERIFY_IS_NOT_NULL(scrollBar);
}
void TabTests::TryCreateTab()
{
// Just try creating all of:
// 1. one of our pure c++ types (Profile)
// 2. one of our c++winrt types (TermControl)
// 3. one of our types that uses MUX/Xaml (Tab).
// Just creating all of them is enough to know that everything is working.
const auto profileGuid{ Utils::CreateGuid() };
winrt::Microsoft::Terminal::TerminalControl::TermControl term{};
VERIFY_IS_NOT_NULL(term);
auto newTab = std::make_shared<Tab>(profileGuid, term);
VERIFY_IS_NOT_NULL(newTab);
}
}

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap">
<!-- This file is used as the Appxmanifest for tests that _need_ to run in a
packaged environment. It will be copied to the test's OutDir as part of the
PostBuid step. It's highly similar to the "PackagedCwaFullTrust" manifest that
TAEF ships with, with the following modifications:
1. All of our winrt types are included in this manifest, including types from
MUX.dll. Should this list of types ever change, we'll need to manually
update this file. The easiest way of doing that is deploying the app from
VS, then copying the Extensions from the Appxmanifest.xml that's generated
under `src/cascadia/CascadiaPackage/bin/$(platform)/$(configuration)/appx`.
2. We also _NEED_ the two vclibs listed under the `PackageDependency` block.
If your test fails for whatever reason, it's likely possible you're testing a
type that's _not_ included in this file for some reason. So, here be dragons. -->
<Identity Name="TerminalApp.LocalTests.Package"
ProcessorArchitecture="neutral"
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
Version="1.0.0.0"
ResourceId="en-us" />
<Properties>
<DisplayName>TerminalApp.LocalTests.Package Host Process</DisplayName>
<PublisherDisplayName>Microsoft Corp.</PublisherDisplayName>
<Logo>taef.png</Logo>
<Description>TAEF Packaged Cwa FullTrust Application Host Process</Description>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.18362.0" MaxVersionTested="10.0.18362.0" />
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.27023.1" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug.UWPDesktop" MinVersion="14.0.27027.1" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
</Dependencies>
<Resources>
<Resource Language="en-us" />
</Resources>
<Applications>
<Application Id="TE.ProcessHost" Executable="TE.ProcessHost.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="TAEF Packaged Cwa FullTrust Application Host Process" Square150x150Logo="taef.png" Square44x44Logo="taef.png" Description="TAEF Packaged Cwa Application Host Process" BackgroundColor="#222222">
<uap:SplashScreen Image="taef.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust"/>
</Capabilities>
</Package>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<!-- This file is copied into ut_app/TerminalApp.Unit.Tests.manifest as part
of the pre-build step for that project. Changes should only be made to the
WindowsTerminal version of the file. -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 1903 -->
<!-- See https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/xaml-islands -->
<maxversiontested Id="10.0.18362.0"/>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
</assembly>

View File

@ -0,0 +1,176 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)\common.openconsole.props" Condition="'$(OpenConsoleDir)'==''" />
<Import Project="$(OpenConsoleDir)\src\common.build.pre.props" />
<!-- ========================= Headers ======================== -->
<ItemGroup>
<ClInclude Include="precomp.h" />
</ItemGroup>
<!-- ========================= Cpp Files ======================== -->
<ItemGroup>
<ClCompile Include="SettingsTests.cpp" />
<ClCompile Include="TabTests.cpp" />
<ClCompile Include="precomp.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<!-- You _NEED_ to include this file and the jsoncpp IncludePath (below) if
you want to use jsoncpp -->
<ClCompile Include="$(OpenConsoleDir)\dep\jsoncpp\jsoncpp.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<!-- ========================= Project References ======================== -->
<ItemGroup>
<ProjectReference Include="$(OpenConsoleDir)\src\cascadia\TerminalApp\lib\TerminalAppLib.vcxproj" />
<ProjectReference Include="$(OpenConsoleDir)\src\types\lib\types.vcxproj" />
<!-- If you don't reference these projects here, the
_ConsoleGenerateAdditionalWinmdManifests step won't gather the winmd's -->
<ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalSettings\TerminalSettings.vcxproj" />
<ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalControl\TerminalControl.vcxproj" />
<ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalConnection\TerminalConnection.vcxproj" />
<ProjectReference Include="$(OpenConsoleDir)src\cascadia\TerminalApp\TerminalApp.vcxproj" />
</ItemGroup>
<!-- ========================= Globals ======================== -->
<PropertyGroup>
<ProjectGuid>{CA5CAD1A-b11c-4ddb-a4fe-c3afae9b5506}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>TerminalAppLocalTests</RootNamespace>
<ProjectName>LocalTests_TerminalApp</ProjectName>
<TargetName>TerminalApp.LocalTests</TargetName>
<WindowsTargetPlatformMinVersion>10.0.18362.0</WindowsTargetPlatformMinVersion>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<!-- ====================== Compiler & Linker Flags ===================== -->
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..;$(OpenConsoleDir)\dep\jsoncpp\json;$(OpenConsoleDir)src\inc;$(OpenConsoleDir)src\inc\test;$(WinRT_IncludePath)\..\cppwinrt\winrt;"$(OpenConsoleDir)\src\cascadia\TerminalApp\lib\Generated Files";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>
<!-- Manually disable unreachable code warning, because jconcpp has a ton of that. -->
<DisableSpecificWarnings>4702;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>WindowsApp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<PropertyGroup>
<GenerateManifest>true</GenerateManifest>
<EmbedManifest>true</EmbedManifest>
</PropertyGroup>
<!-- Careful reordering these. Some default props (contained in these files) are order sensitive. -->
<Import Project="$(OpenConsoleDir)src\common.build.dll.props" />
<Import Project="$(OpenConsoleDir)src\common.build.post.props" />
<Import Project="$(OpenConsoleDir)src\common.build.tests.props" />
<PropertyGroup>
<!-- Manually change our outdir to be in a subdirectory. We don't really want
to put our output in the bin root, because if we do, we'll copy
TerminalApp.winmd to the bin root, and then every subsequent mdmerge step
(in _any_ cppwinrt project) will automatically try to pick up
TerminalApp.winmd as a dependency (which is just wrong). This MUST be done
after importing common.build.post.props-->
<OutDir>$(OpenConsoleDir)\bin\$(Platform)\$(Configuration)\$(ProjectName)\</OutDir>
<IntDir>$(OpenConsoleDir)\obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
<PropertyGroup>
<_CppWinrtBinRoot>&quot;$(OpenConsoleDir)$(Platform)\$(Configuration)\&quot;</_CppWinrtBinRoot>
<!-- From Microsoft.UI.Xaml.targets -->
<Native-Platform Condition="'$(Platform)' == 'Win32'">x86</Native-Platform>
<Native-Platform Condition="'$(Platform)' != 'Win32'">$(Platform)</Native-Platform>
<_MUXBinRoot>&quot;$(OpenConsoleDir)packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\runtimes\win10-$(Native-Platform)\native\&quot;</_MUXBinRoot>
</PropertyGroup>
<!-- We actually can just straight up reference MUX here, it's fine -->
<Import Project="..\..\..\packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\build\native\Microsoft.UI.Xaml.targets" Condition="Exists('..\..\..\packages\Microsoft.UI.Xaml.2.2.190611001-prerelease\build\native\Microsoft.UI.Xaml.targets')" />
<Import Project="..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets" Condition="Exists('..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.0.0-preview6.2\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets')" />
<!-- This project will generate individual sxs manifests for each of our winrt libraries -->
<Import Project="$(OpenConsoleDir)\build\rules\GenerateSxsManifestsFromWinmds.targets" />
<!-- This is important: actually add the _LocalTestsGenerateCombinedManifests
target to the list of targets to run. -->
<PropertyGroup>
<BeforeLinkTargets Condition="'$(WindowsTargetPlatformVersion)' &gt;= '10.0.18362.0'">
$(BeforeLinkTargets);
_LocalTestsGenerateCombinedManifests;
_LocalTestsBuildAppxManifest;
_LocalTestsCopyDependencies;
</BeforeLinkTargets>
</PropertyGroup>
<!-- Step 1: Combine all our SxS manifests into a single SxS manifest. TAEF
needs us to specify a single activation context at runtime, so we need a
single file with all our types in it.-->
<Target Name="_LocalTestsGenerateCombinedManifests"
Inputs="@(_ConsoleWinmdManifest)"
Outputs="$(OutDir)$(TargetName).manifest"
DependsOnTargets="_ConsoleGenerateAdditionalWinmdManifests">
<Exec Command="mt.exe -manifest @(_ConsoleWinmdManifest, ' -manifest ') -out:$(OutDir)$(TargetName).manifest" />
</Target>
<!-- Step 2: Take our combined SxS manifest, and use it to build an
Appxmanifest.xml. We'll use the Appxmanifest.prototype.xml in this project's
directory as a base, and the script will tak all our activatableClasses and
turn them into appxmanifest-compatible Extensions -->
<Target Name="_LocalTestsBuildAppxManifest"
Inputs="$(OutDir)$(TargetName).manifest"
Outputs="$(OutDir)$(TargetName).AppxManifest.xml"
DependsOnTargets="_LocalTestsGenerateCombinedManifests">
<Exec Command="powershell.exe ExecutionPolicy Unrestricted $(OpenConsoleDir)\tools\GenerateAppxFromManifest.ps1 -SxSManifest $(OutDir)$(TargetName).manifest -AppxManifestPrototype $(TargetName).AppxManifest.prototype.xml -OutPath $(OutDir)$(TargetName).AppxManifest.xml" />
</Target>
<!-- Step 3: Manually copy all our dependent DLLs into our OutDir. For SxS
activation to work, they all need to be in the same directory as our test dll.
This is using code that's heavliy cribbed from WindowsTerminal.vcxproj, which
is already cribbed from the GetPackagingOutputs in
Microsoft.*.AppxPackage.targets. We're filtering this list down to the dlls,
pris and xbfs, because this list _can_ contain directories, which will make
the Copy task explode. -->
<PropertyGroup>
<_ContinueOnError Condition="'$(BuildingProject)' == 'true'">true</_ContinueOnError>
<_ContinueOnError Condition="'$(BuildingProject)' != 'true'">false</_ContinueOnError>
</PropertyGroup>
<!-- First gather the files... -->
<Target Name="MyGetPackagingOutputs" Returns="@(MyPackagingOutputs)">
<MSBuild
Projects="@(ProjectReferenceWithConfiguration)"
Targets="GetPackagingOutputs"
BuildInParallel="$(BuildInParallel)"
Properties="%(ProjectReferenceWithConfiguration.SetConfiguration); %(ProjectReferenceWithConfiguration.SetPlatform)"
Condition="'@(ProjectReferenceWithConfiguration)' != ''
and '%(ProjectReferenceWithConfiguration.BuildReference)' == 'true'
and '%(ProjectReferenceWithConfiguration.ReferenceOutputAssembly)' == 'true'"
ContinueOnError="$(_ContinueOnError)">
<Output TaskParameter="TargetOutputs" ItemName="_PackagingOutputsFromOtherProjects"/>
</MSBuild>
<ItemGroup>
<MyPackagingOutputs Include="@(_PackagingOutputsFromOtherProjects)" Condition="'%(Extension)'=='.dll' Or '%(Extension)'=='.pri' Or '%(Extension)'=='.xbf'" />
</ItemGroup>
</Target>
<!-- Then copy the files to our outdir -->
<Target Name="_LocalTestsCopyDependencies"
DependsOnTargets="MyGetPackagingOutputs">
<Copy SourceFiles="@(MyPackagingOutputs)"
SkipUnchangedFiles="true"
DestinationFolder="$(OutDir)"
/>
</Target>
</Project>

View File

@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"

View File

@ -0,0 +1,53 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- precomp.h
Abstract:
- Contains external headers to include in the precompile phase of console build process.
- Avoid including internal project headers. Instead include them only in the classes that need them (helps with test project building).
Author(s):
- Carlos Zamora (cazamor) April 2019
--*/
#pragma once
// This includes support libraries from the CRT, STL, WIL, and GSL
#include "LibraryIncludes.h"
// This is inexplicable, but for whatever reason, cppwinrt conflicts with the
// SDK definition of this function, so the only fix is to undef it.
// from WinBase.h
// Windows::UI::Xaml::Media::Animation::IStoryboard::GetCurrentTime
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
#include <WexTestClass.h>
#include <json.h>
#include "consoletaeftemplates.hpp"
// Needed just for XamlIslands to work at all:
#include <winrt/Windows.system.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.UI.Xaml.Hosting.h>
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
// Common includes for most tests:
#include "../../inc/argb.h"
#include "../../inc/conattrs.hpp"
#include "../../types/inc/utils.hpp"
#include "../../inc/DefaultSettings.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/windows.ui.core.h>
#include <winrt/Windows.ui.input.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.ui.xaml.media.h>
#include <winrt/Windows.ui.xaml.input.h>
#include <windows.ui.xaml.media.dxinterop.h>

View File

@ -1,46 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "../TerminalApp/ColorScheme.h"
using namespace Microsoft::Console;
using namespace TerminalApp;
using namespace WEX::Logging;
using namespace WEX::TestExecution;
namespace TerminalAppUnitTests
{
// Unfortunately, these tests _WILL NOT_ work in our CI, until we have a lab
// machine available that can run Windows version 18362. Until then, these
// tests will be commented out. GH#1012 should move our CI to that version.
// When that happens, these tests can be re-added.
// class SettingsTests
// {
// // Use a custom manifest to ensure that we can activate winrt types from
// // our test. This property will tell taef to manually use this as the
// // sxs manifest during this test class. It includes all the cppwinrt
// // types we've defined, so if your test is crashing for an unknown
// // reason, make sure it's included in that file.
// // If you want to do anything XAML-y, you'll need to run yor test in a
// // packaged context. See TabTests.cpp for more details on that.
// BEGIN_TEST_CLASS(SettingsTests)
// TEST_CLASS_PROPERTY(L"ActivationContext", L"TerminalApp.Unit.Tests.manifest")
// END_TEST_CLASS()
// TEST_METHOD(TryCreateWinRTType);
// };
// void SettingsTests::TryCreateWinRTType()
// {
// winrt::Microsoft::Terminal::Settings::TerminalSettings settings{};
// VERIFY_IS_NOT_NULL(settings);
// auto oldFontSize = settings.FontSize();
// settings.FontSize(oldFontSize + 5);
// auto newFontSize = settings.FontSize();
// VERIFY_ARE_NOT_EQUAL(oldFontSize, newFontSize);
// }
}

View File

@ -1,112 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "../TerminalApp/ColorScheme.h"
#include "../TerminalApp/Tab.h"
using namespace Microsoft::Console;
using namespace TerminalApp;
using namespace WEX::Logging;
using namespace WEX::TestExecution;
namespace TerminalAppUnitTests
{
// Unfortunately, these tests _WILL NOT_ work in our CI, until we have a lab
// machine available that can run Windows version 18362. Until then, these
// tests will be commented out. GH#1012 should move our CI to that version.
// When that happens, these tests can be re-added.
// class TabTests
// {
// // For this set of tests, we need to activate some XAML content. To do
// // that, we need to be able to activate Xaml Islands(XI), using the Xaml
// // Hosting APIs. Because XI looks at the manifest of the exe running, we
// // can't just use the TerminalApp.Unit.Tests.manifest as our
// // ActivationContext. XI is going to inspect `te.exe`s manifest to try
// // and find the maxversiontested property, but te.exe hasn't set that.
// // Instead, this test will run as a UAP application, as a packaged
// // centenial (win32) app. We'll specify our own AppxManifest, so that
// // we'll be able to also load all the dll's for the types we've defined
// // (and want to use here). This does come with a minor caveat, as
// // deploying the appx takes a bit, so use sparingly (though it will
// // deploy once per class when used like this.)
// BEGIN_TEST_CLASS(TabTests)
// TEST_CLASS_PROPERTY(L"RunAs", L"UAP")
// TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.Unit.Tests.AppxManifest.xml")
// END_TEST_CLASS()
// // These four tests act as canary tests. If one of them fails, then they
// // can help you identify if something much lower in the stack has
// // failed.
// TEST_METHOD(TryInitXamlIslands);
// TEST_METHOD(TryCreateLocalWinRTType);
// TEST_METHOD(TryCreateXamlObjects);
// TEST_METHOD(TryCreateTab);
// TEST_CLASS_SETUP(ClassSetup)
// {
// winrt::init_apartment(winrt::apartment_type::single_threaded);
// // Initialize the Xaml Hosting Manager
// _manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread();
// _source = winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource{};
// return true;
// }
// private:
// winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _manager{ nullptr };
// winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr };
// };
// void TabTests::TryInitXamlIslands()
// {
// // Ensures that XAML Islands was initialized correctly
// VERIFY_IS_NOT_NULL(_manager);
// VERIFY_IS_NOT_NULL(_source);
// }
// void TabTests::TryCreateLocalWinRTType()
// {
// // Verify we can create a WinRT type we authored
// // Just creating it is enough to know that everything is working.
// winrt::Microsoft::Terminal::Settings::TerminalSettings settings{};
// VERIFY_IS_NOT_NULL(settings);
// auto oldFontSize = settings.FontSize();
// settings.FontSize(oldFontSize + 5);
// auto newFontSize = settings.FontSize();
// VERIFY_ARE_NOT_EQUAL(oldFontSize, newFontSize);
// }
// void TabTests::TryCreateXamlObjects()
// {
// // Verify we can create a some XAML objects
// // Just creating all of them is enough to know that everything is working.
// winrt::Windows::UI::Xaml::Controls::UserControl controlRoot;
// VERIFY_IS_NOT_NULL(controlRoot);
// winrt::Windows::UI::Xaml::Controls::Grid root;
// VERIFY_IS_NOT_NULL(root);
// winrt::Windows::UI::Xaml::Controls::SwapChainPanel swapChainPanel;
// VERIFY_IS_NOT_NULL(swapChainPanel);
// winrt::Windows::UI::Xaml::Controls::Primitives::ScrollBar scrollBar;
// VERIFY_IS_NOT_NULL(scrollBar);
// }
// void TabTests::TryCreateTab()
// {
// // Just try creating all of:
// // 1. one of our pure c++ types (Profile)
// // 2. one of our c++winrt types (TermControl)
// // 3. one of our types that uses MUX/Xaml (Tab).
// // Just creating all of them is enough to know that everything is working.
// const auto profileGuid{ Utils::CreateGuid() };
// winrt::Microsoft::Terminal::TerminalControl::TermControl term{};
// VERIFY_IS_NOT_NULL(term);
// auto newTab = std::make_shared<Tab>(profileGuid, term);
// VERIFY_IS_NOT_NULL(newTab);
// }
}

View File

@ -11,8 +11,6 @@
<!-- ========================= Cpp Files ======================== -->
<ItemGroup>
<ClCompile Include="JsonTests.cpp" />
<ClCompile Include="SettingsTests.cpp" />
<ClCompile Include="TabTests.cpp" />
<ClCompile Include="precomp.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>

View File

@ -29,25 +29,14 @@ Author(s):
#include <json.h>
#include "consoletaeftemplates.hpp"
// Needed just for XamlIslands to work at all:
#include <winrt/Windows.system.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.UI.Xaml.Hosting.h>
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
// Common includes for most tests:
#include "../../inc/argb.h"
#include "../../inc/conattrs.hpp"
#include "../../types/inc/utils.hpp"
#include "../../inc/DefaultSettings.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/windows.ui.core.h>
#include <winrt/Windows.ui.input.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.ui.xaml.media.h>
#include <winrt/Windows.ui.xaml.input.h>
#include <windows.ui.xaml.media.dxinterop.h>
// Are you thinking about adding WinRT things here? If so, you probably want to
// add your test to TerminalApp.LocalTests, not TerminalApp.UnitTests. The
// UnitTests run in CI, while the LocalTests do not. However, since the CI can't
// run XAML islands or unpackaged WinRT, any tests using those features will
// need to be added to the LocalTests.

View File

@ -0,0 +1,74 @@
# This script is used for taking all the activatable classes from a SxS manifest
# and adding them as Extensions to an Appxmanifest.xml.
# Params:
# - SxSManifest: The path to the SxS manifest to get the types from
# - AppxManifestPrototype: The path to an AppxManifest.xml-style XML document to add the Extensions to
# - SxSManifest: The path to write the updated XML doc to.
param (
[parameter(Mandatory=$true, Position=0)]
[string]$SxSManifest,
[parameter(Mandatory=$true, Position=1)]
[string]$AppxManifestPrototype,
[parameter(Mandatory=$true, Position=2)]
[string]$OutPath
)
# Load the xml files.
[xml]$manifestData = Get-Content $SxSManifest
[xml]$appxPrototypeData = Get-Content $AppxManifestPrototype
# You need to make sure each element we add is part of the same namespace as the
# Package, otherwise powershell will append a bunch of `xmlns=""` properties
# that will make the appx deployment reject the manifest.
$rootNS = $appxPrototypeData.Package.NamespaceURI
# Create an XML element for all the extensions we're adding.
$Extensions = $appxPrototypeData.CreateNode("element", "Extensions", $rootNS)
$assembly = $manifestData.assembly
$files = $assembly.file
$files | ForEach-Object {
$Extension = $appxPrototypeData.CreateNode("element", "Extension", $rootNS)
$Extension.SetAttribute("Category", "windows.activatableClass.inProcessServer")
$InProcessServer = $appxPrototypeData.CreateNode("element", "InProcessServer", $rootNS)
$Path = $appxPrototypeData.CreateNode("element", "Path", $rootNS)
# You need to stash the result here, otherwise a blank line will be echod to
# the console.
$placeholder = $Path.InnerText = $_.name
$InProcessServer.AppendChild($Path)
$Extension.AppendChild($InProcessServer) | Out-Null
foreach($class in $_.activatableClass) {
$ActivatableClass = $appxPrototypeData.CreateNode("element", "ActivatableClass", $rootNS)
$ActivatableClass.SetAttribute("ActivatableClassId", $class.name)
$ActivatableClass.SetAttribute("ThreadingModel", $class.threadingModel)
$InProcessServer.AppendChild($ActivatableClass) | Out-Null
}
$Extensions.AppendChild($Extension) | Out-Null
}
# Add our fully constructed list of extensions to the original Appxmanifest prototype
$appxPrototypeData.Package.AppendChild($Extensions) | Out-Null
# Write the modified xml back out.
$appxPrototypeData.save($OutPath)
# Left as a helper for debugging:
# $StringWriter = New-Object System.IO.StringWriter;
# $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter;
# $XmlWriter.Formatting = "indented";
# $appxPrototypeData.WriteTo($XmlWriter);
# $XmlWriter.Flush();
# $StringWriter.Flush();
# Write-Output $StringWriter.ToString();

View File

@ -159,7 +159,7 @@ function Invoke-OpenConsoleTests()
[switch]$FTOnly,
[parameter(Mandatory=$false)]
[ValidateSet('host', 'interactivityWin32', 'terminal', 'adapter', 'feature', 'uia', 'textbuffer', 'types', 'terminalCore', 'terminalApp')]
[ValidateSet('host', 'interactivityWin32', 'terminal', 'adapter', 'feature', 'uia', 'textbuffer', 'types', 'terminalCore', 'terminalApp', 'localTerminalApp')]
[string]$Test,
[parameter(Mandatory=$false)]

View File

@ -12,4 +12,5 @@ call %TAEF% ^
%OPENCON%\bin\%PLATFORM%\%_LAST_BUILD_CONF%\ConAdapter.Unit.Tests.dll ^
%OPENCON%\bin\%PLATFORM%\%_LAST_BUILD_CONF%\Types.Unit.Tests.dll ^
%OPENCON%\bin\%PLATFORM%\%_LAST_BUILD_CONF%\UnitTests_TerminalApp\Terminal.App.Unit.Tests.dll ^
%OPENCON%\bin\%PLATFORM%\%_LAST_BUILD_CONF%\LocalTests_TerminalApp\TerminalApp.LocalTests.dll ^
%*

View File

@ -4,6 +4,7 @@
<test name="textBuffer" type="unit" binary="TextBuffer.Unit.Tests.dll" />
<test name="terminalCore" type="unit" binary="Terminal.Core.Unit.Tests.dll" />
<test name="terminalApp" type="unit" binary="UnitTests_TerminalApp\Terminal.App.Unit.Tests.dll" />
<test name="localTerminalApp" type="unit" binary="LocalTests_TerminalApp\TerminalApp.LocalTests.dll" />
<test name="interactivityWin32" type="unit" binary="Conhost.Interactivity.Win32.Unit.Tests.dll" />
<test name="terminal" type="unit" binary="ConParser.Unit.Tests.dll" />
<test name="adapter" type="unit" binary="ConAdapter.Unit.Tests.dll" />