Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-addins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez Gual <lluis@novell.com>2011-01-31 20:28:05 +0300
committerLluis Sanchez Gual <lluis@novell.com>2011-01-31 20:28:05 +0300
commit6a1a2111c0fd04c416d6296bd2af0445300583f3 (patch)
tree999344436dc4a6b2f647fc330bb7d5177e9a205c
parent790cd81d0e8d977ef7783132678ddf030a5a5c68 (diff)
Fix property localization logic and tests.
-rw-r--r--Mono.Addins.Setup/Mono.Addins.Setup/AddinPropertyCollection.cs23
-rw-r--r--Mono.Addins/Mono.Addins.Description/AddinDescription.cs14
-rw-r--r--Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs17
-rw-r--r--Mono.Addins/Mono.Addins/AddinInfo.cs38
-rw-r--r--Test/UnitTests/SimpleApp.addin.xml4
-rw-r--r--Test/UnitTests/TestAddinDescription.cs79
6 files changed, 115 insertions, 60 deletions
diff --git a/Mono.Addins.Setup/Mono.Addins.Setup/AddinPropertyCollection.cs b/Mono.Addins.Setup/Mono.Addins.Setup/AddinPropertyCollection.cs
index 0eddfae..800460d 100644
--- a/Mono.Addins.Setup/Mono.Addins.Setup/AddinPropertyCollection.cs
+++ b/Mono.Addins.Setup/Mono.Addins.Setup/AddinPropertyCollection.cs
@@ -49,20 +49,27 @@ namespace Mono.Addins.Setup
{
locale = NormalizeLocale (locale);
string lang = GetLocaleLang (locale);
- AddinProperty best = null;
+ AddinProperty sameLangDifCountry = null;
+ AddinProperty sameLang = null;
AddinProperty defaultLoc = null;
+
foreach (var p in this) {
if (p.Name == name) {
if (p.Locale == locale)
return p.Value;
- else if (GetLocaleLang (p.Locale) == lang)
- best = p;
+ string plang = GetLocaleLang (p.Locale);
+ if (plang == p.Locale && plang == lang) // No country specified
+ sameLang = p;
+ else if (plang == lang)
+ sameLangDifCountry = p;
else if (p.Locale == null)
defaultLoc = p;
}
}
- if (best != null)
- return best.Value;
+ if (sameLang != null)
+ return sameLang.Value;
+ else if (sameLangDifCountry != null)
+ return sameLangDifCountry.Value;
else if (defaultLoc != null)
return defaultLoc.Value;
else
@@ -89,6 +96,12 @@ namespace Mono.Addins.Setup
public void SetPropertyValue (string name, string locale, string value)
{
+ if (string.IsNullOrEmpty (name))
+ throw new ArgumentException ("name can't be null or empty");
+
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
locale = NormalizeLocale (locale);
foreach (var p in this) {
diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs
index ace36ef..e05fd57 100644
--- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs
+++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs
@@ -268,7 +268,12 @@ namespace Mono.Addins.Description
/// The category.
/// </value>
public string Category {
- get { return category != null ? category : string.Empty; }
+ get {
+ string val = Properties.GetPropertyValue ("Category");
+ if (val.Length > 0)
+ return val;
+ return category ?? string.Empty;
+ }
set { category = value; }
}
@@ -731,8 +736,8 @@ namespace Mono.Addins.Description
elem.RemoveAttribute ("isroot");
// Name will return the file name when HasUserId=false
- if (Name.Length > 0)
- elem.SetAttribute ("name", Name);
+ if (!string.IsNullOrEmpty (name))
+ elem.SetAttribute ("name", name);
else
elem.RemoveAttribute ("name");
@@ -811,7 +816,8 @@ namespace Mono.Addins.Description
else
elem.AppendChild (oldHeader);
}
- oldHeader.RemoveAll ();
+ else
+ oldHeader.RemoveAll ();
foreach (var prop in properties) {
XmlElement propElem = elem.OwnerDocument.CreateElement (prop.Name);
if (!string.IsNullOrEmpty (prop.Locale))
diff --git a/Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs b/Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs
index 82af8b2..ca24de7 100644
--- a/Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs
+++ b/Mono.Addins/Mono.Addins.Description/AddinPropertyCollection.cs
@@ -47,20 +47,27 @@ namespace Mono.Addins.Description
{
locale = NormalizeLocale (locale);
string lang = GetLocaleLang (locale);
- AddinProperty best = null;
+ AddinProperty sameLangDifCountry = null;
+ AddinProperty sameLang = null;
AddinProperty defaultLoc = null;
+
foreach (var p in this) {
if (p.Name == name) {
if (p.Locale == locale)
return p.Value;
- else if (GetLocaleLang (p.Locale) == lang)
- best = p;
+ string plang = GetLocaleLang (p.Locale);
+ if (plang == p.Locale && plang == lang) // No country specified
+ sameLang = p;
+ else if (plang == lang)
+ sameLangDifCountry = p;
else if (p.Locale == null)
defaultLoc = p;
}
}
- if (best != null)
- return best.Value;
+ if (sameLang != null)
+ return sameLang.Value;
+ else if (sameLangDifCountry != null)
+ return sameLangDifCountry.Value;
else if (defaultLoc != null)
return defaultLoc.Value;
else
diff --git a/Mono.Addins/Mono.Addins/AddinInfo.cs b/Mono.Addins/Mono.Addins/AddinInfo.cs
index 162f6bf..b1125f7 100644
--- a/Mono.Addins/Mono.Addins/AddinInfo.cs
+++ b/Mono.Addins/Mono.Addins/AddinInfo.cs
@@ -80,6 +80,9 @@ namespace Mono.Addins
public string Name {
get {
+ string s = Properties.GetPropertyValue ("Name");
+ if (s.Length > 0)
+ return s;
if (name != null && name.Length > 0)
return name;
string sid = id;
@@ -101,27 +104,52 @@ namespace Mono.Addins
}
public string Author {
- get { return author; }
+ get {
+ string s = Properties.GetPropertyValue ("Author");
+ if (s.Length > 0)
+ return s;
+ return author;
+ }
set { author = value; }
}
public string Copyright {
- get { return copyright; }
+ get {
+ string s = Properties.GetPropertyValue ("Copyright");
+ if (s.Length > 0)
+ return s;
+ return copyright;
+ }
set { copyright = value; }
}
public string Url {
- get { return url; }
+ get {
+ string s = Properties.GetPropertyValue ("Url");
+ if (s.Length > 0)
+ return s;
+ return url;
+ }
set { url = value; }
}
public string Description {
- get { return description; }
+ get {
+ string s = Properties.GetPropertyValue ("Description");
+ if (s.Length > 0)
+ return s;
+ return description;
+ }
set { description = value; }
}
public string Category {
- get { return category; }
+ get {
+ string s = Properties.GetPropertyValue ("Category");
+ if (s.Length > 0)
+ return s;
+ return category;
+ }
set { category = value; }
}
diff --git a/Test/UnitTests/SimpleApp.addin.xml b/Test/UnitTests/SimpleApp.addin.xml
index 0119aa2..c4e3076 100644
--- a/Test/UnitTests/SimpleApp.addin.xml
+++ b/Test/UnitTests/SimpleApp.addin.xml
@@ -10,10 +10,10 @@
<Header>
<Name>A simple application</Name>
- <Name lang="ca">Una aplicació simple</Name>
+ <Name locale="ca">Una aplicació simple</Name>
<Description>SimpleApp description</Description>
<Author>Lluis Sanchez</Author>
- <copyright>GPL</copyright>
+ <Copyright>GPL</Copyright>
<Prop1>Val1</Prop1>
<Prop1 locale="ca-ES">Val1Cat</Prop1>
</Header>
diff --git a/Test/UnitTests/TestAddinDescription.cs b/Test/UnitTests/TestAddinDescription.cs
index d42d9b9..6e6b54e 100644
--- a/Test/UnitTests/TestAddinDescription.cs
+++ b/Test/UnitTests/TestAddinDescription.cs
@@ -32,7 +32,8 @@ using Mono.Addins;
namespace UnitTests
{
- public class TestAddinDescription
+ [TestFixture]
+ public class TestAddinDescription: TestBase
{
CultureInfo oldc;
@@ -56,47 +57,47 @@ namespace UnitTests
AddinDescription desc = new AddinDescription ();
desc.Properties.SetPropertyValue ("prop1", null, "val1");
- Assert.Equals ("val1", desc.Properties.GetPropertyValue ("prop1"));
- Assert.Equals ("val1", desc.Properties.GetPropertyValue ("prop1", "en"));
- Assert.Equals ("val1", desc.Properties.GetPropertyValue ("prop1", "en-US"));
- Assert.Equals ("val1", desc.Properties.GetPropertyValue ("prop1", "en_US"));
- Assert.Equals ("val1", desc.Properties.GetPropertyValue ("prop1", null));
+ Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1"));
+ Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", "en"));
+ Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", "en-US"));
+ Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", "en_US"));
+ Assert.AreEqual ("val1", desc.Properties.GetPropertyValue ("prop1", null));
- desc.Properties.SetPropertyValue ("prop2", "ca", "val2");
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
+ desc.Properties.SetPropertyValue ("prop2", "ca", "valCa");
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en-US"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en_US"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", null));
- desc.Properties.SetPropertyValue ("prop2", "ca_ES", "val3");
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca"));
- Assert.Equals ("val3", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
- Assert.Equals ("val3", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
+ desc.Properties.SetPropertyValue ("prop2", "ca_ES", "valCaEs");
+ Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca"));
+ Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
+ Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en-US"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", "en_US"));
Assert.IsEmpty (desc.Properties.GetPropertyValue ("prop2", null));
desc.Properties.SetPropertyValue ("prop2", null, "val4");
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca"));
- Assert.Equals ("val3", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
- Assert.Equals ("val3", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
- Assert.Equals ("val2", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
- Assert.Equals ("val4", desc.Properties.GetPropertyValue ("prop2", "en"));
- Assert.Equals ("val4", desc.Properties.GetPropertyValue ("prop2", "en-US"));
- Assert.Equals ("val4", desc.Properties.GetPropertyValue ("prop2", "en_US"));
- Assert.Equals ("val4", desc.Properties.GetPropertyValue ("prop2", null));
+ Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca"));
+ Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca-ES"));
+ Assert.AreEqual ("valCaEs", desc.Properties.GetPropertyValue ("prop2", "ca_ES"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca-AN"));
+ Assert.AreEqual ("valCa", desc.Properties.GetPropertyValue ("prop2", "ca_AN"));
+ Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", "en"));
+ Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", "en-US"));
+ Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", "en_US"));
+ Assert.AreEqual ("val4", desc.Properties.GetPropertyValue ("prop2", null));
}
[Test]
@@ -104,15 +105,15 @@ namespace UnitTests
{
Addin ad = AddinManager.Registry.GetAddin ("SimpleApp.Core");
- Assert.Equals ("Una aplicació simple", ad.Name);
- Assert.Equals ("A simple application", ad.Properties.GetPropertyValue ("Name","en-US"));
- Assert.Equals ("SimpleApp description", ad.Description);
- Assert.Equals ("Lluis Sanchez", ad.Description.Author);
- Assert.Equals ("GPL", ad.Description.Copyright);
- Assert.Equals ("Val1", ad.Properties.GetPropertyValue ("Prop1","en-US"));
- Assert.Equals ("Val1Cat", ad.Properties.GetPropertyValue ("Prop1"));
- Assert.Equals ("Val1", ad.Properties.GetPropertyValue ("Prop2","en-US"));
- Assert.Equals ("Val2", ad.Properties.GetPropertyValue ("Prop2"));
+ Assert.AreEqual ("Una aplicació simple", ad.Name);
+ Assert.AreEqual ("A simple application", ad.Properties.GetPropertyValue ("Name","en-US"));
+ Assert.AreEqual ("SimpleApp description", ad.Description.Description);
+ Assert.AreEqual ("Lluis Sanchez", ad.Description.Author);
+ Assert.AreEqual ("GPL", ad.Description.Copyright);
+ Assert.AreEqual ("Val1", ad.Properties.GetPropertyValue ("Prop1","en-US"));
+ Assert.AreEqual ("Val1Cat", ad.Properties.GetPropertyValue ("Prop1"));
+ Assert.AreEqual ("Val2", ad.Properties.GetPropertyValue ("Prop2","en-US"));
+ Assert.AreEqual ("Val2Cat", ad.Properties.GetPropertyValue ("Prop2"));
}
}
}