Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4fef6cef authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "device_iot_config: Add mock and fix stack btm test"

parents 880d674e 0e8dd557
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
#include "stack/include/sec_hci_link_interface.h"
#include "stack/l2cap/l2c_int.h"
#include "test/mock/mock_osi_list.h"
#include "test/mock/mock_device_iot_config.h"
#include "test/mock/mock_stack_hcic_hcicmds.h"
#include "types/raw_address.h"

+154 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * 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 <cstdint>
#include <functional>
#include <map>
#include <string>

extern std::map<std::string, int> mock_function_count_map;

// Mock include file to share data between tests and mock
#include "test/mock/mock_device_iot_config.h"

namespace test {
namespace mock {
namespace device_iot_config {

struct device_iot_config_get_int device_iot_config_get_int;
struct device_iot_config_set_int device_iot_config_set_int;
struct device_iot_config_int_add_one device_iot_config_int_add_one;
struct device_iot_config_get_hex device_iot_config_get_hex;
struct device_iot_config_set_hex device_iot_config_set_hex;
struct device_iot_config_set_hex_if_greater device_iot_config_set_hex_if_greater;
struct device_iot_config_get_str device_iot_config_get_str;
struct device_iot_config_set_str device_iot_config_set_str;
struct device_iot_config_get_bin device_iot_config_get_bin;
struct device_iot_config_set_bin device_iot_config_set_bin;
struct device_iot_config_get_bin_length device_iot_config_get_bin_length;
struct device_iot_config_has_section device_iot_config_has_section;
struct device_iot_config_exist device_iot_config_exist;
struct device_iot_config_remove device_iot_config_remove;
struct device_iot_config_clear device_iot_config_clear;
struct device_iot_config_flush device_iot_config_flush;
struct device_debug_iot_config_dump device_debug_iot_config_dump;

}  // namespace device_iot_config
}  // namespace mock
}  // namespace test

// Mocked functions, if any
bool device_iot_config_get_int(const std::string& section, const std::string& key,
                     int& value) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_get_int(section, key, value);
}

bool device_iot_config_set_int(const std::string& section,
                               const std::string& key, int value) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_set_int(section, key, value);
}

bool device_iot_config_int_add_one(const std::string& section,
                               const std::string& key) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_int_add_one(section, key);
}

bool device_iot_config_get_hex(const std::string& section,
                               const std::string& key, int& value) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_get_hex(section, key, value);
}

bool device_iot_config_set_hex(const std::string& section,
                               const std::string& key, int value, int byte_num) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_set_hex(section, key, value, byte_num);
}

bool device_iot_config_set_hex_if_greater(const std::string& section,
                               const std::string& key, int value, int byte_num) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_set_hex_if_greater(section, key, value, byte_num);
}

bool device_iot_config_get_str(const std::string& section,
                               const std::string& key, char* value,
                               int* size_bytes) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_get_str(section, key, value, size_bytes);
}

bool device_iot_config_set_str(const std::string& section,
                               const std::string& key,
                               const std::string& value) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_set_str(section, key, value);
}

bool device_iot_config_get_bin(const std::string& section,
                               const std::string& key, uint8_t* value,
                               size_t* length) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_get_bin(section, key, value, length);
}

bool device_iot_config_set_bin(const std::string& section,
                               const std::string& key, const uint8_t* value,
                               size_t length) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_set_bin(section, key, value, length);
}

size_t device_iot_config_get_bin_length(const std::string& section,
                                        const std::string& key) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_get_bin_length(section, key);
}

bool device_iot_config_has_section(const std::string& section) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_has_section(section);
}

bool device_iot_config_exist(const std::string& section,
                             const std::string& key) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_exist(section, key);
}

bool device_iot_config_remove(const std::string& section,
                              const std::string& key) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_remove(section, key);
}

void device_iot_config_flush(void) {
  mock_function_count_map[__func__]++;
  test::mock::device_iot_config::device_iot_config_flush();
}

bool device_iot_config_clear(void) {
  mock_function_count_map[__func__]++;
  return test::mock::device_iot_config::device_iot_config_clear();
}

void device_debug_iot_config_dump(int fd) {
  mock_function_count_map[__func__]++;
  test::mock::device_iot_config::device_debug_iot_config_dump(fd);
}
+277 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * 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.
 */

extern std::map<std::string, int> mock_function_count_map;

namespace test {
namespace mock {
namespace device_iot_config {

// Shared state between mocked functions and tests
// Name: device_iot_config_get_int
// Params: const std::string& section, const std::string& key, int& value
// Return: bool
struct device_iot_config_get_int {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     int& value)>
      body{[this](const std::string& section, const std::string& key,
                  int& value) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key,
                  int& value) {
    return body(section, key, value);
  };
};
extern struct device_iot_config_get_int device_iot_config_get_int;

// Name: device_iot_config_set_int
// Params: const std::string& section, const std::string& key, int& value
// Return: bool
struct device_iot_config_set_int {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     int value)>
      body{[this](const std::string& section, const std::string& key,
                  int value) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key,
                  int value) {
    return body(section, key, value);
  };
};
extern struct device_iot_config_set_int device_iot_config_set_int;

// Name: device_iot_config_int_add_one
// Params: const std::string& section, const std::string& key
// Return: bool
struct device_iot_config_int_add_one {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key)> body{
      [this](const std::string& section, const std::string& key) {
        return return_value;
      }};
  bool operator()(const std::string& section, const std::string& key) {
    return body(section, key);
  };
};
extern struct device_iot_config_int_add_one device_iot_config_int_add_one;

