提交 ddcd8cd2 编写于 作者: P panqiangbiao

add more xts

Signed-off-by: Npanqiangbiao <panqiangbiao@huawei.com>
上级 81ce3fe8
......@@ -13,8 +13,6 @@
* limitations under the License.
*/
require('./favoriteTestCallBack.test.js')
require('./favoriteTestPromise.test.js')
require('./fileTestPromise.test.js')
require('./fileTestPromise.test.js')
require('./favoriteTestPromise.test.js')
require('./fileAsset2.test.js')
......
/*
* Copyright (C) 2022 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 featureAbility from '@ohos.ability.featureAbility'
import {
describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it,
expect
} from 'deccjsunit/index';
describe('fileAssetTestPromise.test.js', async function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () { });
beforeEach(function () { });
afterEach(function () { });
afterAll(function () { });
const fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
const count = 3;
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01
* @tc.name : getFileAssets
* @tc.desc : more file type all
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function (done) {
try {
let allTypefetchOp = {
selections: '',
selectionArgs: [],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02
* @tc.name : getFileAssets
* @tc.desc : more file type image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function (done) {
try {
let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03
* @tc.name : getFileAssets
* @tc.desc : more file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function (done) {
try {
let audioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(audioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(audioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04
* @tc.name : getFileAssets
* @tc.desc : more file type video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function (done) {
try {
let videoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(videoAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(videoAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05
* @tc.name : getFileAssets
* @tc.desc : more file type image and video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function (done) {
try {
let imageAndVideoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAndVideoAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06
* @tc.name : getFileAssets
* @tc.desc : more file type image and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function (done) {
try {
let imageAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/** order: 'date_added DESC LIMIT 0,500'
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07
* @tc.name : getFileAssets
* @tc.desc : more file type video and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function (done) {
try {
let videoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(videoAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08
* @tc.name : getFileAssets
* @tc.desc : more file type image video and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08', 0, async function (done) {
try {
let imgAndVideoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imgAndVideoAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imgAndVideoAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09
* @tc.name : getFileAssets
* @tc.desc : one file tpe image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10
* @tc.name : getFileAssets
* @tc.desc : one file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11
* @tc.name : getFileAssets
* @tc.desc : one file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11 count:' + fetchFileResult.getCount());
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12
* @tc.name : getFileAssets
* @tc.desc : no file type image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
const album = albumList[0];
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 albumId:' + album.albumId);
expect(album.albumId == 0).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13
* @tc.name : getFileAssets
* @tc.desc : no file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
const album = albumList[0];
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 albumId:' + album.albumId);
expect(album.albumId == 0).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14
* @tc.name : getFileAssets
* @tc.desc : no file type video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
const album = albumList[0];
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 albumId:' + album.albumId);
expect(album.albumId == 0).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
});
/*
* Copyright (C) 2022 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 featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
describe('fileAssetTestPromise.test.js', async function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
var media = mediaLibrary.getMediaLibrary(context);
console.info('MediaLibraryTest : getMediaLibrary OUT');
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
const fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
const count = 3;
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01
* @tc.name : getFileAssets
* @tc.desc : more file type all
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_01', 0, async function (done) {
try {
let allTypefetchOp = {
selections: '',
selectionArgs: [],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02
* @tc.name : getFileAssets
* @tc.desc : more file type image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_02', 0, async function (done) {
try {
let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03
* @tc.name : getFileAssets
* @tc.desc : more file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_03', 0, async function (done) {
try {
let audioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(audioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(audioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04
* @tc.name : getFileAssets
* @tc.desc : more file type video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_04', 0, async function (done) {
try {
let videoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(videoAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(videoAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05
* @tc.name : getFileAssets
* @tc.desc : more file type image and video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_05', 0, async function (done) {
try {
let imageAndVideoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAndVideoAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06
* @tc.name : getFileAssets
* @tc.desc : more file type image and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_06', 0, async function (done) {
try {
let imageAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imageAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/** order: 'date_added DESC LIMIT 0,500'
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07
* @tc.name : getFileAssets
* @tc.desc : more file type video and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_07', 0, async function (done) {
try {
let videoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(videoAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08
* @tc.name : getFileAssets
* @tc.desc : more file type image video and audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_08', 0, async function (done) {
try {
let imgAndVideoAndAudioAlbumfetchOp = {
selections:
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: [imageType.toString(), videoType.toString(), audioType.toString()],
order: 'date_added DESC LIMIT 0,3',
};
const albumList = await media.getAlbums(imgAndVideoAndAudioAlbumfetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(imgAndVideoAndAudioAlbumfetchOp);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09
* @tc.name : getFileAssets
* @tc.desc : one file tpe image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_09', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10
* @tc.name : getFileAssets
* @tc.desc : one file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_10', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11
* @tc.name : getFileAssets
* @tc.desc : one file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_11', 0, async function (done) {
try {
let albumfetchOpOne = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpOne);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(albumfetchOpOne);
expect(fetchFileResult.getCount() <= count).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12
* @tc.name : getFileAssets
* @tc.desc : no file type image
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_12', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [imageType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13
* @tc.name : getFileAssets
* @tc.desc : no file type audio
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_13', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [audioType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14
* @tc.name : getFileAssets
* @tc.desc : no file type video
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_ALBUM_GET_ASSETS_PROMISE_001_14', 0, async function (done) {
try {
let albumfetchOpNone = {
selections: fileKeyObj.MEDIA_TYPE + '= ? AND date_added < 0',
selectionArgs: [videoType.toString()],
order: 'date_added DESC LIMIT 0,1',
};
const albumList = await media.getAlbums(albumfetchOpNone);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
expect(false).assertTrue();
done();
}
});
});
/*
* Copyright (C) 2022 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 featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
let videoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let imageAndVideoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString()],
};
let imageAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), audioType.toString()],
};
let videoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString(), audioType.toString()],
};
function printAlbumMessage(test_num, album) {
console.info(`MediaLibraryTest : ALBUM_CALLBACK getAlbum ${test_num} album.albumId: ${album.albumId}`);
console.info(`MediaLibraryTest : ALBUM_CALLBACK getAlbum ${test_num} album.albumName: ${album.albumName}`);
console.info(`MediaLibraryTest : ALBUM_CALLBACK getAlbum ${test_num} album.albumUri: ${album.albumUri}`);
console.info(`MediaLibraryTest : ALBUM_CALLBACK getAlbum ${test_num} album.dateModified: ${album.dateModified}`);
console.info(`MediaLibraryTest : ALBUM_CALLBACK getAlbum ${test_num} album.count: ${album.count}`);
console.info(`MediaLibraryTest : ALBUM_CALLBACK getAlbum ${test_num} album.relativePath: ${album.relativePath}`);
console.info(`MediaLibraryTest : ALBUM_CALLBACK getAlbum ${test_num} album.coverUri: ${album.coverUri}`);
}
function checkAlbumAttr(done, album) {
if (album.albumId == undefined || album.albumName == undefined || album.albumUri == undefined || album.count == undefined || album.relativePath == undefined || album.coverUri == undefined) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 failed');
expect(false).assertTrue();
done();
}
}
describe('album.promise.test.js', async function () {
var context = featureAbility.getContext();
var media = mediaLibrary.getMediaLibrary(context);
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
// ------------------------------ 001 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01
* @tc.name : getAlbums
* @tc.desc : Get Album by AllTypefetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
printAlbumMessage('001_01', album);
checkAlbumAttr(done, album);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_02', album);
checkAlbumAttr(done, album);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_02 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_02 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03
* @tc.name : getAlbums
* @tc.desc : Get Album by videoAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03', 0, async function (done) {
try {
const albumList = await media.getAlbums(videoAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_03', album);
checkAlbumAttr(done, album);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_03 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_03 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04
* @tc.name : getAlbums
* @tc.desc : Get Album by audioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04', 0, async function (done) {
try {
const albumList = await media.getAlbums(audioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_04', album);
checkAlbumAttr(done, album);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_04 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_04 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAndVideoAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_05', album);
checkAlbumAttr(done, album);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_05 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_05 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAndAudioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_06', album);
checkAlbumAttr(done, album);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_06 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_06 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07
* @tc.name : getAlbums
* @tc.desc : Get Album by videoAndAudioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07', 0, async function (done) {
try {
const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_07', album);
checkAlbumAttr(done, album);
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_07 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 001_07 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 001 test end -------------------------
// ------------------------------ 002 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01
* @tc.name : getAlbums
* @tc.desc : Get Album by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01', 0, async function (done) {
try {
await media.getAlbums(666);
expect(false).assertTrue();
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_01 failed');
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_01 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02
* @tc.name : getAlbums
* @tc.desc : Get Album by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02', 0, async function (done) {
try {
await media.getAlbums('666');
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_02 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_02 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03
* @tc.name : getAlbums
* @tc.desc : Get Album by 0
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03', 0, async function (done) {
try {
await media.getAlbums(0);
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_03 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_03 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04
* @tc.name : getAlbums
* @tc.desc : Get Album by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04', 0, async function (done) {
try {
await media.getAlbums(true);
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_04 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_04 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05
* @tc.name : getAlbums
* @tc.desc : Get Album by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05', 0, async function (done) {
try {
await media.getAlbums(false);
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_05 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getalbum 002_05 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp3
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06', 0, async function (done) {
let fileHasArgsfetchOp3 = {
selections: fileKeyObj.MEDIA_TYPE + ' = ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp3);
const album = albumList[0];
expect(album.albumId == 0).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 002_06 passed');
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp4
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07', 0, async function (done) {
let fileHasArgsfetchOp4 = {
selections: '666' + '= ?',
selectionArgs: [videoType.toString()],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp4);
const album = albumList[0];
expect(album.albumId == 0).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 002_07 passed');
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp5
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08', 0, async function (done) {
let fileHasArgsfetchOp5 = {
selections: '666' + '= ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp5);
const album = albumList[0];
expect(album.albumId == 0).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getFileAssets 002_08 passed');
expect(false).assertTrue();
done();
}
});
// ------------------------------ 002 test end -------------------------
// ------------------------------ 003 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01
* @tc.name : commitModify
* @tc.desc : Modify Album name to 'hello'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName);
const newName = 'newhello';
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let passed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 passed');
expect(true).assertTrue();
done();
passed = true;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_01 failed, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02
* @tc.name : commitModify
* @tc.desc : Modify Album name ''
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 album.albumName(old) = ' + album.albumName);
const newName = '';
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_02 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04
* @tc.name : commitModify
* @tc.desc : Modify Album name 'i123456...119'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_04 album.albumName(old) = ' + album.albumName);
let newName = true;
for (var i = 0; i < 1200; i++) {
newName += 'i';
}
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_04 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_04 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05
* @tc.name : commitModify
* @tc.desc : Modify Album name true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_05 album.albumName(old) = ' + album.albumName);
const newName = true;
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_05 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_05 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06
* @tc.name : commitModify
* @tc.desc : Modify Album name false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_06 album.albumName(old) = ' + album.albumName);
const newName = false;
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_06 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 003_06 passed');
expect(true).assertTrue();
}
done();
});
// ------------------------------ 003 test end -------------------------
// ------------------------------ 004 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01
* @tc.name : album.coverUri
* @tc.desc : check album.coverUri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
const asset = await fetchFileResult.getFirstObject();
expect(asset.uri == album.coverUri).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 004_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 004 test end -------------------------
// ------------------------------ 006 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01
* @tc.name : commitModify
* @tc.desc : Modify Album albumUri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
album.albumUri = 'testalbumUri';
await album.commitModify();
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 006_01 failed');
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 006_01 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02
* @tc.name : commitModify
* @tc.desc : Modify Album name false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
album.coverUri = 'testcoverUri';
await album.commitModify();
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 006_02 failed');
expect(false).assertTrue();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE Modify 006_02 passed');
expect(true).assertTrue();
}
done();
});
// ------------------------------ 006 test end -------------------------
// ------------------------------ 005 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01
* @tc.name : deleteAsset
* @tc.desc : delete album
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
let fetchFileResult = await album.getFileAssets(allTypefetchOp);
let datas = await fetchFileResult.getAllObject();
for (let j = 0; j < datas.length; j++) {
const asset = datas[j];
await media.deleteAsset(asset.uri);
}
const albumId = album.albumId;
const newAlbumList = await media.getAlbums(allTypefetchOp);
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 005_01 failed');
expect(false).assertTrue();
done();
}
}
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 005_01 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('MediaLibraryTest : ALBUM_PROMISE getAlbum 005_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 005 test end -------------------------
});
/*
* Copyright (C) 2022 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 featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
let imageAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
let videoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let imageAndVideoAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString()],
};
let imageAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), audioType.toString()],
};
let videoAndAudioAlbumfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString(), audioType.toString()],
};
function printAlbumMessage(testNum, album) {
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumId: ${album.albumId}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumName: ${album.albumName}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.albumUri: ${album.albumUri}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.dateModified: ${album.dateModified}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.count: ${album.count}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.relativePath: ${album.relativePath}`);
console.info(`ALBUM_CALLBACK getAlbum ${testNum} album.coverUri: ${album.coverUri}`);
}
function checkAlbumAttr(done, album) {
if (
album.albumId == undefined ||
album.albumName == undefined ||
album.albumUri == undefined ||
album.count == undefined ||
album.relativePath == undefined ||
album.coverUri == undefined
) {
console.info('ALBUM_PROMISE getAlbum 001_01 failed');
expect(false).assertTrue();
done();
}
}
describe('album.promise.test.js', async function () {
var context = featureAbility.getContext();
var media = mediaLibrary.getMediaLibrary(context);
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
// ------------------------------ 001 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01
* @tc.name : getAlbums
* @tc.desc : Get Album by AllTypefetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
printAlbumMessage('001_01', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_01 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_02', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_02 success');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_02 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03
* @tc.name : getAlbums
* @tc.desc : Get Album by videoAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_03', 0, async function (done) {
try {
const albumList = await media.getAlbums(videoAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_03', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_03 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_03 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04
* @tc.name : getAlbums
* @tc.desc : Get Album by audioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_04', 0, async function (done) {
try {
const albumList = await media.getAlbums(audioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_04', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_04 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_04 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAndVideoAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_05', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAndVideoAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_05', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_05 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_05 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06
* @tc.name : getAlbums
* @tc.desc : Get Album by imageAndAudioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_06', 0, async function (done) {
try {
const albumList = await media.getAlbums(imageAndAudioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_06', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_06 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_06 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07
* @tc.name : getAlbums
* @tc.desc : Get Album by videoAndAudioAlbumfetchOp, print all album info,
* print all asset info, check asset info (mediaType, albumId, albumUri, albumName),
* check media types (imageType, audioType)
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_001_07', 0, async function (done) {
try {
const albumList = await media.getAlbums(videoAndAudioAlbumfetchOp);
const album = albumList[0];
printAlbumMessage('001_07', album);
checkAlbumAttr(done, album);
console.info('ALBUM_PROMISE getAlbum 001_07 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 001_07 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 001 test end -------------------------
// ------------------------------ 002 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01
* @tc.name : getAlbums
* @tc.desc : Get Album by 666
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_01', 0, async function (done) {
try {
await media.getAlbums(666);
expect(false).assertTrue();
console.info('ALBUM_PROMISE getalbum 002_01 failed');
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_01 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02
* @tc.name : getAlbums
* @tc.desc : Get Album by '666'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_02', 0, async function (done) {
try {
await media.getAlbums('666');
console.info('ALBUM_PROMISE getalbum 002_02 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_02 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03
* @tc.name : getAlbums
* @tc.desc : Get Album by 0
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_03', 0, async function (done) {
try {
await media.getAlbums(0);
console.info('ALBUM_PROMISE getalbum 002_03 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_03 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04
* @tc.name : getAlbums
* @tc.desc : Get Album by true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_04', 0, async function (done) {
try {
await media.getAlbums(true);
console.info('ALBUM_PROMISE getalbum 002_04 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_04 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05
* @tc.name : getAlbums
* @tc.desc : Get Album by false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_002_05', 0, async function (done) {
try {
await media.getAlbums(false);
console.info('ALBUM_PROMISE getalbum 002_05 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getalbum 002_05 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp3
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06', 0, async function (done) {
let fileHasArgsfetchOp3 = {
selections: fileKeyObj.MEDIA_TYPE + ' = ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp3);
console.info(
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_06 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getFileAssets 002_06 passed');
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp4
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07', 0, async function (done) {
let fileHasArgsfetchOp4 = {
selections: '666' + '= ?',
selectionArgs: [videoType.toString()],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp4);
console.info(
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_07 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getFileAssets 002_07 passed');
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08
* @tc.name : album.getFileAssets
* @tc.desc : Get Album Assets by fileHasArgsfetchOp5
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08', 0, async function (done) {
let fileHasArgsfetchOp5 = {
selections: '666' + '= ?',
selectionArgs: ['666'],
};
try {
const albumList = await media.getAlbums(fileHasArgsfetchOp5);
console.info(
'SUB_MEDIA_MEDIALIBRARY_GETALBUMASSETS_PROMISE_002_08 length:' + albumList.length
);
expect(albumList.length == 0).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getFileAssets 002_08 passed');
expect(false).assertTrue();
done();
}
});
// ------------------------------ 002 test end -------------------------
// ------------------------------ 003 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01
* @tc.name : commitModify
* @tc.desc : Modify Album name to 'hello'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_01 album.albumName(old) = ' + album.albumName);
const newName = 'newhello';
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let passed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_01 passed');
expect(true).assertTrue();
done();
passed = true;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_01 failed, message = ' + error);
expect(false).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02
* @tc.name : commitModify
* @tc.desc : Modify Album name ''
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_02 album.albumName(old) = ' + album.albumName);
const newName = '';
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_02 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_02 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04
* @tc.name : commitModify
* @tc.desc : Modify Album name 'i123456...119'
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_04', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_04 album.albumName(old) = ' + album.albumName);
let newName = true;
for (var i = 0; i < 1200; i++) {
newName += 'i';
}
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_04 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_04 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05
* @tc.name : commitModify
* @tc.desc : Modify Album name true
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_05', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_05 album.albumName(old) = ' + album.albumName);
const newName = true;
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_05 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_05 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06
* @tc.name : commitModify
* @tc.desc : Modify Album name false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_003_06', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const albumId = album.albumId;
console.info('ALBUM_PROMISE Modify 003_06 album.albumName(old) = ' + album.albumName);
const newName = false;
album.albumName = newName;
await album.commitModify();
const newAlbumList = await media.getAlbums(allTypefetchOp);
let changed = false;
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId && album.albumName == newName) {
console.info('ALBUM_PROMISE Modify 003_06 failed');
expect(false).assertTrue();
done();
changed = true;
}
}
expect(!changed).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE Modify 003_06 passed');
expect(true).assertTrue();
}
done();
});
// ------------------------------ 003 test end -------------------------
// ------------------------------ 004 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01
* @tc.name : album.coverUri
* @tc.desc : check album.coverUri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_004_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
const asset = await fetchFileResult.getFirstObject();
expect(asset.uri == album.coverUri).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 004_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 004 test end -------------------------
// ------------------------------ 006 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01
* @tc.name : commitModify
* @tc.desc : Modify Album albumUri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
album.albumUri = 'testalbumUri';
await album.commitModify();
console.info('ALBUM_PROMISE Modify 006_01 failed');
expect(false).assertTrue();
} catch (error) {
console.info('ALBUM_PROMISE Modify 006_01 passed');
expect(true).assertTrue();
}
done();
});
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02
* @tc.name : commitModify
* @tc.desc : Modify Album name false
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_MODIFYALBUM_PROMISE_006_02', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
album.coverUri = 'testcoverUri';
await album.commitModify();
console.info('ALBUM_PROMISE Modify 006_02 failed');
expect(false).assertTrue();
} catch (error) {
console.info('ALBUM_PROMISE Modify 006_02 passed');
expect(true).assertTrue();
}
done();
});
// ------------------------------ 006 test end -------------------------
// ------------------------------ 005 test start -------------------------
/**
* @tc.number : SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01
* @tc.name : deleteAsset
* @tc.desc : delete album
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MEDIALIBRARY_GETALBUM_PROMISE_005_01', 0, async function (done) {
try {
const albumList = await media.getAlbums(allTypefetchOp);
const album = albumList[0];
let fetchFileResult = await album.getFileAssets(allTypefetchOp);
let datas = await fetchFileResult.getAllObject();
for (let j = 0; j < datas.length; j++) {
const asset = datas[j];
await media.deleteAsset(asset.uri);
}
const albumId = album.albumId;
const newAlbumList = await media.getAlbums(allTypefetchOp);
for (let i = 0; i < newAlbumList.length; i++) {
const album = newAlbumList[i];
if (album.albumId == albumId) {
console.info('ALBUM_PROMISE getAlbum 005_01 failed');
expect(false).assertTrue();
done();
}
}
console.info('ALBUM_PROMISE getAlbum 005_01 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info('ALBUM_PROMISE getAlbum 005_01 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
// ------------------------------ 005 test end -------------------------
});
......@@ -19,23 +19,23 @@ import featureAbility from '@ohos.ability.featureAbility';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
function printAttr(asset) {
for (const key in asset) {
console.info(`${key}: asset[key]`)
console.info(`${key}: asset[key]`);
}
}
function checkAttrs(done, asset, t_num) {
let passed =true
function checkAttrs(done, asset, tNum) {
let passed = true;
for (const key in asset) {
if(asset[key]== undefined) {
passed = false
break
if (asset[key] == undefined) {
passed = false;
break;
}
}
if (passed) {
console.info(`FileAssetTest : FileAsset checkAttrs ${t_num} passed`);
console.info(`FileAsset checkAttrs ${tNum} passed`);
expect(true).assertTrue();
done();
} else {
console.info(`FileAssetTest : FileAsset checkAttrs ${t_num} failed`);
console.info(`FileAsset checkAttrs ${tNum} failed`);
expect(false).assertTrue();
done();
}
......@@ -101,7 +101,7 @@ describe('fileAsset2.test.js', async function () {
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 001 failed, message = ' + error);
console.info('FileAsset commitModify 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -137,7 +137,7 @@ describe('fileAsset2.test.js', async function () {
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 002 failed, message = ' + error);
console.info('FileAsset commitModify 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -182,7 +182,7 @@ describe('fileAsset2.test.js', async function () {
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 003 failed, message = ' + error);
console.info('FileAsset commitModify 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -221,7 +221,7 @@ describe('fileAsset2.test.js', async function () {
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 004 failed, message = ' + error);
console.info('FileAsset commitModify 004 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -246,11 +246,11 @@ describe('fileAsset2.test.js', async function () {
await asset.commitModify();
console.info('FileAssetTest : FileAsset commitModify 005 failed');
console.info('FileAsset commitModify 005 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 005 passed');
console.info('FileAsset commitModify 005 passed');
expect(true).assertTrue();
done();
}
......@@ -275,11 +275,11 @@ describe('fileAsset2.test.js', async function () {
await asset.commitModify();
console.info('FileAssetTest : FileAsset commitModify 006 failed');
console.info('FileAsset commitModify 006 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 006 passed');
console.info('FileAsset commitModify 006 passed');
expect(true).assertTrue();
done();
}
......@@ -301,7 +301,7 @@ describe('fileAsset2.test.js', async function () {
expect(!isDir).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset isDirectory 001 failed, message = ' + error);
console.info('FileAsset isDirectory 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -321,11 +321,9 @@ describe('fileAsset2.test.js', async function () {
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done,asset, '001')
checkAttrs(done, asset, '001');
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 001 failed, message = ' + error);
console.info('FileAsset checkAttr 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -345,11 +343,9 @@ describe('fileAsset2.test.js', async function () {
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done,asset, '002')
checkAttrs(done, asset, '002');
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 002 failed, message = ' + error);
console.info('FileAsset checkAttr 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -369,11 +365,9 @@ describe('fileAsset2.test.js', async function () {
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done,asset, '003')
checkAttrs(done, asset, '003');
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 003 failed, message = ' + error);
console.info('FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......@@ -394,10 +388,9 @@ describe('fileAsset2.test.js', async function () {
const fetchFileResult = await album.getFileAssets(allTypefetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done,asset, '004')
checkAttrs(done, asset, '004');
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 003 failed, message = ' + error);
console.info('FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
......
......@@ -15,15 +15,7 @@
import mediaLibrary from '@ohos.multimedia.medialibrary';
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
import {
describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it,
expect
} from 'deccjsunit/index';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
let fileKeyObj = mediaLibrary.FileKey;
let fetchOp = {
selections: fileKeyObj.PATH + ' LIKE ? ',
......@@ -61,16 +53,35 @@ let filesfetchOp = {
};
let imageAndAudiofetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ',
selectionArgs: [imageType.toString(), audioType.toString()],
};
let imageAndVideoAndfilefetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selections:
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: [imageType.toString(), videoType.toString(), fileType.toString()],
};
let imageAndVideoAndfileAndAudiofetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString(), videoType.toString(), fileType.toString(), audioType.toString()],
selections:
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: [
imageType.toString(),
videoType.toString(),
fileType.toString(),
audioType.toString(),
],
};
let allTypefetchOp = {
......@@ -95,10 +106,10 @@ describe('GET_ALBUM.test.js', function () {
afterAll(function () {});
var timestamp = new Date().getTime();
var jpgName = timestamp + ".jpg";
var videoName = timestamp + ".mp4";
var audioName = timestamp + ".mp3";
var fileName = timestamp + ".mp3";
var jpgName = timestamp + '.jpg';
var videoName = timestamp + '.mp4';
var audioName = timestamp + '.mp3';
var fileName = timestamp + '.mp3';
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_GETMEDIALIBRAY_001
......@@ -119,299 +130,8 @@ describe('GET_ALBUM.test.js', function () {
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001
* @tc.name : ON
* @tc.desc : ON Image ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_001', 0, async function (done) {
try {
let conut = 0;
media.on(['image'], () => {
conut++;
});
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
expect(conut == 1).assertTrue();
media.off(['image']);
done();
} catch (error) {
console.info(`MediaLibraryTest : on 001 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['image']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002
* @tc.name : ON
* @tc.desc : ON Video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_002', 0, async function (done) {
try {
let conut = 0;
media.on(['video'], () => {
conut++;
});
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
expect(conut == 1).assertTrue();
media.off(['video']);
done();
} catch (error) {
console.info(`MediaLibraryTest : on 002 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['video']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003
* @tc.name : ON
* @tc.desc : ON Audio ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_003', 0, async function (done) {
try {
let conut = 0;
media.on(['audio'], () => {
conut++;
});
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
expect(conut == 1).assertTrue();
media.off(['audio']);
done();
} catch (error) {
console.info(`MediaLibraryTest : on 003 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['audio']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004
* @tc.name : ON
* @tc.desc : ON File ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_004', 0, async function (done) {
try {
let conut = 0;
media.on(['file'], () => {
conut++;
});
const fetchFileResult = await media.getFileAssets(filesfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
expect(conut == 1).assertTrue();
media.off(['file']);
done();
} catch (error) {
console.info(`MediaLibraryTest : on 004 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['file']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005
* @tc.name : ON
* @tc.desc : ON Album ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
// it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_005', 0, async function (done) {
// try {
// let conut = 0;
// media.on(['album'], () => {
// conut++;
// console.info('MediaLibraryTest : on 005 passed');
// expect(true).assertTrue();
// media.off(['album']);
// done();
// });
// const dataList = await media.getAlbums(imagesfetchOp);
// const asset = dataList[0];
// asset.title = 'changename';
// await asset.commitModify();
// await new Promise((res) => setTimeout(() => res(), 3000));
// if (conut == 0) {
// console.info('MediaLibraryTest : on 005 failed');
// expect(false).assertTrue();
// media.off(['album']);
// done();
// }
// } catch (error) {
// console.info(`MediaLibraryTest : on 005 failed, error: ${error}`);
// expect(false).assertTrue();
// media.off(['album']);
// done();
// }
// });
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006
* @tc.name : ON
* @tc.desc : ON File image file ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_006', 0, async function (done) {
try {
let conut = 0;
media.on(['image', 'file'], () => {
conut++;
});
const fileResult = await media.getFileAssets(filesfetchOp);
const fileList = await fileResult.getAllObject();
const file = fileList[0];
file.title = 'changename1';
await file.commitModify();
const imageResult = await media.getFileAssets(imagesfetchOp);
const imageList = await imageResult.getAllObject();
const image = imageList[0];
image.title = 'changename2';
await image.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
expect(conut == 2).assertTrue();
media.off(['image', 'file']);
done();
} catch (error) {
console.info(`MediaLibraryTest : on 006 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['image', 'file']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_007
* @tc.name : ON
* @tc.desc : ON 'image', 'file', 'audio' ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_007', 0, async function (done) {
try {
const arr = ['image', 'file', 'audio'];
let conut = 0;
media.on(arr, () => {
conut++;
});
const fileResult = await media.getFileAssets(filesfetchOp);
const fileList = await fileResult.getAllObject();
const file = fileList[0];
file.title = 'changename1';
await file.commitModify();
const imageResult = await media.getFileAssets(imagesfetchOp);
const imageList = await imageResult.getAllObject();
const image = imageList[0];
image.title = 'changename2';
await image.commitModify();
const audioResult = await media.getFileAssets(audiosfetchOp);
const audioList = await audioResult.getAllObject();
const audio = audioList[0];
audio.title = 'changename';
await audio.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
expect(conut == arr.length).assertTrue();
media.off(arr);
done();
} catch (error) {
console.info(`MediaLibraryTest : on 007 failed, error: ${error}`);
expect(false).assertTrue();
media.off(arr);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_008
* @tc.name : ON
* @tc.desc : ON image, file, audio video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
// it('SUB_MEDIA_MIDIALIBRARY_PROMISE_ON_008', 0, async function (done) {
// try {
// const arr = ['image', 'file', 'audio', 'video'];
// let conut = 0;
// media.on(arr, () => {
// conut++;
// });
// const fileResult = await media.getFileAssets(filesfetchOp);
// const fileList = await fileResult.getAllObject();
// const file = fileList[0];
// file.title = 'changename1';
// await file.commitModify();
// const imageResult = await media.getFileAssets(imagesfetchOp);
// const imageList = await imageResult.getAllObject();
// const image = imageList[0];
// image.title = 'changename2';
// await image.commitModify();
// const audioResult = await media.getFileAssets(audiosfetchOp);
// const audioList = await audioResult.getAllObject();
// const audio = audioList[0];
// audio.title = 'changename';
// await audio.commitModify();
// const videoResult = await media.getFileAssets(videosfetchOp);
// const videoList = await videoResult.getAllObject();
// const video = videoList[0];
// video.title = 'changename';
// await video.commitModify();
// await new Promise((res) => setTimeout(() => res(), 3000));
// expect(conut == arr.length).assertTrue();
// media.off(arr);
// done();
// } catch (error) {
// console.info(`MediaLibraryTest : on 008 failed, error: ${error}`);
// expect(false).assertTrue();
// media.off(arr);
// done();
// }
// });
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_001
* @tc.name : getFileAssets
......@@ -612,7 +332,13 @@ describe('GET_ALBUM.test.js', function () {
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_010', 0, async function (done) {
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selections:
fileKeyObj.MEDIA_TYPE +
'abc= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: ['abc', videoType.toString(), fileType.toString()],
};
try {
......@@ -637,7 +363,15 @@ describe('GET_ALBUM.test.js', function () {
*/
it('SUB__MEDIA_MIDIALIBRARY_PROMISE_GETFILEASSETS_011', 0, async function (done) {
let fetchOp = {
selections: fileKeyObj.MEDIA_TYPE + 'abc= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ? or ' + fileKeyObj.MEDIA_TYPE + '= ?',
selections:
fileKeyObj.MEDIA_TYPE +
'abc= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ? or ' +
fileKeyObj.MEDIA_TYPE +
'= ?',
selectionArgs: ['abc', videoType.toString(), fileType.toString(), audioType.toString()],
};
try {
......@@ -1097,319 +831,4 @@ describe('GET_ALBUM.test.js', function () {
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_001
* @tc.name : off
* @tc.desc : off Image ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_001', 0, async function (done) {
try {
media.on(['image'], () => {
console.info('MediaLibraryTest : off 001 failed');
expect(false).assertTrue();
media.off(['image']);
done();
});
media.off(['image']);
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
console.info('MediaLibraryTest : off 001 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 001 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['image']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_002
* @tc.name : off
* @tc.desc : off video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_002', 0, async function (done) {
try {
media.on(['video'], () => {
console.info('MediaLibraryTest : off 002 failed');
expect(false).assertTrue();
media.off(['video']);
done();
});
media.off(['video']);
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
console.info('MediaLibraryTest : off 002 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 002 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['video']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_003
* @tc.name : off
* @tc.desc : off audio ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_003', 0, async function (done) {
try {
media.on(['audio'], () => {
console.info('MediaLibraryTest : off 003 failed');
expect(false).assertTrue();
media.off(['audio']);
done();
});
media.off(['audio']);
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
console.info('MediaLibraryTest : off 003 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 003 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['audio']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_004
* @tc.name : off
* @tc.desc : off file ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_004', 0, async function (done) {
try {
media.on(['file'], () => {
console.info('MediaLibraryTest : off 004 failed');
expect(false).assertTrue();
media.off(['file']);
done();
});
media.off(['file']);
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const dataList = await fetchFileResult.getAllObject();
const asset = dataList[0];
asset.title = 'changename';
await asset.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
console.info('MediaLibraryTest : off 004 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 004 failed, error: ${error}`);
expect(false).assertTrue();
media.off(['file']);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_005
* @tc.name : off
* @tc.desc : off file audio ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_005', 0, async function (done) {
try {
const arr = ['file', 'audio'];
media.on(arr, () => {
console.info('MediaLibraryTest : off 005 failed');
expect(false).assertTrue();
media.off(arr);
done();
});
media.off(arr);
const fileResult = await media.getFileAssets(filesfetchOp);
const fileList = await fileResult.getAllObject();
const file = fileList[0];
file.title = 'changename1';
await file.commitModify();
const audioResult = await media.getFileAssets(audiosfetchOp);
const audioList = await audioResult.getAllObject();
const audio = audioList[0];
audio.title = 'changename';
await audio.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
console.info('MediaLibraryTest : off 005 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 005 failed, error: ${error}`);
expect(false).assertTrue();
media.off(arr);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_006
* @tc.name : off
* @tc.desc : off file audio image ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_006', 0, async function (done) {
try {
const arr = ['file', 'audio', 'image'];
media.on(arr, () => {
console.info('MediaLibraryTest : off 006 failed');
expect(false).assertTrue();
media.off(arr);
done();
});
media.off(arr);
const fileResult = await media.getFileAssets(filesfetchOp);
const fileList = await fileResult.getAllObject();
const file = fileList[0];
file.title = 'changename1';
await file.commitModify();
const audioResult = await media.getFileAssets(audiosfetchOp);
const audioList = await audioResult.getAllObject();
const audio = audioList[0];
audio.title = 'changename';
await audio.commitModify();
const imageResult = await media.getFileAssets(imagesfetchOp);
const imageList = await imageResult.getAllObject();
const image = imageList[0];
image.title = 'changename2';
await image.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
console.info('MediaLibraryTest : off 006 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 006 failed, error: ${error}`);
expect(false).assertTrue();
media.off(arr);
done();
}
});
/**
* @tc.number : SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_007
* @tc.name : off
* @tc.desc : off file audio image video ASSET
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_MIDIALIBRARY_PROMISE_Off_007', 0, async function (done) {
try {
const arr = ['file', 'audio', 'image', 'video'];
media.on(arr, () => {
console.info('MediaLibraryTest : off 007 failed');
expect(false).assertTrue();
media.off(arr);
done();
});
media.off(arr);
const fileResult = await media.getFileAssets(filesfetchOp);
const fileList = await fileResult.getAllObject();
const file = fileList[0];
file.title = 'changename1';
await file.commitModify();
const imageResult = await media.getFileAssets(imagesfetchOp);
const imageList = await imageResult.getAllObject();
const image = imageList[0];
image.title = 'changename2';
await image.commitModify();
const audioResult = await media.getFileAssets(audiosfetchOp);
const audioList = await audioResult.getAllObject();
const audio = audioList[0];
audio.title = 'changename';
await audio.commitModify();
const videoResult = await media.getFileAssets(videosfetchOp);
const videoList = await videoResult.getAllObject();
const video = videoList[0];
video.title = 'changename';
await video.commitModify();
await new Promise((res) => setTimeout(() => res(), 3000));
console.info('MediaLibraryTest : off 007 passed');
expect(true).assertTrue();
done();
} catch (error) {
console.info(`MediaLibraryTest : off 007 failed, error: ${error}`);
expect(false).assertTrue();
media.off(arr);
done();
}
});
/**
* @tc.number : SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001
* @tc.name : release
* @tc.desc : Release MediaLibrary instance
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
// it('SUB__MEDIA_MIDIALIBRARY_PROMISE_RELEASE_001', 0, async function (done) {
// try {
// await media.release();
// console.info('MediaLibraryTest : release 001 passed');
// expect(true).assertTrue();
// done();
// } catch (error) {
// console.info(`MediaLibraryTest : release 001 failed, error: ${error}`);
// expect(false).assertTrue();
// done();
// }
// });
});
\ No newline at end of file
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册