parcelable_update_engine_status_unittest.cc 4.0 KB

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