mirror of
https://gitee.com/openharmony/security_asset
synced 2025-02-21 08:50:54 +00:00
change test dir
Match-id-cd62da0fafd2e52a69aa60a6c0373479f228bb11
This commit is contained in:
parent
6e2c0651a0
commit
0d27cf5107
2
BUILD.gn
2
BUILD.gn
@ -31,7 +31,7 @@ group("asset_bin_test") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"test/unittest/crypto_manager_test:crypto_manager_test",
|
||||
"test/unittest/db_operator_test:db_operator_test",
|
||||
"services/db_operator:db_operator_test",
|
||||
"test/unittest/inner_api_rust:asset_rust_test",
|
||||
"test/unittest/kits_ndk:asset_ndk_test",
|
||||
]
|
||||
|
@ -11,6 +11,5 @@ members = [
|
||||
"services/db_operator",
|
||||
"services/os_dependency",
|
||||
"test/unittest/inner_api_rust",
|
||||
"test/unittest/db_operator_test",
|
||||
"test/unittest/crypto_manager_test",
|
||||
]
|
||||
|
@ -12,6 +12,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "asset/asset_UT_test"
|
||||
|
||||
ohos_rust_static_library("asset_db_operator") {
|
||||
sources = [
|
||||
@ -35,6 +38,18 @@ ohos_rust_static_library("asset_db_operator") {
|
||||
part_name = "asset"
|
||||
}
|
||||
|
||||
ohos_rust_unittest("db_operator_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "src/lib.rs" ]
|
||||
deps = [
|
||||
":asset_sqlite3_wrapper",
|
||||
"../../frameworks/os_dependency/log:asset_log",
|
||||
"../../frameworks/definition:asset_definition",
|
||||
]
|
||||
subsystem_name = "security"
|
||||
part_name = "asset"
|
||||
}
|
||||
|
||||
ohos_static_library("asset_sqlite3_wrapper") {
|
||||
sources = [ "src/sqlite3_wrapper.c" ]
|
||||
deps = [ "//third_party/sqlite:sqlite" ]
|
||||
|
@ -110,6 +110,9 @@ pub fn default_update_database_func(db: &Database, old_ver: u32, new_ver: u32) -
|
||||
/// format database path
|
||||
#[inline(always)]
|
||||
fn fmt_db_path(user_id: i32) -> String {
|
||||
#[cfg(test)]
|
||||
return format!("/data/asset_test/{}/asset.db", user_id);
|
||||
#[cfg(not(test))]
|
||||
format!("/data/service/el1/public/asset_service/{}/asset.db", user_id)
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,9 @@ pub mod statement;
|
||||
#[path = "table.rs"]
|
||||
#[allow(dead_code)]
|
||||
pub mod table;
|
||||
#[cfg(test)]
|
||||
#[path = "../../../test/unittest/db_operator_test/src/test_for_helper.rs"]
|
||||
mod test_for_helper;
|
||||
#[path = "transaction.rs"]
|
||||
pub mod transaction;
|
||||
#[path = "types.rs"]
|
||||
|
@ -1,28 +0,0 @@
|
||||
# Copyright (C) 2023 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("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "asset/asset_UT_test"
|
||||
|
||||
ohos_rust_unittest("db_operator_test") {
|
||||
module_out_path = module_output_path
|
||||
sources = [ "src/lib.rs" ]
|
||||
deps = [
|
||||
"../../../frameworks/definition:asset_definition",
|
||||
"../../../services/db_operator:asset_db_operator",
|
||||
]
|
||||
subsystem_name = "security"
|
||||
part_name = "asset"
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
# Copyright (C) 2023 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.
|
||||
|
||||
[package]
|
||||
name = "db_operator_test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
asset_definition = { path = "../../../frameworks/definition" }
|
||||
asset_db_operator = { path = "../../../services/db_operator" }
|
@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_for_helper;
|
@ -19,7 +19,7 @@ use std::{
|
||||
io::Write,
|
||||
};
|
||||
|
||||
use asset_db_operator::{
|
||||
use crate::{
|
||||
database::*,
|
||||
database_table_helper::{do_transaction, DatabaseHelper},
|
||||
types::{column, from_data_value_to_str_value, DbMap, QueryOptions},
|
||||
@ -27,7 +27,7 @@ use asset_db_operator::{
|
||||
use asset_definition::Value;
|
||||
|
||||
pub fn test_for_default_asset(user_id: i32) {
|
||||
fs::create_dir_all(format!("/data/service/el1/public/asset_service/{}/", user_id)).unwrap();
|
||||
fs::create_dir_all(format!("/data/asset_test/{}/", user_id)).unwrap();
|
||||
// let _ = Database::drop_default_database(user_id);
|
||||
let mut def = DbMap::from([
|
||||
("Secret", Value::Bytes(b"blob".to_vec())),
|
||||
@ -156,7 +156,7 @@ fn trans_call(db: &Database) -> bool {
|
||||
|
||||
#[test]
|
||||
pub fn test_for_transaction3() {
|
||||
fs::create_dir_all(format!("/data/service/el1/public/asset_service/{}/", 6)).unwrap();
|
||||
fs::create_dir_all(format!("/data/asset_test/{}/", 6)).unwrap();
|
||||
let ret = do_transaction(6, trans_call).unwrap();
|
||||
assert!(ret);
|
||||
let trans = |db: &Database| -> bool {
|
||||
@ -170,7 +170,7 @@ pub fn test_for_transaction3() {
|
||||
|
||||
#[test]
|
||||
pub fn test_for_error() {
|
||||
fs::create_dir_all(format!("/data/service/el1/public/asset_service/{}/", 1)).unwrap();
|
||||
fs::create_dir_all(format!("/data/asset_test/{}/", 1)).unwrap();
|
||||
let stmt = DatabaseHelper::insert_datas(
|
||||
1,
|
||||
&DbMap::from([
|
||||
@ -183,7 +183,7 @@ pub fn test_for_error() {
|
||||
|
||||
#[test]
|
||||
pub fn test_for_master_backup() {
|
||||
fs::create_dir_all(format!("/data/service/el1/public/asset_service/{}/", 5)).unwrap();
|
||||
fs::create_dir_all(format!("/data/asset_test/{}/", 5)).unwrap();
|
||||
let _ = Database::drop_default_database_and_backup(5);
|
||||
let db = DatabaseHelper::open_default_database_table(5).unwrap();
|
||||
let def = DbMap::from([
|
||||
@ -203,17 +203,12 @@ pub fn test_for_master_backup() {
|
||||
|
||||
db.insert_datas(&def).unwrap();
|
||||
drop(db);
|
||||
let mut db_file =
|
||||
OpenOptions::new().read(true).write(true).open("/data/service/el1/public/asset_service/5/asset.db").unwrap(); // write master db
|
||||
let mut db_file = OpenOptions::new().read(true).write(true).open("/data/asset_test/5/asset.db").unwrap(); // write master db
|
||||
let _ = db_file.write(b"buffer buffer buffer").unwrap();
|
||||
let db = DatabaseHelper::open_default_database_table(5).unwrap(); // will recovery master db
|
||||
db.insert_datas(&def).unwrap();
|
||||
drop(db);
|
||||
let mut back_file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open("/data/service/el1/public/asset_service/5/asset.db.backup")
|
||||
.unwrap(); // write backup db
|
||||
let mut back_file = OpenOptions::new().read(true).write(true).open("/data/asset_test/5/asset.db.backup").unwrap(); // write backup db
|
||||
let _ = back_file.write(b"bad message info").unwrap();
|
||||
let db = DatabaseHelper::open_default_database_table(5).unwrap(); // will recovery backup db
|
||||
db.insert_datas(&def).unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user