<commit_before>// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>

#include "ccomptr.h"
#include "common_action_mocks.h"
#include "i_cordebug_mocks.h"
#include "i_evalcoordinator_mock.h"
#include "dbgarray.h"

using ::testing::DoAll;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::SetArrayArgument;
using ::testing::_;
using google::cloud::diagnostics::debug::Variable;
using google_cloud_debugger::CComPtr;
using google_cloud_debugger::DbgArray;
using std::string;

namespace google_cloud_debugger_test {

class DbgArrayTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    // By default, sets array_value_ to the second argument
    // whenever QueryInterface is called.
    ON_CALL(array_value_, QueryInterface(_, _))
        .WillByDefault(
            DoAll(SetArgPointee<1>(&array_value_), Return(S_OK)));
  }

  void SetUpArray() {
    EXPECT_CALL(array_type_, GetFirstTypeParameter(_))
      .WillRepeatedly(DoAll(SetArgPointee<0>(&array_element_type_), Return(S_OK)));

    EXPECT_CALL(array_element_type_, GetType(_))
      .WillRepeatedly(DoAll(SetArgPointee<0>(CorElementType::ELEMENT_TYPE_I4), Return(S_OK)));

    // If queried for ICorDebugHeapValue2, returns heap_value.
    // This happens when the Initialize function tries to create a strong
    // handle of the array.
    ON_CALL(array_value_, QueryInterface(__uuidof(ICorDebugHeapValue2), _))
      .WillByDefault(DoAll(SetArgPointee<1>(&heap_value_), Return(S_OK)));

    // Makes heap_value returns handle_value if CreateHandle is called.
    EXPECT_CALL(heap_value_, CreateHandle(_, _))
        .WillRepeatedly(
            DoAll(SetArgPointee<1>(&handle_value_), Return(S_OK)));

    // The handle should dereference to the array value.
    ON_CALL(handle_value_, Dereference(_))
      .WillByDefault(
            DoAll(SetArgPointee<0>(&array_value_), Return(S_OK)));

    // Initialize function should issue call to get dimensions
    // and ranks of the array.
    EXPECT_CALL(array_value_, GetDimensions(_, _))
      .WillRepeatedly(DoAll(SetArrayArgument<1>(dimensions_, dimensions_ + 1), Return(S_OK)));

    EXPECT_CALL(array_type_, GetRank(_))
      .WillRepeatedly(DoAll(SetArgPointee<0>(1), Return(S_OK)));<commit_msg>Add comments for DbgArray Test Fixture<commit_after>// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>

#include "ccomptr.h"
#include "common_action_mocks.h"
#include "i_cordebug_mocks.h"
#include "i_evalcoordinator_mock.h"
#include "dbgarray.h"

using ::testing::DoAll;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::SetArrayArgument;
using ::testing::_;
using google::cloud::diagnostics::debug::Variable;
using google_cloud_debugger::CComPtr;
using google_cloud_debugger::DbgArray;
using std::string;

namespace google_cloud_debugger_test {

// Test Fixture for DbgArray.
// Contains various ICorDebug mock objects needed.
class DbgArrayTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    // By default, sets array_value_ to the second argument
    // whenever QueryInterface is called.
    ON_CALL(array_value_, QueryInterface(_, _))
        .WillByDefault(
            DoAll(SetArgPointee<1>(&array_value_), Return(S_OK)));
  }

  // Sets up various mock objects so when we use them with
  // a DbgArray class, we will get an array with 2 elements.
  void SetUpArray() {
    EXPECT_CALL(array_type_, GetFirstTypeParameter(_))
      .WillRepeatedly(DoAll(SetArgPointee<0>(&array_element_type_), Return(S_OK)));

    EXPECT_CALL(array_element_type_, GetType(_))
      .WillRepeatedly(DoAll(SetArgPointee<0>(CorElementType::ELEMENT_TYPE_I4), Return(S_OK)));

    // If queried for ICorDebugHeapValue2, returns heap_value.
    // This happens when the Initialize function tries to create a strong
    // handle of the array.
    ON_CALL(array_value_, QueryInterface(__uuidof(ICorDebugHeapValue2), _))
      .WillByDefault(DoAll(SetArgPointee<1>(&heap_value_), Return(S_OK)));

    // Makes heap_value returns handle_value if CreateHandle is called.
    EXPECT_CALL(heap_value_, CreateHandle(_, _))
        .WillRepeatedly(
            DoAll(SetArgPointee<1>(&handle_value_), Return(S_OK)));

    // The handle should dereference to the array value.
    ON_CALL(handle_value_, Dereference(_))
      .WillByDefault(
            DoAll(SetArgPointee<0>(&array_value_), Return(S_OK)));

    // Initialize function should issue call to get dimensions
    // and ranks of the array.
    EXPECT_CALL(array_value_, GetDimensions(_, _))
      .WillRepeatedly(DoAll(SetArrayArgument<1>(dimensions_, dimensions_ + 1), Return(S_OK)));

    EXPECT_CALL(array_type_, GetRank(_))
      .WillRepeatedly(DoAll(SetArgPointee<0>(1), Return(S_OK)));
{'fraction_non_alphanumeric': 0.11270903010033445, 'fraction_numerical': 0.0071906354515050164, 'mean_word_length': 4.4323342415985465, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2356312', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1836, 'n_words': 498}