~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to tests/UnitTests/MonoDevelop.VersionControl.Views/EditorCompareWidgetBaseTest.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// EditorCompareWidgetBaseTest.cs
 
3
//  
 
4
// Author:
 
5
//       IBBoard <dev@ibboard.co.uk>
 
6
// 
 
7
// Copyright (c) 2011 IBBoard
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using NUnit.Framework;
 
28
using Mono.TextEditor.Utils;
 
29
using Cairo;
 
30
 
 
31
namespace MonoDevelop.VersionControl.Views
 
32
{
 
33
        [TestFixture()]
 
34
        public class EditorCompareWidgetBaseTest
 
35
        {
 
36
                private delegate void ColorAssertion (Color color);
 
37
 
 
38
                [Test()]
 
39
                public void TestRemovalLineColorIsRed ()
 
40
                {
 
41
                        CheckCombinationsAreColor (new Hunk (0, 0, 1, 0), AssertIsRed);
 
42
                        CheckCombinationsAreColor (new Hunk (0, 0, 2, 0), AssertIsRed);
 
43
                }
 
44
 
 
45
                [Test()]
 
46
                public void TestAdditionLineColorIsGreen ()
 
47
                {
 
48
                        CheckCombinationsAreColor (new Hunk (0, 0, 0, 1), AssertIsGreen);
 
49
                        CheckCombinationsAreColor (new Hunk (0, 0, 0, 2), AssertIsGreen);
 
50
                }
 
51
 
 
52
                [Test()]
 
53
                public void TestAdditionAndRemovalLineColorIsGreen ()
 
54
                {
 
55
                        CheckCombinationsAreColor (new Hunk (0, 0, 1, 1), AssertIsBlue);
 
56
                        CheckCombinationsAreColor (new Hunk (0, 0, 2, 2), AssertIsBlue);
 
57
                        CheckCombinationsAreColor (new Hunk (0, 0, 1, 2), AssertIsBlue);
 
58
                        CheckCombinationsAreColor (new Hunk (0, 0, 2, 1), AssertIsBlue);
 
59
                }
 
60
 
 
61
                [Test()]
 
62
                public void TestDarkColorsAreDarker ()
 
63
                {
 
64
                        CheckDarkColoursAreDarker (new Hunk (0, 0, 1, 0));
 
65
                        CheckDarkColoursAreDarker (new Hunk (0, 0, 0, 1));
 
66
                        CheckDarkColoursAreDarker (new Hunk (0, 0, 1, 1));
 
67
                }
 
68
 
 
69
                private void CheckCombinationsAreColor (Hunk hunk, ColorAssertion assertion)
 
70
                {
 
71
                        assertion (GetColor (hunk, true, true));
 
72
                        assertion (GetColor (hunk, true, false));
 
73
                        assertion (GetColor (hunk, false, true));
 
74
                        assertion (GetColor (hunk, false, false));
 
75
                }
 
76
 
 
77
                private Color GetColor (Hunk hunk, bool removeSide, bool dark)
 
78
                {
 
79
                        return EditorCompareWidgetBase.GetColor (hunk, removeSide, dark, 1.0);
 
80
                }
 
81
 
 
82
                private void AssertIsRed (Color color)
 
83
                {
 
84
                        Assert.Greater (color.R, color.G);
 
85
                        Assert.Greater (color.R, color.B);
 
86
                }
 
87
 
 
88
                private void AssertIsGreen (Color color)
 
89
                {
 
90
                        Assert.Greater (color.G, color.R);
 
91
                        Assert.Greater (color.G, color.B);
 
92
                }
 
93
 
 
94
                private void AssertIsBlue (Color color)
 
95
                {
 
96
                        Assert.Greater (color.B, color.G);
 
97
                        Assert.Greater (color.B, color.R);
 
98
                }
 
99
 
 
100
                private void CheckDarkColoursAreDarker (Hunk hunk)
 
101
                {
 
102
                        Color dark = GetColor (hunk, true, true);
 
103
                        Color light = GetColor (hunk, true, false);
 
104
                        Assert.Less (dark.R, light.R);
 
105
                        Assert.Less (dark.B, light.B);
 
106
                        Assert.Less (dark.G, light.G);
 
107
                }
 
108
        }
 
109
}
 
110