wheee!
[asdcplib.git] / src / asdcp-mem-test.cpp
1 /*
2 Copyright (c) 2004, John Hurst
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9    notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11    notice, this list of conditions and the following disclaimer in the
12    documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14    derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 /*! \file    asdcp-mem-test.cpp
28     \version $Id$
29     \brief   AS-DCP frame buffer allocation test
30 */
31
32
33 #include <AS_DCP_internal.h>
34 #include <FortunaRNG.h>
35
36 #include <iostream>
37 #include <assert.h>
38
39 using namespace ASDCP;
40
41 const ui32_t buf_size = 1024;
42 FortunaRNG RNG;
43
44 //
45 int a()
46 {
47   FrameBuffer FB;
48   FB.Capacity(buf_size);
49   assert(FB.Capacity() == buf_size);
50   RNG.FillRandom(FB.Data(), FB.Capacity());
51
52   return 0;
53 }
54
55 //
56 int b()
57 {
58   byte_t* buf = (byte_t*)malloc(buf_size);
59   assert(buf);
60   RNG.FillRandom(buf, buf_size);
61
62   {
63     FrameBuffer FB;
64     FB.SetData(buf, buf_size);
65     assert(FB.Data() == buf);
66     assert(FB.Capacity() == buf_size);
67     // ~FB() is called...
68   }
69
70   free(buf);
71   return 0;
72 }
73
74 //
75 int c()
76 {
77   byte_t* buf = (byte_t*)malloc(buf_size);
78   assert(buf);
79   RNG.FillRandom(buf, buf_size);
80
81   {
82     FrameBuffer FB;
83     FB.SetData(buf, buf_size);
84     assert(FB.Data() == buf);
85     assert(FB.Capacity() == buf_size);
86
87     FB.SetData(0,0);
88     assert(FB.Data() == 0);
89     assert(FB.Capacity() == 0);
90
91     FB.Capacity(buf_size);
92     assert(FB.Capacity() == buf_size);
93     RNG.FillRandom(FB.Data(), FB.Capacity());
94     // ~FB() is called...
95   }
96
97   free(buf);
98   return 0;
99 }
100
101 //
102 int d()
103 {
104   mem_ptr<DataChunk> Chunk(new DataChunk(1024));
105
106
107 #if 0
108
109   //  MPEG2::Parser     mPFile;
110   MPEG2::MXFReader  mRFile;
111   Result_t result = mRFile.OpenRead("../test/write_test_mpeg.mxf");
112   assert(ASDCP_SUCCESS(result));
113
114   //  MPEG2::MXFWriter  mWFile;
115   JP2K::CodestreamParser  jPCFile;
116   JP2K::SequenceParser    jPSFile;
117   JP2K::MXFReader   jRFile;
118   JP2K::MXFWriter   jWFile;
119
120   PCM::WAVParser    pPFile;
121   PCM::MXFReader    pRFile;
122   PCM::MXFWriter    pWFile;
123 #endif
124   return 0;
125 }
126
127 //
128 int
129 main( int argc, char **argv )
130 {
131   ui32_t i = 0x00010000;
132   fputs("Watch your process monitor, memory usage should not change after startup.\n", stderr);
133
134   while ( i-- )
135     {
136       a();
137       b();
138       c();
139       d();
140
141       if ( i && ( i % 1000 ) == 0 )
142         fputc('.', stderr);
143     }
144
145   fputc('\n', stderr);
146   return 0;
147 }
148
149
150 //
151 // end asdcp-mem-test.cpp
152 //