~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Test/UnitTests/TestAddinDescription.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// TestAddinDescription.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
 
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 System.IO;
 
29
using Mono.Addins.Description;
 
30
using System.Globalization;
 
31
using Mono.Addins;
 
32
using System.Xml;
 
33
 
 
34
namespace UnitTests
 
35
{
 
36
        [TestFixture]
 
37
        public class TestAddinDescription: TestBase
 
38
        {
 
39
                CultureInfo oldc;
 
40
                
 
41
                [SetUp]
 
42
                public void TestSetup ()
 
43
                {
 
44
                        oldc = System.Threading.Thread.CurrentThread.CurrentCulture;
 
45
                        CultureInfo ci = CultureInfo.GetCultureInfo("ca-ES");
 
46
                        System.Threading.Thread.CurrentThread.CurrentCulture = ci;
 
47
                }
 
48
                
 
49
                [TearDown]
 
50
                public void TestTeardown ()
 
51
                {
 
52
                        System.Threading.Thread.CurrentThread.CurrentCulture = oldc;
 
53
                }
 
54
                
 
55
                [Test]
 
56
                public void PropertyLocalization ()
 
57
                {
 
58
                        AddinDescription desc = new AddinDescription ();
 
59
                        
 
60
                        desc.Properties.SetPropertyValue ("prop1", "val1");
 
61
                        Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1"));
 
62
                        Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", "en"));
 
63
                        Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", "en-US"));
 
64
                        Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", "en_US"));
 
65
                        Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", null));
 
66
                        
 
67
                        desc.Properties.SetPropertyValue ("prop2", "valCa", "ca");
 
68
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2"));
 
69
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca"));
 
70
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
 
71
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
 
72
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
 
73
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
 
74
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en"));
 
75
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en-US"));
 
76
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en_US"));
 
77
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", null));
 
78
                        
 
79
                        desc.Properties.SetPropertyValue ("prop2", "valCaEs", "ca_ES");
 
80
                        Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2"));
 
81
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca"));
 
82
                        Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
 
83
                        Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
 
84
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
 
85
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
 
86
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en"));
 
87
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en-US"));
 
88
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en_US"));
 
89
                        Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", null));
 
90
                        
 
91
                        desc.Properties.SetPropertyValue ("prop2", "val4", null);
 
92
                        Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2"));
 
93
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca"));
 
94
                        Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
 
95
                        Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
 
96
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
 
97
                        Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
 
98
                        Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", "en"));
 
99
                        Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", "en-US"));
 
100
                        Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", "en_US"));
 
101
                        Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", null));
 
102
                }
 
103
                
 
104
                [Test]
 
105
                public void PropertiesFromAddin ()
 
106
                {
 
107
                        Addin ad = AddinManager.Registry.GetAddin ("SimpleApp.Core");
 
108
                        
 
109
                        Assert.AreEqual ("Una aplicació simple", ad.Name);
 
110
                        Assert.AreEqual ("A simple application", ad.Properties.GetPropertyValue ("Name","en-US"));
 
111
                        Assert.AreEqual ("SimpleApp description", ad.Description.Description);
 
112
                        Assert.AreEqual ("Lluis Sanchez", ad.Description.Author);
 
113
                        Assert.AreEqual ("GPL", ad.Description.Copyright);
 
114
                        Assert.AreEqual ("Val1", ad.Properties.GetPropertyValue ("Prop1","en-US"));
 
115
                        Assert.AreEqual ("Val1Cat", ad.Properties.GetPropertyValue ("Prop1"));
 
116
                        Assert.AreEqual ("Val2", ad.Properties.GetPropertyValue ("Prop2","en-US"));
 
117
                        Assert.AreEqual ("Val2Cat", ad.Properties.GetPropertyValue ("Prop2"));
 
118
                        
 
119
                        oldc = System.Threading.Thread.CurrentThread.CurrentCulture;
 
120
                        System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("es-ES");
 
121
                        
 
122
                        Assert.AreEqual ("Una aplicación simple", ad.Name);
 
123
                        Assert.AreEqual ("Descripción de SimpleApp", ad.Description.Description);
 
124
                        
 
125
                        System.Threading.Thread.CurrentThread.CurrentCulture = oldc;
 
126
                }
 
127
                
 
128
                AddinDescription DescFromResource (string res)
 
129
                {
 
130
                        using (Stream s = GetType().Assembly.GetManifestResourceStream (res)) {
 
131
                                return AddinDescription.Read (s, ".");
 
132
                        }
 
133
                }
 
134
                
 
135
                XmlDocument XmlFromResource (string res)
 
136
                {
 
137
                        using (Stream s = GetType().Assembly.GetManifestResourceStream (res)) {
 
138
                                XmlDocument doc = new XmlDocument ();
 
139
                                doc.Load (s);
 
140
                                return doc;
 
141
                        }
 
142
                }
 
143
                
 
144
                [Test]
 
145
                public void ReadCoreProperties ()
 
146
                {
 
147
                        AddinDescription desc = DescFromResource ("TestManifest2.xml");
 
148
                        
 
149
                        Assert.AreEqual ("Core", desc.LocalId);
 
150
                        Assert.AreEqual ("0.1.0", desc.Version);
 
151
                        Assert.AreEqual ("0.0.1", desc.CompatVersion);
 
152
                        Assert.AreEqual (false, desc.EnabledByDefault);
 
153
                        Assert.AreEqual (AddinFlags.CantDisable | AddinFlags.CantUninstall | AddinFlags.Hidden, desc.Flags);
 
154
                        Assert.AreEqual (true, desc.IsRoot);
 
155
                        Assert.AreEqual ("SimpleApp", desc.Namespace);
 
156
                }
 
157
                
 
158
                [Test]
 
159
                public void WriteCorePropertiesAsElems ()
 
160
                {
 
161
                        AddinDescription desc = DescFromResource ("TestManifest2.xml");
 
162
                        XmlDocument doc1 = XmlFromResource ("TestManifest2.xml");
 
163
                        
 
164
                        XmlDocument doc2 = desc.SaveToXml ();
 
165
                        Assert.AreEqual (Util.Infoset (doc1), Util.Infoset (doc2));
 
166
                        
 
167
                        desc.LocalId = "Core2";
 
168
                        desc.Version = "0.2.0";
 
169
                        desc.CompatVersion = "0.0.2";
 
170
                        desc.EnabledByDefault = true;
 
171
                        desc.Flags = AddinFlags.CantUninstall;
 
172
                        desc.IsRoot = false;
 
173
                        desc.Namespace = "SimpleApp2";
 
174
                        
 
175
                        doc1 = XmlFromResource ("TestManifest2-bis.xml");
 
176
                        doc2 = desc.SaveToXml ();
 
177
                        
 
178
                        Assert.AreEqual (Util.Infoset (doc1), Util.Infoset (doc2));
 
179
                }
 
180
                
 
181
                [Test]
 
182
                public void WriteCorePropertiesAsProps ()
 
183
                {
 
184
                        AddinDescription desc = DescFromResource ("TestManifest3.xml");
 
185
                        XmlDocument doc1 = XmlFromResource ("TestManifest3.xml");
 
186
                        XmlDocument doc2 = desc.SaveToXml ();
 
187
                        Assert.AreEqual (Util.Infoset (doc1), Util.Infoset (doc2));
 
188
                }
 
189
        }
 
190
}
 
191