sl@0: # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # sl@0: sl@0: package TestScriptResults; sl@0: use strict; sl@0: use Exporter; sl@0: use base 'Exporter'; sl@0: sl@0: # Crashing enums sl@0: my $KTestDidNotCrash = 0; sl@0: my $KTestCrashed = 1; sl@0: sl@0: # Test Harness enums sl@0: our $KCoreConfTest = "CoreConf"; sl@0: our $KTEFTest = "TEF"; sl@0: our $KTEFNoTestcasesTest = "TEFNoTestcases"; # Some of the older MM TEF tests were implemented without using testcases, in these cases we use the test steps in their place sl@0: our $KTestFrameworkTest = "TF"; sl@0: sl@0: our @EXPORT = qw($KCoreConfTest, $KTEFTest, $KTEFNoTestcasesTest, $KTestFrameworkTest); sl@0: sl@0: # Constructor sl@0: sub TestScriptResults sl@0: { sl@0: my $this = {}; sl@0: $this->{ScriptName} = undef; sl@0: $this->{FilePath} = undef; sl@0: $this->{DidItCrash} = $KTestDidNotCrash; sl@0: $this->{TotalNumberTestCases} = undef; sl@0: $this->{Inconclusives} = [1]; # First entry gives the next free index sl@0: $this->{Fails} = [1]; # First entry gives the next free index sl@0: $this->{TestHarness} = undef; sl@0: bless($this); sl@0: return $this; sl@0: } sl@0: sl@0: sub SetScriptName sl@0: { sl@0: my $this = shift; sl@0: $this->{ScriptName} = shift; sl@0: } sl@0: sl@0: sub ScriptName sl@0: { sl@0: my $this = shift; sl@0: return $this->{ScriptName}; sl@0: } sl@0: sl@0: sub SetFilePath sl@0: { sl@0: my $this = shift; sl@0: $this->{FilePath} = shift; sl@0: } sl@0: sl@0: sub FilePath sl@0: { sl@0: my $this = shift; sl@0: return $this->{FilePath}; sl@0: } sl@0: sl@0: sub CoreConfTest sl@0: { sl@0: my $this = shift; sl@0: $this->{TestHarness} = $KCoreConfTest; sl@0: } sl@0: sl@0: sub TEFTest sl@0: { sl@0: my $this = shift; sl@0: $this->{TestHarness} = $KTEFTest; sl@0: } sl@0: sl@0: sub TEFNoTestcasesTest sl@0: { sl@0: my $this = shift; sl@0: $this->{TestHarness} = $KTEFNoTestcasesTest; sl@0: } sl@0: sl@0: sub TestFrameworkTest sl@0: { sl@0: my $this = shift; sl@0: $this->{TestHarness} = $KTestFrameworkTest; sl@0: } sl@0: sl@0: sub TestHarness sl@0: { sl@0: my $this = shift; sl@0: return $this->{TestHarness}; sl@0: } sl@0: sl@0: sub AddInconclusiveResult sl@0: { sl@0: my $this = shift; sl@0: my $currentFreeIndex = $this->{Inconclusives}[0]; sl@0: $this->{Inconclusives}[$currentFreeIndex] = shift; sl@0: $currentFreeIndex++; sl@0: $this->{Inconclusives}[0] = $currentFreeIndex; sl@0: } sl@0: sl@0: sub ResetInconclusives sl@0: { sl@0: my $this = shift; sl@0: $this->{Inconclusives}[0] = 1; sl@0: } sl@0: sl@0: sub Inconclusives sl@0: { sl@0: my $this = shift; sl@0: my @inconList = @{$this->{Inconclusives}}; sl@0: my $finalIndex = $inconList[0] - 1; sl@0: return @inconList[1 .. $finalIndex]; sl@0: } sl@0: sl@0: sub AddFailureResult sl@0: { sl@0: my $this = shift; sl@0: my $currentFreeIndex = $this->{Fails}[0]; sl@0: $this->{Fails}[$currentFreeIndex] = shift; sl@0: $currentFreeIndex++; sl@0: $this->{Fails}[0] = $currentFreeIndex; sl@0: } sl@0: sl@0: sub ResetFailures sl@0: { sl@0: my $this = shift; sl@0: $this->{Fails}[0] = 1; sl@0: } sl@0: sl@0: sub Failures sl@0: { sl@0: my $this = shift; sl@0: my @failureList = @{$this->{Fails}}; sl@0: my $finalIndex = $failureList[0] - 1; sl@0: return @failureList[1 .. $finalIndex]; sl@0: } sl@0: sl@0: sub SetTotalTestCount sl@0: { sl@0: my $this = shift; sl@0: $this->{TotalNumberTestCases} = shift; sl@0: } sl@0: sl@0: sub TotalTestCount sl@0: { sl@0: my $this = shift; sl@0: return $this->{TotalNumberTestCases}; sl@0: } sl@0: sl@0: sub TestCrashed sl@0: { sl@0: my $this = shift; sl@0: $this->{DidItCrash} = $KTestCrashed; sl@0: } sl@0: sl@0: sub ResetCrashed sl@0: { sl@0: my $this = shift; sl@0: $this->{DidItCrash} = $KTestDidNotCrash; sl@0: } sl@0: sl@0: sub DidItCrash sl@0: { sl@0: my $this = shift; sl@0: return $this->{DidItCrash}; sl@0: } sl@0: sl@0: sub AnyFailures sl@0: { sl@0: my $this = shift; sl@0: if (($this->{Fails}[0] > 1) || ($this->{Inconclusives}[0] > 1) || ($this->DidItCrash())) sl@0: { sl@0: return 1; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: sub DebugPrint sl@0: { sl@0: my $this = shift; sl@0: print "\nTest script: $this->{ScriptName}\n$this->{FilePath}\n"; sl@0: if ($this->{DidItCrash} == $KTestCrashed) sl@0: { sl@0: print "It CRASHED\n"; sl@0: } sl@0: print "Test cases run: $this->{TotalNumberTestCases}\n"; sl@0: sl@0: my $lastIndex = $this->{Inconclusives}[0] - 1; sl@0: if ($lastIndex > 0) sl@0: { sl@0: print "INCONCLUSIVES:\n"; sl@0: foreach my $inconclusiveResult (@{$this->{Inconclusives}}[1 .. $lastIndex]) sl@0: { sl@0: print "$inconclusiveResult\n"; sl@0: } sl@0: } sl@0: sl@0: $lastIndex = $this->{Fails}[0] - 1; sl@0: if ($lastIndex > 0) sl@0: { sl@0: print "FAILS:\n"; sl@0: foreach my $failResult (@{$this->{Fails}}[1 .. $lastIndex]) sl@0: { sl@0: print "$failResult\n"; sl@0: } sl@0: } sl@0: }