• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_DATA_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_DATA_H
18 #include <cstddef>
19 #include <memory>
20 namespace OHOS::Ace::Testing {
21 inline size_t g_imageDataSize = 0;
22 class TestingData {
23 public:
24     typedef void (*DataReleaseProc)(const void* ptr, void* context);
25 
26     TestingData() = default;
27     virtual ~TestingData() = default;
28 
BuildWithCopy(const void * data,size_t length)29     virtual bool BuildWithCopy(const void* data, size_t length)
30     {
31         return length > 0 ? true : false;
32     }
33 
BuildWithProc(const void * ptr,size_t length,DataReleaseProc proc,void * ctx)34     virtual bool BuildWithProc(const void* ptr, size_t length, DataReleaseProc proc, void* ctx)
35     {
36         return length > 0 ? true : false;
37     }
38 
GetSize()39     virtual size_t GetSize() const
40     {
41         if (!testImageDataSize) {
42             return 0;
43         }
44         return *testImageDataSize;
45     }
46 
GetData()47     virtual void* GetData() const
48     {
49         return nullptr;
50     }
51 
MakeFromFileName(const char path[])52     static std::shared_ptr<TestingData> MakeFromFileName(const char path[])
53     {
54         return std::make_shared<TestingData>();
55     }
56 
BuildFromMalloc(const void * data,size_t length)57     virtual bool BuildFromMalloc(const void* data, size_t length)
58     {
59         return true;
60     }
61 
BuildUninitialized(size_t length)62     virtual bool BuildUninitialized(size_t length)
63     {
64         return true;
65     }
66 
WritableData()67     virtual void* WritableData()
68     {
69         return nullptr;
70     }
71 
72     inline static size_t* testImageDataSize = &g_imageDataSize;
73 };
74 } // namespace OHOS::Ace::Testing
75 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_TEST_TESTING_DATA_H
76