-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include some testcases and solution files
- Loading branch information
Showing
16 changed files
with
313 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.