chore: bootstrap repository foundation
Solution layout, build rules with zero-package guard, in-house test framework, localization runtime, brand mark rasteriser with ICO/PNG generation, Core contracts (imaging, video, domain model, TIFF reader), Titano.Tools (make-icon, i18n, xaml-lint, package-guard) and docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
109 files changed
+7523
No files matched your search
@@ -0,0 +1,62 @@
|
||||
using Titano.Core.Branding;
|
||||
using Titano.Core.Codecs.Ico;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Branding;
|
||||
|
||||
public sealed class BrandMarkTests
|
||||
{
|
||||
[Test]
|
||||
public void TickOpacityRampsFromDimToFull()
|
||||
{
|
||||
Assert.Approximately(0.14, BrandMark.TickOpacity(0), 1e-9);
|
||||
Assert.Approximately(1.0, BrandMark.TickOpacity(11), 1e-9);
|
||||
Assert.Monotonic(Enumerable.Range(0, 12).Select(BrandMark.TickOpacity), strict: true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SunPixelIsSunColour()
|
||||
{
|
||||
var rgba = BrandMark.Render(BrandVariant.App, 256);
|
||||
var o = (104 * 256 + 152) * 4;
|
||||
Assert.Equal(BrandMark.Sun.R, rgba[o]);
|
||||
Assert.Equal(BrandMark.Sun.G, rgba[o + 1]);
|
||||
Assert.Equal(BrandMark.Sun.B, rgba[o + 2]);
|
||||
Assert.Equal((byte)255, rgba[o + 3]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CornersOutsideRoundedPlateAreTransparent()
|
||||
{
|
||||
var rgba = BrandMark.Render(BrandVariant.App, 64);
|
||||
Assert.Equal((byte)0, rgba[3]);
|
||||
Assert.Equal((byte)255, rgba[(32 * 64 + 32) * 4 + 3]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MonoHasNoPlate()
|
||||
{
|
||||
var rgba = BrandMark.Render(BrandVariant.Mono, 64);
|
||||
Assert.Equal((byte)0, rgba[(4 * 64 + 32) * 4 + 3]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SvgMatchesDesignMaster()
|
||||
{
|
||||
var master = File.ReadAllText(Path.Combine(TestContext.RepositoryRoot, "branding", "titano.svg")).Replace("\r", "", StringComparison.Ordinal);
|
||||
Assert.Equal(master.Trim(), BrandMark.ToSvg(BrandVariant.App).Trim());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IcoHasAllSizes()
|
||||
{
|
||||
var sizes = new[] { 16, 32, 48, 256 };
|
||||
var ico = IcoWriter.Write(sizes.Select(s => (s, BrandMark.Render(BrandVariant.App, s))).ToList());
|
||||
Assert.Equal((byte)0, ico[0]);
|
||||
Assert.Equal((byte)1, ico[2]);
|
||||
Assert.Equal(sizes.Length, ico[4] | ico[5] << 8);
|
||||
// 256 px entry stored as PNG.
|
||||
var lastOffset = BitConverter.ToInt32(ico, 6 + 16 * 3 + 12);
|
||||
Assert.Equal((byte)0x89, ico[lastOffset]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Titano.Core.IO;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Foundation;
|
||||
|
||||
public sealed class AtomicFileTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public void ReplacesContentAndLeavesNoTemporaryFiles()
|
||||
{
|
||||
var dir = context.CreateTempDirectory();
|
||||
var path = Path.Combine(dir, "sequence.json");
|
||||
AtomicFile.WriteAllText(path, "one");
|
||||
AtomicFile.WriteAllText(path, "two");
|
||||
Assert.Equal("two", File.ReadAllText(path));
|
||||
Assert.Count(1, Directory.GetFiles(dir));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FailedWriteKeepsPreviousContent()
|
||||
{
|
||||
var dir = context.CreateTempDirectory();
|
||||
var path = Path.Combine(dir, "project.json");
|
||||
AtomicFile.WriteAllText(path, "stable");
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => AtomicFile.WriteAsync(path, async (s, ct) =>
|
||||
{
|
||||
await s.WriteAsync("partial"u8.ToArray(), ct);
|
||||
throw new InvalidOperationException("boom");
|
||||
}));
|
||||
Assert.Equal("stable", File.ReadAllText(path));
|
||||
Assert.Count(1, Directory.GetFiles(dir));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Text;
|
||||
using Titano.Core.Hashing;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Foundation;
|
||||
|
||||
public sealed class Crc32Tests
|
||||
{
|
||||
[Test]
|
||||
public void CheckValueMatchesStandard() => Assert.Equal(0xCBF43926u, Crc32.Compute("123456789"u8));
|
||||
|
||||
[Test]
|
||||
public void IncrementalEqualsOneShot()
|
||||
{
|
||||
var data = Encoding.ASCII.GetBytes(new string('x', 1000) + "titano");
|
||||
var crc = new Crc32();
|
||||
crc.Append(data.AsSpan(0, 7));
|
||||
crc.Append(data.AsSpan(7, 500));
|
||||
crc.Append(data.AsSpan(507));
|
||||
Assert.Equal(Crc32.Compute(data), crc.GetCurrentHashAsUInt32());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmptyInputIsZero() => Assert.Equal(0u, Crc32.Compute([]));
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Foundation;
|
||||
|
||||
public sealed class ImageBufferTests
|
||||
{
|
||||
[Test]
|
||||
public void PlanesAreIndependentAndClearedByDefault()
|
||||
{
|
||||
using var image = new ImageBuffer(4, 3);
|
||||
Assert.Equal(12, image.PlaneLength);
|
||||
Assert.True(image.Data.ToArray().All(v => v == 0));
|
||||
image[1, 2, 1] = 0.5f;
|
||||
Assert.Equal(0.5f, image.Plane(1)[1 * 4 + 2]);
|
||||
Assert.Equal(0f, image.Plane(0)[1 * 4 + 2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CloneCopiesPixels()
|
||||
{
|
||||
using var image = new ImageBuffer(2, 2, 1);
|
||||
image[0, 1, 1] = 3f;
|
||||
using var clone = image.Clone();
|
||||
image[0, 1, 1] = 0f;
|
||||
Assert.Equal(3f, clone[0, 1, 1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DisposedBufferThrows()
|
||||
{
|
||||
var image = new ImageBuffer(1, 1);
|
||||
image.Dispose();
|
||||
Assert.Throws<ObjectDisposedException>(() => _ = image.Storage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Case("IMG_0001.CR2", ImageFileFormat.Cr2)]
|
||||
[Case("a.jpeg", ImageFileFormat.Jpeg)]
|
||||
[Case("photo.HEIC", ImageFileFormat.Heif)]
|
||||
[Case("notes.txt", ImageFileFormat.Unknown)]
|
||||
public void FormatFromExtension(string name, ImageFileFormat expected) =>
|
||||
Assert.Equal(expected, ImageFormatInfo.FromPath(name).Format);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Globalization;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests.Localization;
|
||||
|
||||
public sealed class PluralRulesTests
|
||||
{
|
||||
[Theory]
|
||||
[Case("en", 1L, PluralCategory.One)]
|
||||
[Case("en", 0L, PluralCategory.Other)]
|
||||
[Case("fr", 0L, PluralCategory.One)]
|
||||
[Case("ru", 21L, PluralCategory.One)]
|
||||
[Case("ru", 22L, PluralCategory.Few)]
|
||||
[Case("ru", 11L, PluralCategory.Many)]
|
||||
[Case("ru", 25L, PluralCategory.Many)]
|
||||
[Case("pl", 12L, PluralCategory.Many)]
|
||||
[Case("pl", 23L, PluralCategory.Few)]
|
||||
[Case("cs", 3L, PluralCategory.Few)]
|
||||
[Case("ja", 1L, PluralCategory.Other)]
|
||||
[Case("ar", 11L, PluralCategory.Many)]
|
||||
public void SelectsCldrCategory(string culture, long count, PluralCategory expected) =>
|
||||
Assert.Equal(expected, PluralRules.Select(CultureInfo.GetCultureInfo(culture), count));
|
||||
|
||||
[Test]
|
||||
public void BestMatchFallsBackToEnglish()
|
||||
{
|
||||
Assert.Equal("it", Languages.BestMatch(CultureInfo.GetCultureInfo("it-CH")).Name);
|
||||
Assert.Equal("pt-BR", Languages.BestMatch(CultureInfo.GetCultureInfo("pt-BR")).Name);
|
||||
Assert.Equal("en", Languages.BestMatch(CultureInfo.GetCultureInfo("sw")).Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryShippedLanguageIsAKnownCulture()
|
||||
{
|
||||
foreach (var code in Languages.Shipped) Assert.NotNull(CultureInfo.GetCultureInfo(code));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Core.Tests;
|
||||
|
||||
internal static class TestMain
|
||||
{
|
||||
public static Task<int> Main(string[] args) => TestRunner.RunAsync(args, typeof(TestMain).Assembly);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace>Titano.Core.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Titano.Testing\Titano.Testing.csproj" />
|
||||
<ProjectReference Include="..\..\src\Titano.Core\Titano.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\Titano.Data\Titano.Data.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user