[eglib] Prefer <langinfo.h> to <localcharset.h>
[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 #if NET_4_0
25
26 using System.Collections;
27 using NUnit.Framework;
28 using System.Collections.Specialized;
29 namespace MonoTests.System.Collections.Specialized {
30
31         internal static class CollectionChangedEventValidators {
32                 #region Validators
33
34                 internal static void AssertEquivalentLists(IList expected, IList actual, string message)
35                 {
36                         if (expected == null) {
37                                 Assert.IsNull (actual, "LISTEQ_1A::" + message);
38                                 return;
39                         } else
40                                 Assert.IsNotNull (actual, "LISTEQ_1B::" + message);
41
42                         Assert.AreEqual (expected.Count, actual.Count, "LISTEQ_2::" + message);
43
44                         for (int i = 0; i < expected.Count; i++)
45                                 Assert.AreEqual (expected [i], actual [i], "LISTEQ_3::" + message);
46                 }
47
48                 private static void ValidateCommon(NotifyCollectionChangedEventArgs args, NotifyCollectionChangedAction action, IList newItems, IList oldItems, int newIndex, int oldIndex, string message)
49                 {
50                         Assert.IsNotNull (args, "NCCVAL_1::" + message);
51
52                         Assert.AreEqual (action, args.Action, "NCCVAL_2::" + message);
53
54                         AssertEquivalentLists (newItems, args.NewItems, "NCCVAL_3::" + message);
55                         AssertEquivalentLists (oldItems, args.OldItems, "NCCVAL_4::" + message);
56
57                         Assert.AreEqual (newIndex, args.NewStartingIndex, "NCCVAL_5::" + message);
58                         Assert.AreEqual (oldIndex, args.OldStartingIndex, "NCCVAL_6::" + message);
59                 }
60
61                 internal static void ValidateResetOperation(NotifyCollectionChangedEventArgs args, string message)
62                 {
63                         ValidateCommon (args, NotifyCollectionChangedAction.Reset, null, null, -1, -1, message);
64                 }
65
66                 internal static void ValidateAddOperation(NotifyCollectionChangedEventArgs args, IList newItems, string message)
67                 {
68                         ValidateAddOperation (args, newItems, -1, message);
69                 }
70
71                 internal static void ValidateAddOperation(NotifyCollectionChangedEventArgs args, IList newItems, int startIndex, string message)
72                 {
73                         ValidateCommon (args, NotifyCollectionChangedAction.Add, newItems, null, startIndex, -1, message);
74                 }
75
76                 internal static void ValidateRemoveOperation(NotifyCollectionChangedEventArgs args, IList oldItems, string message)
77                 {
78                         ValidateRemoveOperation (args, oldItems, -1, message);
79                 }
80
81                 internal static void ValidateRemoveOperation(NotifyCollectionChangedEventArgs args, IList oldItems, int startIndex, string message)
82                 {
83                         ValidateCommon (args, NotifyCollectionChangedAction.Remove, null, oldItems, -1, startIndex, message);
84                 }
85
86                 internal static void ValidateReplaceOperation(NotifyCollectionChangedEventArgs args, IList oldItems, IList newItems, string message)
87                 {
88                         ValidateReplaceOperation (args, oldItems, newItems, -1, message);
89                 }
90
91                 internal static void ValidateReplaceOperation(NotifyCollectionChangedEventArgs args, IList oldItems, IList newItems, int startIndex, string message)
92                 {
93                         ValidateCommon (args, NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex, startIndex, message);
94                 }
95
96                 internal static void ValidateMoveOperation(NotifyCollectionChangedEventArgs args, IList changedItems, int newIndex, int oldIndex, string message)
97                 {
98                         ValidateCommon (args, NotifyCollectionChangedAction.Move, changedItems, changedItems, newIndex, oldIndex, message);
99                 }
100
101                 #endregion
102         }
103 }
104
105 #endif