deleteFileAssetsPerformance.test.js 6.1 KB
Newer Older
G
gudehe 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import mediaLibrary from '@ohos.multimedia.medialibrary';
Z
zhang-daiyue 已提交
17
import featureAbility from '@ohos.ability.featureAbility'
G
gudehe 已提交
18 19 20 21 22

import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'


describe('deleteFileAssetsPerformance.test.js', function () {
Z
zhang-daiyue 已提交
23 24 25 26
    var context = featureAbility.getContext();
    console.info('MediaLibraryTest : getMediaLibrary IN');
    const media = mediaLibrary.getMediaLibrary(context);
    console.info('MediaLibraryTest : getMediaLibrary OUT');
G
gudehe 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

    let fileList_;
    let fileKeyObj = mediaLibrary.FileKey
    let type = mediaLibrary.MediaType.IMAGE
    let fetchOp = {
        selections : fileKeyObj.MEDIA_TYPE + " = ? ",
        selectionArgs : [type.toString()],
        order : fileKeyObj.DATE_ADDED,
    }
    beforeAll(function () {
        onsole.info('MediaLibraryTest: beforeAll');
    })

    beforeEach(function () {
        console.info('MediaLibraryTest: beforeEach');
    })
    afterEach(function () {
        console.info('MediaLibraryTest: afterEach');
    })
    afterAll(function () {
        console.info('MediaLibraryTest: afterAll');
    })

    /*
     * @tc.number    : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01
     * @tc.name      : Create an image file asset in predefined path 
     * @tc.desc      : Create an image file asset in predefined path
     * @tc.size      : MEDIUM
     * @tc.type      : Function
     * @tc.level     : Level 0
     */

    console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 begin');
    it('SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01', 0, async function (done) {
        media.getFileAssets(fetchOp, (getFileAssetsErr, queryResultSet) => {
            if (queryResultSet != undefined) {
                console.info('MediaLibraryTest : getAllObject Successfull '+ queryResultSet.getCount());
                if (queryResultSet.getCount() > 0) {
                    queryResultSet.getAllObject((getAllObjectErr, fileList) => {
                        if (fileList != undefined) {
                            fileList_ = fileList;
                            console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 :PASS');
                            expect(true).assertTrue();
                            done();
                        } else {
                            console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 :FAIL'
                                + getAllObjectErr.message);
                            expect(false).assertTrue();
                            done();
                        }
                    });
                } else {
                    console.info('MediaLibraryTest : getFileAssets :No data');
                    expect(true).assertTrue();
                    done();
                }
            } else {
                console.info('MediaLibraryTest : getFileAssets Unsuccessfull '+ getFileAssetsErr.message);
                console.info('MediaLibraryTest : getFileAssets :FAIL');
                expect(false).assertTrue();
                done();
            }
        });
    });
    console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_GET_FILE_ASSETS_FOR_DELETE_01 end');

    /*
     * @tc.number    : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_ASSET_01
     * @tc.name      : Create an image file asset in predefined path 
     * @tc.desc      : Create an image file asset in predefined path
     * @tc.size      : MEDIUM
     * @tc.type      : Function
     * @tc.level     : Level 0
     */

    console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 begin');
    it('SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01', 0, async function (done) {
        if (fileList_ != undefined) {
            let counteEnd = 0;
Z
zhang-daiyue 已提交
106
            for (let i = 0; i < fileList_.length; i++) {
G
gudehe 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
                let fileAsset = fileList_[i];
                console.info('MediaLibraryTest : uri is '+ fileAsset.uri);
                media.deleteAsset(fileAsset.uri, (deleteAssetErr, deleteRows) => {
                    if (deleteRows >= 0) {
                        console.info('MediaLibraryTest : Delete Asset Successfull '+ deleteRows);
                        counteEnd++;
                        if (counteEnd == fileList_.length){
                            console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 : PASS');
                            expect(true).assertTrue();
                            done();
                        } else if (i == fileList_.length - 1) {
                            console.info('MediaLibraryTest : delete has error');
                            console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :Partial');
                            expect(false).assertTrue();
                            done();
                        }
                    } else {
                        console.info('MediaLibraryTest : delete error '+ deleteAssetErr.message);
                        console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :FAIL');
                        expect(false).assertTrue();
                        done();
                    }
                });
            }
        } else {
            console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 :FAIL'
                + getAllObjectErr.message);
            expect(false).assertTrue();
            done();
        }
    });
    console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_DELETE_FILE_PERFORMANCE_01 end');
});