Browse Source

+ created some tests for fcl-sound

git-svn-id: trunk@47447 -
nickysn 4 years ago
parent
commit
bed8b8bfd3

+ 13 - 0
.gitattributes

@@ -4317,6 +4317,19 @@ packages/fcl-sound/fpmake.pp svneol=native#text/plain
 packages/fcl-sound/src/fpwavformat.pas svneol=native#text/plain
 packages/fcl-sound/src/fpwavreader.pas svneol=native#text/plain
 packages/fcl-sound/src/fpwavwriter.pas svneol=native#text/plain
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16.wav -text svneol=unset#audio/x-wav
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16.wav.info.txt svneol=native#text/plain
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16_tag.wav -text svneol=unset#audio/x-wav
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16_tag.wav.info.txt svneol=native#text/plain
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_24.wav -text svneol=unset#audio/x-wav
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_24.wav.info.txt svneol=native#text/plain
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_32.wav -text svneol=unset#audio/x-wav
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_32.wav.info.txt svneol=native#text/plain
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_8.wav -text svneol=unset#audio/x-wav
+packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_8.wav.info.txt svneol=native#text/plain
+packages/fcl-sound/tests/tcwavreader.pas svneol=native#text/plain
+packages/fcl-sound/tests/testfclsound.lpi svneol=native#text/plain
+packages/fcl-sound/tests/testfclsound.lpr svneol=native#text/plain
 packages/fcl-stl/Makefile svneol=native#text/plain
 packages/fcl-stl/Makefile.fpc svneol=native#text/plain
 packages/fcl-stl/Makefile.fpc.fpcmake svneol=native#text/plain

BIN
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16.wav


+ 1 - 0
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16.wav.info.txt

@@ -0,0 +1 @@
+44100 1 16

BIN
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16_tag.wav


+ 1 - 0
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_16_tag.wav.info.txt

@@ -0,0 +1 @@
+44100 1 16

BIN
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_24.wav


+ 1 - 0
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_24.wav.info.txt

@@ -0,0 +1 @@
+44100 1 24

BIN
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_32.wav


+ 1 - 0
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_32.wav.info.txt

@@ -0,0 +1 @@
+44100 1 32

BIN
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_8.wav


+ 1 - 0
packages/fcl-sound/tests/data/wav/reader/valid/44k_mono_8.wav.info.txt

@@ -0,0 +1 @@
+44100 1 8

+ 67 - 0
packages/fcl-sound/tests/tcwavreader.pas

@@ -0,0 +1,67 @@
+unit tcwavreader;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, fpcunit, testutils, testregistry,
+  fpwavreader;
+
+type
+
+  { TTestWavReader }
+
+  TTestWavReader= class(TTestCase)
+  private
+    procedure TestValidFile(const FileName: string);
+  published
+    procedure TestValidFiles;
+  end;
+
+implementation
+
+procedure TTestWavReader.TestValidFile(const FileName: string);
+const
+  CorrectFileDir = 'data/wav/reader/valid/';
+var
+  WavReader: TWavReader;
+  InfoFile: TextFile;
+  ExpectedSampleRate, ExpectedChannels, ExpectedBitsPerSample : Integer;
+begin
+  AssignFile(InfoFile, CorrectFileDir + FileName + '.info.txt');
+  Reset(InfoFile);
+  try
+    Readln(InfoFile, ExpectedSampleRate, ExpectedChannels, ExpectedBitsPerSample);
+  finally
+    CloseFile(InfoFile);
+  end;
+
+  WavReader := TWavReader.Create;
+  try
+    if not WavReader.LoadFromFile(CorrectFileDir + FileName) then
+      Fail('Error loading wave file');
+    AssertEquals('Incorrect sample rate', ExpectedSampleRate, WavReader.fmt.SampleRate);
+    AssertEquals('Incorrect number of channels', ExpectedChannels, WavReader.fmt.Channels);
+    AssertEquals('Incorrect number of bits per sample', ExpectedBitsPerSample, WavReader.fmt.BitsPerSample);
+  finally
+    FreeAndNil(WavReader);
+  end;
+end;
+
+procedure TTestWavReader.TestValidFiles;
+begin
+  TestValidFile('44k_mono_8.wav');
+  TestValidFile('44k_mono_16.wav');
+  TestValidFile('44k_mono_24.wav');
+  TestValidFile('44k_mono_32.wav');
+  TestValidFile('44k_mono_16_tag.wav');
+end;
+
+
+
+initialization
+
+  RegisterTest(TTestWavReader);
+end.
+

+ 75 - 0
packages/fcl-sound/tests/testfclsound.lpi

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="11"/>
+    <General>
+      <SessionStorage Value="InProjectDir"/>
+      <MainUnit Value="0"/>
+      <Title Value="testfclsound"/>
+      <ResourceType Value="res"/>
+      <UseXPManifest Value="True"/>
+    </General>
+    <BuildModes Count="1">
+      <Item1 Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+      <Modes Count="0"/>
+    </RunParams>
+    <RequiredPackages Count="3">
+      <Item1>
+        <PackageName Value="fpcunittestrunner"/>
+      </Item1>
+      <Item2>
+        <PackageName Value="LCL"/>
+      </Item2>
+      <Item3>
+        <PackageName Value="FCL"/>
+      </Item3>
+    </RequiredPackages>
+    <Units Count="2">
+      <Unit0>
+        <Filename Value="testfclsound.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit0>
+      <Unit1>
+        <Filename Value="tcwavreader.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit1>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <Target>
+      <Filename Value="testfclsound"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <Linking>
+      <Options>
+        <Win32>
+          <GraphicApplication Value="True"/>
+        </Win32>
+      </Options>
+    </Linking>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 15 - 0
packages/fcl-sound/tests/testfclsound.lpr

@@ -0,0 +1,15 @@
+program testfclsound;
+
+{$mode objfpc}{$H+}
+
+uses
+  Interfaces, Forms, GuiTestRunner, tcwavreader;
+
+{$R *.res}
+
+begin
+  Application.Initialize;
+  Application.CreateForm(TGuiTestRunner, TestRunner);
+  Application.Run;
+end.
+