2 // GSettingsExtractorTests.cs
5 // Andres G. Aragoneses <knocte@gmail.com>
7 // Copyright 2012 Andres G. Aragoneses
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
32 using Banshee
.Configuration
;
34 using NUnit
.Framework
;
36 namespace GSettingsSchemaExtractor
41 internal class StringType
{
42 public static readonly SchemaEntry
<string> DefaultExportFormat
= new SchemaEntry
<string> (
43 "player_window", "default_export_format",
46 "The default playlist export format"
51 public void SchemaWithString ()
53 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (StringType) }
);
55 Assert
.That (result
, Is
.Not
.Null
);
56 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
58 <schema id=""org.gnome.banshee.player_window"" path=""/apps/banshee/player_window/"" gettext-domain=""banshee"">
59 <key name=""default-export-format"" type=""s"">
60 <default>'m3u'</default>
61 <summary>Export Format</summary>
62 <description>The default playlist export format</description>
70 internal class BooleanType
72 public static readonly SchemaEntry
<bool> ShowInitialImportDialog
= new SchemaEntry
<bool>(
73 "import", "show_initial_import_dialog",
75 "Show the Initial Import Dialog",
76 "Show the Initial Import Dialog when the Banshee library is empty"
81 public void SchemaWithBoolean ()
83 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (BooleanType) }
);
85 Assert
.That (result
, Is
.Not
.Null
);
86 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
88 <schema id=""org.gnome.banshee.import"" path=""/apps/banshee/import/"" gettext-domain=""banshee"">
89 <key name=""show-initial-import-dialog"" type=""b"">
90 <default>true</default>
91 <summary>Show the Initial Import Dialog</summary>
92 <description>Show the Initial Import Dialog when the Banshee library is empty</description>
99 internal class IntegerType
{
100 public static readonly SchemaEntry
<int> VolumeSchema
= new SchemaEntry
<int> (
101 "player_engine", "volume",
104 "Volume of playback relative to mixer output"
109 public void SchemaWithInt ()
111 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (IntegerType) }
);
113 Assert
.That (result
, Is
.Not
.Null
);
114 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
116 <schema id=""org.gnome.banshee.player_engine"" path=""/apps/banshee/player_engine/"" gettext-domain=""banshee"">
117 <key name=""volume"" type=""i"">
118 <default>80</default>
119 <summary>Volume</summary>
120 <description>Volume of playback relative to mixer output</description>
127 internal class DoubleType
{
128 public static readonly SchemaEntry
<double> CoverArtSize
= new SchemaEntry
<double> (
129 "player_window", "cover_art_size",
132 "Surface size of cover art in the album grid"
137 public void SchemaWithDouble ()
139 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (DoubleType) }
);
141 Assert
.That (result
, Is
.Not
.Null
);
142 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
144 <schema id=""org.gnome.banshee.player_window"" path=""/apps/banshee/player_window/"" gettext-domain=""banshee"">
145 <key name=""cover-art-size"" type=""d"">
146 <default>20.5</default>
147 <summary>Cover art size</summary>
148 <description>Surface size of cover art in the album grid</description>
155 internal class ArrayType
{
156 public static readonly SchemaEntry
<string[]> CurrentFiltersSchema
= new SchemaEntry
<string[]> (
157 "sources.fsq", "current_filters",
158 new string[] { "album", "artist" }
,
165 public void SchemaWithArray ()
167 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (ArrayType) }
);
169 Assert
.That (result
, Is
.Not
.Null
);
170 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
172 <schema id=""org.gnome.banshee.sources.fsq"" path=""/apps/banshee/sources/fsq/"" gettext-domain=""banshee"">
173 <key name=""current-filters"" type=""as"">
174 <default>['album','artist']</default>
176 <description></description>
183 internal class ArrayTypeWithEmptyDefaultValue
{
184 public static readonly SchemaEntry
<string[]> CurrentFiltersSchema
= new SchemaEntry
<string[]> (
185 "sources.fsq", "current_filters",
193 public void SchemaWithEmptyArrayAsDefaultValue ()
195 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (ArrayTypeWithEmptyDefaultValue) }
);
197 Assert
.That (result
, Is
.Not
.Null
);
198 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
200 <schema id=""org.gnome.banshee.sources.fsq"" path=""/apps/banshee/sources/fsq/"" gettext-domain=""banshee"">
201 <key name=""current-filters"" type=""as"">
202 <default>[]</default>
204 <description></description>
212 public void SchemaWithMoreThanOneKey ()
214 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (
215 new Type
[] { typeof (IntegerType), typeof (DoubleType), typeof (StringType) }
);
217 Assert
.That (result
, Is
.Not
.Null
);
218 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
220 <schema id=""org.gnome.banshee.player_engine"" path=""/apps/banshee/player_engine/"" gettext-domain=""banshee"">
221 <key name=""volume"" type=""i"">
222 <default>80</default>
223 <summary>Volume</summary>
224 <description>Volume of playback relative to mixer output</description>
227 <schema id=""org.gnome.banshee.player_window"" path=""/apps/banshee/player_window/"" gettext-domain=""banshee"">
228 <key name=""cover-art-size"" type=""d"">
229 <default>20.5</default>
230 <summary>Cover art size</summary>
231 <description>Surface size of cover art in the album grid</description>
233 <key name=""default-export-format"" type=""s"">
234 <default>'m3u'</default>
235 <summary>Export Format</summary>
236 <description>The default playlist export format</description>
243 internal class StringTypeWithNullDefaultValue
{
244 public static readonly SchemaEntry
<string> LastScrobbleUrlSchema
= new SchemaEntry
<string> (
245 "plugins.audioscrobbler", "api_url",
247 "AudioScrobbler API URL",
248 "URL for the AudioScrobbler API (supports turtle.libre.fm, for instance)"
253 public void SchemaWithNullDefaultValue ()
255 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (StringTypeWithNullDefaultValue) }
);
257 Assert
.That (result
, Is
.Not
.Null
);
258 Assert
.That (result
.ToString ().Trim (), Is
.EqualTo (@"
260 <schema id=""org.gnome.banshee.plugins.audioscrobbler"" path=""/apps/banshee/plugins/audioscrobbler/"" gettext-domain=""banshee"">
261 <key name=""api-url"" type=""s"">
262 <default>''</default>
263 <summary>AudioScrobbler API URL</summary>
264 <description>URL for the AudioScrobbler API (supports turtle.libre.fm, for instance)</description>
271 internal class TypeWithInternalSchema
{
272 internal static readonly SchemaEntry
<int> VolumeSchema
= new SchemaEntry
<int> (
273 "player_engine", "volume",
276 "Volume of playback relative to mixer output"
281 public void SchemaNonPublic ()
283 StringBuilder result
= GSettingsSchemaExtractorProgram
.Extract (new Type
[] { typeof (TypeWithInternalSchema) }
);
285 Assert
.That (result
, Is
.Not
.Null
);
286 Assert
.That (result
.ToString ().Trim (), Is
.StringContaining ("<schema id="));