Add call to parent constructor.
[asdcplib-cth.git] / src / asdcp-mem-test.cpp
1 /*
2 Copyright (c) 2004-2009, 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: asdcp-mem-test.cpp,v 1.4 2009/04/09 19:24:14 msheby Exp $
29     \brief   AS-DCP frame buffer allocation test
30 */
31
32
33 #include <AS_DCP_internal.h>
34 //#include <KM_platform.h>
35 #include <KM_prng.h>
36
37 #include <iostream>
38 #include <assert.h>
39
40 using namespace ASDCP;
41 using namespace Kumu;
42
43 const ui32_t buf_size = 1024;
44 FortunaRNG RNG;
45
46 //
47 int a()
48 {
49   FrameBuffer FB;
50   FB.Capacity(buf_size);
51   assert(FB.Capacity() == buf_size);
52   RNG.FillRandom(FB.Data(), FB.Capacity());
53
54   return 0;
55 }
56
57 //
58 int b()
59 {
60   byte_t* buf = (byte_t*)malloc(buf_size);
61   assert(buf);
62   RNG.FillRandom(buf, buf_size);
63
64   {
65     FrameBuffer FB;
66     FB.SetData(buf, buf_size);
67     assert(FB.Data() == buf);
68     assert(FB.Capacity() == buf_size);
69     // ~FB() is called...
70   }
71
72   free(buf);
73   return 0;
74 }
75
76 //
77 int c()
78 {
79   byte_t* buf = (byte_t*)malloc(buf_size);
80   assert(buf);
81   RNG.FillRandom(buf, buf_size);
82
83   {
84     FrameBuffer FB;
85     FB.SetData(buf, buf_size);
86     assert(FB.Data() == buf);
87     assert(FB.Capacity() == buf_size);
88
89     FB.SetData(0,0);
90     assert(FB.Data() == 0);
91     assert(FB.Capacity() == 0);
92
93     FB.Capacity(buf_size);
94     assert(FB.Capacity() == buf_size);
95     RNG.FillRandom(FB.Data(), FB.Capacity());
96     // ~FB() is called...
97   }
98
99   free(buf);
100   return 0;
101 }
102
103 //
104 int d()
105 {
106   //  MPEG2::Parser     mPFile;
107   MPEG2::MXFReader  mRFile;
108   Result_t result = mRFile.OpenRead("../tests/write_test_mpeg.mxf");
109   assert(ASDCP_SUCCESS(result));
110
111   //  MPEG2::MXFWriter  mWFile;
112   JP2K::CodestreamParser  jPCFile;
113   JP2K::SequenceParser    jPSFile;
114   JP2K::MXFReader   jRFile;
115   JP2K::MXFWriter   jWFile;
116
117   PCM::WAVParser    pPFile;
118   PCM::MXFReader    pRFile;
119   PCM::MXFWriter    pWFile;
120   return 0;
121 }
122
123 //
124 int
125 main( int argc, char **argv )
126 {
127   ui32_t i = 0x00010000;
128   fputs("Watch your process monitor, memory usage should not change after startup.\n", stderr);
129
130   while ( i-- )
131     {
132       a();
133       b();
134       c();
135       d();
136
137       if ( i && ( i % 1000 ) == 0 )
138         fputc('.', stderr);
139     }
140
141   fputc('\n', stderr);
142   return 0;
143 }
144
145
146 //
147 // end asdcp-mem-test.cpp
148 //