Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/talk/base/byteorder_unittest.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 3.3 KB
Line 
1/*
2 * libjingle
3 * Copyright 2012 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 *  1. Redistributions of source code must retain the above copyright notice,
9 *     this list of conditions and the following disclaimer.
10 *  2. Redistributions in binary form must reproduce the above copyright notice,
11 *     this list of conditions and the following disclaimer in the documentation
12 *     and/or other materials provided with the distribution.
13 *  3. The name of the author may not be used to endorse or promote products
14 *     derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/base/byteorder.h"
29
30#include "talk/base/basictypes.h"
31#include "talk/base/gunit.h"
32
33namespace talk_base {
34
35// Test memory set functions put values into memory in expected order.
36TEST(ByteOrderTest, TestSet) {
37  uint8 buf[8] = { 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u };
38  Set8(buf, 0, 0xfb);
39  Set8(buf, 1, 0x12);
40  EXPECT_EQ(0xfb, buf[0]);
41  EXPECT_EQ(0x12, buf[1]);
42  SetBE16(buf, 0x1234);
43  EXPECT_EQ(0x12, buf[0]);
44  EXPECT_EQ(0x34, buf[1]);
45  SetLE16(buf, 0x1234);
46  EXPECT_EQ(0x34, buf[0]);
47  EXPECT_EQ(0x12, buf[1]);
48  SetBE32(buf, 0x12345678);
49  EXPECT_EQ(0x12, buf[0]);
50  EXPECT_EQ(0x34, buf[1]);
51  EXPECT_EQ(0x56, buf[2]);
52  EXPECT_EQ(0x78, buf[3]);
53  SetLE32(buf, 0x12345678);
54  EXPECT_EQ(0x78, buf[0]);
55  EXPECT_EQ(0x56, buf[1]);
56  EXPECT_EQ(0x34, buf[2]);
57  EXPECT_EQ(0x12, buf[3]);
58  SetBE64(buf, UINT64_C(0x0123456789abcdef));
59  EXPECT_EQ(0x01, buf[0]);
60  EXPECT_EQ(0x23, buf[1]);
61  EXPECT_EQ(0x45, buf[2]);
62  EXPECT_EQ(0x67, buf[3]);
63  EXPECT_EQ(0x89, buf[4]);
64  EXPECT_EQ(0xab, buf[5]);
65  EXPECT_EQ(0xcd, buf[6]);
66  EXPECT_EQ(0xef, buf[7]);
67  SetLE64(buf, UINT64_C(0x0123456789abcdef));
68  EXPECT_EQ(0xef, buf[0]);
69  EXPECT_EQ(0xcd, buf[1]);
70  EXPECT_EQ(0xab, buf[2]);
71  EXPECT_EQ(0x89, buf[3]);
72  EXPECT_EQ(0x67, buf[4]);
73  EXPECT_EQ(0x45, buf[5]);
74  EXPECT_EQ(0x23, buf[6]);
75  EXPECT_EQ(0x01, buf[7]);
76}
77
78// Test memory get functions get values from memory in expected order.
79TEST(ByteOrderTest, TestGet) {
80  uint8 buf[8];
81  buf[0] = 0x01u;
82  buf[1] = 0x23u;
83  buf[2] = 0x45u;
84  buf[3] = 0x67u;
85  buf[4] = 0x89u;
86  buf[5] = 0xabu;
87  buf[6] = 0xcdu;
88  buf[7] = 0xefu;
89  EXPECT_EQ(0x01u, Get8(buf, 0));
90  EXPECT_EQ(0x23u, Get8(buf, 1));
91  EXPECT_EQ(0x0123u, GetBE16(buf));
92  EXPECT_EQ(0x2301u, GetLE16(buf));
93  EXPECT_EQ(0x01234567u, GetBE32(buf));
94  EXPECT_EQ(0x67452301u, GetLE32(buf));
95  EXPECT_EQ(UINT64_C(0x0123456789abcdef), GetBE64(buf));
96  EXPECT_EQ(UINT64_C(0xefcdab8967452301), GetLE64(buf));
97}
98
99}  // namespace talk_base
100
Note: See TracBrowser for help on using the repository browser.