1 /*
2  * Copyright (c) 2023 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 
16 use crate::common::*;
17 use asset_sdk::*;
18 
19 #[test]
remove_alias_non_exist()20 fn remove_alias_non_exist() {
21     expect_error_eq(ErrCode::NotFound, remove_by_alias("remove_alias_non_exist".as_bytes()).unwrap_err());
22 }
23 
24 #[test]
remove_condition_non_exist()25 fn remove_condition_non_exist() {
26     let delete_condition =
27         AssetMap::from([(Tag::DataLabelCritical1, Value::Bytes("remove_condition_non_exist".as_bytes().to_vec()))]);
28     expect_error_eq(ErrCode::NotFound, asset_sdk::Manager::build().unwrap().remove(&delete_condition).unwrap_err());
29 }
30 
31 #[test]
remove_condition_exist_and_query()32 fn remove_condition_exist_and_query() {
33     let function_name = function!().as_bytes();
34     let critical_label = "remove_condition_exist_and_query".as_bytes();
35     let mut condition = AssetMap::from([
36         (Tag::Alias, Value::Bytes(function_name.to_owned())),
37         (Tag::Secret, Value::Bytes(function_name.to_owned())),
38         (Tag::DataLabelCritical2, Value::Bytes(critical_label.to_owned())),
39     ]);
40     condition.insert_attr(Tag::Accessibility, Accessibility::DevicePowerOn);
41     asset_sdk::Manager::build().unwrap().add(&condition).unwrap();
42     condition.remove(&Tag::Alias);
43     condition.remove(&Tag::Secret);
44     asset_sdk::Manager::build().unwrap().remove(&condition).unwrap();
45     expect_error_eq(ErrCode::NotFound, asset_sdk::Manager::build().unwrap().query(&condition).unwrap_err());
46 }
47