Coverage for /Syzygy/common/align_unittest.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%57570.C++test

Line-by-line coverage:

   1    :  // Copyright 2011 Google 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 "syzygy/common/align.h"
  16    :  #include "gtest/gtest.h"
  17    :  
  18    :  namespace common {
  19    :  
  20  E :  TEST(AlignTest, IsPowerOfTwo) {
  21  E :    EXPECT_FALSE(IsPowerOfTwo(0));
  22  E :    EXPECT_TRUE(IsPowerOfTwo(1));
  23  E :    EXPECT_TRUE(IsPowerOfTwo(2));
  24  E :    EXPECT_FALSE(IsPowerOfTwo(3));
  25  E :    EXPECT_TRUE(IsPowerOfTwo(4));
  26  E :    EXPECT_TRUE(IsPowerOfTwo(0x80000000));
  27  E :    EXPECT_FALSE(IsPowerOfTwo(0x80000001U));
  28  E :  }
  29    :  
  30  E :  TEST(AlignTest, AlignUp) {
  31    :    // Try power of two alignments.
  32  E :    EXPECT_EQ(0, AlignUp(0, 1));
  33  E :    EXPECT_EQ(1, AlignUp(1, 1));
  34    :  
  35  E :    EXPECT_EQ(0, AlignUp(0, 2));
  36  E :    EXPECT_EQ(2, AlignUp(1, 2));
  37    :  
  38  E :    EXPECT_EQ(0x8000000, AlignUp(3, 0x8000000));
  39  E :    EXPECT_EQ(0x8000000, AlignUp(0x8000000, 0x8000000));
  40    :  
  41    :    // And non-power of two alignments.
  42  E :    EXPECT_EQ(0, AlignUp(0, 3));
  43  E :    EXPECT_EQ(3, AlignUp(1, 3));
  44    :  
  45  E :    EXPECT_EQ(0, AlignUp(0, 7));
  46  E :    EXPECT_EQ(7, AlignUp(1, 7));
  47    :  
  48  E :    EXPECT_EQ(0, AlignUp(0, 0x8000123));
  49  E :    EXPECT_EQ(0x8000123, AlignUp(3, 0x8000123));
  50  E :  }
  51    :  
  52  E :  TEST(AlignTest, AlignDown) {
  53    :    // Try power of two alignments.
  54  E :    EXPECT_EQ(0, AlignDown(0, 1));
  55  E :    EXPECT_EQ(1, AlignDown(1, 1));
  56    :  
  57  E :    EXPECT_EQ(0, AlignDown(0, 2));
  58  E :    EXPECT_EQ(0, AlignDown(1, 2));
  59    :  
  60  E :    EXPECT_EQ(0x8000000, AlignDown(0x8000000, 0x8000000));
  61  E :    EXPECT_EQ(0x8000000, AlignDown(0x8000003, 0x8000000));
  62    :  
  63    :    // And non-power of two alignments.
  64  E :    EXPECT_EQ(0, AlignDown(0, 3));
  65  E :    EXPECT_EQ(0, AlignDown(1, 3));
  66  E :    EXPECT_EQ(6, AlignDown(7, 3));
  67    :  
  68  E :    EXPECT_EQ(0, AlignDown(0, 7));
  69  E :    EXPECT_EQ(14, AlignDown(14, 7));
  70    :  
  71  E :    EXPECT_EQ(0, AlignDown(1234, 0x8000123));
  72  E :    EXPECT_EQ(0x8000123, AlignDown(0x8000123, 0x8000123));
  73  E :    EXPECT_EQ(0x8000123, AlignDown(0x8000124, 0x8000123));
  74  E :  }
  75    :  
  76  E :  TEST(AlignTest, IsAligned) {
  77    :    // Try power of two alignments.
  78  E :    EXPECT_TRUE(IsAligned(0, 1));
  79  E :    EXPECT_TRUE(IsAligned(1, 1));
  80    :  
  81  E :    EXPECT_TRUE(IsAligned(0, 2));
  82  E :    EXPECT_FALSE(IsAligned(1, 2));
  83    :  
  84  E :    EXPECT_TRUE(IsAligned(0x8000000, 0x8000000));
  85  E :    EXPECT_FALSE(IsAligned(0x8000003, 0x8000000));
  86    :  
  87    :    // And non-power of two alignments.
  88  E :    EXPECT_TRUE(IsAligned(0, 3));
  89  E :    EXPECT_FALSE(IsAligned(1, 3));
  90  E :    EXPECT_FALSE(IsAligned(7, 3));
  91  E :    EXPECT_TRUE(IsAligned(3, 3));
  92    :  
  93  E :    EXPECT_TRUE(IsAligned(0, 7));
  94  E :    EXPECT_TRUE(IsAligned(14, 7));
  95  E :    EXPECT_FALSE(IsAligned(13, 7));
  96    :  
  97  E :    EXPECT_FALSE(IsAligned(1234, 0x8000123));
  98  E :    EXPECT_TRUE(IsAligned(0x8000123, 0x8000123));
  99  E :    EXPECT_FALSE(IsAligned(0x8000124, 0x8000123));
 100  E :  }
 101    :  
 102    :  }  // namespace common

Coverage information generated Thu Sep 06 11:30:46 2012.