Coverage for /Syzygy/common/com_utils_unittest.cc

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

Line-by-line coverage:

   1    :  // Copyright 2014 Google Inc. All Rights Reserved.
   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    :  // Unit tests for COM utils.
  16    :  
  17    :  #include "syzygy/common/com_utils.h"
  18    :  
  19    :  #include <atlcomcli.h>
  20    :  
  21    :  #include "gtest/gtest.h"
  22    :  
  23    :  namespace common {
  24    :  
  25  E :  TEST(ComUtils, AlwaysError) {
  26  E :    EXPECT_EQ(AlwaysError(S_OK, E_INVALIDARG), E_INVALIDARG);
  27  E :    EXPECT_EQ(AlwaysError(E_FAIL, E_INVALIDARG), E_FAIL);
  28    :  
  29  E :    EXPECT_EQ(AlwaysError(S_OK), E_FAIL);
  30  E :    EXPECT_EQ(AlwaysError(E_FAIL), E_FAIL);
  31    :  
  32  E :    EXPECT_EQ(AlwaysErrorFromWin32(NO_ERROR, E_INVALIDARG), E_INVALIDARG);
  33  E :    EXPECT_EQ(AlwaysErrorFromWin32(NO_ERROR), E_FAIL);
  34    :  
  35    :    EXPECT_EQ(AlwaysErrorFromWin32(ERROR_ACCESS_DENIED, E_INVALIDARG),
  36  E :              HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED));
  37    :    EXPECT_EQ(AlwaysErrorFromWin32(ERROR_ACCESS_DENIED),
  38  E :              HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED));
  39    :  
  40  E :    DWORD last_error = ::GetLastError();
  41    :  
  42  E :    ::SetLastError(NO_ERROR);
  43  E :    EXPECT_EQ(AlwaysErrorFromLastError(E_INVALIDARG), E_INVALIDARG);
  44  E :    EXPECT_EQ(AlwaysErrorFromLastError(), E_FAIL);
  45    :  
  46  E :    ::SetLastError(ERROR_ACCESS_DENIED);
  47    :    EXPECT_EQ(AlwaysErrorFromLastError(E_INVALIDARG),
  48  E :              HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED));
  49    :    EXPECT_EQ(AlwaysErrorFromLastError(),
  50  E :              HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED));
  51    :  
  52  E :    ::SetLastError(last_error);
  53  E :  }
  54    :  
  55  E :  TEST(ComUtils, ToString) {
  56  E :    CComBSTR filled(L"hello");
  57  E :    EXPECT_STREQ(ToString(filled), L"hello");
  58    :  
  59  E :    CComBSTR empty;
  60  E :    EXPECT_STREQ(ToString(empty), L"");
  61  E :  }
  62    :  
  63  E :  TEST(ComUtils, HrLog) {
  64    :    {
  65  E :      std::ostringstream stream;
  66  E :      stream << LogHr(S_OK);
  67  E :      std::string str = stream.str();
  68  E :      EXPECT_NE(str.find("0x0,"), std::string::npos);
  69  E :      EXPECT_NE(str.find("msg="), std::string::npos);
  70  E :    }
  71    :  
  72    :    {
  73  E :      std::ostringstream stream;
  74  E :      stream << LogHr(E_FAIL);
  75  E :      std::string str = stream.str();
  76  E :      EXPECT_NE(str.find("0x80004005,"), std::string::npos);
  77  E :      EXPECT_NE(str.find("msg=Unspecified error"), std::string::npos);
  78  E :    }
  79  E :  }
  80    :  
  81  E :  TEST(ComUtils, WeLog) {
  82    :    {
  83  E :      std::ostringstream stream;
  84  E :      stream << LogWe(ERROR_SUCCESS);
  85  E :      std::string str = stream.str();
  86  E :      EXPECT_NE(str.find("[we=0,"), std::string::npos);
  87    :      EXPECT_NE(str.find("msg=The operation completed successfully"),
  88  E :                std::string::npos);
  89  E :    }
  90    :  
  91    :    {
  92  E :      std::ostringstream stream;
  93  E :      stream << LogWe(ERROR_INVALID_FUNCTION);
  94  E :      std::string str = stream.str();
  95  E :      EXPECT_NE(str.find("[we=1,"), std::string::npos);
  96  E :      EXPECT_NE(str.find("msg=Incorrect function"), std::string::npos);
  97  E :    }
  98  E :  }
  99    :  
 100    :  }  // namespace common

Coverage information generated Thu Jan 14 17:40:38 2016.