2020-03-17 19:19:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-03-27 23:32:07 +08:00
|
|
|
#include "shared/source/utilities/io_functions.h"
|
|
|
|
|
|
|
|
#include <cstdint>
|
2020-07-16 20:01:25 +08:00
|
|
|
#include <set>
|
2020-06-08 22:19:52 +08:00
|
|
|
#include <string>
|
2020-03-17 19:19:38 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
2020-03-27 23:32:07 +08:00
|
|
|
namespace IoFunctions {
|
2020-03-17 19:19:38 +08:00
|
|
|
extern uint32_t mockFopenCalled;
|
|
|
|
extern uint32_t mockVfptrinfCalled;
|
|
|
|
extern uint32_t mockFcloseCalled;
|
2020-07-13 21:14:16 +08:00
|
|
|
extern uint32_t mockGetenvCalled;
|
2020-03-17 19:19:38 +08:00
|
|
|
|
2020-06-08 22:19:52 +08:00
|
|
|
extern bool returnMockEnvValue;
|
|
|
|
extern std::string mockEnvValue;
|
2020-07-16 20:01:25 +08:00
|
|
|
extern std::set<std::string> notMockableEnvValues;
|
2020-06-08 22:19:52 +08:00
|
|
|
|
2020-03-19 17:53:05 +08:00
|
|
|
inline FILE *mockFopen(const char *filename, const char *mode) {
|
2020-03-17 19:19:38 +08:00
|
|
|
mockFopenCalled++;
|
|
|
|
return reinterpret_cast<FILE *>(0x40);
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:53:05 +08:00
|
|
|
inline int mockVfptrinf(FILE *stream, const char *format, va_list arg) {
|
2020-03-17 19:19:38 +08:00
|
|
|
mockVfptrinfCalled++;
|
|
|
|
return 0x10;
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:53:05 +08:00
|
|
|
inline int mockFclose(FILE *stream) {
|
2020-03-17 19:19:38 +08:00
|
|
|
mockFcloseCalled++;
|
|
|
|
return 0;
|
|
|
|
}
|
2020-06-08 22:19:52 +08:00
|
|
|
|
|
|
|
inline char *mockGetenv(const char *name) noexcept {
|
2020-07-13 21:14:16 +08:00
|
|
|
mockGetenvCalled++;
|
2020-07-16 20:01:25 +08:00
|
|
|
if (notMockableEnvValues.find(name) == notMockableEnvValues.end()) {
|
|
|
|
if (returnMockEnvValue) {
|
|
|
|
return const_cast<char *>(mockEnvValue.c_str());
|
|
|
|
}
|
2020-06-08 22:19:52 +08:00
|
|
|
}
|
|
|
|
return getenv(name);
|
|
|
|
}
|
|
|
|
|
2020-03-27 23:32:07 +08:00
|
|
|
} // namespace IoFunctions
|
2020-03-17 19:19:38 +08:00
|
|
|
} // namespace NEO
|