1 /*
2  * Copyright (C) 2024 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 RINGTONE_UNITTEST_UTILS_H
17 #define RINGTONE_UNITTEST_UTILS_H
18 
19 #include <condition_variable>
20 
21 #include "iringtone_scanner_callback.h"
22 #include "ringtone_asset.h"
23 
24 namespace OHOS {
25 namespace Media {
26 const std::string STORAGE_FILES_DIR = "/storage/cloud/files/";
27 
28 class TestRingtoneScannerCallback : public IRingtoneScannerCallback {
29 public:
30     TestRingtoneScannerCallback();
31     ~TestRingtoneScannerCallback() = default;
32 
33     int32_t status_;
34     std::condition_variable condVar_;
35     int32_t OnScanFinished(const int32_t status, const std::string &uri, const std::string &path) override;
36 };
37 
38 class RingtoneUnitTestUtils {
39 public:
RingtoneUnitTestUtils()40     RingtoneUnitTestUtils() {}
~RingtoneUnitTestUtils()41     virtual ~RingtoneUnitTestUtils() {}
42     static void Init();
43     static void InitRootDirs();
44     static void CleanTestFiles();
45     static bool CreateFileFS(const std::string& filePath);
46     static void WaitForCallback(std::shared_ptr<TestRingtoneScannerCallback> callback);
47 private:
48     static inline bool isValid_ = false;
49     static inline std::unordered_map<std::string, std::shared_ptr<RingtoneAsset>> rootDirAssetMap_;
50 };
51 }
52 }
53 
54 #endif // RINGTONE_UNITTEST_UTILS_H
55