~ubuntu-branches/ubuntu/saucy/openmcdf/saucy

« back to all changes in this revision

Viewing changes to src/OpenMcdfPerfTest/Helpers.cs

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2013-04-08 11:02:15 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130408110215-aleqo4zhjc3qgxnb
Tags: 1.5.4-1
* New upstream: 1.5.4
  - Use Hexbox for hexadecimal viewing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.Text;
 
4
 
 
5
namespace OpenMcdfPerfTest
 
6
{
 
7
    public static class Helpers
 
8
    {
 
9
        public static byte[] GetBuffer(int count)
 
10
        {
 
11
            Random r = new Random();
 
12
            byte[] b = new byte[count];
 
13
            r.NextBytes(b);
 
14
            return b;
 
15
        }
 
16
 
 
17
        public static byte[] GetBuffer(int count, byte c)
 
18
        {
 
19
            byte[] b = new byte[count];
 
20
            for (int i = 0; i < b.Length; i++)
 
21
            {
 
22
                b[i] = c;
 
23
            }
 
24
 
 
25
            return b;
 
26
        }
 
27
 
 
28
        public static bool CompareBuffer(byte[] b, byte[] p)
 
29
        {
 
30
            if (b == null && p == null)
 
31
                throw new Exception("Null buffers");
 
32
 
 
33
            if (b == null && p != null) 
 
34
                return false;
 
35
 
 
36
            if (b != null && p == null) 
 
37
                return false;
 
38
 
 
39
            if (b.Length != p.Length)
 
40
                return false;
 
41
 
 
42
            for (int i = 0; i < b.Length; i++)
 
43
            {
 
44
                if (b[i] != p[i])
 
45
                    return false;
 
46
            }
 
47
 
 
48
            return true;
 
49
        }
 
50
    }
 
51
}