ProteoWizard
pwiz
utility
misc
endian_test.cpp
Go to the documentation of this file.
1
//
2
// $Id: endian_test.cpp 6141 2014-05-05 21:03:47Z chambm $
3
//
4
//
5
// Original author: Darren Kessner <darren@proteowizard.org>
6
//
7
// Copyright 2007 Spielberg Family Center for Applied Proteomics
8
// Cedars-Sinai Medical Center, Los Angeles, California 90048
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License");
11
// you may not use this file except in compliance with the License.
12
// You may obtain a copy of the License at
13
//
14
// http://www.apache.org/licenses/LICENSE-2.0
15
//
16
// Unless required by applicable law or agreed to in writing, software
17
// distributed under the License is distributed on an "AS IS" BASIS,
18
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
// See the License for the specific language governing permissions and
20
// limitations under the License.
21
//
22
23
24
#include "
Std.hpp
"
25
#include "
endian.hpp
"
26
#include "
pwiz/utility/misc/unit.hpp
"
27
28
using namespace
pwiz::util
;
29
30
31
void
test
()
32
{
33
unsigned
char
bytes[] = {0xce, 0xfa, 0xca, 0xca, 0xfe, 0xca, 0x20, 0x04};
34
unsigned
int
n = *
reinterpret_cast<
unsigned
int
*
>
(bytes);
35
36
#if defined(PWIZ_LITTLE_ENDIAN)
37
unit_assert
(n == 0xcacaface);
38
unit_assert
(
endianize32
(n) == 0xcefacaca);
39
#elif defined(PWIZ_BIG_ENDIAN)
40
unit_assert
(n == 0xcefacaca);
41
unit_assert
(
endianize32
(n) == 0xcacaface);
42
#endif
43
44
unsigned
long
long
m = *
reinterpret_cast<
unsigned
long
long
*
>
(bytes);
45
46
#if defined(PWIZ_LITTLE_ENDIAN)
47
unit_assert
(m == 0x420cafecacafacell);
48
unit_assert
(
endianize64
(m) == 0xcefacacafeca2004ll);
49
#elif defined(PWIZ_BIG_ENDIAN)
50
unit_assert
(m == 0xcefacacafeca2004ll);
51
unit_assert
(
endianize64
(m) == 0x420cafecacafacell);
52
#endif
53
}
54
55
56
int
main
(
int
argc,
char
* argv[])
57
{
58
TEST_PROLOG
(argc, argv)
59
60
try
61
{
62
test
();
63
}
64
catch
(exception& e)
65
{
66
TEST_FAILED
(e.what())
67
}
68
catch
(...)
69
{
70
TEST_FAILED
(
"Caught unknown exception."
)
71
}
72
73
TEST_EPILOG
74
}
75
76
pwiz::util::endianize64
unsigned long long endianize64(unsigned long long n)
Definition:
endian.hpp:80
TEST_EPILOG
#define TEST_EPILOG
Definition:
unit.hpp:182
Std.hpp
pwiz::util::endianize32
unsigned int endianize32(unsigned int n)
Definition:
endian.hpp:74
main
int main(int argc, char *argv[])
Definition:
endian_test.cpp:56
endian.hpp
unit.hpp
pwiz::util
Definition:
almost_equal.hpp:33
test
void test()
Definition:
endian_test.cpp:31
TEST_FAILED
#define TEST_FAILED(x)
Definition:
unit.hpp:176
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition:
unit.hpp:174
unit_assert
#define unit_assert(x)
Definition:
unit.hpp:85
Generated by
1.8.12