From 7982e7e3fe93c145666a10ee198b9023ad10213e Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 24 Dec 2015 08:38:21 +0300 Subject: [PATCH] msvc unittests for dlangui --- dlangui-msvc.sln | 38 +++++ dlangui-msvc.visualdproj | 217 +++++++++++++++++++++++-- src/dlangui/core/css.d | 48 +++--- src/dlangui/core/dom.d | 65 ++++---- src/dlangui/platforms/common/startup.d | 19 +++ 5 files changed, 316 insertions(+), 71 deletions(-) diff --git a/dlangui-msvc.sln b/dlangui-msvc.sln index bd813809..9d7fba3b 100644 --- a/dlangui-msvc.sln +++ b/dlangui-msvc.sln @@ -51,6 +51,8 @@ Global Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 + Unittest|Win32 = Unittest|Win32 + Unittest|x64 = Unittest|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Debug|Win32.ActiveCfg = Debug|Win32 @@ -61,6 +63,10 @@ Global {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Release|Win32.Build.0 = Release|Win32 {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Release|x64.ActiveCfg = Release|x64 {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Release|x64.Build.0 = Release|x64 + {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Unittest|Win32.ActiveCfg = Unittest|Win32 + {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Unittest|Win32.Build.0 = Unittest|Win32 + {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Unittest|x64.ActiveCfg = Unittest|x64 + {52A2ABB9-2CF7-4D5F-AE8C-75B21F8585A5}.Unittest|x64.Build.0 = Unittest|x64 {1C8C4726-B356-4533-90C7-88BDA875BF30}.Debug|Win32.ActiveCfg = Debug|Win32 {1C8C4726-B356-4533-90C7-88BDA875BF30}.Debug|Win32.Build.0 = Debug|Win32 {1C8C4726-B356-4533-90C7-88BDA875BF30}.Debug|x64.ActiveCfg = Debug|x64 @@ -69,6 +75,10 @@ Global {1C8C4726-B356-4533-90C7-88BDA875BF30}.Release|Win32.Build.0 = Release|Win32 {1C8C4726-B356-4533-90C7-88BDA875BF30}.Release|x64.ActiveCfg = Release|x64 {1C8C4726-B356-4533-90C7-88BDA875BF30}.Release|x64.Build.0 = Release|x64 + {1C8C4726-B356-4533-90C7-88BDA875BF30}.Unittest|Win32.ActiveCfg = Release|Win32 + {1C8C4726-B356-4533-90C7-88BDA875BF30}.Unittest|Win32.Build.0 = Release|Win32 + {1C8C4726-B356-4533-90C7-88BDA875BF30}.Unittest|x64.ActiveCfg = Release|x64 + {1C8C4726-B356-4533-90C7-88BDA875BF30}.Unittest|x64.Build.0 = Release|x64 {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Debug|Win32.ActiveCfg = Debug|Win32 {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Debug|Win32.Build.0 = Debug|Win32 {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Debug|x64.ActiveCfg = Debug|x64 @@ -77,6 +87,10 @@ Global {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Release|Win32.Build.0 = Release|Win32 {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Release|x64.ActiveCfg = Release|x64 {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Release|x64.Build.0 = Release|x64 + {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Unittest|Win32.ActiveCfg = Release|Win32 + {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Unittest|Win32.Build.0 = Release|Win32 + {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Unittest|x64.ActiveCfg = Release|x64 + {79EA1B6E-D87E-4C45-A12D-7AD00C398F1F}.Unittest|x64.Build.0 = Release|x64 {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Debug|Win32.ActiveCfg = Debug|Win32 {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Debug|Win32.Build.0 = Debug|Win32 {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Debug|x64.ActiveCfg = Debug|x64 @@ -85,6 +99,10 @@ Global {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Release|Win32.Build.0 = Release|Win32 {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Release|x64.ActiveCfg = Release|x64 {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Release|x64.Build.0 = Release|x64 + {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Unittest|Win32.ActiveCfg = Release|Win32 + {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Unittest|Win32.Build.0 = Release|Win32 + {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Unittest|x64.ActiveCfg = Release|x64 + {B1CA031C-C195-4938-8F3E-8BFF7DA68933}.Unittest|x64.Build.0 = Release|x64 {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Debug|Win32.ActiveCfg = Debug|Win32 {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Debug|Win32.Build.0 = Debug|Win32 {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Debug|x64.ActiveCfg = Debug|x64 @@ -93,6 +111,10 @@ Global {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Release|Win32.Build.0 = Release|Win32 {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Release|x64.ActiveCfg = Release|x64 {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Release|x64.Build.0 = Release|x64 + {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Unittest|Win32.ActiveCfg = Release|Win32 + {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Unittest|Win32.Build.0 = Release|Win32 + {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Unittest|x64.ActiveCfg = Release|x64 + {9F5147FF-DB71-4CEC-BF2F-803143E42BCD}.Unittest|x64.Build.0 = Release|x64 {954B6A84-1EEC-42B0-B215-2A17842B1101}.Debug|Win32.ActiveCfg = Debug|Win32 {954B6A84-1EEC-42B0-B215-2A17842B1101}.Debug|Win32.Build.0 = Debug|Win32 {954B6A84-1EEC-42B0-B215-2A17842B1101}.Debug|x64.ActiveCfg = Debug|x64 @@ -101,12 +123,20 @@ Global {954B6A84-1EEC-42B0-B215-2A17842B1101}.Release|Win32.Build.0 = Release|Win32 {954B6A84-1EEC-42B0-B215-2A17842B1101}.Release|x64.ActiveCfg = Release|x64 {954B6A84-1EEC-42B0-B215-2A17842B1101}.Release|x64.Build.0 = Release|x64 + {954B6A84-1EEC-42B0-B215-2A17842B1101}.Unittest|Win32.ActiveCfg = Release|Win32 + {954B6A84-1EEC-42B0-B215-2A17842B1101}.Unittest|Win32.Build.0 = Release|Win32 + {954B6A84-1EEC-42B0-B215-2A17842B1101}.Unittest|x64.ActiveCfg = Release|x64 + {954B6A84-1EEC-42B0-B215-2A17842B1101}.Unittest|x64.Build.0 = Release|x64 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Debug|Win32.ActiveCfg = Debug|Win32 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Debug|Win32.Build.0 = Debug|Win32 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Debug|x64.ActiveCfg = Debug|x64 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Release|Win32.ActiveCfg = Release|Win32 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Release|Win32.Build.0 = Release|Win32 {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Release|x64.ActiveCfg = Release|x64 + {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Unittest|Win32.ActiveCfg = Release|Win32 + {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Unittest|Win32.Build.0 = Release|Win32 + {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Unittest|x64.ActiveCfg = Release|x64 + {DA4E9F22-21EB-4A71-AF1F-3B5BC370CBA0}.Unittest|x64.Build.0 = Release|x64 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Debug|Win32.ActiveCfg = Debug|Win32 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Debug|Win32.Build.0 = Debug|Win32 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Debug|x64.ActiveCfg = Debug|x64 @@ -114,12 +144,20 @@ Global {533AF38D-98E7-446F-9689-805BDFF3CE84}.Release|Win32.ActiveCfg = Release|Win32 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Release|Win32.Build.0 = Release|Win32 {533AF38D-98E7-446F-9689-805BDFF3CE84}.Release|x64.ActiveCfg = Release|x64 + {533AF38D-98E7-446F-9689-805BDFF3CE84}.Unittest|Win32.ActiveCfg = Release|Win32 + {533AF38D-98E7-446F-9689-805BDFF3CE84}.Unittest|Win32.Build.0 = Release|Win32 + {533AF38D-98E7-446F-9689-805BDFF3CE84}.Unittest|x64.ActiveCfg = Release|x64 + {533AF38D-98E7-446F-9689-805BDFF3CE84}.Unittest|x64.Build.0 = Release|x64 {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Debug|Win32.ActiveCfg = Debug|Win32 {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Debug|Win32.Build.0 = Debug|Win32 {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Debug|x64.ActiveCfg = Debug|x64 {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Release|Win32.ActiveCfg = Release|Win32 {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Release|Win32.Build.0 = Release|Win32 {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Release|x64.ActiveCfg = Release|x64 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Unittest|Win32.ActiveCfg = Release|Win32 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Unittest|Win32.Build.0 = Release|Win32 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Unittest|x64.ActiveCfg = Release|x64 + {29CF2CAC-2C0C-4F17-9292-E1706AC7EBBF}.Unittest|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/dlangui-msvc.visualdproj b/dlangui-msvc.visualdproj index 33fea24b..632890b9 100644 --- a/dlangui-msvc.visualdproj +++ b/dlangui-msvc.visualdproj @@ -33,7 +33,7 @@ 0 0 0 - 1 + 0 0 0 0 @@ -44,7 +44,7 @@ 0 0 0 - 2.043 + 2 0 0 0 @@ -102,6 +102,108 @@ *.obj;*.cmd;*.build;*.json;*.dep + + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + + views views/res views/res/i18n views/res/mdpi views/res/hdpi + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + EmbedStandardResources ForceLogs + 0 + 0 + 0 + + + + 0 + + 1 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + + + + + $(OutDir)\$(ProjectName).exe + 1 + 2 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + 0 0 @@ -306,6 +408,108 @@ *.obj;*.cmd;*.build;*.json;*.dep + + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 0 + 0 + 0 + $(CC) -c + 1 + $(DMDInstallDir)windows\bin\dmd.exe + + views views/res views/res/i18n views/res/mdpi views/res/hdpi + $(ConfigurationName) + $(OutDir) + + + 0 + + + + + 0 + + + 1 + $(IntDir)\$(TargetName).json + 0 + + 0 + EmbedStandardResources ForceLogs + 0 + 0 + 0 + + + + 0 + + 1 + $(VisualDInstallDir)cv2pdb\cv2pdb.exe + 0 + 0 + 0 + + + + + + + + $(OutDir)\$(ProjectName).lib + 1 + 2 + 0 + + + + *.obj;*.cmd;*.build;*.json;*.dep + 0 0 @@ -467,15 +671,6 @@ - - - - - - - - - diff --git a/src/dlangui/core/css.d b/src/dlangui/core/css.d index 6deb2e82..31504aba 100644 --- a/src/dlangui/core/css.d +++ b/src/dlangui/core/css.d @@ -609,29 +609,27 @@ private bool parseColor(ref string src, ref CssLength value) } -version(unittest) { - void testCSS() { - CssStyle style = new CssStyle(); - CssDeclaration decl = new CssDeclaration(); - CssWhiteSpace whiteSpace = CssWhiteSpace.inherit; - CssTextAlign textAlign = CssTextAlign.inherit; - CssTextAlign textAlignLast = CssTextAlign.inherit; - CssTextDecoration textDecoration = CssTextDecoration.inherit; - CssHyphenate hyphenate = CssHyphenate.inherit; - string src = "{ display: inline; text-decoration: underline; white-space: pre; text-align: right; text-align-last: left; hyphenate: auto }"; - assert(decl.parse(src, true)); - assert(style.display == CssDisplay.block); - assert(style.textDecoration == CssTextDecoration.inherit); - assert(style.whiteSpace == CssWhiteSpace.inherit); - assert(style.textAlign == CssTextAlign.inherit); - assert(style.textAlignLast == CssTextAlign.inherit); - assert(style.hyphenate == CssHyphenate.inherit); - decl.apply(style); - assert(style.display == CssDisplay.inline); - assert(style.textDecoration == CssTextDecoration.underline); - assert(style.whiteSpace == CssWhiteSpace.pre); - assert(style.textAlign == CssTextAlign.right); - assert(style.textAlignLast == CssTextAlign.left); - assert(style.hyphenate == CssHyphenate.auto_); - } +unittest { + CssStyle style = new CssStyle(); + CssDeclaration decl = new CssDeclaration(); + CssWhiteSpace whiteSpace = CssWhiteSpace.inherit; + CssTextAlign textAlign = CssTextAlign.inherit; + CssTextAlign textAlignLast = CssTextAlign.inherit; + CssTextDecoration textDecoration = CssTextDecoration.inherit; + CssHyphenate hyphenate = CssHyphenate.inherit; + string src = "{ display: inline; text-decoration: underline; white-space: pre; text-align: right; text-align-last: left; hyphenate: auto }"; + assert(decl.parse(src, true)); + assert(style.display == CssDisplay.block); + assert(style.textDecoration == CssTextDecoration.inherit); + assert(style.whiteSpace == CssWhiteSpace.inherit); + assert(style.textAlign == CssTextAlign.inherit); + assert(style.textAlignLast == CssTextAlign.inherit); + assert(style.hyphenate == CssHyphenate.inherit); + decl.apply(style); + assert(style.display == CssDisplay.inline); + assert(style.textDecoration == CssTextDecoration.underline); + assert(style.whiteSpace == CssWhiteSpace.pre); + assert(style.textAlign == CssTextAlign.right); + assert(style.textAlignLast == CssTextAlign.left); + assert(style.hyphenate == CssHyphenate.auto_); } diff --git a/src/dlangui/core/dom.d b/src/dlangui/core/dom.d index a3d1f70d..b75bcb4e 100644 --- a/src/dlangui/core/dom.d +++ b/src/dlangui/core/dom.d @@ -403,40 +403,35 @@ enum Ns : ns_id { xsi } -version(unittest) { - void testDOM() { - import std.algorithm : equal; - //import std.stdio; - IdentMap!(elem_id) map; - map.init!Tag(); - //writeln("running DOM unit test"); - assert(map["pre"] == Tag.pre); - assert(map["body"] == Tag.body_); - assert(map[Tag.div].equal("div")); - - Document doc = new Document(); - auto body_ = doc.appendElement(null, "body"); - assert(body_.id == Tag.body_); - assert(body_.name.equal("body")); - auto div = body_.appendElement(null, "div"); - assert(body_.childCount == 1); - assert(div.id == Tag.div); - assert(div.name.equal("div")); - auto t1 = div.appendText("Some text"d); - assert(div.childCount == 1); - assert(div.child(0).text.equal("Some text"d)); - auto t2 = div.appendText("Some more text"d); - assert(div.childCount == 2); - assert(div.childIndex(t1) == 0); - assert(div.childIndex(t2) == 1); - - div.setAttr(Ns.none, Attr.id, "div_id"); - assert(div.attrValue(Ns.none, Attr.id).equal("div_id")); - - destroy(doc); - } -} - unittest { - testDOM(); + import std.algorithm : equal; + //import std.stdio; + IdentMap!(elem_id) map; + map.init!Tag(); + //writeln("running DOM unit test"); + assert(map["pre"] == Tag.pre); + assert(map["body"] == Tag.body_); + assert(map[Tag.div].equal("div")); + + Document doc = new Document(); + auto body_ = doc.appendElement(null, "body"); + assert(body_.id == Tag.body_); + assert(body_.name.equal("body")); + auto div = body_.appendElement(null, "div"); + assert(body_.childCount == 1); + assert(div.id == Tag.div); + assert(div.name.equal("div")); + auto t1 = div.appendText("Some text"d); + assert(div.childCount == 1); + assert(div.child(0).text.equal("Some text"d)); + auto t2 = div.appendText("Some more text"d); + assert(div.childCount == 2); + assert(div.childIndex(t1) == 0); + assert(div.childIndex(t2) == 1); + + div.setAttr(Ns.none, Attr.id, "div_id"); + assert(div.attrValue(Ns.none, Attr.id).equal("div_id")); + + destroy(doc); } + diff --git a/src/dlangui/platforms/common/startup.d b/src/dlangui/platforms/common/startup.d index 034848d2..af1dbe43 100644 --- a/src/dlangui/platforms/common/startup.d +++ b/src/dlangui/platforms/common/startup.d @@ -252,3 +252,22 @@ extern (C) void releaseResourcesOnAppExit() { } } } + +version(unittest) { + version (Windows) { + mixin APP_ENTRY_POINT; + + /// entry point for dlangui based application + extern (C) int UIAppMain(string[] args) { + // just to enable running unit tests + import core.runtime; + import std.stdio; + if (!runModuleUnitTests()) { + writeln("Error occured in unit tests. Press enter."); + readln(); + return 1; + } + return 0; + } + } +}