Skip to content

Commit

Permalink
Include some testcases and solution files
Browse files Browse the repository at this point in the history
  • Loading branch information
pweerd committed May 25, 2024
1 parent 0a53d4c commit 4e4354c
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 105 deletions.
101 changes: 0 additions & 101 deletions AlbumImport.csproj

This file was deleted.

22 changes: 18 additions & 4 deletions AlbumImporter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlbumImport", "AlbumImport.csproj", "{A8763DBE-7B61-40F5-938D-1CA0E8C2FBE4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlbumImporter", "AlbumImporter\AlbumImporter.csproj", "{9111B35C-3DBC-45A8-8795-7DC2E2400B82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F49E9EF5-E9A5-4A12-8134-97E724DED5AF}"
ProjectSection(SolutionItems) = preProject
import.sample.xml = import.sample.xml
import.xml = import.xml
index.config.js = index.config.js
index_captions.config.js = index_captions.config.js
index_faces.config.js = index_faces.config.js
index_ids.config.js = index_ids.config.js
index_ocr.config.js = index_ocr.config.js
index_without_stemmer.config.js = index_without_stemmer.config.js
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A8763DBE-7B61-40F5-938D-1CA0E8C2FBE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8763DBE-7B61-40F5-938D-1CA0E8C2FBE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Release|Any CPU.Build.0 = Release|Any CPU
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
87 changes: 87 additions & 0 deletions UnitTests/DirectoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright © 2023, De Bitmanager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Bitmanager.Core;
using Bitmanager.Test;
using AlbumImporter;

namespace UnitTests {
[TestClass]
public class DirectoryTests: TestBaseSimple {
private readonly DirectoryMetaExtractor dir = new DirectoryMetaExtractor ();
[TestMethod]
public void TestDirectoryExtract () {
check (null, null, @"");
check (null, null, @"c:");
check (null, null, @"c:\");
check ("aap", null, @"c:\aap");
check (null, null, @"c:\");

check ("1993-1994", "1993-01-01", @"c:\1993 - 1994 ");
check ("geboorte kim", "1993-01-01", @"c\1993 geboorte kim ");
check ("geboorte kim", "1993-01-01", @"c\1993 geboorte kim \123");
check ("geboorte kim", "1993-03-01", @"c\1993\03\ geboorte kim");
check ("geboorte kim", "1993-03-05", @"c\1993\03\05 geboorte kim");
check ("geboorte kim", "1993-03-05", @"c\1993\0305 geboorte kim");
check ("geboorte kim", "1994-03-05", @"c\1993\19940305 geboorte kim");
check ("aap", "1993-01-01", @"c\1993 geboorte kim \aap");
check (null, "1993-04-01", @"c\1993\04");
check ("Zeiltocht Thijs", "1995-01-01", @"D:\Fotos\Medialab\1995 - Zeiltocht Thijs");

}


//root: skip_dir_names=2
//lvl1: skip_dir_names=?
//lvl2: skip_dir_names=?
//lvl3: skip_dir_names=0
//lvl4: skip_dir_names=?
[TestMethod]
public void TestSettings() {
string root = base.testAssembly.FindDirectoryToRoot ("data", Bitmanager.IO.FindToTootFlags.Except);
string deepest = Path.Combine (root, @"lvl1\lvl2\lvl3\lvl4");
var cache = new DirectorySettingsCache (null);
var settings4 = cache.GetSettings (deepest, root.Length);
deepest = Path.GetDirectoryName (deepest);
var settings3 = cache.GetSettings (deepest, root.Length);
deepest = Path.GetDirectoryName (deepest);
var settings2 = cache.GetSettings (deepest, root.Length);
deepest = Path.GetDirectoryName (deepest);
var settings1 = cache.GetSettings (deepest, root.Length);
deepest = Path.GetDirectoryName (deepest);
var settings0 = cache.GetSettings (deepest, root.Length);

Assert.AreEqual (0, settings0.Names.Length);
Assert.AreEqual (0, settings1.Names.Length);
Assert.AreEqual (1, settings2.Names.Length);
Assert.AreEqual ("lvl2", settings2.Names[0]);
Assert.AreEqual (1, settings3.Names.Length);
Assert.AreEqual ("lvl3", settings3.Names[0]);
Assert.AreEqual (2, settings4.Names.Length);
Assert.AreEqual ("lvl3", settings4.Names[0]);
Assert.AreEqual ("lvl4", settings4.Names[1]);

}

private void check (string album, string date, string name) {
var cache = new DirectorySettingsCache (null);

dir.Extract (cache.GetSettings(name, 3));
Assert.AreEqual (date, dir.StrDate);
Assert.AreEqual (album, dir.Album);
}
}
}
69 changes: 69 additions & 0 deletions UnitTests/FileTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Copyright © 2023, De Bitmanager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AlbumImporter;

namespace UnitTests {
[TestClass]
public class FileTests {
private readonly FileMetaExtractor extractor = new FileMetaExtractor ();
private readonly DateTime testDate = new DateTime (2023, 2, 1, 12, 3, 4, DateTimeKind.Local);

[TestMethod]
public void TestExtract () {
check (null, null, 1, null, "img001.jpg");
check (null, null, 1, null, "img-001.jpg");
check (null, null, 1, null, "sam-001.jpg");
check (null, null, 1, null, "p-001.jpg");
check (null, null, 195, null, "Afbeelding 195.jpg");
check ("WhatsApp", "2023-02-01", 6, null, "IMG-20230709-WA0006.jpg");
check ("BFYV6816", null, 0, null, "BFYV6816.jpg");
check ("BFYV6816", "2022-08-14", 0, null, "20220814_214413 BFYV6816.jpg");
check ("Familiedag 2023", "2023-06-17", 0, "D", "20230617_120214 Familiedag 2023(D)");
check ("1e van 29 mei 2000", null, 137, null, "137 1e van 29 mei 2000.jpg");
check ("wilma", "2022-08-14", 0, null, @"wilma\20220814_214413.jpg");
check (null, "2023-04-01", 570, null, @"2023\04\SGDN0570.JPG");
check ("aap", "2022-08-14", 23, "P", @"wilma\20220814_214413 aap(P)_23.jpg");

check ("fotos", null, 1693, null, @"D\dakkapel\fotos\IMG_1693.JPG");
check ("fotos", null, 1693, null, @"D\dakkapel\fotos\IMG_1693_1.JPG");
check ("Zeiltocht Thijs", "1995-01-01", 2, null, @"D:\Fotos\Medialab\1995 - Zeiltocht Thijs\002.jpg");
check ("Zeiltocht Thijs", "1995-01-01", 0, null, @"D:\Fotos\Medialab\1995 - Zeiltocht Thijs.jpg");
check ("Zeiltocht Thijs", "1995-02-03", 0, null, @"D:\Fotos\Medialab\1995-02-03 - Zeiltocht Thijs.jpg");
check ("Zeiltocht Thijs", "1995-02-03", 0, null, @"D:\Fotos\Medialab\1995\02-03 - Zeiltocht Thijs.jpg");
}

private DirectorySettings getSettings(string name) {
var c = new DirectorySettingsCache(null);
return c.GetSettings(Path.GetDirectoryName(name), 0);
}
private void check (string album, string date, int order, string extra, string name) {

extractor.Extract (getSettings(name), name, testDate);
Assert.AreEqual (date, extractor.StrDate);
Assert.AreEqual (album, extractor.Album);
Assert.AreEqual (extra, extractor.Extra);
Assert.AreEqual (order, extractor.Order);
}
private void check (string album, string date, string name, bool needDate=true) {
extractor.Extract (getSettings (name), name, testDate);
Assert.AreEqual (date, extractor.StrDate);
Assert.AreEqual (album, extractor.Album);
Assert.AreEqual (null, extractor.Extra);
Assert.AreEqual (0, extractor.Order);
}

}
}
17 changes: 17 additions & 0 deletions UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright © 2023, De Bitmanager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

global using Microsoft.VisualStudio.TestTools.UnitTesting;
46 changes: 46 additions & 0 deletions UnitTests/Playground.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AlbumImporter;
using Bitmanager.Test;
using Bitmanager.Json;
using Bitmanager.Xml;
using Bitmanager.ImportPipeline;
using Bitmanager.Core;
using Bitmanager.IO;

namespace UnitTests {
/// <summary>
/// This is not realy a test case. More a playground to quickly check something
/// </summary>
[TestClass]
public class PlayGroundTests : TestBaseSimple {
private string root;
public PlayGroundTests() {
root = testAssembly.FindDirectoryToRoot ("data", FindToTootFlags.Except);
}


[TestMethod]
public void TestPipeline () {
JsonObjectValue result;
result = execPipeline (@"Some file");
//Check the result object
}

private JsonObjectValue execPipeline (string file) {
var xml = new XmlHelper(Path.Combine (root, "playground.xml"));
xml.WriteVal ("datasources/datasource/id/@file", file);
using (var engine = new ImportEngine ()) {
engine.Load (xml);
var report = engine.Import ();
if (report.ErrorState != _ErrorState.OK)
throw new BMException (report.ErrorMessage);
var output = engine.Output;
if (output == null) throw new BMException ("Pipeline generated no output");
Assert.AreEqual (1, output.Count);
logger.Log (output[0].ToJsonString ());
return output[0];
}
}

}
}
Loading

0 comments on commit 4e4354c

Please sign in to comment.