2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
16 * @file ode-tests-common.cpp
17 * @author Pawel Kowalski (p.kowalski2@partner.samsung.com)
18 * @brief Tests for the ODE API
27 #include <dpl/log/log.h>
30 #include <ode/internal-encryption.h>
31 #include "ode-tests-common.h"
33 #define ERRORDESCRIBE(name) case name: return #name
35 const char* ODEErrorToString(int error) {
37 ERRORDESCRIBE(ODE_ERROR_NONE);
38 ERRORDESCRIBE(ODE_ERROR_INVALID_PARAMETER);
39 ERRORDESCRIBE(ODE_ERROR_CONNECTION_REFUSED);
40 ERRORDESCRIBE(ODE_ERROR_PERMISSION_DENIED);
41 ERRORDESCRIBE(ODE_ERROR_NO_SUCH_FILE);
42 ERRORDESCRIBE(ODE_ERROR_NO_SUCH_DEVICE);
43 ERRORDESCRIBE(ODE_ERROR_KEY_REJECTED);
44 ERRORDESCRIBE(ODE_ERROR_NO_DATA);
45 ERRORDESCRIBE(ODE_ERROR_RESOURCE_BUSY);
46 ERRORDESCRIBE(ODE_ERROR_UNKNOWN);
47 default: return "Error not defined";
55 HelperKeys::HelperKeys(const char* device, const char* password, bool initialize) {
61 assert_positive(ode_key_is_initialized, dev, &result);
64 assert_positive(ode_key_init, dev, pass, ODE_KEY_DEFAULT_256BIT);
69 HelperKeys::~HelperKeys() {
70 ode_key_remove_master_key(dev);
71 ode_key_remove(dev, pass);
74 HelperInternalEncryption::HelperInternalEncryption(const char* password) {
78 assert_positive(ode_internal_encryption_is_password_initialized, &result);
81 assert_positive(ode_internal_encryption_init_password, pass);
85 HelperInternalEncryption::~HelperInternalEncryption() {
86 ode_internal_encryption_umount();
87 ode_internal_encryption_clean_password(pass);
90 std::unique_ptr<ServiceManager, std::function<void(ServiceManager*)>> createScopedOdeStopper() {
91 auto sm_start = [](ServiceManager* sm) {
93 sm->startService(true);
96 //TODO: startService should wait until the sm is really started but it does not
97 // because of that the sleep is needed
99 RUNNER_ERROR_MSG("Unexpected exception during service startup");
102 std::unique_ptr<ServiceManager, decltype(sm_start)> sm_stop(
103 new ServiceManager("ode.service", { "ode.socket" }),
104 std::move(sm_start));
106 sm_stop->stopService(true);