summaryrefslogtreecommitdiff
path: root/contrib/testzlib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/testzlib')
-rw-r--r--contrib/testzlib/testzlib.c149
-rw-r--r--contrib/testzlib/testzlib.sln21
-rw-r--r--contrib/testzlib/testzlib.vcproj124
3 files changed, 294 insertions, 0 deletions
diff --git a/contrib/testzlib/testzlib.c b/contrib/testzlib/testzlib.c
new file mode 100644
index 0000000..caae4ef
--- /dev/null
+++ b/contrib/testzlib/testzlib.c
@@ -0,0 +1,149 @@
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <windows.h>
5#include "zlib.h"
6
7int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr)
8{
9 FILE* stream;
10 void* ptr;
11 int retVal=1;
12 stream=fopen(filename, "rb");
13 if (stream==NULL)
14 return 0;
15
16 fseek(stream,0,SEEK_END);
17
18 *plFileSize=ftell(stream);
19 fseek(stream,0,SEEK_SET);
20 ptr=malloc((*plFileSize)+1);
21 if (ptr==NULL)
22 retVal=0;
23 else
24 {
25 if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize))
26 retVal=0;
27 }
28 fclose(stream);
29 *pFilePtr=ptr;
30 return retVal;
31}
32
33int main(int argc, char *argv[])
34{
35 int BlockSizeCompress=0x8000;
36 int BlockSizeUncompress=0x8000;
37 int cprLevel=Z_DEFAULT_COMPRESSION ;
38 long lFileSize;
39 unsigned char* FilePtr;
40 long lBufferSizeCpr;
41 long lBufferSizeUncpr;
42 long lCompressedSize=0;
43 unsigned char* CprPtr;
44 unsigned char* UncprPtr;
45 long lSizeCpr,lSizeUncpr;
46 DWORD dwGetTick;
47
48 if (argc<=1)
49 {
50 printf("run TestZlib <File> [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n");
51 return 0;
52 }
53
54 if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0)
55 {
56 printf("error reading %s\n",argv[1]);
57 return 1;
58 }
59 else printf("file %s read, %u bytes\n",argv[1],lFileSize);
60
61 if (argc>=3)
62 BlockSizeCompress=atol(argv[2]);
63
64 if (argc>=4)
65 BlockSizeUncompress=atol(argv[3]);
66
67 if (argc>=5)
68 cprLevel=(int)atol(argv[4]);
69
70 lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200;
71 lBufferSizeUncpr = lBufferSizeCpr;
72
73 CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress);
74 UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress);
75
76 dwGetTick=GetTickCount();
77 {
78 z_stream zcpr;
79 int ret=Z_OK;
80 long lOrigToDo = lFileSize;
81 long lOrigDone = 0;
82 int step=0;
83 memset(&zcpr,0,sizeof(z_stream));
84 deflateInit(&zcpr,cprLevel);
85
86 zcpr.next_in = FilePtr;
87 zcpr.next_out = CprPtr;
88
89
90 do
91 {
92 long all_read_before = zcpr.total_in;
93 zcpr.avail_in = min(lOrigToDo,BlockSizeCompress);
94 zcpr.avail_out = BlockSizeCompress;
95 ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH);
96 lOrigDone += (zcpr.total_in-all_read_before);
97 lOrigToDo -= (zcpr.total_in-all_read_before);
98 step++;
99 } while (ret==Z_OK);
100
101 lSizeCpr=zcpr.total_out;
102 deflateEnd(&zcpr);
103 dwGetTick=GetTickCount()-dwGetTick;
104 printf("total compress size = %u, in %u step\n",lSizeCpr,step);
105 printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.);
106 }
107
108 dwGetTick=GetTickCount();
109 {
110 z_stream zcpr;
111 int ret=Z_OK;
112 long lOrigToDo = lSizeCpr;
113 long lOrigDone = 0;
114 int step=0;
115 memset(&zcpr,0,sizeof(z_stream));
116 inflateInit(&zcpr);
117
118 zcpr.next_in = CprPtr;
119 zcpr.next_out = UncprPtr;
120
121
122 do
123 {
124 long all_read_before = zcpr.total_in;
125 zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress);
126 zcpr.avail_out = BlockSizeUncompress;
127 ret=inflate(&zcpr,Z_SYNC_FLUSH);
128 lOrigDone += (zcpr.total_in-all_read_before);
129 lOrigToDo -= (zcpr.total_in-all_read_before);
130 step++;
131 } while (ret==Z_OK);
132
133 lSizeUncpr=zcpr.total_out;
134 inflateEnd(&zcpr);
135 dwGetTick=GetTickCount()-dwGetTick;
136 printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step);
137 printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.);
138 }
139
140 if (lSizeUncpr==lFileSize)
141 {
142 if (memcmp(FilePtr,UncprPtr,lFileSize)==0)
143 printf("compare ok\n");
144
145 }
146
147 return 0;
148
149}
diff --git a/contrib/testzlib/testzlib.sln b/contrib/testzlib/testzlib.sln
new file mode 100644
index 0000000..86da716
--- /dev/null
+++ b/contrib/testzlib/testzlib.sln
@@ -0,0 +1,21 @@
1Microsoft Visual Studio Solution File, Format Version 7.00
2Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
3EndProject
4Global
5 GlobalSection(SolutionConfiguration) = preSolution
6 ConfigName.0 = Debug
7 ConfigName.1 = Release
8 EndGlobalSection
9 GlobalSection(ProjectDependencies) = postSolution
10 EndGlobalSection
11 GlobalSection(ProjectConfiguration) = postSolution
12 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.ActiveCfg = Debug|Win32
13 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug.Build.0 = Debug|Win32
14 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.ActiveCfg = Release|Win32
15 {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release.Build.0 = Release|Win32
16 EndGlobalSection
17 GlobalSection(ExtensibilityGlobals) = postSolution
18 EndGlobalSection
19 GlobalSection(ExtensibilityAddIns) = postSolution
20 EndGlobalSection
21EndGlobal
diff --git a/contrib/testzlib/testzlib.vcproj b/contrib/testzlib/testzlib.vcproj
new file mode 100644
index 0000000..8e4233a
--- /dev/null
+++ b/contrib/testzlib/testzlib.vcproj
@@ -0,0 +1,124 @@
1<?xml version="1.0" encoding = "Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.00"
5 Name="testzlib"
6 ProjectGUID="{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}"
7 Keyword="Win32Proj">
8 <Platforms>
9 <Platform
10 Name="Win32"/>
11 </Platforms>
12 <Configurations>
13 <Configuration
14 Name="Debug|Win32"
15 OutputDirectory="Debug"
16 IntermediateDirectory="Debug"
17 ConfigurationType="1"
18 CharacterSet="2">
19 <Tool
20 Name="VCCLCompilerTool"
21 Optimization="0"
22 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
23 MinimalRebuild="TRUE"
24 BasicRuntimeChecks="3"
25 RuntimeLibrary="5"
26 UsePrecompiledHeader="0"
27 WarningLevel="3"
28 Detect64BitPortabilityProblems="TRUE"
29 DebugInformationFormat="4"/>
30 <Tool
31 Name="VCCustomBuildTool"/>
32 <Tool
33 Name="VCLinkerTool"
34 OutputFile="$(OutDir)/testzlib.exe"
35 LinkIncremental="2"
36 GenerateDebugInformation="TRUE"
37 ProgramDatabaseFile="$(OutDir)/testzlib.pdb"
38 SubSystem="1"
39 TargetMachine="1"/>
40 <Tool
41 Name="VCMIDLTool"/>
42 <Tool
43 Name="VCPostBuildEventTool"/>
44 <Tool
45 Name="VCPreBuildEventTool"/>
46 <Tool
47 Name="VCPreLinkEventTool"/>
48 <Tool
49 Name="VCResourceCompilerTool"/>
50 <Tool
51 Name="VCWebServiceProxyGeneratorTool"/>
52 <Tool
53 Name="VCWebDeploymentTool"/>
54 </Configuration>
55 <Configuration
56 Name="Release|Win32"
57 OutputDirectory="Release"
58 IntermediateDirectory="Release"
59 ConfigurationType="1"
60 CharacterSet="2">
61 <Tool
62 Name="VCCLCompilerTool"
63 Optimization="2"
64 InlineFunctionExpansion="1"
65 OmitFramePointers="TRUE"
66 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
67 StringPooling="TRUE"
68 RuntimeLibrary="4"
69 EnableFunctionLevelLinking="TRUE"
70 UsePrecompiledHeader="0"
71 WarningLevel="3"
72 Detect64BitPortabilityProblems="TRUE"
73 DebugInformationFormat="3"/>
74 <Tool
75 Name="VCCustomBuildTool"/>
76 <Tool
77 Name="VCLinkerTool"
78 OutputFile="$(OutDir)/testzlib.exe"
79 LinkIncremental="1"
80 GenerateDebugInformation="TRUE"
81 SubSystem="1"
82 OptimizeReferences="2"
83 EnableCOMDATFolding="2"
84 OptimizeForWindows98="1"
85 TargetMachine="1"/>
86 <Tool
87 Name="VCMIDLTool"/>
88 <Tool
89 Name="VCPostBuildEventTool"/>
90 <Tool
91 Name="VCPreBuildEventTool"/>
92 <Tool
93 Name="VCPreLinkEventTool"/>
94 <Tool
95 Name="VCResourceCompilerTool"/>
96 <Tool
97 Name="VCWebServiceProxyGeneratorTool"/>
98 <Tool
99 Name="VCWebDeploymentTool"/>
100 </Configuration>
101 </Configurations>
102 <Files>
103 <Filter
104 Name="Source Files"
105 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
106 <File
107 RelativePath="testzlib.c">
108 </File>
109 </Filter>
110 <Filter
111 Name="Header Files"
112 Filter="h;hpp;hxx;hm;inl;inc">
113 </Filter>
114 <Filter
115 Name="Resource Files"
116 Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
117 </Filter>
118 <File
119 RelativePath="zlib.lib">
120 </File>
121 </Files>
122 <Globals>
123 </Globals>
124</VisualStudioProject>