Home | History | Annotate | Download | only in update_engine
      1 //
      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 
     23 using android::Parcel;
     24 using android::String16;
     25 using android::brillo::ParcelableUpdateEngineStatus;
     26 using android::status_t;
     27 using update_engine::UpdateEngineStatus;
     28 using update_engine::UpdateStatus;
     29 
     30 TEST(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, parcelable_status.last_checked_time_);
     44   EXPECT_EQ(
     45       String16{chromeos_update_engine::UpdateStatusToString(ue_status.status)},
     46       parcelable_status.current_operation_);
     47   EXPECT_EQ(String16{ue_status.current_version.c_str()},
     48             parcelable_status.current_version_);
     49   EXPECT_EQ(String16{ue_status.current_system_version.c_str()},
     50             parcelable_status.current_system_version_);
     51   EXPECT_EQ(ue_status.progress, parcelable_status.progress_);
     52   EXPECT_EQ(static_cast<int64_t>(ue_status.new_size_bytes),
     53             parcelable_status.new_size_);
     54   EXPECT_EQ(String16{ue_status.new_version.c_str()},
     55             parcelable_status.new_version_);
     56   EXPECT_EQ(String16{ue_status.new_system_version.c_str()},
     57             parcelable_status.new_system_version_);
     58 }
     59 
     60 TEST(ParcelableUpdateEngineStatusTest, TestParceling) {
     61   // This tests the writeToParcel and readFromParcel methods for being correctly
     62   // matched.
     63   UpdateEngineStatus ue_status = {123456789,
     64                                   UpdateStatus::DOWNLOADING,
     65                                   "0.1.2.3",
     66                                   "1.2.3.4",
     67                                   0.5f,
     68                                   34567,
     69                                   "2.3.4.5",
     70                                   "3.4.5.6"};
     71   ParcelableUpdateEngineStatus source_status(ue_status);
     72   Parcel parcel_source, parcel_target;
     73   status_t status = source_status.writeToParcel(&parcel_source);
     74   EXPECT_EQ(::android::OK, status);
     75   size_t parcel_len = parcel_source.dataSize();
     76   status = parcel_target.setData(parcel_source.data(), parcel_len);
     77   EXPECT_EQ(::android::OK, status);
     78   ParcelableUpdateEngineStatus target_status;
     79   status = target_status.readFromParcel(&parcel_target);
     80   EXPECT_EQ(::android::OK, status);
     81 
     82   EXPECT_EQ(source_status.last_checked_time_, target_status.last_checked_time_);
     83   EXPECT_EQ(source_status.current_operation_, target_status.current_operation_);
     84   EXPECT_EQ(source_status.current_version_, target_status.current_version_);
     85   EXPECT_EQ(source_status.current_system_version_,
     86             target_status.current_system_version_);
     87   EXPECT_EQ(source_status.progress_, target_status.progress_);
     88   EXPECT_EQ(source_status.new_size_, target_status.new_size_);
     89   EXPECT_EQ(source_status.new_version_, target_status.new_version_);
     90   EXPECT_EQ(source_status.new_system_version_,
     91             target_status.new_system_version_);
     92 }
     93