Files
compute-runtime/opencl/test/unit_test/mocks/mock_io_functions.h
Mateusz Hoppe 8daf71070d Enhance mocking env variables
Change-Id: I2d0659b6f608467f9c1bc5746742ac5e3454582d
Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
2020-07-30 14:52:14 +02:00

49 lines
1.1 KiB
C++

/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/utilities/io_functions.h"
#include <cstdint>
#include <string>
#include <unordered_map>
namespace NEO {
namespace IoFunctions {
extern uint32_t mockFopenCalled;
extern uint32_t mockVfptrinfCalled;
extern uint32_t mockFcloseCalled;
extern uint32_t mockGetenvCalled;
extern std::unordered_map<std::string, std::string> *mockableEnvValues;
inline FILE *mockFopen(const char *filename, const char *mode) {
mockFopenCalled++;
return reinterpret_cast<FILE *>(0x40);
}
inline int mockVfptrinf(FILE *stream, const char *format, va_list arg) {
mockVfptrinfCalled++;
return 0x10;
}
inline int mockFclose(FILE *stream) {
mockFcloseCalled++;
return 0;
}
inline char *mockGetenv(const char *name) noexcept {
mockGetenvCalled++;
if (mockableEnvValues != nullptr && mockableEnvValues->find(name) != mockableEnvValues->end()) {
return const_cast<char *>(mockableEnvValues->find(name)->second.c_str());
}
return getenv(name);
}
} // namespace IoFunctions
} // namespace NEO