Merge pull request #1936 from esdrubal/DotNetRelativeOrAbsolute
[mono.git] / mcs / class / System / Test / System.Collections.ObjectModel / CollectionChangedEventValidators.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Authors:
21 //      Brian O'Keefe (zer0keefie@gmail.com)
22 //
23
24
25 using System.Collections;
26 using NUnit.Framework;
27 using System.Collections.Specialized;
28 namespace MonoTests.System.Collections.Specialized {
29
30         internal static class CollectionChangedEventValidators {
31                 #region Validators
32
33                 internal static void AssertEquivalentLists(IList expected, IList actual, string message)
34                 {
35                         if (expected == null) {
36                                 Assert.IsNull (actual, "LISTEQ_1A::" + message);
37                                 return;
38                         } else
39                                 Assert.IsNotNull (actual, "LISTEQ_1B::" + message);
40
41                         Assert.AreEqual (expected.Count, actual.Count, "LISTEQ_2::" + message);
42
43                         for (int i = 0; i < expected.Count; i++)
44                                 Assert.AreEqual (expected [i], actual [i], "LISTEQ_3::" + message);
45                 }
46
47                 private static void ValidateCommon(NotifyCollectionChangedEventArgs args, NotifyCollectionChangedAction action, IList newItems, IList oldItems, int newIndex, int oldIndex, string message)
48                 {
49                         Assert.IsNotNull (args, "NCCVAL_1::" + message);
50
51                         Assert.AreEqual (action, args.Action, "NCCVAL_2::" + message);
52
53                         AssertEquivalentLists (newItems, args.NewItems, "NCCVAL_3::" + message);
54                         AssertEquivalentLists (oldItems, args.OldItems, "NCCVAL_4::" + message);
55
56                         Assert.AreEqual (newIndex, args.NewStartingIndex, "NCCVAL_5::" + message);
57                         Assert.AreEqual (oldIndex, args.OldStartingIndex, "NCCVAL_6::" + message);
58                 }
59
60                 internal static void ValidateResetOperation(NotifyCollectionChangedEventArgs args, string message)
61                 {
62                         ValidateCommon (args, NotifyCollectionChangedAction.Reset, null, null, -1, -1, message);
63                 }
64
65                 internal static void ValidateAddOperation(NotifyCollectionChangedEventArgs args, IList newItems, string message)
66                 {
67                         ValidateAddOperation (args, newItems, -1, message);
68                 }
69
70                 internal static void ValidateAddOperation(NotifyCollectionChangedEventArgs args, IList newItems, int startIndex, string message)
71                 {
72                         ValidateCommon (args, NotifyCollectionChangedAction.Add, newItems, null, startIndex, -1, message);
73                 }
74
75                 internal static void ValidateRemoveOperation(NotifyCollectionChangedEventArgs args, IList oldItems, string message)
76                 {
77                         ValidateRemoveOperation (args, oldItems, -1, message);
78                 }
79
80                 internal static void ValidateRemoveOperation(NotifyCollectionChangedEventArgs args, IList oldItems, int startIndex, string message)
81                 {
82                         ValidateCommon (args, NotifyCollectionChangedAction.Remove, null, oldItems, -1, startIndex, message);
83                 }
84
85                 internal static void ValidateReplaceOperation(NotifyCollectionChangedEventArgs args, IList oldItems, IList newItems, string message)
86                 {
87                         ValidateReplaceOperation (args, oldItems, newItems, -1, message);
88                 }
89
90                 internal static void ValidateReplaceOperation(NotifyCollectionChangedEventArgs args, IList oldItems, IList newItems, int startIndex, string message)
91                 {
92                         ValidateCommon (args, NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex, startIndex, message);
93                 }
94
95                 internal static void ValidateMoveOperation(NotifyCollectionChangedEventArgs args, IList changedItems, int newIndex, int oldIndex, string message)
96                 {
97                         ValidateCommon (args, NotifyCollectionChangedAction.Move, changedItems, changedItems, newIndex, oldIndex, message);
98                 }
99
100                 #endregion
101         }
102 }
103