unit uThinClientTests;
{
  COSBI: Comprehensive Open Source Benchmarking Initiative
  Copyright (c) 2004 Van Smith

  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 2
  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, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  The current web address of the GNU General Public License is:
  http://www.gnu.org/licenses/gpl.html

  You can contact the authors of this software at:
  cosbi@vanshardware.com
  See www.vanshardware.com or www.cosbi.org for more contact details.
}

//==============================================================================
// Unit name: uRdpTests
// Unit description: This unit houses most of the tests used in QuickTests.
// Author: Van Smith
// Date: October 29, 2004
// OS dependent: Yes: Windows
// Resolution dependent: No, but resolution and color depth will impact scores.
// External unit dependencies: COSBI_Common, uCOSBI_TestBaseClass, GR32_Blend,
//   GR32_Image, GR32, Maze, uTests
//==============================================================================
// Modification History
// ------------ -------
// Ver  Date   Who    Description
// ==== ====== ====== ==========================================================
// 1.0 041029 Van     Created.
//==============================================================================

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Grids, COSBI_Common, GR32_Blend, GR32_Image,
  GR32, ComCtrls, Gauges, Maze, uCOSBI_TTest, uCOSBI_TGraphicsTest, uOutput,
  jpeg, SHDocVw, OleCtrls, ZipForge, uTests;

type

  TThinClientTest = class( TGraphicsTest )
  private
  protected
  public
    procedure Run; override;
  end; // TRDPTest .............................................................

  // Class name: TtcPlotLinesTest
  // Author: Van Smith
  // Date: May 3, 2002
  TtcPlotLinesTest = class( TThinClientTest )
  private
  protected
  public
    constructor Create; Overload;
    procedure RunTest; Override;
  end; // TtcPlotLinesTest.........................................................

  // Class name: TtcMazeTest
  // Author: Van Smith
  // Date: May 3, 2002
  TtcMazeTest = class( TThinClientTest )
  private
    fMaze : TMaze;
  protected
  public
    constructor Create; Overload;
    procedure RunTest; Override;
    procedure BeforeTest; Override;
    procedure AfterTest; Override;
  end; // TtcMazeTest.........................................................

  // Class name: TtcFilledCircleTest
  // Author: Van Smith
  // Date: May 3, 2002
  TtcFilledCircleTest = class( TThinClientTest )
  private
    fMaze : TMaze;
  protected
  public
    constructor Create; Overload;
    procedure RunTest; Override;
//    procedure BeforeTest; Override;
//    procedure AfterTest; Override;
  end; // TtcFilledCircleTest...................................................

implementation

// TThinClientTest begins........................................................
  procedure TThinClientTest.Run;
    procedure RandomDots;
    var
      x, y, z : integer;
    begin
      Application.ProcessMessages;
      with fPaintBox32 do begin
        // Random dots:
        RandSeed := 1;
        for z := 1 to 20000 do
        begin
          x := Random(Width);
          y := Random(Height);
          case Random(6) of
            0: Canvas.Pixels[x, y] := clBlack;
            1: Canvas.Pixels[x, y] := clGreen;
            2: Canvas.Pixels[x, y] := clBlue;
            3: Canvas.Pixels[x, y] := clRed;
            4: Canvas.Pixels[x, y] := clWhite;
            5: Canvas.Pixels[x, y] := clYellow;
          end;
        end;
      end; // with
      Application.ProcessMessages;
    end; // procedure RandomDots;
  begin
    if fStopWatch = nil then begin
      raise Exception.Create( fTestName + ERR_NO_STOPWATCH );
    end;
    try
      BeforeTest;
      fStopWatch.StartTimer;
      RunTest;
      // try to force RDP server to wait:
      RandomDots;
      fStopWatch.StopTimer;
      fRunCount := fRunCount + 1;
      fLastTime := fStopWatch.ElapsedTime;
      fTotalTime := fTotalTime + fLastTime;
      if fLastTime > fMaxTime then fMaxTime := fLastTime;
      if fLastTime < fMinTime then fMinTime := fLastTime;
    finally
      AfterTest;
    end;
  end; // procedure TThinClientTest.Run;
// TThinClientTest ends.........................................................