// Name: device_iot_config_get_hex
// Params: const std::string& section, const std::string& key, int& value
// Return: bool
struct device_iot_config_get_hex {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     int& value)>
      body{[this](const std::string& section, const std::string& key,
                  int& value) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key,
                  int& value) {
    return body(section, key, value);
  };
};
extern struct device_iot_config_get_hex device_iot_config_get_hex;

// Name: device_iot_config_set_hex
// Params: const std::string& section, const std::string& key, int value, int
// byte_num
// Return: bool
struct device_iot_config_set_hex {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     int value, int byte_num)>
      body{[this](const std::string& section, const std::string& key, int value,
                  int byte_num) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key, int value,
                  int byte_num) {
    return body(section, key, value, byte_num);
  };
};
extern struct device_iot_config_set_hex device_iot_config_set_hex;

// Name: device_iot_config_set_hex_if_greater
// Params: const std::string& section, const std::string& key, int value, int
// byte_num
// Return: bool
struct device_iot_config_set_hex_if_greater {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     int value, int byte_num)>
      body{[this](const std::string& section, const std::string& key, int value,
                  int byte_num) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key, int value,
                  int byte_num) {
    return body(section, key, value, byte_num);
  };
};
extern struct device_iot_config_set_hex_if_greater
    device_iot_config_set_hex_if_greater;

// Name: device_iot_config_get_str
// Params: const std::string& section, const std::string& key, char* value, int*
// size_bytes
// Return: bool
struct device_iot_config_get_str {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     char* value, int* size_bytes)>
      body{[this](const std::string& section, const std::string& key,
                  char* value, int* size_bytes) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key,
                  char* value, int* size_bytes) {
    return body(section, key, value, size_bytes);
  };
};
extern struct device_iot_config_get_str device_iot_config_get_str;

// Name: device_iot_config_set_str
// Params: const std::string& section, const std::string& key, const
// std::string& value
// Return: bool
struct device_iot_config_set_str {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     const std::string& value)>
      body{[this](const std::string& section, const std::string& key,
                  const std::string& value) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key,
                  const std::string& value) {
    return body(section, key, value);
  };
};
extern struct device_iot_config_set_str device_iot_config_set_str;

// Name: device_iot_config_get_bin
// Params: const std::string& section, const std::string& key, uint8_t* value,
// size_t* length
// Return: bool
struct device_iot_config_get_bin {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     uint8_t* value, size_t* length)>
      body{[this](const std::string& section, const std::string& key,
                  uint8_t* value, size_t* length) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key,
                  uint8_t* value, size_t* length) {
    return body(section, key, value, length);
  };
};
extern struct device_iot_config_get_bin device_iot_config_get_bin;

// Name: device_iot_config_set_bin
// Params: const std::string& section, const std::string& key, const uint8_t*
// value, size_t length
// Return: bool
struct device_iot_config_set_bin {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key,
                     const uint8_t* value, size_t length)>
      body{[this](const std::string& section, const std::string& key,
                  const uint8_t* value,
                  size_t length) { return return_value; }};
  bool operator()(const std::string& section, const std::string& key,
                  const uint8_t* value, size_t length) {
    return body(section, key, value, length);
  };
};
extern struct device_iot_config_set_bin device_iot_config_set_bin;

// Name: device_iot_config_get_bin_length
// Params: const std::string& section, const std::string& key
// Return: size_t
struct device_iot_config_get_bin_length {
  size_t return_value{0};
  std::function<size_t(const std::string& section, const std::string& key)>
      body{[this](const std::string& section, const std::string& key) {
        return return_value;
      }};
  size_t operator()(const std::string& section, const std::string& key) {
    return body(section, key);
  };
};
extern struct device_iot_config_get_bin_length device_iot_config_get_bin_length;

// Name: device_iot_config_has_section
// Params: const std::string& section
// Return: bool
struct device_iot_config_has_section {
  bool return_value{false};
  std::function<bool(const std::string& section)> body{
      [this](const std::string& section) { return return_value; }};
  bool operator()(const std::string& section) { return body(section); };
};
extern struct device_iot_config_has_section device_iot_config_has_section;

// Name: device_iot_config_exist
// Params: const std::string& section, const std::string& key
// Return: bool
struct device_iot_config_exist {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key)> body{
      [this](const std::string& section, const std::string& key) {
        return return_value;
      }};
  bool operator()(const std::string& section, const std::string& key) {
    return body(section, key);
  };
};
extern struct device_iot_config_exist device_iot_config_exist;

// Name: device_iot_config_remove
// Params: const std::string& section, const std::string& key
// Return: bool
struct device_iot_config_remove {
  bool return_value{false};
  std::function<bool(const std::string& section, const std::string& key)> body{
      [this](const std::string& section, const std::string& key) {
        return return_value;
      }};
  bool operator()(const std::string& section, const std::string& key) {
    return body(section, key);
  };
};
extern struct device_iot_config_remove device_iot_config_remove;

// Name: device_iot_config_clear
// Params: void
// Return: bool
struct device_iot_config_clear {
  bool return_value{false};
  std::function<bool(void)> body{[this]() { return return_value; }};
  bool operator()(void) { return body(); };
};
extern struct device_iot_config_clear device_iot_config_clear;

// Name: device_iot_config_flush
// Params: void
// Return: void
struct device_iot_config_flush {
  std::function<void(void)> body{[]() {}};
  void operator()(void){ body(); };
};
extern struct device_iot_config_flush device_iot_config_flush;

// Name: device_debug_iot_config_dump
// Params: int fd
// Return: void
struct device_debug_iot_config_dump {
  std::function<void(int fd)> body{[](int fd) {}};
  void operator()(int fd) { body(fd); };
};
extern struct device_debug_iot_config_dump device_debug_iot_config_dump;

}  // namespace device_iot_config
}  // namespace mock
}  // namespace test
 No newline at end of file