Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Test
TestCrc32.cpp
Go to the documentation of this file.
1
#include "
Crc32.h
"
2
#include "
Logger.h
"
3
#include <qmath.h>
4
#include <QTemporaryFile>
5
#include <QtTest/QtTest>
6
#include "
Test/TestCrc32.h
"
7
8
QTEST_MAIN (
TestCrc32
)
9
10
unsigned
char
inBuffer
[] = {
"abcdef"
};
11
unsigned
outExpectedBinary
= 3323750366;
// From cksum of file containing inBuffer contents without carriage return
12
unsigned
outExpectedText
= 773139377;
// From cksum of file containing inBuffer contents without carriage return
13
14
TestCrc32::TestCrc32
(QObject *parent) :
15
QObject(parent)
16
{
17
}
18
19
void
TestCrc32::cleanupTestCase ()
20
{
21
}
22
23
void
TestCrc32::initTestCase ()
24
{
25
const
bool
DEBUG_FLAG
=
false
;
26
27
initializeLogging
(
"engauge_test"
,
28
"engauge_test.log"
,
29
DEBUG_FLAG
);
30
}
31
32
void
TestCrc32::testFileBinary ()
33
{
34
unsigned
outGot = 0;
35
36
QTemporaryFile temp;
37
temp.setAutoRemove (
false
);
38
QString filename;
39
if
(temp.open ()) {
40
41
// Save file name for reading after writing, closing then calculating
42
filename = temp.fileName ();
43
44
int
length =
sizeof
(
inBuffer
) /
sizeof
(
unsigned
char
) - 1;
45
46
QDataStream str (&temp);
47
str.writeBytes ((
const
char
*)
inBuffer
, length);
48
49
temp.close ();
50
51
// Calculate
52
Crc32 crc32;
53
outGot = crc32.
filecrc
(filename);
54
55
QFile::remove (filename);
56
}
57
58
QVERIFY (outGot ==
outExpectedBinary
);
59
}
60
61
void
TestCrc32::testFileText ()
62
{
63
unsigned
outGot = 0;
64
65
QTemporaryFile temp;
66
temp.setAutoRemove (
false
);
67
QString filename;
68
if
(temp.open ()) {
69
70
// Save file name for reading after writing, closing then calculating
71
filename = temp.fileName ();
72
73
QTextStream str (&temp);
74
str << QString ((
const
char
*)
inBuffer
);
75
76
temp.close ();
77
78
// Calculate
79
Crc32 crc32;
80
outGot = crc32.
filecrc
(filename);
81
82
QFile::remove (filename);
83
}
84
85
QVERIFY (outGot ==
outExpectedText
);
86
}
87
88
void
TestCrc32::testMemory ()
89
{
90
Crc32 crc32;
91
92
int
length =
sizeof
(
inBuffer
) /
sizeof
(
unsigned
char
) - 1;
93
94
unsigned
outGot = crc32.
memcrc
(
inBuffer
,
95
length);
96
97
QVERIFY (outGot ==
outExpectedText
);
98
}
Crc32.h
initializeLogging
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition
Logger.cpp:15
Logger.h
outExpectedBinary
unsigned outExpectedBinary
Definition
TestCrc32.cpp:11
outExpectedText
unsigned outExpectedText
Definition
TestCrc32.cpp:12
inBuffer
unsigned char inBuffer[]
Definition
TestCrc32.cpp:10
TestCrc32.h
DEBUG_FLAG
const bool DEBUG_FLAG
Definition
TestExport.cpp:35
Crc32::memcrc
unsigned memcrc(const unsigned char *b, unsigned int n) const
Compute the checksum using data in memory.
Definition
Crc32.cpp:100
Crc32::filecrc
unsigned filecrc(const QString &filename) const
Compute the checksum using data in file.
Definition
Crc32.cpp:69
TestCrc32
Unit tests of crc32 checksum algorithm.
Definition
TestCrc32.h:8
TestCrc32::TestCrc32
TestCrc32(QObject *parent=0)
Single constructor.
Definition
TestCrc32.cpp:14
Generated on
for Engauge Digitizer by
1.17.0