From ef55d94ae90e58f7dc60e91f93306b5d52875ce3 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 28 Jul 2021 14:18:39 +0800 Subject: [PATCH] add unit test and finish operator test --- BallanceTASEditor.sln | 8 +- App.xaml => BallanceTASEditor/App.xaml | 0 App.xaml.cs => BallanceTASEditor/App.xaml.cs | 0 .../BallanceTASEditor.csproj | 8 +- .../Core}/ClipboardUtil.cs | 0 .../Core}/FileOperation.cs | 222 ++++++++++-------- .../Core}/KeyboardState.cs | 0 .../Core}/LimitedStack.cs | 0 {Core => BallanceTASEditor/Core}/TASFile.cs | 37 ++- {Core => BallanceTASEditor/Core}/TASStruct.cs | 0 {Core => BallanceTASEditor/Core}/Util.cs | 2 +- {Core => BallanceTASEditor/Core}/ZlibUtil.cs | 0 .../MainWindow.xaml | 0 .../MainWindow.xaml.cs | 0 .../Properties}/AssemblyInfo.cs | 0 .../Properties}/Resources.Designer.cs | 35 +-- .../Properties}/Resources.resx | 0 .../Properties}/Settings.Designer.cs | 18 +- .../Properties}/Settings.settings | 0 {UI => BallanceTASEditor/UI}/AddItem.xaml | 0 {UI => BallanceTASEditor/UI}/AddItem.xaml.cs | 0 {UI => BallanceTASEditor/UI}/DialogUtil.cs | 0 {UI => BallanceTASEditor/UI}/OperationEnum.cs | 0 {UI => BallanceTASEditor/UI}/SelectionHelp.cs | 0 .../UI}/StyleConverter.cs | 0 {UI => BallanceTASEditor/UI}/TASFlow.xaml | 0 {UI => BallanceTASEditor/UI}/TASFlow.xaml.cs | 0 {UI => BallanceTASEditor/UI}/TASViewer.cs | 0 {UI => BallanceTASEditor/UI}/Util.cs | 0 BallanceTASEditor/app.config | 3 + .../packages.config | 0 .../BallanceTASEditorTests.csproj | 108 +++++++++ BallanceTASEditorTests/Core/TASFileTests.cs | 164 +++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++ BallanceTASEditorTests/packages.config | 5 + 35 files changed, 510 insertions(+), 136 deletions(-) rename App.xaml => BallanceTASEditor/App.xaml (100%) rename App.xaml.cs => BallanceTASEditor/App.xaml.cs (100%) rename BallanceTASEditor.csproj => BallanceTASEditor/BallanceTASEditor.csproj (95%) rename {Core => BallanceTASEditor/Core}/ClipboardUtil.cs (100%) rename {Core => BallanceTASEditor/Core}/FileOperation.cs (71%) rename {Core => BallanceTASEditor/Core}/KeyboardState.cs (100%) rename {Core => BallanceTASEditor/Core}/LimitedStack.cs (100%) rename {Core => BallanceTASEditor/Core}/TASFile.cs (88%) rename {Core => BallanceTASEditor/Core}/TASStruct.cs (100%) rename {Core => BallanceTASEditor/Core}/Util.cs (99%) rename {Core => BallanceTASEditor/Core}/ZlibUtil.cs (100%) rename MainWindow.xaml => BallanceTASEditor/MainWindow.xaml (100%) rename MainWindow.xaml.cs => BallanceTASEditor/MainWindow.xaml.cs (100%) rename {Properties => BallanceTASEditor/Properties}/AssemblyInfo.cs (100%) rename {Properties => BallanceTASEditor/Properties}/Resources.Designer.cs (74%) rename {Properties => BallanceTASEditor/Properties}/Resources.resx (100%) rename {Properties => BallanceTASEditor/Properties}/Settings.Designer.cs (76%) rename {Properties => BallanceTASEditor/Properties}/Settings.settings (100%) rename {UI => BallanceTASEditor/UI}/AddItem.xaml (100%) rename {UI => BallanceTASEditor/UI}/AddItem.xaml.cs (100%) rename {UI => BallanceTASEditor/UI}/DialogUtil.cs (100%) rename {UI => BallanceTASEditor/UI}/OperationEnum.cs (100%) rename {UI => BallanceTASEditor/UI}/SelectionHelp.cs (100%) rename {UI => BallanceTASEditor/UI}/StyleConverter.cs (100%) rename {UI => BallanceTASEditor/UI}/TASFlow.xaml (100%) rename {UI => BallanceTASEditor/UI}/TASFlow.xaml.cs (100%) rename {UI => BallanceTASEditor/UI}/TASViewer.cs (100%) rename {UI => BallanceTASEditor/UI}/Util.cs (100%) create mode 100644 BallanceTASEditor/app.config rename packages.config => BallanceTASEditor/packages.config (100%) create mode 100644 BallanceTASEditorTests/BallanceTASEditorTests.csproj create mode 100644 BallanceTASEditorTests/Core/TASFileTests.cs create mode 100644 BallanceTASEditorTests/Properties/AssemblyInfo.cs create mode 100644 BallanceTASEditorTests/packages.config diff --git a/BallanceTASEditor.sln b/BallanceTASEditor.sln index ed2152a..a85ad1a 100644 --- a/BallanceTASEditor.sln +++ b/BallanceTASEditor.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29418.71 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BallanceTASEditor", "BallanceTASEditor.csproj", "{3127A635-B9E5-4C78-8414-0B9B196EC25E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BallanceTASEditor", "BallanceTASEditor\BallanceTASEditor.csproj", "{3127A635-B9E5-4C78-8414-0B9B196EC25E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BallanceTASEditorTests", "BallanceTASEditorTests\BallanceTASEditorTests.csproj", "{EC35111D-6259-4C69-B7E4-F4E727AC0E1A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {3127A635-B9E5-4C78-8414-0B9B196EC25E}.Debug|Any CPU.Build.0 = Debug|Any CPU {3127A635-B9E5-4C78-8414-0B9B196EC25E}.Release|Any CPU.ActiveCfg = Release|Any CPU {3127A635-B9E5-4C78-8414-0B9B196EC25E}.Release|Any CPU.Build.0 = Release|Any CPU + {EC35111D-6259-4C69-B7E4-F4E727AC0E1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC35111D-6259-4C69-B7E4-F4E727AC0E1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC35111D-6259-4C69-B7E4-F4E727AC0E1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC35111D-6259-4C69-B7E4-F4E727AC0E1A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/App.xaml b/BallanceTASEditor/App.xaml similarity index 100% rename from App.xaml rename to BallanceTASEditor/App.xaml diff --git a/App.xaml.cs b/BallanceTASEditor/App.xaml.cs similarity index 100% rename from App.xaml.cs rename to BallanceTASEditor/App.xaml.cs diff --git a/BallanceTASEditor.csproj b/BallanceTASEditor/BallanceTASEditor.csproj similarity index 95% rename from BallanceTASEditor.csproj rename to BallanceTASEditor/BallanceTASEditor.csproj index f58ed89..47518ce 100644 --- a/BallanceTASEditor.csproj +++ b/BallanceTASEditor/BallanceTASEditor.csproj @@ -8,11 +8,12 @@ WinExe BallanceTASEditor BallanceTASEditor - v4.0 + v4.5 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true + AnyCPU @@ -23,6 +24,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -32,6 +34,7 @@ TRACE prompt 4 + false @@ -49,7 +52,7 @@ - packages\zlib.net.1.0.4.0\lib\zlib.net.dll + ..\packages\zlib.net.1.0.4.0\lib\zlib.net.dll @@ -116,6 +119,7 @@ ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator diff --git a/Core/ClipboardUtil.cs b/BallanceTASEditor/Core/ClipboardUtil.cs similarity index 100% rename from Core/ClipboardUtil.cs rename to BallanceTASEditor/Core/ClipboardUtil.cs diff --git a/Core/FileOperation.cs b/BallanceTASEditor/Core/FileOperation.cs similarity index 71% rename from Core/FileOperation.cs rename to BallanceTASEditor/Core/FileOperation.cs index 6562d2b..8f33f55 100644 --- a/Core/FileOperation.cs +++ b/BallanceTASEditor/Core/FileOperation.cs @@ -29,6 +29,7 @@ namespace BallanceTASEditor.Core.FileOperation { private bool? isSet; private uint internalOffset; + private List changedItems; public SetOperation(SelectionRange _field, SelectionRange _absoluteRange, bool? _isSet) : base() { field = _field; @@ -40,13 +41,19 @@ namespace BallanceTASEditor.Core.FileOperation { for (int i = (int)field.start; i <= (int)field.end; i++) { internalOffset |= ConstValue.Mapping[(FrameDataField)i]; } + + changedItems = new List(); } public override void Do(ref LinkedList mMem, ref LinkedListNode mPointer, ref long mPointerIndex) { base.Do(ref mMem, ref mPointer, ref mPointerIndex); if (mPointer == null) return; + changedItems.Clear(); foreach (var item in mMem.IterateWithSelectionRange(absoluteRange, mPointer, mPointerIndex)) { + // backup item first + changedItems.Add(item.Value.keystates); + if (isSet == null) item.Value.ReverseKeyStates(internalOffset); else if (isSet == true) item.Value.SetKeyStates(internalOffset); else if (isSet == false) item.Value.UnsetKeyStates(internalOffset); @@ -57,11 +64,11 @@ namespace BallanceTASEditor.Core.FileOperation { base.Undo(ref mMem, ref mPointer, ref mPointerIndex); if (mPointer == null) return; + int counter = 0; foreach (var item in mMem.IterateWithSelectionRange(absoluteRange, mPointer, mPointerIndex)) { - // just like do operation, but switch set and unset operation - if (isSet == null) item.Value.ReverseKeyStates(internalOffset); - else if (isSet == true) item.Value.UnsetKeyStates(internalOffset); - else if (isSet == false) item.Value.SetKeyStates(internalOffset); + // restore data + item.Value.keystates = changedItems[counter]; + counter++; } } } @@ -93,7 +100,7 @@ namespace BallanceTASEditor.Core.FileOperation { // find proper pointer after remove first. but we do not apply it in there. // if state is true, it mean the deleted content is placed before pointer previously. we should consider pointer data and we should correct them. - LinkedListNode newPointer; + LinkedListNode newPointer; long newPointerIndex; if (mPointerIndex >= absoluteRange.start) { // if point within removed content, we need to shift it to the head of removed content, @@ -215,7 +222,8 @@ namespace BallanceTASEditor.Core.FileOperation { // if the items are added before pointer, the index should add with the count of added items // but pointer don't need to be shifted. - if (mPointerIndex > absolutePos) + if ((isAddBefore && mPointerIndex >= absolutePos) || + (!isAddBefore && mPointerIndex > absolutePos)) mPointerIndex += count; } } @@ -245,7 +253,7 @@ namespace BallanceTASEditor.Core.FileOperation { mPointerIndex = oldPointerIndex; } } - + public class InsertOperation : RevocableOperation { private long absolutePos; private LinkedList data; @@ -253,32 +261,39 @@ namespace BallanceTASEditor.Core.FileOperation { private bool isOverwritten; private LinkedListNode addStartNode; - private LinkedList oldItems; + private bool isBlankList; private LinkedListNode oldPointer; private long oldPointerIndex; + // because insert including remove oeration(overwritten mode) + // so we need include this for code re-use + private RemoveOperation internalRemoveOper; + + private const long LINKEDLIST_HEAD = -1; + private const long LINKEDLIST_TAIL = -2; + public InsertOperation(long _absolutePos, LinkedList _data, bool _isInsertBefore, bool _isOverwritten) : base() { absolutePos = _absolutePos; data = _data; isInsertBefore = _isInsertBefore; isOverwritten = _isOverwritten; - oldItems = new LinkedList(); } public override void Do(ref LinkedList mMem, ref LinkedListNode mPointer, ref long mPointerIndex) { base.Do(ref mMem, ref mPointer, ref mPointerIndex); if (data.Count == 0) return; - // init backups list and backups 2 data - oldItems.Clear(); - oldPointer = mPointer; - oldPointerIndex = mPointerIndex; + // because this oper have internal oper, so we need backup data after potential remove oper + // so in there, no object need to be backuped // if the list is blank, overwritten is invalid, just normal add them. if (mPointer == null) { - // backups start pointer + // backups + oldPointer = mPointer; + oldPointerIndex = mPointerIndex; addStartNode = null; + isBlankList = true; foreach (var item in data.IterateFull()) { mMem.AddFirst(item.Value); @@ -287,6 +302,12 @@ namespace BallanceTASEditor.Core.FileOperation { mPointerIndex = 0; } else { LinkedListNode node = mMem.FastGetNode(mPointer, mPointerIndex, absolutePos); + + // absolutePos is class member and shouldn't be changed. + // but in overwritten mode, this value need to be changed so we create a temp value in there + // to instead the fucntion of original variable + var modifiedAbsolutePos = absolutePos; + // if list is not a blank list, we should consider overwritten // if in overwritten mode, we need to overwrite data from selected item. // otherwise, not in overwritten mode, just normally add them just like add operation. @@ -294,83 +315,80 @@ namespace BallanceTASEditor.Core.FileOperation { // in overwritten mode, if follwoing item is not enough to fufill the count of overwritten data // normally add them // we use delete and add method to do this - // another protential dangerous spot is pointer can be overwritten, its dangerous, - // so we need create a backup pos to store its relative postion and in add stage set pointer to the new data. + + // now, try init internal remove oper if in overwritten mode + // first, we need compare the length of remained item located in mMem and the length of added item + // then construct remove oper + long remainLength; + if (isInsertBefore) remainLength = absolutePos + 1; + else remainLength = mMem.Count - absolutePos; + + long dataLength = data.Count; + long expectedLength = dataLength > remainLength ? remainLength : dataLength; + long expectedPos; + if (isInsertBefore) expectedPos = absolutePos - expectedLength + 1; + else expectedPos = absolutePos + expectedLength - 1; + + if (isInsertBefore) + internalRemoveOper = new RemoveOperation(new SelectionRange(expectedPos, absolutePos)); + else + internalRemoveOper = new RemoveOperation(new SelectionRange(absolutePos, expectedPos)); - var backupsNode = isInsertBefore ? node.Next : node.Previous; - // backups start pointer - addStartNode = backupsNode; - - long gottenPointerPos = -1; - for(long i = 0; i < data.Count; i++) { - if (node == null) break; - if (node == mPointer) gottenPointerPos = i; - mMem.Remove(node); - - // backup and shift to next - if (isInsertBefore) { - oldItems.AddFirst(node); - node = node.Previous; - } else { - oldItems.AddLast(node); - node = node.Next; - } - } - - node = backupsNode; - if (node == null) { - foreach (var item in data.IterateFullReversed()) { - // add from head - mMem.AddFirst(item); - } - } else { - long counter = 0; - if (isInsertBefore) { - foreach (var item in data.IterateFull()) { - if (node == null) { - // insert from tail instead - mMem.AddLast(item.Value); - } else { - mMem.AddBefore(node, item.Value); - } - - if (counter == gottenPointerPos) - mPointer = node.Previous; - counter++; - } - } else { - foreach (var item in data.IterateFullReversed()) { - if (node == null) { - // insert from head instead - mMem.AddFirst(item.Value); - } else { - mMem.AddAfter(node, item.Value); - } - - if (counter == gottenPointerPos) - mPointer = node.Next; - counter++; - } - } - } - - } else { - // backups start pointer - addStartNode = node; + node = isInsertBefore ? node.Next : node.Previous; + internalRemoveOper.Do(ref mMem, ref mPointer, ref mPointerIndex); + // now, we can treat it as normal insert(without overwritten) + // but with one exception: absolutePos + // we need re calc absolutePos bucause we have called remove oper if (isInsertBefore) { - foreach (var item in data.IterateFull()) { - mMem.AddBefore(node, item.Value); - } + if (node == null) + modifiedAbsolutePos = LINKEDLIST_TAIL; + else + modifiedAbsolutePos = absolutePos + 1 - expectedLength; } else { - foreach (var item in data.IterateFullReversed()) { - mMem.AddAfter(node, item.Value); - } + if (node == null) + modifiedAbsolutePos = LINKEDLIST_HEAD; + else + modifiedAbsolutePos -= 1; + } + + } + // backups + oldPointer = mPointer; + oldPointerIndex = mPointerIndex; + addStartNode = node; + isBlankList = false; + + if (isInsertBefore) { + foreach (var item in data.IterateFull()) { + if (node == null) + mMem.AddLast(item.Value); + else + mMem.AddBefore(node, item.Value); + } + } else { + foreach (var item in data.IterateFullReversed()) { + if (node == null) + mMem.AddFirst(item.Value); + else + mMem.AddAfter(node, item.Value); } - if (mPointerIndex > absolutePos) - mPointerIndex += data.Count; } + if (modifiedAbsolutePos != LINKEDLIST_TAIL && modifiedAbsolutePos != LINKEDLIST_HEAD) { + if ((isInsertBefore && mPointerIndex >= modifiedAbsolutePos) || + (!isInsertBefore && mPointerIndex > modifiedAbsolutePos)) + mPointerIndex += data.Count; + } + else if (modifiedAbsolutePos == LINKEDLIST_HEAD) + mPointerIndex += data.Count; + + // remove have chance to remove entire list + // so we need restore pointer in that situation + if (mPointer == null) { + mPointer = mMem.First; + mPointerIndex = mPointer == null ? -1 : 0; + } } } @@ -378,41 +396,41 @@ namespace BallanceTASEditor.Core.FileOperation { base.Undo(ref mMem, ref mPointer, ref mPointerIndex); if (data.Count == 0) return; - if (addStartNode == null) { + if (isBlankList) { // original state is blank // just clear mmem is ok mMem.Clear(); + + // re-set pointer + mPointer = oldPointer; + mPointerIndex = oldPointerIndex; } else { // in overwrite or not in overwrite mode, we all need to remove inserted data first if (isInsertBefore) { for (long i = 0; i < data.Count; i++) { - mMem.Remove(addStartNode.Previous); + if (addStartNode == null) + mMem.RemoveLast(); + else + mMem.Remove(addStartNode.Previous); } } else { for (long i = 0; i < data.Count; i++) { - mMem.Remove(addStartNode.Next); + if (addStartNode == null) + mMem.RemoveFirst(); + else + mMem.Remove(addStartNode.Next); } } + // re-set pointer + mPointer = oldPointer; + mPointerIndex = oldPointerIndex; + // if we use overwrite mode, we need re-add lost data if (isOverwritten) { - if (isInsertBefore) { - foreach (var item in oldItems.IterateFull()) { - oldItems.Remove(item); - mMem.AddBefore(addStartNode, item); - } - } else { - foreach (var item in oldItems.IterateFullReversed()) { - oldItems.Remove(item); - mMem.AddAfter(addStartNode, item); - } - } + internalRemoveOper.Undo(ref mMem, ref mPointer, ref mPointerIndex); } } - - // re-set pointer - mPointer = oldPointer; - mPointerIndex = oldPointerIndex; } } diff --git a/Core/KeyboardState.cs b/BallanceTASEditor/Core/KeyboardState.cs similarity index 100% rename from Core/KeyboardState.cs rename to BallanceTASEditor/Core/KeyboardState.cs diff --git a/Core/LimitedStack.cs b/BallanceTASEditor/Core/LimitedStack.cs similarity index 100% rename from Core/LimitedStack.cs rename to BallanceTASEditor/Core/LimitedStack.cs diff --git a/Core/TASFile.cs b/BallanceTASEditor/Core/TASFile.cs similarity index 88% rename from Core/TASFile.cs rename to BallanceTASEditor/Core/TASFile.cs index 021e8e8..6d09c18 100644 --- a/Core/TASFile.cs +++ b/BallanceTASEditor/Core/TASFile.cs @@ -18,7 +18,7 @@ namespace BallanceTASEditor.Core { fs.Close(); fs.Dispose(); mPointer = mMem.First; - mPointerIndex = 0; + mPointerIndex = mPointer == null ? -1 : 0; mRedoStack = new LimitedStack(); mUndoStack = new LimitedStack(); @@ -52,7 +52,7 @@ namespace BallanceTASEditor.Core { public void Get(List container, int count) { // no item. clean container if (mPointer == null) { - for(int j = 0; j < count; j++) { + for (int j = 0; j < count; j++) { container[j].isEnable = false; } return; @@ -62,12 +62,12 @@ namespace BallanceTASEditor.Core { var cachePointer = mPointer; var startIndex = mPointerIndex; int i; - for(i = 0; i < count && cachePointer != null; i++, startIndex++) { + for (i = 0; i < count && cachePointer != null; i++, startIndex++) { container[i].Reload(startIndex, cachePointer.Value); container[i].isEnable = true; cachePointer = cachePointer.Next; } - for(; i < count; i++) { + for (; i < count; i++) { container[i].isEnable = false; } } @@ -222,5 +222,34 @@ namespace BallanceTASEditor.Core { mFilename = newfile; Save(); } + + +#if DEBUG + // following code only should be used in debug mode and served for testbench + public TASFile(LinkedList items) { + mFilename = ""; + mMem = items; + mPointer = mMem.First; + mPointerIndex = mPointer == null ? -1 : 0; + + mRedoStack = new LimitedStack(); + mUndoStack = new LimitedStack(); + } + + public string Output2TestString() { + StringBuilder sb = new StringBuilder(); + + if (mPointer == null) sb.Append("null;"); + else sb.Append($"{mPointer.Value.keystates.ToString()};"); + sb.Append($"{mPointerIndex};"); + + foreach (var item in mMem.IterateFull()) { + sb.Append(item.Value.keystates.ToString()); + sb.Append(","); + } + return sb.ToString(); + } +#endif + } } diff --git a/Core/TASStruct.cs b/BallanceTASEditor/Core/TASStruct.cs similarity index 100% rename from Core/TASStruct.cs rename to BallanceTASEditor/Core/TASStruct.cs diff --git a/Core/Util.cs b/BallanceTASEditor/Core/Util.cs similarity index 99% rename from Core/Util.cs rename to BallanceTASEditor/Core/Util.cs index beb5865..4d2a3ce 100644 --- a/Core/Util.cs +++ b/BallanceTASEditor/Core/Util.cs @@ -149,7 +149,7 @@ namespace BallanceTASEditor.Core { return (num >= start && num <= end); } public long GetCount() { - return end - start; + return end - start + 1; } } diff --git a/Core/ZlibUtil.cs b/BallanceTASEditor/Core/ZlibUtil.cs similarity index 100% rename from Core/ZlibUtil.cs rename to BallanceTASEditor/Core/ZlibUtil.cs diff --git a/MainWindow.xaml b/BallanceTASEditor/MainWindow.xaml similarity index 100% rename from MainWindow.xaml rename to BallanceTASEditor/MainWindow.xaml diff --git a/MainWindow.xaml.cs b/BallanceTASEditor/MainWindow.xaml.cs similarity index 100% rename from MainWindow.xaml.cs rename to BallanceTASEditor/MainWindow.xaml.cs diff --git a/Properties/AssemblyInfo.cs b/BallanceTASEditor/Properties/AssemblyInfo.cs similarity index 100% rename from Properties/AssemblyInfo.cs rename to BallanceTASEditor/Properties/AssemblyInfo.cs diff --git a/Properties/Resources.Designer.cs b/BallanceTASEditor/Properties/Resources.Designer.cs similarity index 74% rename from Properties/Resources.Designer.cs rename to BallanceTASEditor/Properties/Resources.Designer.cs index 8f442dc..1803682 100644 --- a/Properties/Resources.Designer.cs +++ b/BallanceTASEditor/Properties/Resources.Designer.cs @@ -1,53 +1,54 @@ //------------------------------------------------------------------------------ // // 此代码由工具生成。 -// 运行时版本: 4.0.30319.42000 +// 运行时版本:4.0.30319.42000 // -// 对此文件的更改可能导致不正确的行为,如果 -// 重新生成代码,则所做更改将丢失。 +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ namespace BallanceTASEditor.Properties { - - + using System; + + /// - /// 强类型资源类,用于查找本地化字符串等。 + /// 一个强类型的资源类,用于查找本地化的字符串等。 /// // 此类是由 StronglyTypedResourceBuilder // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 - // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // (以 /str 作为命令选项),或重新生成 VS 项目。 - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { - + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } - + /// - /// 返回此类使用的缓存 ResourceManager 实例。 + /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { - if ((resourceMan == null)) { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BallanceTASEditor.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// - /// 覆盖当前线程的 CurrentUICulture 属性 - /// 使用此强类型的资源类的资源查找。 + /// 重写当前线程的 CurrentUICulture 属性 + /// 重写当前线程的 CurrentUICulture 属性。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { diff --git a/Properties/Resources.resx b/BallanceTASEditor/Properties/Resources.resx similarity index 100% rename from Properties/Resources.resx rename to BallanceTASEditor/Properties/Resources.resx diff --git a/Properties/Settings.Designer.cs b/BallanceTASEditor/Properties/Settings.Designer.cs similarity index 76% rename from Properties/Settings.Designer.cs rename to BallanceTASEditor/Properties/Settings.Designer.cs index 756ca5a..5ad972c 100644 --- a/Properties/Settings.Designer.cs +++ b/BallanceTASEditor/Properties/Settings.Designer.cs @@ -1,22 +1,22 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ namespace BallanceTASEditor.Properties { - - + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - + public static Settings Default { get { return defaultInstance; diff --git a/Properties/Settings.settings b/BallanceTASEditor/Properties/Settings.settings similarity index 100% rename from Properties/Settings.settings rename to BallanceTASEditor/Properties/Settings.settings diff --git a/UI/AddItem.xaml b/BallanceTASEditor/UI/AddItem.xaml similarity index 100% rename from UI/AddItem.xaml rename to BallanceTASEditor/UI/AddItem.xaml diff --git a/UI/AddItem.xaml.cs b/BallanceTASEditor/UI/AddItem.xaml.cs similarity index 100% rename from UI/AddItem.xaml.cs rename to BallanceTASEditor/UI/AddItem.xaml.cs diff --git a/UI/DialogUtil.cs b/BallanceTASEditor/UI/DialogUtil.cs similarity index 100% rename from UI/DialogUtil.cs rename to BallanceTASEditor/UI/DialogUtil.cs diff --git a/UI/OperationEnum.cs b/BallanceTASEditor/UI/OperationEnum.cs similarity index 100% rename from UI/OperationEnum.cs rename to BallanceTASEditor/UI/OperationEnum.cs diff --git a/UI/SelectionHelp.cs b/BallanceTASEditor/UI/SelectionHelp.cs similarity index 100% rename from UI/SelectionHelp.cs rename to BallanceTASEditor/UI/SelectionHelp.cs diff --git a/UI/StyleConverter.cs b/BallanceTASEditor/UI/StyleConverter.cs similarity index 100% rename from UI/StyleConverter.cs rename to BallanceTASEditor/UI/StyleConverter.cs diff --git a/UI/TASFlow.xaml b/BallanceTASEditor/UI/TASFlow.xaml similarity index 100% rename from UI/TASFlow.xaml rename to BallanceTASEditor/UI/TASFlow.xaml diff --git a/UI/TASFlow.xaml.cs b/BallanceTASEditor/UI/TASFlow.xaml.cs similarity index 100% rename from UI/TASFlow.xaml.cs rename to BallanceTASEditor/UI/TASFlow.xaml.cs diff --git a/UI/TASViewer.cs b/BallanceTASEditor/UI/TASViewer.cs similarity index 100% rename from UI/TASViewer.cs rename to BallanceTASEditor/UI/TASViewer.cs diff --git a/UI/Util.cs b/BallanceTASEditor/UI/Util.cs similarity index 100% rename from UI/Util.cs rename to BallanceTASEditor/UI/Util.cs diff --git a/BallanceTASEditor/app.config b/BallanceTASEditor/app.config new file mode 100644 index 0000000..51278a4 --- /dev/null +++ b/BallanceTASEditor/app.config @@ -0,0 +1,3 @@ + + + diff --git a/packages.config b/BallanceTASEditor/packages.config similarity index 100% rename from packages.config rename to BallanceTASEditor/packages.config diff --git a/BallanceTASEditorTests/BallanceTASEditorTests.csproj b/BallanceTASEditorTests/BallanceTASEditorTests.csproj new file mode 100644 index 0000000..9d1e4f3 --- /dev/null +++ b/BallanceTASEditorTests/BallanceTASEditorTests.csproj @@ -0,0 +1,108 @@ + + + + + Debug + AnyCPU + {EC35111D-6259-4C69-B7E4-F4E727AC0E1A} + Library + Properties + BallanceTASEditorTests + BallanceTASEditorTests + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + ..\packages\MSTest.TestFramework.2.2.5\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.2.5\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + + + {3127A635-B9E5-4C78-8414-0B9B196EC25E} + BallanceTASEditor + + + + + + + + + + False + + + False + + + False + + + False + + + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + + + \ No newline at end of file diff --git a/BallanceTASEditorTests/Core/TASFileTests.cs b/BallanceTASEditorTests/Core/TASFileTests.cs new file mode 100644 index 0000000..fde5883 --- /dev/null +++ b/BallanceTASEditorTests/Core/TASFileTests.cs @@ -0,0 +1,164 @@ +using BallanceTASEditor.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BallanceTASEditor.Core.TASStruct; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace BallanceTASEditor.Core.Tests { + [TestClass()] + public class TASFileTests { + + [DataTestMethod] + [DataRow("1,2,3,4,5", 0, "15;0;15,15,15,4,5,", FrameDataField.Key_Up, FrameDataField.Key_Right, 0, 2, true)] + [DataRow("1,2,3,4,5", 0, "0;0;0,0,0,4,5,", FrameDataField.Key_Up, FrameDataField.Key_Right, 0, 2, false)] + [DataRow("1,2,3,4,5", 0, "14;0;14,13,12,4,5,", FrameDataField.Key_Up, FrameDataField.Key_Right, 0, 2, null)] + public void SetTest(string originStr, long prevShift, string expectedStr, FrameDataField field_start, FrameDataField field_end, long absoluteRange_start, long absoluteRange_end, bool? isSet) { + var test = new TASFile(dataGenerator(originStr)); + test.Shift(prevShift); + var originalText = test.Output2TestString(); + + // test function + test.Set(new SelectionRange((long)field_start, (long)field_end), new SelectionRange(absoluteRange_start, absoluteRange_end), isSet); + var changedText = test.Output2TestString(); + Assert.AreEqual(expectedStr, changedText); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + + // test redo + test.Redo(); + Assert.AreEqual(changedText, test.Output2TestString()); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + } + + [DataTestMethod] + [DataRow("1,2,3,4,5", 0, "3;0;3,4,5,", 0, 1)] + [DataRow("1,2,3,4,5", 0, "null;-1;", 0, 4)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,3,", 3, 4)] + [DataRow("1,2,3,4,5", 0, "2;0;2,3,4,5,", 0, 0)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,3,4,", 4, 4)] + [DataRow("1,2,3,4,5", 2, "1;0;1,5,", 1, 3)] + [DataRow("1,2,3,4,5", 2, "5;0;5,", 0, 3)] + [DataRow("1,2,3,4,5", 2, "1;0;1,", 1, 4)] + [DataRow("1,2,3,4,5", 3, "4;0;4,5,", 0, 2)] + [DataRow("1,2,3,4,5", 4, "5;1;4,5,", 0, 2)] + public void RemoveTest(string originStr, long prevShift, string expectedStr, long absoluteRange_start, long absoluteRange_end) { + var test = new TASFile(dataGenerator(originStr)); + test.Shift(prevShift); + var originalText = test.Output2TestString(); + + // test function + test.Remove(new SelectionRange(absoluteRange_start, absoluteRange_end)); + var changedText = test.Output2TestString(); + Assert.AreEqual(expectedStr, changedText); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + + // test redo + test.Redo(); + Assert.AreEqual(changedText, test.Output2TestString()); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + } + + [DataTestMethod] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,0,0,0,3,4,5,", 2, 3, 240 / 1f, true)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,3,0,0,0,4,5,", 2, 3, 240 / 1f, false)] + [DataRow("1,2,3,4,5", 2, "3;5;1,2,0,0,0,3,4,5,", 2, 3, 240 / 1f, true)] + [DataRow("1,2,3,4,5", 2, "3;2;1,2,3,0,0,0,4,5,", 2, 3, 240 / 1f, false)] + + [DataRow("1,2,3,4,5", 0, "1;3;0,0,0,1,2,3,4,5,", 0, 3, 240 / 1f, true)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,3,4,5,0,0,0,", 4, 3, 240 / 1f, false)] + public void AddTest(string originStr, long prevShift, string expectedStr, long absolutePos, long count, float deltaTime, bool isAddBefore) { + var test = new TASFile(dataGenerator(originStr)); + test.Shift(prevShift); + var originalText = test.Output2TestString(); + + // test function + test.Add(absolutePos, count, deltaTime, isAddBefore); + var changedText = test.Output2TestString(); + Assert.AreEqual(expectedStr, changedText); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + + // test redo + test.Redo(); + Assert.AreEqual(changedText, test.Output2TestString()); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + } + + [DataTestMethod] + [DataRow("1,2,3,4,5", 0, "6;0;6,7,8,9,10,", 0, "6,7,8,9,10", false, true)] + [DataRow("1,2,3,4,5", 0, "6;0;6,7,8,9,10,", 4, "6,7,8,9,10", true, true)] + + [DataRow("1,2,3,4,5", 0, "1;0;1,2,6,7,8,3,4,5,", 2, "6,7,8", true, false)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,3,6,7,8,4,5,", 2, "6,7,8", false, false)] + + [DataRow("1,2,3,4,5", 0, "1;0;1,2,3,4,5,6,7,", 4, "6,7", false, false)] + [DataRow("1,2,3,4,5", 0, "1;2;6,7,1,2,3,4,5,", 0, "6,7", true, false)] + + [DataRow("1,2,3,4,5", 0, "1;0;1,6,7,4,5,", 2, "6,7", true, true)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,6,7,5,", 2, "6,7", false, true)] + [DataRow("1,2,3,4,5", 0, "4;3;6,7,8,4,5,", 2, "6,7,8", true, true)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,6,7,8,", 2, "6,7,8", false, true)] + [DataRow("1,2,3,4,5", 0, "4;4;6,7,8,9,4,5,", 2, "6,7,8,9", true, true)] + [DataRow("1,2,3,4,5", 0, "1;0;1,2,6,7,8,9,", 2, "6,7,8,9", false, true)] + + [DataRow("1,2,3,4,5", 2, "1;0;1,6,7,4,5,", 2, "6,7", true, true)] + [DataRow("1,2,3,4,5", 2, "2;1;1,2,6,7,5,", 2, "6,7", false, true)] + [DataRow("1,2,3,4,5", 2, "4;3;6,7,8,4,5,", 2, "6,7,8", true, true)] + [DataRow("1,2,3,4,5", 2, "2;1;1,2,6,7,8,", 2, "6,7,8", false, true)] + [DataRow("1,2,3,4,5", 2, "4;4;6,7,8,9,4,5,", 2, "6,7,8,9", true, true)] + [DataRow("1,2,3,4,5", 2, "2;1;1,2,6,7,8,9,", 2, "6,7,8,9", false, true)] + + [DataRow("1,2,3,4,5", 2, "3;5;1,2,6,7,8,3,4,5,", 2, "6,7,8", true, false)] + [DataRow("1,2,3,4,5", 2, "3;2;1,2,3,6,7,8,4,5,", 2, "6,7,8", false, false)] + public void InsertTest(string originStr, long prevShift, string expectedStr, long absolutePos, string insertedData, bool isInsertBefore, bool isOverwritten) { + var test = new TASFile(dataGenerator(originStr)); + test.Shift(prevShift); + var originalText = test.Output2TestString(); + + // test function + test.Insert(absolutePos, dataGenerator(insertedData), isInsertBefore, isOverwritten); + var changedText = test.Output2TestString(); + Assert.AreEqual(expectedStr, changedText); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + + // test redo + test.Redo(); + Assert.AreEqual(changedText, test.Output2TestString()); + + // test undo + test.Undo(); + Assert.AreEqual(originalText, test.Output2TestString()); + } + + // example input: 1,2,3,4,5 + private LinkedList dataGenerator(string inputData) { + var ls = new LinkedList(); + foreach (var item in inputData.Split(',')) { + ls.AddLast(new FrameData(float.Parse(item), uint.Parse(item))); + } + return ls; + } + + } +} \ No newline at end of file diff --git a/BallanceTASEditorTests/Properties/AssemblyInfo.cs b/BallanceTASEditorTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..743a508 --- /dev/null +++ b/BallanceTASEditorTests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("BallanceTASEditorTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BallanceTASEditorTests")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +//将 ComVisible 设置为 false 将使此程序集中的类型 +//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ec35111d-6259-4c69-b7e4-f4e727ac0e1a")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BallanceTASEditorTests/packages.config b/BallanceTASEditorTests/packages.config new file mode 100644 index 0000000..5ef5561 --- /dev/null +++ b/BallanceTASEditorTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file