blob: 3e6f7eb37dffa0f108e94d4c17c953cda4334d76 [file] [log] [blame]
Aaron Wood7f92e2b2017-08-28 14:51:21 -07001//
2// Copyright (C) 2017 The Android Open Source Project
3//
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
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
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.
15//
16
17#include "update_engine/parcelable_update_engine_status.h"
18#include "update_engine/update_status_utils.h"
19
20#include <binder/Parcel.h>
21#include <gtest/gtest.h>
22
23using android::Parcel;
24using android::String16;
25using android::brillo::ParcelableUpdateEngineStatus;
26using android::status_t;
27using update_engine::UpdateEngineStatus;
28using update_engine::UpdateStatus;
29
30TEST(ParcelableUpdateEngineStatusTest, TestCreationFromUpdateEngineStatus) {
31 // This test creates an object and verifies that all the UpdateEngineStatus
32 // values are properly reflected in the Parcelable version of the class.
33
34 UpdateEngineStatus ue_status = {123456789,
35 UpdateStatus::DOWNLOADING,
36 "0.1.2.3",
37 "1.2.3.4",
38 0.5f,
39 34567,
40 "2.3.4.5",
41 "3.4.5.6"};
42 ParcelableUpdateEngineStatus parcelable_status(ue_status);
43 EXPECT_EQ(ue_status.last_checked_time_ms,
44 parcelable_status.last_checked_time_);
45 EXPECT_EQ(
46 String16{chromeos_update_engine::UpdateStatusToString(ue_status.status)},
47 parcelable_status.current_operation_);
48 EXPECT_EQ(String16{ue_status.current_version.c_str()},
49 parcelable_status.current_version_);
50 EXPECT_EQ(String16{ue_status.current_system_version.c_str()},
51 parcelable_status.current_system_version_);
52 EXPECT_EQ(ue_status.progress, parcelable_status.progress_);
53 EXPECT_EQ(static_cast<int64_t>(ue_status.new_size_bytes),
54 parcelable_status.new_size_);
55 EXPECT_EQ(String16{ue_status.new_version.c_str()},
56 parcelable_status.new_version_);
57 EXPECT_EQ(String16{ue_status.new_system_version.c_str()},
58 parcelable_status.new_system_version_);
59}
60
61TEST(ParcelableUpdateEngineStatusTest, TestParceling) {
62 // This tests the writeToParcel and readFromParcel methods for being correctly
63 // matched.
64 UpdateEngineStatus ue_status = {123456789,
65 UpdateStatus::DOWNLOADING,
66 "0.1.2.3",
67 "1.2.3.4",
68 0.5f,
69 34567,
70 "2.3.4.5",
71 "3.4.5.6"};
72 ParcelableUpdateEngineStatus source_status(ue_status);
73 Parcel parcel_source, parcel_target;
74 status_t status = source_status.writeToParcel(&parcel_source);
75 EXPECT_EQ(::android::OK, status);
76 size_t parcel_len = parcel_source.dataSize();
77 status = parcel_target.setData(parcel_source.data(), parcel_len);
78 EXPECT_EQ(::android::OK, status);
79 ParcelableUpdateEngineStatus target_status;
80 status = target_status.readFromParcel(&parcel_target);
81 EXPECT_EQ(::android::OK, status);
82
83 EXPECT_EQ(source_status.last_checked_time_, target_status.last_checked_time_);
84 EXPECT_EQ(source_status.current_operation_, target_status.current_operation_);
85 EXPECT_EQ(source_status.current_version_, target_status.current_version_);
86 EXPECT_EQ(source_status.current_system_version_,
87 target_status.current_system_version_);
88 EXPECT_EQ(source_status.progress_, target_status.progress_);
89 EXPECT_EQ(source_status.new_size_, target_status.new_size_);
90 EXPECT_EQ(source_status.new_version_, target_status.new_version_);
91 EXPECT_EQ(source_status.new_system_version_,
92 target_status.new_system_version_);
93}