2
// TestAddinDescription.cs
5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
27
using NUnit.Framework;
29
using Mono.Addins.Description;
30
using System.Globalization;
37
public class TestAddinDescription: TestBase
42
public void TestSetup ()
44
oldc = System.Threading.Thread.CurrentThread.CurrentCulture;
45
CultureInfo ci = CultureInfo.GetCultureInfo("ca-ES");
46
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
50
public void TestTeardown ()
52
System.Threading.Thread.CurrentThread.CurrentCulture = oldc;
56
public void PropertyLocalization ()
58
AddinDescription desc = new AddinDescription ();
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));
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));
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));
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));
105
public void PropertiesFromAddin ()
107
Addin ad = AddinManager.Registry.GetAddin ("SimpleApp.Core");
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"));
119
oldc = System.Threading.Thread.CurrentThread.CurrentCulture;
120
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("es-ES");
122
Assert.AreEqual ("Una aplicación simple", ad.Name);
123
Assert.AreEqual ("Descripción de SimpleApp", ad.Description.Description);
125
System.Threading.Thread.CurrentThread.CurrentCulture = oldc;
128
AddinDescription DescFromResource (string res)
130
using (Stream s = GetType().Assembly.GetManifestResourceStream (res)) {
131
return AddinDescription.Read (s, ".");
135
XmlDocument XmlFromResource (string res)
137
using (Stream s = GetType().Assembly.GetManifestResourceStream (res)) {
138
XmlDocument doc = new XmlDocument ();
145
public void ReadCoreProperties ()
147
AddinDescription desc = DescFromResource ("TestManifest2.xml");
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);
159
public void WriteCorePropertiesAsElems ()
161
AddinDescription desc = DescFromResource ("TestManifest2.xml");
162
XmlDocument doc1 = XmlFromResource ("TestManifest2.xml");
164
XmlDocument doc2 = desc.SaveToXml ();
165
Assert.AreEqual (Util.Infoset (doc1), Util.Infoset (doc2));
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;
173
desc.Namespace = "SimpleApp2";
175
doc1 = XmlFromResource ("TestManifest2-bis.xml");
176
doc2 = desc.SaveToXml ();
178
Assert.AreEqual (Util.Infoset (doc1), Util.Infoset (doc2));
182
public void WriteCorePropertiesAsProps ()
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));