albumTestCallBack.test.js 5.5 KB
Newer Older
G
gudehe 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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
/*
 * 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';


import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
let fileKeyObj = mediaLibrary.FileKey
let AlbumNoArgsfetchOp = {
    selections: "",
    selectionArgs: [],
}
let AlbumHasArgsfetchOp = {
    selections: fileKeyObj.PATH + " LIKE ? ",
    selectionArgs: ["/data/media%"],
}
let type1 = mediaLibrary.MediaType.IMAGE
let fileHasArgsfetchOp = {
    selections: fileKeyObj.MEDIA_TYPE + "= ?",
    selectionArgs: [type1.toString()],
}
let fileNoArgsfetchOp = {
    selections: "",
    selectionArgs: [],
}

describe('album.callback.test.js', function () {

    let mediaType = mediaLibrary.MediaType.IMAGE;
    let path = "Pictures/"
    var asset;
    var media = mediaLibrary.getMediaLibrary();
    var album;
    beforeAll(function () {
        console.info('Album Callback MediaLibraryTest: beforeAll.');

    })

    beforeEach(function () {
        console.info('Album Callback MediaLibraryTest: beforeEach.');

    })
    afterEach(function () {
        console.info('Album Callback MediaLibraryTest: afterEach.');

    })
    afterAll(function () {
        console.info('Album Callback MediaLibraryTest: afterAll.');

    })
Z
zhang-daiyue 已提交
62

G
gudehe 已提交
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 106 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    /*
     * @tc.number    : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001
     * @tc.name      : Get Album by AlbumNoArgsfetchOp
     * @tc.desc      : Get Album by AlbumNoArgsfetchOp
     * @tc.size      : MEDIUM
     * @tc.type      : Function
     * @tc.level     : Level 0
     */

    it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_001', 0, async function (done) {
        asset = await media.createAsset(mediaType, "image0003Callback.jpg", path);
        media.getAlbums(AlbumNoArgsfetchOp, getAlbumsCallBack);
        done();
    });

    /*
     * @tc.number    : SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002
     * @tc.name      : Get Album by AlbumHasArgsfetchOp
     * @tc.desc      : Get Album by AlbumHasArgsfetchOp
     * @tc.size      : MEDIUM
     * @tc.type      : Function
     * @tc.level     : Level 0
     */

    it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_CALLBACK_002', 0, async function (done) {
        media.getAlbums(AlbumHasArgsfetchOp, getAlbumsCallBack);
        done();
    });


    function getAllObjectInfo(data) {
        if (data != undefined) {
            console.info('MediaLibraryTest : ALBUM_CALLBACK id is ' + data.id);
            console.info('MediaLibraryTest : ALBUM_CALLBACK uri is ' + data.uri);
            console.info('MediaLibraryTest : ALBUM_CALLBACK displayName is ' + data.displayName);
            console.info('MediaLibraryTest : ALBUM_CALLBACK mediaType is ' + data.title);
            console.info('MediaLibraryTest : ALBUM_CALLBACK relativePath is ' + data.relativePath);
        } else {
            console.info('MediaLibraryTest : ALBUM_CALLBACK getAllObjectInfo no album');
        }
    }

    function getAlbumsCallBack(err, albumList) {
        if (albumList != undefined) {
            album = albumList[0];
            console.info('MediaLibraryTest : ALBUM_CALLBACK getAlbumsCallBack album.albumName = ' + album.albumName);
            album.albumName = "helloCallBack";
            album.commitModify(commitModifyCallBack);
            album.getFileAssets(fileNoArgsfetchOp, getFileAssetsCallBack);
            album.getFileAssets(fileHasArgsfetchOp, getFileAssetsCallBack);
            done();
        } else {
            console.info('MediaLibraryTest : ASSET_CALLBACK getAlbumsCallBack Unsuccessfull ' + err);
            console.info('MediaLibraryTest : ASSET_CALLBACK getAlbumsCallBack : FAIL');
            done();
        }

    }

    function commitModifyCallBack(err, data) {
        if (data != undefined) {
            console.info('MediaLibraryTest : ALBUM_CALLBACK Modify album.albumName = ' + album.albumName);
            done();
        } else {
            console.info('MediaLibraryTest : ASSET_CALLBACK Modify Unsuccessfull ' + err);
            console.info('MediaLibraryTest : ASSET_CALLBACK Modify : FAIL');
            done();
        }

    }

    function getFileAssetsCallBack(err, albumFetchFileResult) {
        if (albumFetchFileResult != undefined) {
            console.info('MediaLibraryTest : ALBUM_CALLBACK getFileAssetsCallBack success');
            albumFetchFileResult.getAllObject((err1, data1) => {
                if (data1 != undefined) {
                    data1.forEach(getAllObjectInfo);
                    console.info('MediaLibraryTest : getFileAssetsCallBack getAllObject :PASS');
                    done();
                }
                console.info('MediaLibraryTest : getFileAssetsCallBack getFileAssets :No data');
                done();
            });
            done();
        } else {
            console.info('MediaLibraryTest : ASSET_CALLBACK getFileAssetsCallBack Unsuccessfull ' + err);
            console.info('MediaLibraryTest : ASSET_CALLBACK getFileAssetsCallBack : FAIL');
            done();
        }

    }
})