Skip to content

Commit 4e4354c

Browse files
committed
Include some testcases and solution files
1 parent 0a53d4c commit 4e4354c

16 files changed

+313
-105
lines changed

AlbumImport.csproj

Lines changed: 0 additions & 101 deletions
This file was deleted.

AlbumImporter.sln

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,36 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.4.33205.214
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlbumImport", "AlbumImport.csproj", "{A8763DBE-7B61-40F5-938D-1CA0E8C2FBE4}"
7-
EndProject
86
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlbumImporter", "AlbumImporter\AlbumImporter.csproj", "{9111B35C-3DBC-45A8-8795-7DC2E2400B82}"
97
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F49E9EF5-E9A5-4A12-8134-97E724DED5AF}"
11+
ProjectSection(SolutionItems) = preProject
12+
import.sample.xml = import.sample.xml
13+
import.xml = import.xml
14+
index.config.js = index.config.js
15+
index_captions.config.js = index_captions.config.js
16+
index_faces.config.js = index_faces.config.js
17+
index_ids.config.js = index_ids.config.js
18+
index_ocr.config.js = index_ocr.config.js
19+
index_without_stemmer.config.js = index_without_stemmer.config.js
20+
EndProjectSection
21+
EndProject
1022
Global
1123
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1224
Debug|Any CPU = Debug|Any CPU
1325
Release|Any CPU = Release|Any CPU
1426
EndGlobalSection
1527
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{A8763DBE-7B61-40F5-938D-1CA0E8C2FBE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17-
{A8763DBE-7B61-40F5-938D-1CA0E8C2FBE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
1828
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1929
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Debug|Any CPU.Build.0 = Debug|Any CPU
2030
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Release|Any CPU.ActiveCfg = Release|Any CPU
2131
{9111B35C-3DBC-45A8-8795-7DC2E2400B82}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{20398DD0-3F56-4D3E-AA53-3C14BFCB011E}.Release|Any CPU.Build.0 = Release|Any CPU
2236
EndGlobalSection
2337
GlobalSection(SolutionProperties) = preSolution
2438
HideSolutionNode = FALSE

UnitTests/DirectoryTests.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright © 2023, De Bitmanager
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Bitmanager.Core;
18+
using Bitmanager.Test;
19+
using AlbumImporter;
20+
21+
namespace UnitTests {
22+
[TestClass]
23+
public class DirectoryTests: TestBaseSimple {
24+
private readonly DirectoryMetaExtractor dir = new DirectoryMetaExtractor ();
25+
[TestMethod]
26+
public void TestDirectoryExtract () {
27+
check (null, null, @"");
28+
check (null, null, @"c:");
29+
check (null, null, @"c:\");
30+
check ("aap", null, @"c:\aap");
31+
check (null, null, @"c:\");
32+
33+
check ("1993-1994", "1993-01-01", @"c:\1993 - 1994 ");
34+
check ("geboorte kim", "1993-01-01", @"c\1993 geboorte kim ");
35+
check ("geboorte kim", "1993-01-01", @"c\1993 geboorte kim \123");
36+
check ("geboorte kim", "1993-03-01", @"c\1993\03\ geboorte kim");
37+
check ("geboorte kim", "1993-03-05", @"c\1993\03\05 geboorte kim");
38+
check ("geboorte kim", "1993-03-05", @"c\1993\0305 geboorte kim");
39+
check ("geboorte kim", "1994-03-05", @"c\1993\19940305 geboorte kim");
40+
check ("aap", "1993-01-01", @"c\1993 geboorte kim \aap");
41+
check (null, "1993-04-01", @"c\1993\04");
42+
check ("Zeiltocht Thijs", "1995-01-01", @"D:\Fotos\Medialab\1995 - Zeiltocht Thijs");
43+
44+
}
45+
46+
47+
//root: skip_dir_names=2
48+
//lvl1: skip_dir_names=?
49+
//lvl2: skip_dir_names=?
50+
//lvl3: skip_dir_names=0
51+
//lvl4: skip_dir_names=?
52+
[TestMethod]
53+
public void TestSettings() {
54+
string root = base.testAssembly.FindDirectoryToRoot ("data", Bitmanager.IO.FindToTootFlags.Except);
55+
string deepest = Path.Combine (root, @"lvl1\lvl2\lvl3\lvl4");
56+
var cache = new DirectorySettingsCache (null);
57+
var settings4 = cache.GetSettings (deepest, root.Length);
58+
deepest = Path.GetDirectoryName (deepest);
59+
var settings3 = cache.GetSettings (deepest, root.Length);
60+
deepest = Path.GetDirectoryName (deepest);
61+
var settings2 = cache.GetSettings (deepest, root.Length);
62+
deepest = Path.GetDirectoryName (deepest);
63+
var settings1 = cache.GetSettings (deepest, root.Length);
64+
deepest = Path.GetDirectoryName (deepest);
65+
var settings0 = cache.GetSettings (deepest, root.Length);
66+
67+
Assert.AreEqual (0, settings0.Names.Length);
68+
Assert.AreEqual (0, settings1.Names.Length);
69+
Assert.AreEqual (1, settings2.Names.Length);
70+
Assert.AreEqual ("lvl2", settings2.Names[0]);
71+
Assert.AreEqual (1, settings3.Names.Length);
72+
Assert.AreEqual ("lvl3", settings3.Names[0]);
73+
Assert.AreEqual (2, settings4.Names.Length);
74+
Assert.AreEqual ("lvl3", settings4.Names[0]);
75+
Assert.AreEqual ("lvl4", settings4.Names[1]);
76+
77+
}
78+
79+
private void check (string album, string date, string name) {
80+
var cache = new DirectorySettingsCache (null);
81+
82+
dir.Extract (cache.GetSettings(name, 3));
83+
Assert.AreEqual (date, dir.StrDate);
84+
Assert.AreEqual (album, dir.Album);
85+
}
86+
}
87+
}

UnitTests/FileTests.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Copyright © 2023, De Bitmanager
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
using Microsoft.VisualStudio.TestTools.UnitTesting;
16+
using AlbumImporter;
17+
18+
namespace UnitTests {
19+
[TestClass]
20+
public class FileTests {
21+
private readonly FileMetaExtractor extractor = new FileMetaExtractor ();
22+
private readonly DateTime testDate = new DateTime (2023, 2, 1, 12, 3, 4, DateTimeKind.Local);
23+
24+
[TestMethod]
25+
public void TestExtract () {
26+
check (null, null, 1, null, "img001.jpg");
27+
check (null, null, 1, null, "img-001.jpg");
28+
check (null, null, 1, null, "sam-001.jpg");
29+
check (null, null, 1, null, "p-001.jpg");
30+
check (null, null, 195, null, "Afbeelding 195.jpg");
31+
check ("WhatsApp", "2023-02-01", 6, null, "IMG-20230709-WA0006.jpg");
32+
check ("BFYV6816", null, 0, null, "BFYV6816.jpg");
33+
check ("BFYV6816", "2022-08-14", 0, null, "20220814_214413 BFYV6816.jpg");
34+
check ("Familiedag 2023", "2023-06-17", 0, "D", "20230617_120214 Familiedag 2023(D)");
35+
check ("1e van 29 mei 2000", null, 137, null, "137 1e van 29 mei 2000.jpg");
36+
check ("wilma", "2022-08-14", 0, null, @"wilma\20220814_214413.jpg");
37+
check (null, "2023-04-01", 570, null, @"2023\04\SGDN0570.JPG");
38+
check ("aap", "2022-08-14", 23, "P", @"wilma\20220814_214413 aap(P)_23.jpg");
39+
40+
check ("fotos", null, 1693, null, @"D\dakkapel\fotos\IMG_1693.JPG");
41+
check ("fotos", null, 1693, null, @"D\dakkapel\fotos\IMG_1693_1.JPG");
42+
check ("Zeiltocht Thijs", "1995-01-01", 2, null, @"D:\Fotos\Medialab\1995 - Zeiltocht Thijs\002.jpg");
43+
check ("Zeiltocht Thijs", "1995-01-01", 0, null, @"D:\Fotos\Medialab\1995 - Zeiltocht Thijs.jpg");
44+
check ("Zeiltocht Thijs", "1995-02-03", 0, null, @"D:\Fotos\Medialab\1995-02-03 - Zeiltocht Thijs.jpg");
45+
check ("Zeiltocht Thijs", "1995-02-03", 0, null, @"D:\Fotos\Medialab\1995\02-03 - Zeiltocht Thijs.jpg");
46+
}
47+
48+
private DirectorySettings getSettings(string name) {
49+
var c = new DirectorySettingsCache(null);
50+
return c.GetSettings(Path.GetDirectoryName(name), 0);
51+
}
52+
private void check (string album, string date, int order, string extra, string name) {
53+
54+
extractor.Extract (getSettings(name), name, testDate);
55+
Assert.AreEqual (date, extractor.StrDate);
56+
Assert.AreEqual (album, extractor.Album);
57+
Assert.AreEqual (extra, extractor.Extra);
58+
Assert.AreEqual (order, extractor.Order);
59+
}
60+
private void check (string album, string date, string name, bool needDate=true) {
61+
extractor.Extract (getSettings (name), name, testDate);
62+
Assert.AreEqual (date, extractor.StrDate);
63+
Assert.AreEqual (album, extractor.Album);
64+
Assert.AreEqual (null, extractor.Extra);
65+
Assert.AreEqual (0, extractor.Order);
66+
}
67+
68+
}
69+
}

UnitTests/GlobalUsings.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright © 2023, De Bitmanager
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
global using Microsoft.VisualStudio.TestTools.UnitTesting;

UnitTests/Playground.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using AlbumImporter;
3+
using Bitmanager.Test;
4+
using Bitmanager.Json;
5+
using Bitmanager.Xml;
6+
using Bitmanager.ImportPipeline;
7+
using Bitmanager.Core;
8+
using Bitmanager.IO;
9+
10+
namespace UnitTests {
11+
/// <summary>
12+
/// This is not realy a test case. More a playground to quickly check something
13+
/// </summary>
14+
[TestClass]
15+
public class PlayGroundTests : TestBaseSimple {
16+
private string root;
17+
public PlayGroundTests() {
18+
root = testAssembly.FindDirectoryToRoot ("data", FindToTootFlags.Except);
19+
}
20+
21+
22+
[TestMethod]
23+
public void TestPipeline () {
24+
JsonObjectValue result;
25+
result = execPipeline (@"Some file");
26+
//Check the result object
27+
}
28+
29+
private JsonObjectValue execPipeline (string file) {
30+
var xml = new XmlHelper(Path.Combine (root, "playground.xml"));
31+
xml.WriteVal ("datasources/datasource/id/@file", file);
32+
using (var engine = new ImportEngine ()) {
33+
engine.Load (xml);
34+
var report = engine.Import ();
35+
if (report.ErrorState != _ErrorState.OK)
36+
throw new BMException (report.ErrorMessage);
37+
var output = engine.Output;
38+
if (output == null) throw new BMException ("Pipeline generated no output");
39+
Assert.AreEqual (1, output.Count);
40+
logger.Log (output[0].ToJsonString ());
41+
return output[0];
42+
}
43+
}
44+
45+
}
46+
}

0 commit comments

Comments
 (0)