[banshee/gtk3] buid: add tests for current GConfSchemaExtractor implementation



commit e5e6124b82ff22a0208c0d24eee9b191b0586f29
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Tue Dec 18 02:22:50 2012 +0000

    buid: add tests for current GConfSchemaExtractor implementation
    
    This will help soon, for the new GSettingsSchemaExtractor.

 build/GConfSchemaExtractor.cs      |   39 ++++++--
 build/GConfSchemaExtractor.csproj  |   54 +++++++++++
 build/GConfSchemaExtractorTests.cs |  182 ++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+), 9 deletions(-)
---
diff --git a/build/GConfSchemaExtractor.cs b/build/GConfSchemaExtractor.cs
index 7eafee1..11469cb 100644
--- a/build/GConfSchemaExtractor.cs
+++ b/build/GConfSchemaExtractor.cs
@@ -5,16 +5,38 @@ using System.Text.RegularExpressions;
 using System.Collections.Generic;
 using System.Reflection;
 
-public class GConfSchemaExtractor
+public class GConfSchemaExtractorProgram
 {
-	private static Dictionary<string, StringBuilder> entries = 
-		new Dictionary<string, StringBuilder>();
-    private static int schema_count = 0;
+    private static Dictionary<string, StringBuilder> entries;
+    private static int schema_count;
 
     public static void Main(string [] args)
     {
-        Assembly asm = Assembly.LoadFrom(args[0]);
-        foreach(Type type in asm.GetTypes()) {
+        if (args.Length != 2) {
+            Console.Error.WriteLine ("Usage: gconf-schema-extractor.exe Foo.dll bar.schema");
+            Environment.Exit (1);
+        }
+
+        Extract (args [0], args [1]);
+    }
+
+    private static void Extract (string assemblyName, string outputFile)
+    {
+        Assembly asm = Assembly.LoadFrom (assemblyName);
+        StringBuilder sbuilder = Extract (asm.GetTypes ());
+        if (sbuilder != null) {
+            using (StreamWriter writer = new StreamWriter (outputFile)) {
+                writer.Write (sbuilder.ToString ());
+            }
+        }
+    }
+
+    internal static StringBuilder Extract (IEnumerable<Type> types)
+    {
+        schema_count = 0;
+        entries = new Dictionary<string, StringBuilder> ();
+
+        foreach (Type type in types) {
             foreach(FieldInfo field in type.GetFields()) {
                 if(field.FieldType.IsGenericType && 
                     field.FieldType.GetGenericTypeDefinition().Name.StartsWith("SchemaEntry")) {
@@ -51,10 +73,9 @@ public class GConfSchemaExtractor
             final.Append("  </schemalist>\n");
             final.Append("</gconfschemafile>\n");
 
-            using(StreamWriter writer = new StreamWriter(args[1])) {
-                writer.Write(final.ToString());
-            }
+            return final;
         }
+        return null;
     }
 
     private static string GetString(object o, string name)
diff --git a/build/GConfSchemaExtractor.csproj b/build/GConfSchemaExtractor.csproj
new file mode 100644
index 0000000..72ab63b
--- /dev/null
+++ b/build/GConfSchemaExtractor.csproj
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003";>
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{1E874712-E2F2-4FC1-BBB7-62CBF7A126B9}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>GConfSchemaExtractor</RootNamespace>
+    <AssemblyName>GConfSchemaExtractor</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>True</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>False</Optimize>
+    <OutputPath>.</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <Externalconsole>True</Externalconsole>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <DebugType>none</DebugType>
+    <Optimize>True</Optimize>
+    <OutputPath>.</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+    <Externalconsole>True</Externalconsole>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
+      <Private>False</Private>
+    </Reference>
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <ItemGroup>
+    <Compile Include="GConfSchemaExtractor.cs" />
+    <Compile Include="GConfSchemaExtractorTests.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\src\Core\Banshee.Core\Banshee.Core.csproj">
+      <Project>{2ADB831A-A050-47D0-B6B9-9C19D60233BB}</Project>
+      <Name>Banshee.Core</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\src\Hyena\Hyena\Hyena.csproj">
+      <Project>{95374549-9553-4C1E-9D89-667755F90E12}</Project>
+      <Name>Hyena</Name>
+    </ProjectReference>
+  </ItemGroup>
+</Project>
diff --git a/build/GConfSchemaExtractorTests.cs b/build/GConfSchemaExtractorTests.cs
new file mode 100644
index 0000000..780aac8
--- /dev/null
+++ b/build/GConfSchemaExtractorTests.cs
@@ -0,0 +1,182 @@
+//
+// GConfSchemaExtractorTests.cs
+//
+// Author:
+//   Andres G. Aragoneses <knocte gmail com>
+//
+// Copyright 2012 Andres G. Aragoneses
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Text;
+
+using Banshee.Configuration;
+
+using NUnit.Framework;
+
+namespace GConfSchemaExtractor
+{
+    [TestFixture]
+    public class Tests
+    {
+        internal class StringType {
+            public static readonly SchemaEntry<string> DefaultExportFormat = new SchemaEntry<string> (
+                "player_window", "default_export_format",
+                "m3u",
+                "Export Format",
+                "The default playlist export format"
+            );
+        }
+
+        [Test]
+        public void SchemaWithString ()
+        {
+            StringBuilder result = GConfSchemaExtractorProgram.Extract (new Type [] { typeof (StringType) });
+
+            Assert.That (result, Is.Not.Null);
+            Assert.That (result.ToString ().Trim (), Is.EqualTo (@"
+<?xml version=""1.0""?>
+<gconfschemafile>
+  <schemalist>
+    <schema>
+      <key>/schemas/apps/banshee/player_window/default_export_format</key>
+      <applyto>/apps/banshee/player_window/default_export_format</applyto>
+      <owner>banshee</owner>
+      <type>string</type>
+      <default>m3u</default>
+      <locale name=""C"">
+        <short>Export Format</short>
+        <long>The default playlist export format</long>
+      </locale>
+    </schema>
+  </schemalist>
+</gconfschemafile>"
+            .Trim ()));
+        }
+
+
+        internal class BooleanType
+        {
+            public static readonly SchemaEntry<bool> ShowInitialImportDialog = new SchemaEntry<bool>(
+                "import", "show_initial_import_dialog",
+                true,
+                "Show the Initial Import Dialog",
+                "Show the Initial Import Dialog when the Banshee library is empty"
+            );
+        }
+
+        [Test]
+        public void SchemaWithBoolean ()
+        {
+            StringBuilder result = GConfSchemaExtractorProgram.Extract (new Type [] { typeof (BooleanType) });
+
+            Assert.That (result, Is.Not.Null);
+            Assert.That (result.ToString ().Trim (), Is.EqualTo (@"
+<?xml version=""1.0""?>
+<gconfschemafile>
+  <schemalist>
+    <schema>
+      <key>/schemas/apps/banshee/import/show_initial_import_dialog</key>
+      <applyto>/apps/banshee/import/show_initial_import_dialog</applyto>
+      <owner>banshee</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name=""C"">
+        <short>Show the Initial Import Dialog</short>
+        <long>Show the Initial Import Dialog when the Banshee library is empty</long>
+      </locale>
+    </schema>
+  </schemalist>
+</gconfschemafile>"
+            .Trim ()));
+        }
+
+        internal class IntegerType {
+            public static readonly SchemaEntry<bool> ShowCoverArt = new SchemaEntry<bool> (
+                "player_window", "show_cover_art",
+                false,
+                "Show cover art",
+                "Show cover art below source view if available"
+            );
+        }
+
+        [Test]
+        public void SchemaWithInt ()
+        {
+            StringBuilder result = GConfSchemaExtractorProgram.Extract (new Type [] { typeof (IntegerType) });
+
+            Assert.That (result, Is.Not.Null);
+            Assert.That (result.ToString ().Trim (), Is.EqualTo (@"
+<?xml version=""1.0""?>
+<gconfschemafile>
+  <schemalist>
+    <schema>
+      <key>/schemas/apps/banshee/player_window/show_cover_art</key>
+      <applyto>/apps/banshee/player_window/show_cover_art</applyto>
+      <owner>banshee</owner>
+      <type>bool</type>
+      <default>false</default>
+      <locale name=""C"">
+        <short>Show cover art</short>
+        <long>Show cover art below source view if available</long>
+      </locale>
+    </schema>
+  </schemalist>
+</gconfschemafile>"
+                .Trim ()));
+        }
+
+        internal class DoubleType {
+            public static readonly SchemaEntry<double> CoverArtSize = new SchemaEntry<double> (
+                "player_window", "cover_art_size",
+                20.5,
+                "Cover art size",
+                "Surface size of cover art in the album grid"
+            );
+        }
+
+        [Test]
+        public void SchemaWithDouble ()
+        {
+            StringBuilder result = GConfSchemaExtractorProgram.Extract (new Type [] { typeof (DoubleType) });
+
+            Assert.That (result, Is.Not.Null);
+            Assert.That (result.ToString ().Trim (), Is.EqualTo (@"
+<?xml version=""1.0""?>
+<gconfschemafile>
+  <schemalist>
+    <schema>
+      <key>/schemas/apps/banshee/player_window/cover_art_size</key>
+      <applyto>/apps/banshee/player_window/cover_art_size</applyto>
+      <owner>banshee</owner>
+      <type>float</type>
+      <default>20.5</default>
+      <locale name=""C"">
+        <short>Cover art size</short>
+        <long>Surface size of cover art in the album grid</long>
+      </locale>
+    </schema>
+  </schemalist>
+</gconfschemafile>"
+            .Trim ()));
+        }
+    }
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]