• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the 'License');
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an 'AS IS' BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
17import request from '@ohos.request';
18import * as pubfun from './Publicfunction.js'
19import file from '@system.file';
20
21var typeProgress = 'progress';
22var typeHeaderReceive = 'headerReceive';
23var typeFail = 'fail';
24let uploadTask;
25let file7url = 'internal://cache/test.txt';
26
27describe('UploadTest', function () {
28    beforeAll(function () {
29        console.info('beforeAll: Prerequisites at the test suite level, ' +
30        'which are executed before the test suite is executed.');
31
32      file.writeText({
33        uri: 'internal://cache/test.txt',
34        text: '1234567',
35        success: function() {
36          console.log('[Upload] <<UI>> call test.jpg writeText success.');
37        },
38        fail: function(data, code) {
39          console.error('Upload => call fail test.jpg fail, code: ' + code + ', data: ' + data);
40        },
41      });
42    })
43    beforeEach(function () {
44        console.info('beforeEach: Prerequisites at the test case level,' +
45        ' which are executed before each test case is executed.');
46    })
47    afterEach(function () {
48        console.info('afterEach: Test case-level clearance conditions, ' +
49        'which are executed after each test case is executed.');
50    })
51    afterAll(function () {
52        console.info('afterAll: Test suite-level cleanup condition, ' +
53        'which is executed after the test suite is executed');
54    })
55
56    /*
57        * @tc.number    : InitUploadtaskCallback001
58        * @tc.name      : Use getEntries get the value by mixing the string key
59        * @tc.desc      : Mixed strings value can be obtained correctly
60        * @tc.size      : MediumTest
61        * @tc.type      : Function
62        * @tc.level     : Level 1
63    */
64    it('InitUploadtaskCallback001', 0, async function (done) {
65        try {
66            console.log("Testupdate before getuploadconfig");
67            let UploadConfig = pubfun.getUploadConfig(file7url)
68            console.log("Testupdate before upload UploadConfig = " + JSON.stringify(UploadConfig));
69            console.log("Testupdate before upload");
70            await pubfun.publicupload(UploadConfig).then((data) => {
71                console.log("Testupdate going upload uploadTask = " + data);
72                uploadTask = data;
73                expect(true).assertEqual((data != undefined) || (data != "") || (data != {}));
74                done();
75            }).catch((err) => {
76                console.log("InitUploadtaskCallback001 fail 1" + JSON.stringify(err));
77                expect(err).assertFail();
78                done();
79            })
80        } catch (e) {
81            console.log("InitUploadtaskCallback001 fail 2" + JSON.stringify(e));
82            expect(e).assertFail();
83            done();
84        }
85    })
86
87    /*
88        * @tc.number    : SwitchOnProgressCallback001
89        * @tc.name      : Use getEntries get the value by mixing the string key
90        * @tc.desc      : Mixed strings value can be obtained correctly
91        * @tc.size      : MediumTest
92        * @tc.type      : Function
93        * @tc.level     : Level 1
94    */
95    it('SwitchOnProgressCallback001', 0, async function (done) {
96        try {
97            pubfun.publiconprogress(uploadTask, typeProgress);
98            expect(true).assertEqual(0 == 0);
99            done();
100        } catch (err) {
101            console.log("Testupdate SwitchOnProgressCallback001 catch err " + JSON.stringify(err));
102            expect(err).assertFail();
103            done();
104        }
105    });
106
107    /*
108        * @tc.number    : SwitchOffProgressCallback001
109        * @tc.name      : Use getEntries get the value by mixing the string key
110        * @tc.desc      : Mixed strings value can be obtained correctly
111        * @tc.size      : MediumTest
112        * @tc.type      : Function
113        * @tc.level     : Level 1
114    */
115    it('SwitchOffProgressCallback001', 0, async function (done) {
116        try {
117            pubfun.publiconprogress(uploadTask, typeProgress);
118            expect(true).assertEqual(0 == 0);
119
120            await pubfun.publicoffprogress(uploadTask, typeProgress).then((data) => {
121                console.log("SwitchOffProgressCallback001 data" + JSON.stringify(data));
122                expect(7).assertEqual(data.totalSize);
123                done();
124            }).catch((err) => {
125                console.log("SwitchOffProgressCallback001 fail 2" + JSON.stringify(err));
126                expect(err).assertFail();
127                done();
128            })
129        } catch (e) {
130            console.log("SwitchOffProgressCallback001 fail 3" + JSON.stringify(e));
131            expect(e).assertFail();
132            done();
133        }
134    })
135
136    /*
137        * @tc.number    : SwitchOnFailCallback001
138        * @tc.name      : Use getEntries get the value by mixing the string key
139        * @tc.desc      : Mixed strings value can be obtained correctly
140        * @tc.size      : MediumTest
141        * @tc.type      : Function
142        * @tc.level     : Level 1
143    */
144    it('SwitchOnFailCallback001', 0, async function (done) {
145        try {
146            await pubfun.publicon(uploadTask, typeFail).then((data) => {
147                console.log("SwitchOnFailCallback001 data " + data);
148                expect(true).assertEqual(data != 0);
149                done();
150            }).catch((err) => {
151                console.log("SwitchOnFailCallback001 fail 2" + JSON.stringify(err));
152                expect(err).assertFail();
153                done();
154            })
155        } catch (e) {
156            console.log("SwitchOnFailCallback001 fail 3" + JSON.stringify(e));
157            expect(e).assertFail();
158            done();
159        }
160    })
161
162    /*
163        * @tc.number    : SwitchOffFailCallback001
164        * @tc.name      : Use getEntries get the value by mixing the string key
165        * @tc.desc      : Mixed strings value can be obtained correctly
166        * @tc.size      : MediumTest
167        * @tc.type      : Function
168        * @tc.level     : Level 1
169    */
170    it('SwitchOffFailCallback001', 0, async function (done) {
171        try {
172            await pubfun.publicon(uploadTask, typeFail)
173            await pubfun.publicoff(uploadTask, typeFail).then((data) => {
174                console.log("SwitchOffFailCallback001 data " + data);
175                expect(true).assertEqual(data != 0);
176                done();
177            }).catch((err) => {
178                console.log("SwitchOffFailCallback001 fail 2" + JSON.stringify(err));
179                done();
180                expect(err).assertFail();
181            })
182        } catch (e) {
183            console.log("SwitchOffFailCallback001 fail 3" + JSON.stringify(e));
184            expect(e).assertFail();
185            done();
186        }
187    })
188
189    /*
190        * @tc.number    : RemoveCallback001
191        * @tc.name      : Use getEntries get the value by mixing the string key
192        * @tc.desc      : Mixed strings value can be obtained correctly
193        * @tc.size      : MediumTest
194        * @tc.type      : Function
195        * @tc.level     : Level 1
196    */
197    it('RemoveCallback001', 0, async function (done) {
198        try {
199            await pubfun.publicremove(uploadTask).then((data) => {
200                console.log("RemoveCallback001 data " + data);
201                expect(true).assertEqual(data);
202                done();
203            }).catch((err) => {
204                console.log("RemoveCallback001 fail 2" + JSON.stringify(err));
205                expect(err).assertFail();
206                done();
207            })
208        } catch (e) {
209            console.log("RemoveCallback001 fail 3" + JSON.stringify(e));
210            expect(e).assertFail();
211            done();
212        }
213    })
214})