TZIVI-254: IVI needs a newer version of cmake
[profile/ivi/cmake.git] / Utilities / KWIML / test / test_ABI_endian.h.in
1 /*============================================================================
2   Kitware Information Macro Library
3   Copyright 2010-2011 Kitware, Inc.
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include <stdio.h>
13
14 #ifdef __cplusplus
15 # define LANG "C++ "
16 #else
17 # define LANG "C "
18 #endif
19
20 static int test_ABI_endian(void)
21 {
22   int result = 1;
23   {
24 #if defined(@KWIML@_ABI_ENDIAN_ID)
25   int expect;
26   union { short s; unsigned char c[sizeof(short)]; } x;
27   x.s = 1;
28   expect = (x.c[0] == 1 ?
29             @KWIML@_ABI_ENDIAN_ID_LITTLE : @KWIML@_ABI_ENDIAN_ID_BIG);
30   printf(LANG "@KWIML@_ABI_ENDIAN_ID: expected [%d], got [%d]",
31          expect, @KWIML@_ABI_ENDIAN_ID);
32   if(@KWIML@_ABI_ENDIAN_ID == expect)
33     {
34     printf(", PASSED\n");
35     }
36   else
37     {
38     printf(", FAILED\n");
39     result = 0;
40     }
41 #else
42   printf(LANG "@KWIML@_ABI_ENDIAN_ID: unknown, FAILED\n");
43   result = 0;
44 #endif
45   }
46   return result;
47 }