Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
read-write-util-test.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <iostream>
18 #include <limits.h>
19 #include <gtest/gtest.h>
20 #include "exec/read-write-util.h"
21 #include "util/cpu-info.h"
22 
23 #include "common/names.h"
24 
25 namespace impala {
26 
27 template<typename T>
28 void TestBigEndian(T value) {
29  uint8_t buffer[sizeof(T)];
30  ReadWriteUtil::PutInt(buffer, value);
31  EXPECT_EQ(value, ReadWriteUtil::GetInt<T>(buffer));
32 }
33 
34 // Test put and get of big endian values
35 TEST(ReadWriteUtil, BigEndian) {
36  TestBigEndian<uint16_t>(0);
37  TestBigEndian<uint16_t>(0xff);
38  TestBigEndian<uint16_t>(0xffff);
39 
40  TestBigEndian<uint32_t>(0);
41  TestBigEndian<uint32_t>(0xff);
42  TestBigEndian<uint32_t>(0xffff);
43  TestBigEndian<uint32_t>(0xffffff);
44  TestBigEndian<uint32_t>(0xffffffff);
45 
46  TestBigEndian<uint64_t>(0);
47  TestBigEndian<uint64_t>(0xff);
48  TestBigEndian<uint64_t>(0xffff);
49  TestBigEndian<uint64_t>(0xffffff);
50  TestBigEndian<uint64_t>(0xffffffff);
51  TestBigEndian<uint64_t>(0xffffffffff);
52  TestBigEndian<uint64_t>(0xffffffffffff);
53  TestBigEndian<uint64_t>(0xffffffffffffff);
54 }
55 
56 }
57 
58 int main(int argc, char **argv) {
60  ::testing::InitGoogleTest(&argc, argv);
61  return RUN_ALL_TESTS();
62 }
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
void TestBigEndian(T value)
static void PutInt(uint8_t *buf, uint16_t integer)
int main(int argc, char **argv)
static void Init()
Initialize CpuInfo.
Definition: cpu-info.cc:75