提交 81ce3fe8 编写于 作者: P panqiangbiao

add more xts

Signed-off-by: Npanqiangbiao <panqiangbiao@huawei.com>
上级 3be47e9c
......@@ -2,9 +2,9 @@
"description": "Configuration for mediaLibrary Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "120000",
"test-timeout": "600000",
"package": "ohos.acts.multimedia.mediaLibrary",
"shell-timeout": "120000"
"shell-timeout": "600000"
},
"kits": [
{
......
......@@ -15,3 +15,11 @@
require('./favoriteTestCallBack.test.js')
require('./favoriteTestPromise.test.js')
require('./fileTestPromise.test.js')
require('./fileTestPromise.test.js')
require('./favoriteTestPromise.test.js')
require('./fileAsset2.test.js')
require('./fileAssetTestPromise.test.js')
require('./mediaLibraryTestPromise.test.js')
require('./albumGetFileAssetsPromise.test.js')
require('./albumTestPromise.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) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mediaLibrary from '@ohos.multimedia.medialibrary';
import 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]`)
}
}
function checkAttrs(done, asset, t_num) {
let passed =true
for (const key in asset) {
if(asset[key]== undefined) {
passed = false
break
}
}
if (passed) {
console.info(`FileAssetTest : FileAsset checkAttrs ${t_num} passed`);
expect(true).assertTrue();
done();
} else {
console.info(`FileAssetTest : FileAsset checkAttrs ${t_num} failed`);
expect(false).assertTrue();
done();
}
}
describe('fileAsset2.test.js', async function () {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let videoType = mediaLibrary.MediaType.VIDEO;
let audioType = mediaLibrary.MediaType.AUDIO;
let imagesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
let videosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [videoType.toString()],
};
let audiosfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [audioType.toString()],
};
let allTypefetchOp = {
selections: '',
selectionArgs: [],
};
const context = featureAbility.getContext();
const media = mediaLibrary.getMediaLibrary(context);
beforeAll(function () {});
beforeEach(function () {});
afterEach(function () {});
afterAll(function () {});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_001
* @tc.name : commitModify
* @tc.desc : Modify displayName
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const newName = 'newName';
asset.displayName = newName;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.displayName == newName) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_002
* @tc.name : commitModify
* @tc.desc : Modify title
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const newTitle = 'newTitle';
asset.title = newTitle;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.title == newTitle) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_003
* @tc.name : commitModify
* @tc.desc : Modify relativePath
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_003', 0, async function (done) {
try {
const path1 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_IMAGE);
const path2 = await media.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
let relativePath = asset.relativePath;
let newrelativePath = path1;
if (relativePath == path1) {
newrelativePath = path2;
}
asset.relativePath = newrelativePath;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.relativePath == newrelativePath) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_004
* @tc.name : commitModify
* @tc.desc : Modify orientation
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_004', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
let neworientation = 1;
if (asset.orientation == 1) {
neworientation = 0;
}
asset.orientation = neworientation;
const id = asset.id;
await asset.commitModify();
const fetchFileResult2 = await media.getFileAssets(imagesfetchOp);
const dataList = await fetchFileResult2.getAllObject();
let passed = false;
for (let i = 0; i < dataList.length; i++) {
const asset = dataList[i];
if (asset.id == id && asset.orientation == neworientation) {
passed = true;
break;
}
}
expect(passed).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 004 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_005
* @tc.name : commitModify
* @tc.desc : Modify uri
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_005', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const id = asset.id;
const newUri = 'newUri';
asset.uri = newUri;
await asset.commitModify();
console.info('FileAssetTest : FileAsset commitModify 005 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 005 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_commitModify_promise_006
* @tc.name : commitModify
* @tc.desc : Modify mediaType
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_commitModify_promise_006', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const id = asset.id;
const newMediaType = 'newMediaType';
asset.mediaType = newMediaType;
await asset.commitModify();
console.info('FileAssetTest : FileAsset commitModify 006 failed');
expect(false).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset commitModify 006 passed');
expect(true).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_isDirectory_promise_001
* @tc.name : isDirectory
* @tc.desc : isDirectory asset
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_isDirectory_promise_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
const isDir = await asset.isDirectory();
expect(!isDir).assertTrue();
done();
} catch (error) {
console.info('FileAssetTest : FileAsset isDirectory 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_001
* @tc.name : attrs
* @tc.desc : imagesfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_001', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(imagesfetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done,asset, '001')
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 001 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_002
* @tc.name : attrs
* @tc.desc : videosfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_002', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(videosfetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done,asset, '002')
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 002 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_003
* @tc.name : attrs
* @tc.desc : audiosfetchOp attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_003', 0, async function (done) {
try {
const fetchFileResult = await media.getFileAssets(audiosfetchOp);
const asset = await fetchFileResult.getFirstObject();
printAttr(asset);
checkAttrs(done,asset, '003')
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
/**
* @tc.number : SUB_MEDIA_FILEASSET_checkAttr_promise_004
* @tc.name : attrs
* @tc.desc : album attrs print and check
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_MEDIA_FILEASSET_checkAttr_promise_004', 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();
printAttr(asset);
checkAttrs(done,asset, '004')
} catch (error) {
console.info('FileAssetTest : FileAsset checkAttr 003 failed, message = ' + error);
expect(false).assertTrue();
done();
}
});
});
......@@ -41,17 +41,18 @@ let filesfetchOp = {
selectionArgs: [fileType.toString()],
};
function checkAssetAttr(done, attr, testNum, asset, checkType) {
function checkAssetAttr(done, attr, test_num, asset, checkType) {
if (checkType && asset[attr] != checkType) {
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`);
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${test_num} failed`);
expect(false).assertTrue();
done();
} else if (asset[attr] == undefined) {
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${testNum} failed`);
console.info(`MediaLibraryTest : ASSET_PROMISE getFileAssets ${test_num} failed`);
expect(false).assertTrue();
done();
}
}
describe('file.promise.test.js', function () {
var context = featureAbility.getContext();
console.info('MediaLibraryTest : getMediaLibrary IN');
......@@ -84,7 +85,7 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(imageType, 'image01.jpg', path);
const creatAsset1 = await media.createAsset(imageType, 'image03.jpg', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
......@@ -92,7 +93,7 @@ describe('file.promise.test.js', function () {
await asset1.close(fd1);
const asset2 = dataList[1];
const creatAsset2 = await media.createAsset(imageType, 'image02.jpg', path);
const creatAsset2 = await media.createAsset(imageType, 'image04.jpg', path);
const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2);
......@@ -248,15 +249,16 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(imagesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 passed');
expect(true).assertTrue();
done();
......@@ -266,9 +268,15 @@ describe('file.promise.test.js', function () {
done();
}
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed');
expect(false).assertTrue();
done();
if (newAsset.dateModified != undefined) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed');
expect(false).assertTrue();
done();
}
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 001_07 failed, message = ' + error);
......@@ -447,7 +455,7 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(videoType, 'video01.mp4', path);
const creatAsset1 = await media.createAsset(videoType, 'video03.mp4', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
......@@ -455,7 +463,7 @@ describe('file.promise.test.js', function () {
await asset1.close(fd1);
const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(videoType, 'video02.mp4', path);
const creatAsset2 = await media.createAsset(videoType, 'video04.mp4', path);
const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2);
......@@ -610,15 +618,16 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(videosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 passed');
expect(true).assertTrue();
done();
......@@ -628,9 +637,15 @@ describe('file.promise.test.js', function () {
done();
}
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed');
expect(false).assertTrue();
done();
if (newAsset.dateModified != undefined) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed');
expect(false).assertTrue();
done();
}
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 002_07 failed, message = ' + error);
......@@ -839,7 +854,7 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(audioType, 'audio01.mp3', path);
const creatAsset1 = await media.createAsset(audioType, 'audio03.mp3', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
......@@ -847,7 +862,7 @@ describe('file.promise.test.js', function () {
await asset1.close(fd1);
const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(audioType, 'audio02.mp3', path);
const creatAsset2 = await media.createAsset(audioType, 'audio04.mp3', path);
const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2);
......@@ -1003,15 +1018,17 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(audiosfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 passed');
expect(true).assertTrue();
done();
......@@ -1021,9 +1038,15 @@ describe('file.promise.test.js', function () {
done();
}
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed');
expect(false).assertTrue();
done();
if (newAsset.dateModified != undefined) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed');
expect(false).assertTrue();
done();
}
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 003_07 failed, message = ' + error);
......@@ -1202,7 +1225,7 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset1 = dataList[0];
const creatAsset1 = await media.createAsset(fileType, 'file01.txt', path);
const creatAsset1 = await media.createAsset(fileType, 'file03.txt', path);
const fd1 = await asset1.open('rw');
const creatAssetFd1 = await creatAsset1.open('rw');
await copyFile(fd1, creatAssetFd1);
......@@ -1210,7 +1233,7 @@ describe('file.promise.test.js', function () {
await asset1.close(fd1);
const asset2 = dataList[0];
const creatAsset2 = await media.createAsset(fileType, 'file02.txt', path);
const creatAsset2 = await media.createAsset(fileType, 'file04.txt', path);
const fd2 = await asset2.open('rw');
const creatAssetFd2 = await creatAsset2.open('rw');
await copyFile(fd2, creatAssetFd2);
......@@ -1366,15 +1389,16 @@ describe('file.promise.test.js', function () {
const fileAssets = await media.getFileAssets(filesfetchOp);
const dataList = await fileAssets.getAllObject();
const asset = dataList[0];
asset.displayName = 'hhhhhh';
asset.commitModify();
asset.title = `title_${new Date().getTime()}`;
await asset.commitModify();
const id = asset.id;
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ["" + id] };
const idOP = { selections: fileKeyObj.ID + '= ?', selectionArgs: ['' + id] };
const newAssets = await media.getFileAssets(idOP);
const newdataList = await newAssets.getAllObject();
const newAsset = newdataList[0];
if(newAsset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified ) {
if (asset.dateModified != undefined) {
if (newAsset.dateModified != asset.dateModified) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 passed');
expect(true).assertTrue();
done();
......@@ -1384,9 +1408,15 @@ describe('file.promise.test.js', function () {
done();
}
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed');
expect(false).assertTrue();
done();
if (newAsset.dateModified != undefined) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 passed');
expect(true).assertTrue();
done();
} else {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed');
expect(false).assertTrue();
done();
}
}
} catch (error) {
console.info('MediaLibraryTest : ASSET_PROMISE getFileAssets 004_07 failed, message = ' + error);
......@@ -1461,4 +1491,3 @@ describe('file.promise.test.js', function () {
});
// ------------------------------- file type end -----------------------------
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册