Update license headers and add new license files
[contrib/qtwebsockets.git] / tests / auto / qdefaultmaskgenerator / tst_defaultmaskgenerator.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Kurt Pattyn <pattyn.kurt@gmail.com>.
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL21$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** In addition, as a special exception, Digia gives you certain additional
27 ** rights. These rights are described in the Digia Qt LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** $QT_END_LICENSE$
31 **
32 ****************************************************************************/
33 #include <QtTest/QtTest>
34 #include <QtTest/qtestcase.h>
35 #include <QtTest/QSignalSpy>
36 #include <QtCore/QBuffer>
37 #include <QtCore/QByteArray>
38 #include <QtCore/QDebug>
39
40 #include "private/qdefaultmaskgenerator_p.h"
41
42 QT_USE_NAMESPACE
43
44 class tst_QDefaultMaskGenerator : public QObject
45 {
46     Q_OBJECT
47
48 public:
49     tst_QDefaultMaskGenerator();
50
51 private Q_SLOTS:
52     void initTestCase();
53     void cleanupTestCase();
54     void init();
55     void cleanup();
56
57     void tst_randomnessWithoutSeed();
58     void tst_randomnessWithSeed();
59
60 private:
61 };
62
63
64
65 tst_QDefaultMaskGenerator::tst_QDefaultMaskGenerator()
66 {
67 }
68
69 void tst_QDefaultMaskGenerator::initTestCase()
70 {
71 }
72
73 void tst_QDefaultMaskGenerator::cleanupTestCase()
74 {
75 }
76
77 void tst_QDefaultMaskGenerator::init()
78 {
79 }
80
81 void tst_QDefaultMaskGenerator::cleanup()
82 {
83 }
84
85 void tst_QDefaultMaskGenerator::tst_randomnessWithoutSeed()
86 {
87     //generate two series of data, and see if they differ
88     {
89         QDefaultMaskGenerator generator;
90
91         QVector<quint32> series1, series2;
92         for (int i = 0; i < 1000; ++i)
93             series1 << generator.nextMask();
94         for (int i = 0; i < 1000; ++i)
95             series2 << generator.nextMask();
96
97         QVERIFY(series1 != series2);
98     }
99 }
100
101 void tst_QDefaultMaskGenerator::tst_randomnessWithSeed()
102 {
103     //generate two series of data, and see if they differ
104     //the generator is seeded
105     {
106         QDefaultMaskGenerator generator;
107         generator.seed();
108
109         QVector<quint32> series1, series2;
110         for (int i = 0; i < 1000; ++i)
111             series1 << generator.nextMask();
112         for (int i = 0; i < 1000; ++i)
113             series2 << generator.nextMask();
114
115         QVERIFY(series1 != series2);
116     }
117     //generates two series of data with 2 distinct generators
118     //both generators are seeded
119     {
120         QDefaultMaskGenerator generator1, generator2;
121         generator1.seed();
122         generator2.seed();
123
124         QVector<quint32> series1, series2;
125         for (int i = 0; i < 1000; ++i) {
126             series1 << generator1.nextMask();
127             series2 << generator2.nextMask();
128         }
129
130         QVERIFY(series1 != series2);
131     }
132     //generates two series of data with 2 distinct generators
133     //only one of the two is seeded
134     {
135         QDefaultMaskGenerator generator1, generator2;
136         generator1.seed();
137
138         QVector<quint32> series1, series2;
139         for (int i = 0; i < 1000; ++i) {
140             series1 << generator1.nextMask();
141             series2 << generator2.nextMask();
142         }
143
144         QVERIFY(series1 != series2);
145     }
146 }
147
148 QTEST_MAIN(tst_QDefaultMaskGenerator)
149
150 #include "tst_defaultmaskgenerator.moc"