• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
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 
16 #ifndef MOCK_JS_NATIVE_ENGINE_H
17 #define MOCK_JS_NATIVE_ENGINE_H
18 
19 #include "gmock/gmock.h"
20 #include "native_engine/native_engine.h"
21 
22 class MockJsNativeEngine : public NativeEngine {
23 public:
MockJsNativeEngine()24     MockJsNativeEngine() : NativeEngine(nullptr)
25     {}
26 
~MockJsNativeEngine()27     virtual ~MockJsNativeEngine()
28     {}
29 
GetGlobal()30     NativeValue *GetGlobal() override
31     {
32         GTEST_LOG_(INFO) << "MockJsNativeEngine::GetGlobal called";
33         return nullptr;
34     }
35 
CreateNull()36     NativeValue *CreateNull() override
37     {
38         return nullptr;
39     }
40 
CreateUndefined()41     NativeValue *CreateUndefined() override
42     {
43         return nullptr;
44     }
45 
CreateBoolean(bool value)46     NativeValue *CreateBoolean(bool value) override
47     {
48         return nullptr;
49     }
50 
CreateNumber(int32_t value)51     NativeValue *CreateNumber(int32_t value) override
52     {
53         return nullptr;
54     }
55 
CreateNumber(uint32_t value)56     NativeValue *CreateNumber(uint32_t value) override
57     {
58         return nullptr;
59     }
60 
CreateNumber(int64_t value)61     NativeValue *CreateNumber(int64_t value) override
62     {
63         return nullptr;
64     }
65 
CreateNumber(double value)66     NativeValue *CreateNumber(double value) override
67     {
68         return nullptr;
69     }
70 
CreateBigInt(int64_t value)71     NativeValue *CreateBigInt(int64_t value) override
72     {
73         return nullptr;
74     }
75 
CreateBigInt(uint64_t value)76     NativeValue *CreateBigInt(uint64_t value) override
77     {
78         return nullptr;
79     }
80 
CreateString(const char * value,size_t length)81     NativeValue *CreateString(const char *value, size_t length) override
82     {
83         GTEST_LOG_(INFO) << "MockJsNativeEngine::CreateString called";
84         return nullptr;
85     }
86 
CreateString16(const char16_t * value,size_t length)87     NativeValue *CreateString16(const char16_t *value, size_t length) override
88     {
89         return nullptr;
90     }
91 
CreateSymbol(NativeValue * value)92     NativeValue *CreateSymbol(NativeValue *value) override
93     {
94         return nullptr;
95     }
96 
97     NativeValue *CreateExternal(void *value, NativeFinalize callback, void *hint, size_t nativeBindingSize = 0) override
98     {
99         return nullptr;
100     }
101 
CreateObject()102     NativeValue *CreateObject() override
103     {
104         return nullptr;
105     }
106 
CreateFunction(const char * name,size_t length,NativeCallback cb,void * value)107     NativeValue *CreateFunction(const char *name, size_t length, NativeCallback cb, void *value) override
108     {
109         return nullptr;
110     }
111 
CreateArray(size_t length)112     NativeValue *CreateArray(size_t length) override
113     {
114         return nullptr;
115     }
116 
CreateBuffer(void ** value,size_t length)117     NativeValue *CreateBuffer(void **value, size_t length) override
118     {
119         return nullptr;
120     }
121 
CreateBufferCopy(void ** value,size_t length,const void * data)122     NativeValue *CreateBufferCopy(void **value, size_t length, const void *data) override
123     {
124         return nullptr;
125     }
126 
CreateBufferExternal(void * value,size_t length,NativeFinalize cb,void * hint)127     NativeValue *CreateBufferExternal(void *value, size_t length, NativeFinalize cb, void *hint) override
128     {
129         return nullptr;
130     }
131 
CreateArrayBuffer(void ** value,size_t length)132     NativeValue *CreateArrayBuffer(void **value, size_t length) override
133     {
134         return nullptr;
135     }
136 
CreateArrayBufferExternal(void * value,size_t length,NativeFinalize cb,void * hint)137     NativeValue *CreateArrayBufferExternal(void *value, size_t length, NativeFinalize cb, void *hint) override
138     {
139         return nullptr;
140     }
141 
CreateTypedArray(NativeTypedArrayType type,NativeValue * value,size_t length,size_t offset)142     NativeValue *CreateTypedArray(NativeTypedArrayType type, NativeValue *value, size_t length, size_t offset) override
143     {
144         return nullptr;
145     }
146 
CreateDataView(NativeValue * value,size_t length,size_t offset)147     NativeValue *CreateDataView(NativeValue *value, size_t length, size_t offset) override
148     {
149         return nullptr;
150     }
151 
CreatePromise(NativeDeferred ** deferred)152     NativeValue *CreatePromise(NativeDeferred **deferred) override
153     {
154         return nullptr;
155     }
156 
SetPromiseRejectCallback(NativeReference * rejectCallbackRef,NativeReference * checkCallbackRef)157     void SetPromiseRejectCallback(NativeReference *rejectCallbackRef, NativeReference *checkCallbackRef) override
158     {}
159 
160     MOCK_METHOD2(CreateError, NativeValue *(NativeValue *, NativeValue *));
161 
InitTaskPoolThread(NativeEngine * engine,NapiConcurrentCallback callback)162     bool InitTaskPoolThread(NativeEngine* engine, NapiConcurrentCallback callback) override
163     {
164         return false;
165     }
InitTaskPoolFunc(NativeEngine * engine,NativeValue * func)166     bool InitTaskPoolFunc(NativeEngine* engine, NativeValue* func) override
167     {
168         return false;
169     }
170 
CallFunction(NativeValue * thisVar,NativeValue * function,NativeValue * const * argv,size_t argc)171     NativeValue *CallFunction(
172         NativeValue *thisVar, NativeValue *function, NativeValue *const *argv, size_t argc) override
173     {
174         GTEST_LOG_(INFO) << "MockJsNativeEngine::CallFunction called";
175         return nullptr;
176     }
177 
RunScript(NativeValue * script)178     NativeValue *RunScript(NativeValue *script) override
179     {
180         return nullptr;
181     }
182 
RunScriptPath(const char * path)183     NativeValue *RunScriptPath(const char *path) override
184     {
185         return nullptr;
186     }
187 
RunScriptBuffer(const char * path,std::vector<uint8_t> & buffer,bool isBundle)188     NativeValue *RunScriptBuffer(const char *path, std::vector<uint8_t> &buffer, bool isBundle) override
189     {
190         return nullptr;
191     }
192 
RunBufferScript(std::vector<uint8_t> & buffer)193     NativeValue *RunBufferScript(std::vector<uint8_t> &buffer) override
194     {
195         return nullptr;
196     }
197 
RunActor(std::vector<uint8_t> & buffer,const char * descriptor)198     NativeValue *RunActor(std::vector<uint8_t> &buffer, const char *descriptor) override
199     {
200         return nullptr;
201     }
202 
DefineClass(const char * name,NativeCallback callback,void * data,const NativePropertyDescriptor * properties,size_t length)203     NativeValue *DefineClass(const char *name, NativeCallback callback, void *data,
204         const NativePropertyDescriptor *properties, size_t length) override
205     {
206         return nullptr;
207     }
208 
CreateInstance(NativeValue * constructor,NativeValue * const * argv,size_t argc)209     NativeValue *CreateInstance(NativeValue *constructor, NativeValue *const *argv, size_t argc) override
210     {
211         GTEST_LOG_(INFO) << "MockJsNativeEngine::CreateInstance called";
212         return nullptr;
213     }
214 
215     NativeReference *CreateReference(NativeValue *value, uint32_t initialRefcount, NativeFinalize callback = nullptr,
216         void *data = nullptr, void *hint = nullptr) override
217     {
218         GTEST_LOG_(INFO) << "MockJsNativeEngine::CreateReference called";
219         return nullptr;
220     }
221 
222     MOCK_METHOD1(Throw, bool(NativeValue *error));
223 
Throw(NativeErrorType type,const char * code,const char * message)224     bool Throw(NativeErrorType type, const char *code, const char *message) override
225     {
226         return true;
227     }
228 
CreateRuntime()229     void *CreateRuntime() override
230     {
231         return nullptr;
232     }
233 
Serialize(NativeEngine * context,NativeValue * value,NativeValue * transfer)234     NativeValue *Serialize(NativeEngine *context, NativeValue *value, NativeValue *transfer) override
235     {
236         return nullptr;
237     }
238 
Deserialize(NativeEngine * context,NativeValue * recorder)239     NativeValue *Deserialize(NativeEngine *context, NativeValue *recorder) override
240     {
241         return nullptr;
242     }
243 
DeleteSerializationData(NativeValue * value)244     void DeleteSerializationData(NativeValue* value) const override
245     {}
246 
LoadModule(NativeValue * str,const std::string & fileName)247     NativeValue *LoadModule(NativeValue *str, const std::string &fileName) override
248     {
249         return nullptr;
250     }
251 
252     void StartCpuProfiler(const std::string &fileName = "") override
253     {}
254 
StopCpuProfiler()255     void StopCpuProfiler() override
256     {}
257 
ResumeVM()258     void ResumeVM() override
259     {}
260 
ValueToNativeValue(JSValueWrapper & value)261     NativeValue *ValueToNativeValue(JSValueWrapper &value) override
262     {
263         return nullptr;
264     }
265 
CreateDate(double value)266     NativeValue *CreateDate(double value) override
267     {
268         return nullptr;
269     }
270 
CreateBigWords(int sign_bit,size_t word_count,const uint64_t * words)271     NativeValue *CreateBigWords(int sign_bit, size_t word_count, const uint64_t *words) override
272     {
273         return nullptr;
274     }
275 
SuspendVM()276     bool SuspendVM() override
277     {
278         return true;
279     }
280 
IsSuspended()281     bool IsSuspended() override
282     {
283         return true;
284     }
285 
CheckSafepoint()286     bool CheckSafepoint() override
287     {
288         return true;
289     }
290 
BuildNativeAndJsStackTrace(std::string & stackTraceStr)291     bool BuildNativeAndJsStackTrace(std::string &stackTraceStr) override
292     {
293         return true;
294     }
295 
BuildJsStackTrace(std::string & stackTraceStr)296     bool BuildJsStackTrace(std::string &stackTraceStr) override
297     {
298         return true;
299     }
300 
BuildJsStackInfoList(uint32_t tid,std::vector<JsFrameInfo> & jsFrames)301     bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrameInfo> &jsFrames) override
302     {
303         GTEST_LOG_(INFO) << "MockJsNativeEngine::BuildJsStackInfoList called";
304         return true;
305     }
306 
DeleteWorker(NativeEngine * hostEngine,NativeEngine * workerEngine)307     bool DeleteWorker(NativeEngine *hostEngine, NativeEngine *workerEngine) override
308     {
309         return true;
310     }
311 
312     bool StartHeapTracking(double timeInterval, bool isVmMode = true) override
313     {
314         return true;
315     }
316 
StopHeapTracking(const std::string & filePath)317     bool StopHeapTracking(const std::string &filePath) override
318     {
319         return true;
320     }
321 
IsExceptionPending()322     bool IsExceptionPending() const override
323     {
324         return false;
325     }
326 
GetAndClearLastException()327     NativeValue* GetAndClearLastException() override
328     {
329         return nullptr;
330     }
331 
TriggerFatalException(NativeValue * error)332     bool TriggerFatalException(NativeValue* error) override
333     {
334         return true;
335     }
336 
AdjustExternalMemory(int64_t ChangeInBytes,int64_t * AdjustedValue)337     bool AdjustExternalMemory(int64_t ChangeInBytes, int64_t *AdjustedValue) override
338     {
339         return true;
340     }
341 
PrintStatisticResult()342     void PrintStatisticResult() override
343     {}
344 
StartRuntimeStat()345     void StartRuntimeStat() override
346     {}
347 
StopRuntimeStat()348     void StopRuntimeStat() override
349     {}
350 
NotifyApplicationState(bool inBackground)351     void NotifyApplicationState(bool inBackground) override
352     {
353         GTEST_LOG_(INFO) << "MockJsNativeEngine::NotifyApplicationState called";
354     }
355 
NotifyIdleTime(int idleMicroSec)356     void NotifyIdleTime(int idleMicroSec) override
357     {}
358 
359     void NotifyMemoryPressure(bool inHighMemoryPressure = false) override
360     {}
361 
RegisterUncaughtExceptionHandler(UncaughtExceptionCallback callback)362     void RegisterUncaughtExceptionHandler(UncaughtExceptionCallback callback) override
363     {}
364 
HandleUncaughtException()365     void HandleUncaughtException() override
366     {}
367 
368     void DumpHeapSnapshot(
369         bool isVmMode = true, DumpFormat dumpFormat = DumpFormat::JSON, bool isPrivate = false) override
370     {
371         GTEST_LOG_(INFO) << "MockJsNativeEngine::DumpHeapSnapshot called";
372     }
373 
374     void DumpHeapSnapshot(
375         const std::string &path, bool isVmMode = true, DumpFormat dumpFormat = DumpFormat::JSON) override
376     {}
377 
GetArrayBufferSize()378     size_t GetArrayBufferSize() override
379     {
380         return 0;
381     }
382 
GetHeapTotalSize()383     size_t GetHeapTotalSize() override
384     {
385         return 0;
386     }
387 
GetHeapUsedSize()388     size_t GetHeapUsedSize() override
389     {
390         return 0;
391     }
GetScopeManager()392     NativeScopeManager *GetScopeManager()
393     {
394         GTEST_LOG_(INFO) << "MockJsNativeEngine::GetScopeManager called";
395         return nullptr;
396     }
CreateNativeBindingObject(void * detach,void * attach)397     NativeValue* CreateNativeBindingObject(void* detach, void* attach)
398     {
399         return nullptr;
400     }
CreateNBObject(DetachCallback detach,AttachCallback attach)401     NativeValue* CreateNBObject(DetachCallback detach, AttachCallback attach)
402     {
403         return nullptr;
404     }
405 };
406 
407 #endif /* MOCK_JS_NATIVE_ENGINE_H */
408