ProteoWizard
Main Page
Namespaces
Classes
Files
File List
File Members
pwiz
utility
misc
endian_test.cpp
Go to the documentation of this file.
1
//
2
// $Id: endian_test.cpp 4129 2012-11-20 00:05:37Z 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,
const
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
Generated on Mon Nov 26 2012 18:05:49 for ProteoWizard by
1.8.1.1