// TtcPlotLinesTest begins........................................................

  constructor TtcPlotLinesTest.Create;
  begin
    inherited;
    fTestName   := 'Thin Client Plot Lines';
    fTestDescription := 'Plots lines a pixel at a time';
    fTestVersion:= '1.0';
    fTestType   := ttThinClient;
    fTestAuthor := 'Van Smith';
    fReferenceTime := 7.708;
    fQTestType := qtTCPlotLines;
  end;

  procedure TtcPlotLinesTest.RunTest;
  var
    x : integer;
    y : integer;
  begin
    with fPaintBox32 do begin
      for x := Width downto 0 do
        for y := Height downto 0 do
          Canvas.Pixels[x, y] := clRed;
      for x := Width downto 0 do
        for y := Height downto 0 do
          Canvas.Pixels[x, y] := clBlack;
      Application.ProcessMessages;
      for y := Height downto 0 do
        for x := Width downto 0 do
          Canvas.Pixels[x, y] := clRed;
      for y := Height downto 0 do
        for x := Width downto 0 do
          Canvas.Pixels[x, y] := clBlack;
      Application.ProcessMessages;
      for x := 0 to Width do
        for y := 0 to Height do
          Canvas.Pixels[x, y] := clRed;
      for x := 0 to Width do
        for y := 0 to Height do
          Canvas.Pixels[x, y] := clBlack;
      Application.ProcessMessages;
      for y := 0 to Height do
        for x := 0 to Width do
          Canvas.Pixels[x, y] := clRed;
      for y := 0 to Height do
        for x := 0 to Width do
          Canvas.Pixels[x, y] := clBlack;
    end; // with
  end; // procedure TtcPlotLinesTest.RunTest;

// TtcPlotLinesTest ends..........................................................

// TtcMazeTest begins.............................................................

  constructor TtcMazeTest.Create;
  begin
    inherited;
    fTestName   := 'Thin Client Maze';
    fTestDescription := 'Generates mazes and graphically solves them';
    fTestVersion:= '1.0';
    fTestType   := ttCpu;
    fTestAuthor := 'Van Smith, Chris Yeager';
    fReferenceTime := 7.082;
    fQTestType := qtTCMaze;
  end;

  procedure TtcMazeTest.BeforeTest;
  begin
    inherited;
    fMaze := TMaze.Create( fPaintBox32 );
  end; // procedure TtcMazeTest.BeforeTest

  procedure TtcMazeTest.RunTest;
  var
    n : integer;
  begin
    RandSeed := -1;
    for n := 1 to 20 do begin
      with fMaze do begin
        Make(250, 250);
        Solve(True);
      end;// with lMaze
    end;
  end; // procedure TtcMazeTest.RunTest;

  procedure TtcMazeTest.AfterTest;
  begin
    inherited;
    FreeAndNil( fMaze );
  end; // procedure TtcMazeTest.BeforeTest

// TtcMazeTest ends...............................................................

// TtcFilledCircleTest begins.....................................................

  constructor TtcFilledCircleTest.Create;
  begin
    inherited;
    fTestName   := 'Thin Client Filled Circles';
    fTestDescription := 'Paints random filled circles';
    fTestVersion:= '1.0';
    fTestType   := tt2dGraphics;
    fTestAuthor := 'Van Smith';
    fReferenceTime := 2.196;
    fQTestType := qtCircles;
  end;

  procedure TtcFilledCircleTest.RunTest;
  var
    x : integer;
    y : integer;
    z : integer;
    r : integer;
  begin
    with fPaintBox32 do begin
      Canvas.Pen.Color := clRed;
      Canvas.Brush.Color := clBlack;
      Canvas.Brush.Style := bsSolid;
      RandSeed := 1;
      for z := 1 to 10000 do
      begin
        x := Random(Width);
        y := Random(Height);
        r := Random(Height div 2);
        case Random(6) of
          0: Canvas.Brush.Color := clBlack;
          1: Canvas.Brush.Color := clGreen;
          2: Canvas.Brush.Color := clBlue;
          3: Canvas.Brush.Color := clRed;
          4: Canvas.Brush.Color := clWhite;
          5: Canvas.Brush.Color := clYellow;
        end;
        Canvas.Ellipse(x - r, y - r, x + r, y + r);
        //Canvas.Pixels[x, y] := clWhite;
      end;
    end; // with
  end; // procedure TtcFilledCircleTest.RunTest;

// TtcFilledCircleTest ends.......................................................


end.
