Core Overview

The Core component provides general low level functionality. The Core component produces two different assemblies, CoreOss.dll and TestFrameworkOss.dll, which are discussed in the sections below.

CoreOss.dll

The primary classes of interest in CoreOss.dll are,

  • OptionParser - Provides command line option parsing
  • App - Provides a default command line application framework
  • AppWinForm - Provides a default windowed application framework

OptionParser Class

The option parser class automatically generates the -h or --help option, which produces a formatted output of the all the command line options, (along with the option's description), supported by the application.

The option parser supports options of the following types,

  • Strings (OptionString)
  • Integers (OptionInt)
  • Unsigned integers (OptionUint)
  • Booleans (OptionBool)

Example usage of the option parser,

using System;
using Linn;           // to include OptionParser

class Program
{
    static void Main()
    {
        string[] cmdLineArgs = System.Environment.GetCommandLineArgs();

        string iName = cmdLineArgs[0];

        string[] args = new string[cmdLineArgs.Length - 1];
        Array.Copy(cmdLineArgs, 1, args, 0, cmdLineArgs.Length - 1);

        iOptionParser = new OptionParser(args);
        iOptionParser.Usage = "usage: " + iName;

        iStringOption = new OptionString("-s", "--string", "default", "A string option for testing", "TESTSTRING");
        iOptionParser.AddOption(iStringOption);

        System.Console.WriteLine("string option supplied was " + iStringOption.Value);
    }
}

App Class

The App class provides a command line application with a default option parser with the standard -h/--help option as well as a -t/--trace option. The -t/--trace option allows the trace level to be specified dynamically at the application's runtime.

The App framework also provides a mechanism for catching unhandled exceptions and logging them to an ICrashLogDumper. The default ICrashLogDumper for App is one that writes the exception to a file with the same name as the executable with a .log extension.

Example usage of the App framework,

using Linn;   // to include App

class Program
{
    static void Main()
    {
        App app = new App();

        // add some new options
        OptionParser optParser = app.OptionParser;
        
        iStringOption = new OptionString("-s", "--string", "default", "A string option for testing", "TESTSTRING");
        optParser .AddOption(iStringOption);

        // do some other stuff...

        app.Dispose();
    }
}

AppWinForm

The AppWinForm class provides the same functionality as App does, but for a windowed application.

Example usage of the AppWinForm framework,

using Linn;   // to include AppWinForm

class Program
{
    static void Main()
    {
        App app = new App();
        AppWinForm appWin = new AppWinForm(app);

        // add some new options
        OptionParser optParser = app.OptionParser;
        
        iStringOption = new OptionString("-s", "--string", "default", "A string option for testing", "TESTSTRING");
        optParser .AddOption(iStringOption);

        // do some other stuff...

        appWin.Dispose();
    }
}

TestFrameworkOss.dll

The classes of interest in TestFrameworkOss.dll are,

  • Suite - A class defining a suite of tests to run
  • Runner - A class defining a run of test suites

Suite

The Suite class defines a collection of tests to be run.

Suite supports the following test statements,

  • TEST - a boolean test
  • TEST_THROWS - tests for a particular exception being thrown
  • TEST_THROWS_NEW - tests for a particular exception being thrown during a new operation

Example usage of Suite,

using Linn.TestFramework;     // to include Suite

internal class SuiteTest : Suite
{
    internal public SuiteTest(string aDescription)
        : base(aDescription)
    {}

    public override void Test()
    {
        TEST(1==1);
    }
}

Runner

The Runner class allows for running multiple Suites of tests.

Example usage of Runner,

using Linn.TestFramework;     // to include Runner

class UnitTest
{
    static void Main()
    {
        App app = new App();
        app.Start();

        Runner runner = new Runner("Test runner");
        runner.Add( new SuiteTest("Test suite") );
        runner.Run();
     }
}