Skip to content

Commit a147a2a

Browse files
Opt, 从MegaUI中分离
1 parent b52b1bf commit a147a2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+23997
-0
lines changed

.github/workflows/Build&Test.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Build&Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
Build:
7+
runs-on: windows-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: 初始化
13+
working-directory: ${{env.GITHUB_WORKSPACE}}
14+
run: |
15+
mkdir -p Bin
16+
17+
$ProgramFiles = ${env:ProgramFiles(x86)}
18+
19+
if (-not $ProgramFiles)
20+
{
21+
$ProgramFiles = $env:ProgramFiles
22+
}
23+
24+
$BuiltInVsWhereExe = "$ProgramFiles\Microsoft Visual Studio\Installer\vswhere.exe"
25+
26+
if (-not (Test-Path $BuiltInVsWhereExe))
27+
{
28+
throw "找不到vswhere.exe!"
29+
}
30+
31+
Write-Output $BuiltInVsWhereExe
32+
33+
$LatestVisualStudioRoot = & $BuiltInVsWhereExe -latest -prerelease -property installationPath
34+
35+
if (-not (Test-Path $LatestVisualStudioRoot))
36+
{
37+
throw "找不到 VisualStudioRoot!"
38+
}
39+
40+
echo "LatestVisualStudioRoot=$LatestVisualStudioRoot" >> $env:GITHUB_ENV
41+
42+
$MSBuildBinPath="$LatestVisualStudioRoot\MSBuild\Current\Bin"
43+
44+
if (-not (Test-Path $MSBuildBinPath))
45+
{
46+
$installationVersion = & $BuiltInVsWhereExe -latest -prerelease -property installationVersion
47+
$majorVersion = "$installationVersion".Split('.')[0]
48+
49+
$MSBuildBinPath="$LatestVisualStudioRoot\MSBuild\$majorVersion.0\Bin"
50+
}
51+
52+
if (-not (Test-Path $MSBuildBinPath))
53+
{
54+
throw "找不到 MSBuildBinPath!"
55+
}
56+
57+
echo "MSBuildBinPath=$MSBuildBinPath" >> $env:GITHUB_ENV
58+
59+
if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase"))
60+
{
61+
$BuildVersion = $env:GITHUB_REF.Remove(0, 11);
62+
echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV
63+
64+
$Prerelease = $BuildVersion.contains("-");
65+
echo "Prerelease=$Prerelease" >> $env:GITHUB_ENV
66+
67+
# github的内置版本有Bug,此行必须添加,否则无法获得内容
68+
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
69+
70+
$releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10)
71+
echo "-p \"releaseNotes=$releaseNotes\"" | out-file NuGet\metadata.txt -NoNewline
72+
echo "-p \"version=$BuildVersion\"" | out-file NuGet\metadata.txt -Append
73+
}
74+
else
75+
{
76+
$BuildVersion = "100.0.0-Alpha"
77+
$releaseNotes = "CI Build"
78+
echo "-p \"releaseNotes=$releaseNotes\"" | out-file NuGet\metadata.txt -NoNewline
79+
echo "-p \"version=$BuildVersion\"" | out-file NuGet\metadata.txt -Append
80+
}
81+
82+
echo "-p \"commit=$env:GITHUB_SHA\"" | out-file NuGet\metadata.txt -Append
83+
84+
- name: 执行单元测试
85+
if: contains(github.ref, 'tags/') != 'true'
86+
working-directory: ${{env.GITHUB_WORKSPACE}}
87+
shell: pwsh
88+
run: |
89+
# Procdump工具,用于单元测试崩溃诊断
90+
Invoke-WebRequest -Uri https://download.sysinternals.com/files/Procdump.zip -OutFile Bin\Procdump.zip
91+
&7z e Bin\Procdump.zip "-o$Env:GITHUB_WORKSPACE\Bin"
92+
93+
# MSBuild、PROCDUMP_PATH目录更新到 Path
94+
$Env:Path="$Env:GITHUB_WORKSPACE\Bin;${{env.MSBuildBinPath}};${{env.LatestVisualStudioRoot}}\Common7\IDE\CommonExtensions\Microsoft\TestWindow;" + $Env:Path
95+
96+
# 编译单元测试项目
97+
&msbuild UnitTest\UnitTest.vcxproj "-p:Configuration=Release;Platform=Win32;SolutionDir=$Env:GITHUB_WORKSPACE\\"
98+
if($lastexitcode -ne 0)
99+
{
100+
throw "UnitTest\UnitTest.vcxproj 编译失败!退出代码:$lastexitcode"
101+
}
102+
103+
&msbuild UnitTest\UnitTest.vcxproj "-p:Configuration=Release;Platform=x64;SolutionDir=$Env:GITHUB_WORKSPACE\\"
104+
if($lastexitcode -ne 0)
105+
{
106+
throw "UnitTest\UnitTest.vcxproj 编译失败!退出代码:$lastexitcode"
107+
}
108+
109+
$RunFaild = 0
110+
111+
&vstest.console Release\UnitTest.dll "/logger:trx;LogFileName=UnitTestWin32.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full" "/Diag:TestResults\Win32.log"
112+
if($lastexitcode -ne 0)
113+
{
114+
$RunFaild = 1
115+
}
116+
117+
&vstest.console x64\Release\UnitTest.dll "/logger:trx;LogFileName=UnitTestWin64.trx" "/Blame:CollectDump;CollectAlways=false;DumpType=full" "/Diag:TestResults\Win64.log"
118+
if($lastexitcode -ne 0)
119+
{
120+
$RunFaild = 1
121+
}
122+
123+
if($RunFaild -ne 0)
124+
{
125+
throw "单元测试失败!"
126+
}
127+
- uses: dorny/test-reporter@v1
128+
if: contains(fromJSON('["push", "create"]'), github.event_name) && contains(github.ref, 'tags/') != 'true' && (success() || failure())
129+
with:
130+
name: 单元测试报告
131+
path: TestResults/*.trx
132+
reporter: dotnet-trx
133+
134+
- name: 文件打包
135+
working-directory: ${{env.GITHUB_WORKSPACE}}
136+
shell: cmd
137+
run: |
138+
::打包Nuget
139+
nuget pack NuGet\YY.Base.nuspec @NuGet\metadata.txt
140+
141+
- uses: actions/upload-artifact@v4
142+
with:
143+
path: |
144+
*.nupkg
145+
146+
# 失败时我们收集一些信息,用于诊断
147+
- uses: actions/upload-artifact@v4
148+
if: failure()
149+
with:
150+
name: ErrorLog
151+
path: |
152+
TestResults\**\*.*
153+
Release\UnitTest.dll
154+
Release\UnitTest.pdb
155+
Release\*.log
156+
x64\Release\UnitTest.dll
157+
x64\Release\UnitTest.pdb
158+
x64\Release\*.log
159+
160+
- name: 内容发布
161+
if: contains(github.ref, 'tags/')
162+
working-directory: ${{env.GITHUB_WORKSPACE}}
163+
shell: cmd
164+
run: |
165+
:: 把生成的nuget包发布到nuget中
166+
nuget push YY-Thunks.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json
167+

Directory.Build.props

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
4+
<!--强制引入PackageReferences-->
5+
<ProjectCapability Include="PackageReferences" />
6+
</ItemGroup>
7+
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
8+
<!--指定自己的体系为native-->
9+
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
10+
<!--如果不指定这一行,那么arm64平台会找不到RID而失败-->
11+
<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
12+
</PropertyGroup>
13+
<!--从兼容性考虑,继续向上搜索 Directory.Build.props-->
14+
<PropertyGroup>
15+
<DirectoryBuildPropsPath>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</DirectoryBuildPropsPath>
16+
</PropertyGroup>
17+
<Import Project="$(DirectoryBuildPropsPath)" Condition="'$(DirectoryBuildPropsPath)' != ''"/>
18+
</Project>

NuGet/YY.Base.nuspec

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
3+
<metadata>
4+
<id>YY.Base</id>
5+
<version>$version$</version>
6+
<title>YY.Base</title>
7+
<authors>YY</authors>
8+
<owners>初雨团队</owners>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<license type="expression">MIT</license>
11+
<licenseUrl>https://licenses.nuget.org/MIT</licenseUrl>
12+
<projectUrl>https://github.com/Chuyu-Team/YY.Base/</projectUrl>
13+
<summary>包含线程池、协程支持、智能指针、String等轻量级基础函数库。</summary>
14+
<description>包含线程池、协程支持、智能指针、String等轻量级基础函数库。</description>
15+
<releaseNotes>$releaseNotes$</releaseNotes>
16+
<copyright>Copyright Chuyu</copyright>
17+
<tags>Chuyu YY-Thunks native nativepackage</tags>
18+
<repository type="git" url="https://github.com/Chuyu-Team/YY.Base.git" branch="master" commit="$commit$" />
19+
<dependencies>
20+
<dependency id="YY.NuGet.Import.Helper" version="1.0.1" />
21+
</dependencies>
22+
<contentFiles>
23+
<files include="any\any\YY.Base.txt" buildAction="Content" copyToOutput="false"/>
24+
</contentFiles>
25+
</metadata>
26+
<files>
27+
<file src="..\src\**" target="build\native\src"/>
28+
<file src="..\include\**" target="build\native\include"/>
29+
<file src=".\YY.Base.*" target="build\native"/>
30+
<file src=".\content.txt" target="contentFiles\any\any\YY.Base.txt"/>
31+
<file src=".\content.txt" target="Content\NuGet\YY.Base.txt"/>
32+
</files>
33+
</package>

NuGet/YY.Base.targets

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<IncludePath>$(MSBuildThisFileDirectory)include;$(IncludePath)</IncludePath>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<NuGetExConnentFiles Include="$(MSBuildThisFileDirectory)src\**\*.cpp;$(MSBuildThisFileDirectory)src\**\*.$(TargetPlatformIdentifier).cc" >
8+
<NuGetPackageId>$(MSBuildThisFileName)</NuGetPackageId>
9+
<BuildAction>ClCompile</BuildAction>
10+
<!--关闭预编译头-->
11+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
12+
<SDLCheck>false</SDLCheck>
13+
<ConformanceMode>false</ConformanceMode>
14+
<ObjectFileName>$(IntDir)$(MSBuildThisFileName)\</ObjectFileName>
15+
<!--关闭视警告为错误,万一项目配置了,这会失败。-->
16+
<TreatWarningAsError>false</TreatWarningAsError>
17+
<TreatSpecificWarningsAsErrors></TreatSpecificWarningsAsErrors>
18+
<!--关闭所有警告,这是开源库,你去解决警告吗?-->
19+
<WarningLevel>TurnOffAllWarnings</WarningLevel>
20+
<!--保持默认编译行为 .c 编译为 c,其他cpp-->
21+
<CompileAs>Default</CompileAs>
22+
</NuGetExConnentFiles>
23+
<Natvis Include="$(MSBuildThisFileDirectory)src\YY.Base.natvis" />
24+
</ItemGroup>
25+
</Project>

NuGet/content.txt

Whitespace-only changes.

UnitTest/AsyncFileUnitTest.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "CppUnitTest.h"
2+
#include <atlstr.h>
3+
#include <Windows.h>
4+
#include <tchar.h>
5+
#include <string>
6+
7+
#include <YY/Base/IO/File.h>
8+
9+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
10+
11+
using namespace YY;
12+
13+
namespace UnitTest
14+
{
15+
TEST_CLASS(AsyncFile)
16+
{
17+
public:
18+
static Coroutine<void> ReadFileCoroutine()
19+
{
20+
wchar_t _szFilePath[512] = {};
21+
GetModuleFileNameW((HMODULE)&__ImageBase, _szFilePath, std::size(_szFilePath));
22+
23+
auto _hFile = YY::AsyncFile::Open(_szFilePath, Access::Read, ShareMode::Read | ShareMode::Delete);
24+
auto _cbFile = GetFileSize(_hFile.GetNativeHandle(), nullptr);
25+
26+
Assert::AreNotEqual(_cbFile, 0ul);
27+
28+
std::string _szBuffer;
29+
_szBuffer.resize(_cbFile);
30+
co_await _hFile.AsyncRead(0, _szBuffer.data(), _cbFile);
31+
32+
co_return;
33+
}
34+
35+
TEST_METHOD(异步读取文件)
36+
{
37+
auto _pTaskRunner = SequencedTaskRunner::Create();
38+
39+
wchar_t _szFilePath[512] = {};
40+
GetModuleFileNameW((HMODULE)&__ImageBase, _szFilePath, std::size(_szFilePath));
41+
auto _hFileSrc = CreateFileW(_szFilePath, GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
42+
const auto _cbFileSrc = GetFileSize(_hFileSrc, nullptr);
43+
Assert::AreNotEqual(_hFileSrc, INVALID_HANDLE_VALUE);
44+
45+
std::string _szBufferSrc;
46+
_szBufferSrc.resize(_cbFileSrc);
47+
DWORD _cbRead = 0;
48+
ReadFile(_hFileSrc, _szBufferSrc.data(), _cbFileSrc, &_cbRead, nullptr);
49+
Assert::AreEqual(_cbFileSrc, _cbRead);
50+
51+
auto _hFile = YY::AsyncFile::Open(_szFilePath, Access::Read, ShareMode::Read | ShareMode::Delete);
52+
53+
std::string _szBufferAsyncReadFile;
54+
55+
auto pfnReadFile = [&]() ->Coroutine<void>
56+
{
57+
auto _cbFile = GetFileSize(_hFile.GetNativeHandle(), nullptr);
58+
Assert::AreNotEqual(_cbFile, 0ul);
59+
60+
_szBufferAsyncReadFile.resize(_cbFile);
61+
auto _cbRead = co_await _hFile.AsyncRead(0, _szBufferAsyncReadFile.data(), _cbFile);
62+
_szBufferAsyncReadFile.resize(_cbRead);
63+
co_return;
64+
};
65+
66+
for (int i=2;i;--i)
67+
{
68+
_szBufferAsyncReadFile.clear();
69+
_pTaskRunner->PostTask([&]()
70+
{
71+
pfnReadFile();
72+
});
73+
74+
Sleep(500);
75+
76+
Assert::AreEqual(_szBufferSrc, _szBufferAsyncReadFile);
77+
}
78+
}
79+
};
80+
}

UnitTest/BitMapUnitTest.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "CppUnitTest.h"
2+
#include <atlstr.h>
3+
#include <Windows.h>
4+
#include <tchar.h>
5+
#include <string>
6+
7+
#include <YY/Base/Containers/BitMap.h>
8+
9+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
10+
11+
using namespace YY::Base;
12+
using namespace YY::Base::Containers;
13+
14+
namespace UnitTest
15+
{
16+
TEST_CLASS(BitMapUnitTest)
17+
{
18+
public:
19+
TEST_METHOD(Bit数检测)
20+
{
21+
static_assert(sizeof(BitMap<65>::arrBits) >= sizeof(uint32_t) * 3);
22+
23+
static_assert(sizeof(BitMap<64>::arrBits) == sizeof(uint32_t) * 2);
24+
}
25+
26+
TEST_METHOD(Bit设置获取能力)
27+
{
28+
BitMap<128> TTT;
29+
Assert::AreEqual(TTT.GetItem(126), false);
30+
Assert::AreEqual(TTT.GetSize(), 0u);
31+
32+
TTT.SetItem(126, true);
33+
Assert::AreEqual(TTT.GetItem(126), true);
34+
Assert::AreEqual(TTT.GetSize(), 1u);
35+
Assert::AreEqual(((uint32_t*)&TTT.arrBits)[3], (uint32_t)0x40000000u);
36+
37+
TTT.SetItem(126, false);
38+
Assert::AreEqual(TTT.GetItem(126), false);
39+
Assert::AreEqual(TTT.GetSize(), 0u);
40+
Assert::AreEqual(((uint32_t*)&TTT.arrBits)[3], (uint32_t)0x00000000u);
41+
}
42+
43+
TEST_METHOD(Find验证)
44+
{
45+
{
46+
BitMap<128> TTT;
47+
for (int32_t i = 127; i >= 0; --i)
48+
{
49+
TTT.SetItem(i, true);
50+
51+
Assert::AreEqual(TTT.Find(0), i);
52+
}
53+
}
54+
55+
{
56+
BitMap<128> TTT;
57+
TTT.SetItem(127, true);
58+
59+
Assert::AreEqual(TTT.Find(120), 127);
60+
}
61+
}
62+
};
63+
}

0 commit comments

Comments
 (0)