[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / utils / test / TestBitstreamStats.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "threads/Thread.h"
22 #include "utils/BitstreamStats.h"
23
24 #include "gtest/gtest.h"
25
26 #define BITS (256 * 8)
27 #define BYTES (256)
28
29 class CTestBitstreamStatsThread : public CThread
30 {
31 public:
32   CTestBitstreamStatsThread() :
33     CThread("CTestBitstreamStatsThread"){}
34   
35 };
36
37 TEST(TestBitstreamStats, General)
38 {
39   int i;
40   BitstreamStats a;
41   CTestBitstreamStatsThread t;
42
43   i = 0;
44   a.Start();
45   EXPECT_EQ(0.0, a.GetBitrate());
46   EXPECT_EQ(0.0, a.GetMaxBitrate());
47   EXPECT_EQ(-1.0, a.GetMinBitrate());
48   while (i <= BITS)
49   {
50     a.AddSampleBits(1);
51     i++;
52     t.Sleep(1);
53   }
54   a.CalculateBitrate();
55   EXPECT_GT(a.GetBitrate(), 0.0);
56   EXPECT_GT(a.GetMaxBitrate(), 0.0);
57   EXPECT_GT(a.GetMinBitrate(), 0.0);
58
59   i = 0;
60   while (i <= BYTES)
61   {
62     a.AddSampleBytes(1);
63     t.Sleep(2);
64     i++;
65   }
66   a.CalculateBitrate();
67   EXPECT_GT(a.GetBitrate(), 0.0);
68   EXPECT_GT(a.GetMaxBitrate(), 0.0);
69   EXPECT_LE(a.GetMinBitrate(), a.GetMaxBitrate());
70 }