Permalink
Browse files

[Tests] Unit test gkeyfile parsing functions

  • Loading branch information...
1 parent c2998a9 commit f3cbaca06ede56a063aca4bd87256273b1404e2b @lamalex lamalex committed Aug 15, 2010
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{6930CFC0-D7D8-49E4-817F-BFE9D73AAC0D}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>Tests</RootNamespace>
+ <AssemblyName>Tests</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <ItemGroup>
+ <Reference Include="nunit.framework, Version=2.4.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
+ <Package>nunit</Package>
+ </Reference>
+ <Reference Include="gkeyfile-sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e886e4e52ee77480">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\gkeyfile-sharp.dll</HintPath>
+ </Reference>
+ <Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
+ <Package>glib-sharp-2.0</Package>
+ </Reference>
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="src\" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="src\GKeyFileTests.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Resource Include="src\test-keyfile.keyfile" />
+ </ItemGroup>
+</Project>
View
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests.csproj", "{6930CFC0-D7D8-49E4-817F-BFE9D73AAC0D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6930CFC0-D7D8-49E4-817F-BFE9D73AAC0D}.Debug|x86.ActiveCfg = Debug|x86
+ {6930CFC0-D7D8-49E4-817F-BFE9D73AAC0D}.Debug|x86.Build.0 = Debug|x86
+ {6930CFC0-D7D8-49E4-817F-BFE9D73AAC0D}.Release|x86.ActiveCfg = Release|x86
+ {6930CFC0-D7D8-49E4-817F-BFE9D73AAC0D}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ StartupItem = Tests.csproj
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,36 @@
+<Properties>
+ <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" ctype="Workspace" />
+ <MonoDevelop.Ide.Workbench ActiveDocument="src/GKeyFileTests.cs" ctype="Workbench">
+ <Files>
+ <File FileName="src/GKeyFileTests.cs" Line="42" Column="20" />
+ </Files>
+ <Pads>
+ <Pad Id="ProjectPad">
+ <State expanded="True">
+ <Node name="Tests" expanded="True" selected="True">
+ <Node name="src" expanded="True" />
+ </Node>
+ </State>
+ </Pad>
+ <Pad Id="ClassPad">
+ <State expanded="True">
+ <Node name="Tests" expanded="True" selected="True">
+ <Node name="References" expanded="True" />
+ </Node>
+ </State>
+ </Pad>
+ <Pad Id="MonoDevelop.Debugger.WatchPad">
+ <State />
+ </Pad>
+ <Pad Id="MonoDevelop.NUnit.TestPad">
+ <State expanded="True">
+ <Node name="Tests" selected="True" />
+ </State>
+ </Pad>
+ </Pads>
+ </MonoDevelop.Ide.Workbench>
+ <MonoDevelop.Ide.DebuggingService.Breakpoints>
+ <BreakpointStore />
+ </MonoDevelop.Ide.DebuggingService.Breakpoints>
+ <MonoDevelop.Ide.DebuggingService.PinnedWatches ctype="PinnedWatchStore" />
+</Properties>
@@ -0,0 +1,121 @@
+//
+// GKeyFileTests.cs
+//
+// Author:
+// Alex Launi <alex.launi@gmail.com>
+//
+// Copyright (c) 2010 Alex Launi
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+using System;
+using System.IO;
+using System.Linq;
+
+using NUnit.Framework;
+using NUnit.Framework.Constraints;
+using NUnit.Framework.SyntaxHelpers;
+
+using KeyFile;
+
+[TestFixture()]
+public class GKeyFileTests
+{
+ const string TEST_FILE_NAME = "test-keyfile.keyfile";
+
+ GKeyFile test_keyfile;
+
+ [SetUp]
+ public void Init ()
+ {
+ string testFile = new [] {Environment.CurrentDirectory, "..", "..", "src", TEST_FILE_NAME}.Aggregate (Path.Combine);
+ test_keyfile = new GKeyFile (testFile);
+ }
+
+ /*
+ [Test]
+ public void SetSeperator ()
+ {
+ GKeyFile testKeyfile = new GKeyFile (TEST_FILE_NAME);
+
+ testKeyfile.
+ string[] testSeps = new string[] {";", ":"};
+ foreach (string sep in testSeps) {
+ testKeyfile.ListSeparator = sep;
+ Assert.AreEqual (sep, testKeyfile.ListSeparator);
+ }
+ }
+ */
+
+ [Test]
+ public void GetString ()
+ {
+ Assert.AreEqual ("astring", test_keyfile.GetString ("Group1", "String"));
+ Assert.AreEqual ("a string with spaces", test_keyfile.GetString ("Group1", "StringWithSpaces"));
+ Assert.AreEqual ("a\tstring\nwith escaping", test_keyfile.GetString ("Group1", "StringWithEscaping"));
+ }
+
+ [Test]
+ public void GetBoolean ()
+ {
+ Assert.IsTrue (test_keyfile.GetBoolean ("Group1", "TrueBool"));
+ Assert.IsFalse (test_keyfile.GetBoolean ("Group1", "FalseBool"));
+ }
+
+ [Test]
+ public void GetInteger ()
+ {
+ Assert.AreEqual (256, test_keyfile.GetInteger ("Group1", "Integer"));
+ Assert.AreEqual (-1024, test_keyfile.GetInteger ("Group1", "NegativeInt"));
+ }
+
+ [Test]
+ public void GetDouble ()
+ {
+ Assert.AreEqual (11.28, test_keyfile.GetDouble ("Group1", "Double"));
+ Assert.AreEqual (-28.11, test_keyfile.GetDouble ("Group1", "NegativeDouble"));
+ }
+
+ [Test]
+ public void GetStringList ()
+ {
+ string [] expected = new string [] { "one", "two", "three", "four" };
+
+ CollectionAssert.AreEqual (expected, test_keyfile.GetStringList ("Group1", "StringList"));
+ }
+
+ [Test]
+ public void GetBooleanList ()
+ {
+ bool [] expected = new bool [] { true, false, false, true };
+
+ CollectionAssert.AreEqual (expected, test_keyfile.GetBooleanList ("Group1", "BoolList"));
+ }
+
+ [Test]
+ public void GetIntegerList ()
+ {
+ int [] expected = new int [] { 0, 1, 2, 04, -5 };
+
+ CollectionAssert.AreEqual (expected, test_keyfile.GetIntegerList ("Group1", "IntegerList"));
+ }
+
+ [Test]
+ public void GetDoubleList ()
+ {
+ double [] expected = new double [] { 10, 10.3, 46.3, -0.8 };
+
+ CollectionAssert.AreEqual (expected, test_keyfile.GetDoubleList ("Group1", "DoubleList"));
+ }
+}
@@ -0,0 +1,18 @@
+# This file is part of the GKeyFile-sharp test suite.
+# (C) 2010 Alex Launi
+# This file is a bs gkeyfile for unit testing purposes.
+
+[Group1]
+String=astring
+StringWithSpaces=a string with spaces
+StringWithEscaping=a\tstring\nwith escaping
+TrueBool=true
+FalseBool=false
+Integer=256
+NegativeInt=-1024
+Double=11.28
+NegativeDouble=-28.11
+StringList=one;two;three;four
+BoolList=true;false;false;true
+IntegerList=0;1;2;04;-5
+DoubleList=10;10.3;46.3;-0.8

0 comments on commit f3cbaca

Please sign in to comment.