-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy pathFileFormatTests.cs
More file actions
85 lines (78 loc) · 3.37 KB
/
Copy pathFileFormatTests.cs
File metadata and controls
85 lines (78 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Collections.Generic;
using Cairo;
using NUnit.Framework;
namespace Pinta.Core.Tests;
[TestFixture]
internal sealed class FileFormatTests
{
[TestCase ("sixcolorsinput.gif", "sixcolors_standard_lf.ppm")]
[TestCase ("sixcolorsinput.gif", "sixcolors_chaotic.ppm")]
public void Files_NotEqual (string file1, string file2)
{
string path1 = Utilities.GetAssetPath (file1);
string path2 = Utilities.GetAssetPath (file2);
Assert.That (Utilities.AreFilesEqual (path1, path2), Is.False);
}
[TestCaseSource (nameof (netpbm_pixmap_text_cases))]
public void Export_NetpbmPixmap_TextBased (string inputFile, IEnumerable<string> acceptableOutputs)
{
string inputFilePath = Utilities.GetAssetPath (inputFile);
using ImageSurface loaded = Utilities.LoadImage (inputFilePath);
NetpbmPortablePixmap exporter = new ();
using Gio.MemoryOutputStream memoryOutput = Gio.MemoryOutputStream.NewResizable ();
using GioStream outputStream = new (memoryOutput);
exporter.Export (loaded, outputStream);
outputStream.Close ();
memoryOutput.Close (null);
var exportedBytes = memoryOutput.StealAsBytes ();
bool matched = false;
foreach (string fileName in acceptableOutputs) {
var bytesStream = Gio.MemoryInputStream.NewFromBytes (exportedBytes);
var bytesReader = Gio.DataInputStream.New (bytesStream);
string filePath = Utilities.GetAssetPath (fileName);
using var context = Utilities.OpenFile (filePath);
if (!Utilities.AreFilesEqual (bytesReader, context.DataStream)) continue;
matched = true;
break;
}
Assert.That (matched, Is.True);
}
// TODO: This is just for reference. Find a way to get the image importers not to depend on PintaCore
//[TestCase ("sixcolorsinput.gif", "sixcolors_standard_lf.ppm")]
//[TestCase ("sixcolorsinput.gif", "sixcolors_chaotic.ppm")]
//public void Import_NetpbmPixmap_TextBased (string referenceImageName, string ppmFileName)
//{
// string ppmFilePath = Utilities.GetAssetPath (ppmFileName);
// string referenceImagePath = Utilities.GetAssetPath (referenceImageName);
// using ImageSurface loaded = Utilities.LoadImage (referenceImagePath);
// using Gio.File ppmFile = Gio.FileHelper.NewForPath (ppmFilePath);
// NetpbmPortablePixmap importer = new ();
// Document importedPpm = importer.Import (ppmFile);
// Utilities.CompareImages (importedPpm.Layers[0].Surface, loaded);
//}
static readonly IReadOnlyList<TestCaseData> netpbm_pixmap_text_cases = [
new (
"sixcolorsinput.gif",
new[] { "sixcolors_standard_lf.ppm" }
),
];
[TestCase ("sixcolorsinput.gif", "sixcolors_farbfeld.ff")]
public void Export_Farbfeld (string input, string output)
{
string inputFilePath = Utilities.GetAssetPath (input);
ImageSurface loaded = Utilities.LoadImage (inputFilePath);
FarbfeldFormat exporter = new ();
Gio.MemoryOutputStream memoryOutput = Gio.MemoryOutputStream.NewResizable ();
using GioStream outputStream = new (memoryOutput);
FarbfeldFormat.Export (loaded, outputStream);
outputStream.Close ();
memoryOutput.Close (null);
var exportedBytes = memoryOutput.StealAsBytes ();
var bytesStream = Gio.MemoryInputStream.NewFromBytes (exportedBytes);
var bytesReader = Gio.DataInputStream.New (bytesStream);
string filePath = Utilities.GetAssetPath (output);
using var context = Utilities.OpenFile (filePath);
bool filesAreEqual = Utilities.AreFilesEqual (bytesReader, context.DataStream);
Assert.That (filesAreEqual);
}
}