Studio:Log.pm

From STRIDE Wiki
Revision as of 19:18, 1 December 2008 by Timd (talk | contribs) (New page: <source lang="perl"> use strict; use warnings; use Carp; use Win32::TieRegistry(Delimiter=>"/"); use File::Spec; use Time::HiRes qw (usleep gettimeofday tv_interval sleep); use Win32::OL...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


use strict;
use warnings;
use Carp;
use Win32::TieRegistry(Delimiter=>"/");
use File::Spec;
use Time::HiRes qw (usleep gettimeofday tv_interval sleep);
use Win32::OLE;
Win32::OLE->Option(Warn => 3);

# setup the lib path
use vars qw(
    $studio
    $testSuite
    $ascript
    $StrideDir
    $StrideLibDir
);
BEGIN {
    $StrideDir = 
        $Registry->{"LMachine/SOFTWARE/S2 Technologies/STRIDE/InstallDir"} ||
        $ENV{'STRIDE_DIR'} ||
        'C:\\STRIDE';
    $StrideLibDir = File::Spec->catdir($StrideDir, 'lib', 'perl');
}

###############################
# Imported Libs 
###############################
use lib $StrideLibDir; # Use the above calculated path to finf the lib's

use S2S::Log;

 
# create a test case to which comments will be added
$main::testSuite->Tests->RemoveAll();
my $tcName = "Sample Test Case";
my $tc = $main::testSuite->Tests->Add($tcName);

my $logMsg = $main::ascript->Messages->Item("logMSG")->Owner;

# set up a trace view to capture broadcast log messages
my $tvName = 'Log Viewer';
my $tv = $main::studio->Workspace->TraceViews->Item($tvName);
if (!$tv) {
    $tv = $main::studio->Workspace->TraceViews->Add("HostTraceView");
    $tv->{Name} = $tvName;
}
$tv->Open();
my $tvFilter =$tv->Filters->InterfacesByUniqueId->Item($logMsg->Name);
$tvFilter->{Data} = 1;
$tvFilter->{On} = 1;
$tv->Filters->InterfacesByUniqueId->Apply();


my $log = new Log;

$log->addStudio(
    {
        # accept defaults
    }
);

$log->addFile(
   {
      # accept defaults
   }
);

$log->addBCMessage(
    {
        messageOwner => $logMsg
    }
);

$log->addTestCase(
    {
        testCase => $tc
    }
); 

$log->addAnnotation(
    {
        testSuite => $main::testSuite
    }
);

$log->debug('this is a debug test message');
$log->warning('this is a warning test message');
$log->error('this is an error test message');
$log->fatal('this is a fatal test message');

my $number = 12345;

$log->debug('this is another debug test message: %x and %e ', $number, $number);
$log->warning('this is another warning test message');
$log->error('this is another error test message');
$log->fatal('this is another fatal test message');

$tc->{Status} = "PASS";