• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2024 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 #![cfg(feature = "oh")]
14 use std::fs::File;
15 use std::time::Duration;
16 
17 use download_server::config::{Action, ConfigBuilder, Mode};
18 use test_common::test_init;
19 const FILE_SIZE: u64 = 1042003;
20 
21 #[test]
sdv_start_basic()22 fn sdv_start_basic() {
23     let file_path = "sdv_network_resume.txt";
24 
25     let agent = test_init();
26     let file = File::create(file_path).unwrap();
27     let config = ConfigBuilder::new()
28         .action(Action::Download)
29         .mode(Mode::BackGround)
30         .file_spec(file)
31         .url("https://www.gitee.com/tiga-ultraman/downloadTests/releases/download/v1.01/test.txt")
32         .redirect(true)
33         .build();
34     let task_id = agent.construct(config);
35     agent.start(task_id);
36     agent.subscribe(task_id);
37     ylong_runtime::block_on(async {
38         'main: loop {
39             let messages = agent.pop_task_info(task_id);
40             for message in messages {
41                 message.check_correct();
42                 if message.is_finished() {
43                     break 'main;
44                 }
45             }
46             ylong_runtime::time::sleep(Duration::from_secs(1)).await;
47         }
48         let file = File::open(file_path).unwrap();
49         assert_eq!(FILE_SIZE, file.metadata().unwrap().len());
50     });
51 }
52